core: add min width to dialog

This commit is contained in:
2026-11-11 20:08:45 +07:00
parent faa81af9eb
commit 97106b7a3a
+17 -4
View File
@@ -2,9 +2,10 @@ use gpui::prelude::FluentBuilder as _;
use std::rc::Rc;
use gpui::{
Animation, AnimationExt as _, AnyElement, App, ElementId, FontWeight, InteractiveElement as _,
IntoElement, KeyDownEvent, MouseButton, ParentElement as _, RenderOnce, Role, SharedString,
StatefulInteractiveElement as _, Styled as _, Window, canvas, div, ease_out_quint, relative,
Animation, AnimationExt as _, AnyElement, App, DefiniteLength, ElementId, FontWeight,
InteractiveElement as _, IntoElement, KeyDownEvent, MouseButton, ParentElement as _,
RenderOnce, Role, SharedString, StatefulInteractiveElement as _, Styled as _, Window, canvas,
div, ease_out_quint, relative,
};
use gpui_native_icons::IconRole;
use gpui_native_theme::ActiveTheme as _;
@@ -29,6 +30,7 @@ pub struct Dialog {
on_change: Option<ChangeHandler>,
content: Option<ContentFn>,
actions: Option<ActionsFn>,
min_width: Option<DefiniteLength>,
}
impl Dialog {
@@ -46,6 +48,7 @@ impl Dialog {
on_change: None,
content: None,
actions: None,
min_width: None,
}
}
@@ -105,6 +108,15 @@ impl Dialog {
self.a11y_label = Some(label.into());
self
}
/// Sets the panel's minimum width, defaults to the standard dialog width.
pub fn min_width<W>(mut self, width: W) -> Self
where
W: Into<DefiniteLength>,
{
self.min_width = Some(width.into());
self
}
}
impl RenderOnce for Dialog {
@@ -171,7 +183,8 @@ impl RenderOnce for Dialog {
.track_focus(&focus)
.role(role)
.aria_label(label)
.min_w_64()
.when_some(self.min_width, |panel, width| panel.min_w(width))
.when(self.min_width.is_none(), |panel| panel.min_w_80())
.max_w(relative(0.9))
.p_4()
.gap_3()