feat: add fixed width support to dialog
This commit is contained in:
@@ -33,8 +33,9 @@ use gpui::{
|
||||
};
|
||||
|
||||
use crate::components::button::{Button, ButtonVariant};
|
||||
use crate::components::common::h_flex;
|
||||
use crate::components::common::{DIALOG_LAYER, Sizable, StyledExt as _, floating_panel, v_flex};
|
||||
use crate::components::common::{
|
||||
DIALOG_LAYER, Sizable, StyledExt as _, floating_panel, h_flex, v_flex,
|
||||
};
|
||||
use crate::components::grain::grain;
|
||||
use crate::components::scroll_area::ScrollArea;
|
||||
use crate::icons::IconRole;
|
||||
@@ -98,6 +99,7 @@ pub struct Dialog {
|
||||
content: Option<ContentFn>,
|
||||
actions: Option<ActionsFn>,
|
||||
min_width: Option<DefiniteLength>,
|
||||
width: Option<DefiniteLength>,
|
||||
height: Option<DefiniteLength>,
|
||||
style: StyleRefinement,
|
||||
}
|
||||
@@ -122,6 +124,7 @@ impl Dialog {
|
||||
content: None,
|
||||
actions: None,
|
||||
min_width: None,
|
||||
width: None,
|
||||
height: None,
|
||||
style: StyleRefinement::default(),
|
||||
}
|
||||
@@ -217,6 +220,15 @@ impl Dialog {
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the panel's fixed width, capped at 90% of the window.
|
||||
pub fn width<W>(mut self, width: W) -> Self
|
||||
where
|
||||
W: Into<DefiniteLength>,
|
||||
{
|
||||
self.width = Some(width.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the panel's height, body content taller than the panel scrolls.
|
||||
pub fn height<H>(mut self, height: H) -> Self
|
||||
where
|
||||
@@ -255,11 +267,12 @@ impl RenderOnce for Dialog {
|
||||
})
|
||||
});
|
||||
|
||||
let (scrim_color, foreground, radius, shadows, enter_duration) = {
|
||||
let (scrim_color, foreground, background, radius, shadows, enter_duration) = {
|
||||
let theme = cx.theme();
|
||||
(
|
||||
theme.colors.overlay,
|
||||
theme.colors.foreground,
|
||||
theme.colors.background,
|
||||
theme.radius.overlay,
|
||||
theme.elevations.dialog.shadows(),
|
||||
theme.motion.overlay,
|
||||
@@ -303,15 +316,19 @@ impl RenderOnce for Dialog {
|
||||
.track_focus(&focus)
|
||||
.role(role)
|
||||
.aria_label(label)
|
||||
.when_some(self.min_width, |panel, width| panel.min_w(width))
|
||||
.when(self.min_width.is_none(), |panel| {
|
||||
.when_some(self.width, |panel, width| panel.w(width))
|
||||
.when(self.width.is_none() && self.min_width.is_none(), |panel| {
|
||||
panel.min_w(DIALOG_MIN_WIDTH)
|
||||
})
|
||||
.when_some(self.min_width, |panel, width| panel.min_w(width))
|
||||
.max_w(relative(0.9))
|
||||
.when_some(height, |panel, height| panel.h(height))
|
||||
.text_color(foreground),
|
||||
shadows,
|
||||
)
|
||||
// The panel behind the dialog is `background` (pure white/black), so
|
||||
// the dialog matches it instead of the muted `surface` tint.
|
||||
.bg(background)
|
||||
.overflow_hidden()
|
||||
.on_mouse_down(MouseButton::Left, |_, _, cx| cx.stop_propagation())
|
||||
.on_key_down({
|
||||
|
||||
Reference in New Issue
Block a user