chore: improve ui consistently #35
@@ -60,6 +60,7 @@ impl Render for SettingsDialog {
|
|||||||
|
|
||||||
Dialog::new("settings-dialog")
|
Dialog::new("settings-dialog")
|
||||||
.handle(self.handle.clone())
|
.handle(self.handle.clone())
|
||||||
|
.width(px(600.))
|
||||||
.height(px(560.))
|
.height(px(560.))
|
||||||
.title("Settings")
|
.title("Settings")
|
||||||
.content(move |_, cx| {
|
.content(move |_, cx| {
|
||||||
|
|||||||
@@ -33,8 +33,9 @@ use gpui::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crate::components::button::{Button, ButtonVariant};
|
use crate::components::button::{Button, ButtonVariant};
|
||||||
use crate::components::common::h_flex;
|
use crate::components::common::{
|
||||||
use crate::components::common::{DIALOG_LAYER, Sizable, StyledExt as _, floating_panel, v_flex};
|
DIALOG_LAYER, Sizable, StyledExt as _, floating_panel, h_flex, v_flex,
|
||||||
|
};
|
||||||
use crate::components::grain::grain;
|
use crate::components::grain::grain;
|
||||||
use crate::components::scroll_area::ScrollArea;
|
use crate::components::scroll_area::ScrollArea;
|
||||||
use crate::icons::IconRole;
|
use crate::icons::IconRole;
|
||||||
@@ -98,6 +99,7 @@ pub struct Dialog {
|
|||||||
content: Option<ContentFn>,
|
content: Option<ContentFn>,
|
||||||
actions: Option<ActionsFn>,
|
actions: Option<ActionsFn>,
|
||||||
min_width: Option<DefiniteLength>,
|
min_width: Option<DefiniteLength>,
|
||||||
|
width: Option<DefiniteLength>,
|
||||||
height: Option<DefiniteLength>,
|
height: Option<DefiniteLength>,
|
||||||
style: StyleRefinement,
|
style: StyleRefinement,
|
||||||
}
|
}
|
||||||
@@ -122,6 +124,7 @@ impl Dialog {
|
|||||||
content: None,
|
content: None,
|
||||||
actions: None,
|
actions: None,
|
||||||
min_width: None,
|
min_width: None,
|
||||||
|
width: None,
|
||||||
height: None,
|
height: None,
|
||||||
style: StyleRefinement::default(),
|
style: StyleRefinement::default(),
|
||||||
}
|
}
|
||||||
@@ -217,6 +220,15 @@ impl Dialog {
|
|||||||
self
|
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.
|
/// Sets the panel's height, body content taller than the panel scrolls.
|
||||||
pub fn height<H>(mut self, height: H) -> Self
|
pub fn height<H>(mut self, height: H) -> Self
|
||||||
where
|
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();
|
let theme = cx.theme();
|
||||||
(
|
(
|
||||||
theme.colors.overlay,
|
theme.colors.overlay,
|
||||||
theme.colors.foreground,
|
theme.colors.foreground,
|
||||||
|
theme.colors.background,
|
||||||
theme.radius.overlay,
|
theme.radius.overlay,
|
||||||
theme.elevations.dialog.shadows(),
|
theme.elevations.dialog.shadows(),
|
||||||
theme.motion.overlay,
|
theme.motion.overlay,
|
||||||
@@ -303,15 +316,19 @@ impl RenderOnce for Dialog {
|
|||||||
.track_focus(&focus)
|
.track_focus(&focus)
|
||||||
.role(role)
|
.role(role)
|
||||||
.aria_label(label)
|
.aria_label(label)
|
||||||
.when_some(self.min_width, |panel, width| panel.min_w(width))
|
.when_some(self.width, |panel, width| panel.w(width))
|
||||||
.when(self.min_width.is_none(), |panel| {
|
.when(self.width.is_none() && self.min_width.is_none(), |panel| {
|
||||||
panel.min_w(DIALOG_MIN_WIDTH)
|
panel.min_w(DIALOG_MIN_WIDTH)
|
||||||
})
|
})
|
||||||
|
.when_some(self.min_width, |panel, width| panel.min_w(width))
|
||||||
.max_w(relative(0.9))
|
.max_w(relative(0.9))
|
||||||
.when_some(height, |panel, height| panel.h(height))
|
.when_some(height, |panel, height| panel.h(height))
|
||||||
.text_color(foreground),
|
.text_color(foreground),
|
||||||
shadows,
|
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()
|
.overflow_hidden()
|
||||||
.on_mouse_down(MouseButton::Left, |_, _, cx| cx.stop_propagation())
|
.on_mouse_down(MouseButton::Left, |_, _, cx| cx.stop_propagation())
|
||||||
.on_key_down({
|
.on_key_down({
|
||||||
|
|||||||
Reference in New Issue
Block a user