utils: add shared StyledExt styling helper

This commit is contained in:
2026-11-16 14:02:33 +07:00
parent d7e4047070
commit 745a01d7af
29 changed files with 332 additions and 68 deletions
+17 -5
View File
@@ -4,7 +4,8 @@ use gpui::prelude::FluentBuilder as _;
use gpui::{ use gpui::{
Animation, AnimationExt as _, App, Context, ElementId, Entity, InteractiveElement as _, Animation, AnimationExt as _, App, Context, ElementId, Entity, InteractiveElement as _,
IntoElement, ParentElement as _, RenderOnce, Role, SharedString, IntoElement, ParentElement as _, RenderOnce, Role, SharedString,
StatefulInteractiveElement as _, Styled as _, Window, deferred, div, ease_out_quint, StatefulInteractiveElement as _, StyleRefinement, Styled as _, Window, deferred, div,
ease_out_quint,
}; };
use gpui_native_icons::{Icon, IconRole}; use gpui_native_icons::{Icon, IconRole};
use gpui_native_theme::{ActiveTheme as _, ENTER_SLIDE_DISTANCE, Size, TextRole, Typeset as _}; use gpui_native_theme::{ActiveTheme as _, ENTER_SLIDE_DISTANCE, Size, TextRole, Typeset as _};
@@ -13,6 +14,7 @@ use gpui_native_utils::ResultLogErr as _;
use crate::button::{Button, ButtonVariant}; use crate::button::{Button, ButtonVariant};
use crate::common::DismissHandler; use crate::common::DismissHandler;
use crate::common::Sizable as _; use crate::common::Sizable as _;
use crate::common::StyledExt as _;
use crate::common::TOAST_LAYER; use crate::common::TOAST_LAYER;
use crate::common::v_flex; use crate::common::v_flex;
@@ -48,9 +50,10 @@ pub struct Alert {
title: Option<SharedString>, title: Option<SharedString>,
message: Option<SharedString>, message: Option<SharedString>,
severity: AlertSeverity, severity: AlertSeverity,
style: AlertStyle, presentation: AlertStyle,
icon: Option<Icon>, icon: Option<Icon>,
on_dismiss: Option<DismissHandler>, on_dismiss: Option<DismissHandler>,
style: StyleRefinement,
} }
impl Alert { impl Alert {
@@ -63,9 +66,10 @@ impl Alert {
title: None, title: None,
message: None, message: None,
severity: AlertSeverity::Info, severity: AlertSeverity::Info,
style: AlertStyle::default(), presentation: AlertStyle::default(),
icon: None, icon: None,
on_dismiss: None, on_dismiss: None,
style: StyleRefinement::default(),
} }
} }
@@ -95,7 +99,7 @@ impl Alert {
/// Sets how the alert presents. /// Sets how the alert presents.
pub fn style(mut self, style: AlertStyle) -> Self { pub fn style(mut self, style: AlertStyle) -> Self {
self.style = style; self.presentation = style;
self self
} }
@@ -123,6 +127,12 @@ impl Alert {
} }
} }
impl gpui::Styled for Alert {
fn style(&mut self) -> &mut StyleRefinement {
&mut self.style
}
}
impl RenderOnce for Alert { impl RenderOnce for Alert {
fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement { fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
let theme = cx.theme(); let theme = cx.theme();
@@ -176,7 +186,7 @@ impl RenderOnce for Alert {
.on_click(move |_, _window, cx| on_dismiss(cx)) .on_click(move |_, _window, cx| on_dismiss(cx))
}); });
match self.style { match self.presentation {
AlertStyle::Overlay => { AlertStyle::Overlay => {
let surface = theme.colors.surface; let surface = theme.colors.surface;
let border = if theme.borders.overlays { let border = if theme.borders.overlays {
@@ -199,6 +209,7 @@ impl RenderOnce for Alert {
.border_1() .border_1()
.border_color(border) .border_color(border)
.shadow(theme.elevations.popover.shadows()) .shadow(theme.elevations.popover.shadows())
.refine_style(&self.style)
.when_some(self.icon.clone(), |alert, icon_glyph| { .when_some(self.icon.clone(), |alert, icon_glyph| {
alert.child( alert.child(
div() div()
@@ -219,6 +230,7 @@ impl RenderOnce for Alert {
.flex() .flex()
.overflow_hidden() .overflow_hidden()
.bg(ramp.subtle) .bg(ramp.subtle)
.refine_style(&self.style)
.child(div().flex_none().w_1p5().self_stretch().bg(ramp.base)) .child(div().flex_none().w_1p5().self_stretch().bg(ramp.base))
.child( .child(
div() div()
+12 -3
View File
@@ -3,15 +3,15 @@
use gpui::prelude::FluentBuilder as _; use gpui::prelude::FluentBuilder as _;
use gpui::{ use gpui::{
AnyElement, AnyView, App, ClickEvent, ElementId, InteractiveElement as _, IntoElement, AnyElement, AnyView, App, ClickEvent, ElementId, InteractiveElement as _, IntoElement,
ParentElement, RenderOnce, Role, SharedString, StatefulInteractiveElement as _, Styled as _, ParentElement, RenderOnce, Role, SharedString, StatefulInteractiveElement as _,
Window, canvas, relative, transparent_black, StyleRefinement, Styled as _, Window, canvas, relative, transparent_black,
}; };
use gpui_native_icons::Icon; use gpui_native_icons::Icon;
use gpui_native_theme::{ActiveTheme as _, BORDER_WIDTH, Size}; use gpui_native_theme::{ActiveTheme as _, BORDER_WIDTH, Size};
use gpui_native_utils::{focus_ring, record_anchor_bounds}; use gpui_native_utils::{focus_ring, record_anchor_bounds};
use std::rc::Rc; use std::rc::Rc;
use crate::common::{Sizable, h_flex}; use crate::common::{Sizable, StyledExt as _, h_flex};
use crate::spinner::Spinner; use crate::spinner::Spinner;
/// The single activation handler, shared by pointer, Enter, and Space. /// The single activation handler, shared by pointer, Enter, and Space.
@@ -64,6 +64,7 @@ pub struct Button {
a11y_label: Option<SharedString>, a11y_label: Option<SharedString>,
tooltip: Option<TooltipBuilder>, tooltip: Option<TooltipBuilder>,
on_click: Option<ClickHandler>, on_click: Option<ClickHandler>,
style: StyleRefinement,
} }
impl Button { impl Button {
@@ -88,6 +89,7 @@ impl Button {
a11y_label: None, a11y_label: None,
tooltip: None, tooltip: None,
on_click: None, on_click: None,
style: StyleRefinement::default(),
} }
} }
@@ -188,6 +190,12 @@ impl ParentElement for Button {
} }
} }
impl gpui::Styled for Button {
fn style(&mut self) -> &mut StyleRefinement {
&mut self.style
}
}
impl Sizable for Button { impl Sizable for Button {
fn apply_size(&mut self, size: Size) { fn apply_size(&mut self, size: Size) {
self.size = size; self.size = size;
@@ -277,6 +285,7 @@ impl RenderOnce for Button {
.border_color(border) .border_color(border)
.when_some(background, |button, background| button.bg(background)) .when_some(background, |button, background| button.bg(background))
.text_color(foreground) .text_color(foreground)
.refine_style(&self.style)
.when_some(a11y_label, |button, label| button.aria_label(label)) .when_some(a11y_label, |button, label| button.aria_label(label))
.child( .child(
h_flex() h_flex()
+11 -2
View File
@@ -5,13 +5,13 @@ use std::rc::Rc;
use gpui::prelude::FluentBuilder as _; use gpui::prelude::FluentBuilder as _;
use gpui::{ use gpui::{
App, ElementId, InteractiveElement as _, IntoElement, ParentElement as _, RenderOnce, Role, App, ElementId, InteractiveElement as _, IntoElement, ParentElement as _, RenderOnce, Role,
SharedString, StatefulInteractiveElement as _, Styled as _, Toggled, Window, SharedString, StatefulInteractiveElement as _, StyleRefinement, Styled as _, Toggled, Window,
}; };
use gpui_native_icons::{IconRole, icon}; use gpui_native_icons::{IconRole, icon};
use gpui_native_theme::{ActiveTheme as _, Size}; use gpui_native_theme::{ActiveTheme as _, Size};
use gpui_native_utils::focus_ring; use gpui_native_utils::focus_ring;
use crate::common::{Sizable, h_flex}; use crate::common::{Sizable, StyledExt as _, h_flex};
/// The change reporter, fired with the next value by pointer, Enter, and Space. /// The change reporter, fired with the next value by pointer, Enter, and Space.
type ChangeHandler = Box<dyn Fn(bool, &mut Window, &mut App)>; type ChangeHandler = Box<dyn Fn(bool, &mut Window, &mut App)>;
@@ -28,6 +28,7 @@ pub struct Checkbox {
debug_selector: Option<Rc<dyn Fn() -> String>>, debug_selector: Option<Rc<dyn Fn() -> String>>,
a11y_label: Option<SharedString>, a11y_label: Option<SharedString>,
on_change: Option<ChangeHandler>, on_change: Option<ChangeHandler>,
style: StyleRefinement,
} }
impl Checkbox { impl Checkbox {
@@ -45,6 +46,7 @@ impl Checkbox {
debug_selector: None, debug_selector: None,
a11y_label: None, a11y_label: None,
on_change: None, on_change: None,
style: StyleRefinement::default(),
} }
} }
@@ -97,6 +99,12 @@ impl Checkbox {
} }
} }
impl gpui::Styled for Checkbox {
fn style(&mut self) -> &mut StyleRefinement {
&mut self.style
}
}
impl Sizable for Checkbox { impl Sizable for Checkbox {
fn apply_size(&mut self, size: Size) { fn apply_size(&mut self, size: Size) {
self.size = size; self.size = size;
@@ -117,6 +125,7 @@ impl RenderOnce for Checkbox {
.id(self.id) .id(self.id)
.gap_1p5() .gap_1p5()
.text_size(metrics.text_size) .text_size(metrics.text_size)
.refine_style(&self.style)
.when_some(self.debug_selector, |checkbox, selector| { .when_some(self.debug_selector, |checkbox, selector| {
checkbox.debug_selector(move || selector()) checkbox.debug_selector(move || selector())
}) })
+6 -3
View File
@@ -5,15 +5,15 @@ use std::time::Duration;
use gpui::prelude::FluentBuilder as _; use gpui::prelude::FluentBuilder as _;
use gpui::{ use gpui::{
AnyView, App, ClipboardItem, ElementId, Entity, IntoElement, RenderOnce, SharedString, Task, AnyView, App, ClipboardItem, ElementId, Entity, IntoElement, RenderOnce, SharedString,
Window, StyleRefinement, Task, Window,
}; };
use gpui_native_icons::IconRole; use gpui_native_icons::IconRole;
use gpui_native_theme::Size; use gpui_native_theme::Size;
use gpui_native_utils::ResultLogErr as _; use gpui_native_utils::ResultLogErr as _;
use crate::button::{Button, ButtonVariant}; use crate::button::{Button, ButtonVariant};
use crate::common::Sizable; use crate::common::{Sizable, StyledExt as _};
/// How long the check mark shows before reverting to the copy icon. /// How long the check mark shows before reverting to the copy icon.
pub const COPIED_DURATION: Duration = Duration::from_secs(1); pub const COPIED_DURATION: Duration = Duration::from_secs(1);
@@ -35,6 +35,7 @@ pub struct ClipboardButton {
a11y_label: Option<SharedString>, a11y_label: Option<SharedString>,
tooltip: Option<TooltipBuilder>, tooltip: Option<TooltipBuilder>,
on_copied: Option<CopiedHandler>, on_copied: Option<CopiedHandler>,
style: StyleRefinement,
} }
impl ClipboardButton { impl ClipboardButton {
@@ -52,6 +53,7 @@ impl ClipboardButton {
a11y_label: None, a11y_label: None,
tooltip: None, tooltip: None,
on_copied: None, on_copied: None,
style: StyleRefinement::default(),
} }
} }
@@ -127,6 +129,7 @@ impl RenderOnce for ClipboardButton {
.variant(ButtonVariant::Ghost) .variant(ButtonVariant::Ghost)
.with_size(self.size) .with_size(self.size)
.disabled(self.disabled) .disabled(self.disabled)
.refine_style(&self.style)
.debug_selector(move || selector.to_string()) .debug_selector(move || selector.to_string())
.accessibility_label(self.a11y_label.unwrap_or_else(|| "Copy".into())) .accessibility_label(self.a11y_label.unwrap_or_else(|| "Copy".into()))
.when_some(self.tooltip, |button, tooltip| { .when_some(self.tooltip, |button, tooltip| {
+8 -3
View File
@@ -6,13 +6,13 @@ use gpui::prelude::FluentBuilder;
use gpui::{ use gpui::{
AnyElement, App, Context, ElementId, Entity, InteractiveElement as _, IntoElement, KeyBinding, AnyElement, App, Context, ElementId, Entity, InteractiveElement as _, IntoElement, KeyBinding,
MouseButton, ParentElement as _, Render, Role, ScrollHandle, SharedString, MouseButton, ParentElement as _, Render, Role, ScrollHandle, SharedString,
StatefulInteractiveElement as _, Styled as _, Subscription, Window, actions, canvas, deferred, StatefulInteractiveElement as _, StyleRefinement, Styled as _, Subscription, Window, actions,
div, relative, canvas, deferred, div, relative,
}; };
use gpui_native_icons::Icon; use gpui_native_icons::Icon;
use gpui_native_theme::{ActiveTheme as _, POPUP_MAX_HEIGHT, Size}; use gpui_native_theme::{ActiveTheme as _, POPUP_MAX_HEIGHT, Size};
use crate::common::{DIALOG_LAYER, h_flex, v_flex}; use crate::common::{DIALOG_LAYER, StyledExt as _, h_flex, v_flex};
use crate::input::{Input, InputState, InputStateEvent}; use crate::input::{Input, InputState, InputStateEvent};
use crate::scroll_area::{ScrollArea, ScrollAxes}; use crate::scroll_area::{ScrollArea, ScrollAxes};
@@ -104,6 +104,7 @@ pub struct CommandPalette {
commands: Vec<Command>, commands: Vec<Command>,
matcher: CommandMatcher, matcher: CommandMatcher,
on_execute: Option<CommandHandler>, on_execute: Option<CommandHandler>,
style: StyleRefinement,
} }
impl CommandPalette { impl CommandPalette {
@@ -120,6 +121,7 @@ impl CommandPalette {
commands, commands,
matcher: Rc::new(matcher), matcher: Rc::new(matcher),
on_execute: None, on_execute: None,
style: StyleRefinement::default(),
} }
} }
@@ -162,6 +164,7 @@ pub struct CommandPaletteState {
commands: Vec<Command>, commands: Vec<Command>,
matcher: CommandMatcher, matcher: CommandMatcher,
on_execute: Option<CommandHandler>, on_execute: Option<CommandHandler>,
style: StyleRefinement,
query: Entity<InputState>, query: Entity<InputState>,
/// The commands the matcher returned for the query, in display order. /// The commands the matcher returned for the query, in display order.
matches: Vec<Command>, matches: Vec<Command>,
@@ -191,6 +194,7 @@ impl CommandPaletteState {
commands: palette.commands, commands: palette.commands,
matcher: palette.matcher, matcher: palette.matcher,
on_execute: palette.on_execute, on_execute: palette.on_execute,
style: palette.style,
query, query,
matches, matches,
highlight: None, highlight: None,
@@ -451,6 +455,7 @@ impl Render for CommandPaletteState {
.border_color(panel_border) .border_color(panel_border)
.shadow(shadows) .shadow(shadows)
.overflow_hidden() .overflow_hidden()
.refine_style(&self.style)
.on_mouse_down(MouseButton::Left, |_, _, cx| cx.stop_propagation()) .on_mouse_down(MouseButton::Left, |_, _, cx| cx.stop_propagation())
.on_action({ .on_action({
let state = state.clone(); let state = state.clone();
+5 -1
View File
@@ -1,9 +1,10 @@
use gpui::prelude::FluentBuilder as _; use gpui::prelude::FluentBuilder as _;
use gpui::{ use gpui::{
App, ElementId, InteractiveElement as _, IntoElement, MouseButton, MouseDownEvent, App, ElementId, InteractiveElement as _, IntoElement, MouseButton, MouseDownEvent,
ParentElement as _, RenderOnce, SharedString, Window, div, ParentElement as _, RenderOnce, SharedString, StyleRefinement, Window, div,
}; };
use crate::common::StyledExt as _;
use crate::menu::{Menu, MenuItem}; use crate::menu::{Menu, MenuItem};
/// Builds the element that opens the menu on right-click. /// Builds the element that opens the menu on right-click.
@@ -21,6 +22,7 @@ pub struct ContextMenu {
target: Option<TargetFn>, target: Option<TargetFn>,
items: Option<ItemsFn>, items: Option<ItemsFn>,
a11y_label: Option<SharedString>, a11y_label: Option<SharedString>,
style: StyleRefinement,
} }
impl ContextMenu { impl ContextMenu {
@@ -34,6 +36,7 @@ impl ContextMenu {
target: None, target: None,
items: None, items: None,
a11y_label: None, a11y_label: None,
style: StyleRefinement::default(),
} }
} }
@@ -116,6 +119,7 @@ impl RenderOnce for ContextMenu {
.trigger_button(MouseButton::Right) .trigger_button(MouseButton::Right)
.trigger(trigger) .trigger(trigger)
.items(items) .items(items)
.refine_style(&self.style)
.when_some(self.a11y_label.clone(), |menu, label| { .when_some(self.a11y_label.clone(), |menu, label| {
menu.accessibility_label(label) menu.accessibility_label(label)
}) })
+12 -3
View File
@@ -4,14 +4,14 @@ use std::rc::Rc;
use gpui::{ use gpui::{
Animation, AnimationExt as _, AnyElement, App, DefiniteLength, ElementId, Animation, AnimationExt as _, AnyElement, App, DefiniteLength, ElementId,
InteractiveElement as _, IntoElement, KeyDownEvent, MouseButton, ParentElement as _, InteractiveElement as _, IntoElement, KeyDownEvent, MouseButton, ParentElement as _,
RenderOnce, Role, ScrollHandle, SharedString, StatefulInteractiveElement as _, Styled as _, RenderOnce, Role, ScrollHandle, SharedString, StatefulInteractiveElement as _, StyleRefinement,
Window, canvas, deferred, div, ease_out_quint, relative, Styled as _, Window, canvas, deferred, div, ease_out_quint, relative,
}; };
use gpui_native_icons::IconRole; use gpui_native_icons::IconRole;
use gpui_native_theme::{ActiveTheme as _, TextRole, Typeset as _}; use gpui_native_theme::{ActiveTheme as _, TextRole, Typeset as _};
use crate::button::{Button, ButtonVariant}; use crate::button::{Button, ButtonVariant};
use crate::common::{DIALOG_LAYER, Sizable, v_flex}; use crate::common::{DIALOG_LAYER, Sizable, StyledExt as _, v_flex};
use crate::grain::grain; use crate::grain::grain;
use crate::scroll_area::ScrollArea; use crate::scroll_area::ScrollArea;
@@ -35,6 +35,7 @@ pub struct Dialog {
actions: Option<ActionsFn>, actions: Option<ActionsFn>,
min_width: Option<DefiniteLength>, min_width: Option<DefiniteLength>,
height: Option<DefiniteLength>, height: Option<DefiniteLength>,
style: StyleRefinement,
} }
impl Dialog { impl Dialog {
@@ -55,6 +56,7 @@ impl Dialog {
actions: None, actions: None,
min_width: None, min_width: None,
height: None, height: None,
style: StyleRefinement::default(),
} }
} }
@@ -140,6 +142,12 @@ impl Dialog {
} }
} }
impl gpui::Styled for Dialog {
fn style(&mut self) -> &mut StyleRefinement {
&mut self.style
}
}
impl RenderOnce for Dialog { impl RenderOnce for Dialog {
fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement { fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
let root = div().absolute().inset_0(); let root = div().absolute().inset_0();
@@ -307,6 +315,7 @@ impl RenderOnce for Dialog {
.items_center() .items_center()
.justify_center() .justify_center()
.p_4() .p_4()
.refine_style(&self.style)
.child(scrim.with_animation( .child(scrim.with_animation(
"dialog-scrim-enter", "dialog-scrim-enter",
Animation::new(enter_duration).with_easing(ease_out_quint()), Animation::new(enter_duration).with_easing(ease_out_quint()),
+12 -2
View File
@@ -7,14 +7,15 @@ use gpui::prelude::FluentBuilder as _;
use gpui::{ use gpui::{
App, ClickEvent, DefiniteLength, DispatchPhase, ElementId, InteractiveElement as _, App, ClickEvent, DefiniteLength, DispatchPhase, ElementId, InteractiveElement as _,
IntoElement, KeyDownEvent, MouseButton, MouseDownEvent, ParentElement as _, RenderOnce, Role, IntoElement, KeyDownEvent, MouseButton, MouseDownEvent, ParentElement as _, RenderOnce, Role,
SharedString, StatefulInteractiveElement as _, Styled as _, Window, canvas, div, relative, SharedString, StatefulInteractiveElement as _, StyleRefinement, Styled as _, Window, canvas,
div, relative,
}; };
use gpui_native_icons::{Icon, IconRole, icon}; use gpui_native_icons::{Icon, IconRole, icon};
use gpui_native_theme::{ActiveTheme as _, BORDER_WIDTH, Size}; use gpui_native_theme::{ActiveTheme as _, BORDER_WIDTH, Size};
use gpui_native_utils::{focus_handle, focus_ring}; use gpui_native_utils::{focus_handle, focus_ring};
use crate::button::ButtonVariant; use crate::button::ButtonVariant;
use crate::common::{Sizable, h_flex}; use crate::common::{Sizable, StyledExt as _, h_flex};
use crate::menu::{ use crate::menu::{
ChangeHandler, MenuChrome, MenuItem, MenuPanelSpec, TriggerBoundsCell, anchored_menu_panel, ChangeHandler, MenuChrome, MenuItem, MenuPanelSpec, TriggerBoundsCell, anchored_menu_panel,
}; };
@@ -42,6 +43,7 @@ pub struct DropdownMenu {
on_open_change: Option<ChangeHandler>, on_open_change: Option<ChangeHandler>,
items: Option<ItemsFn>, items: Option<ItemsFn>,
min_width: Option<DefiniteLength>, min_width: Option<DefiniteLength>,
style: StyleRefinement,
} }
impl DropdownMenu { impl DropdownMenu {
@@ -65,6 +67,7 @@ impl DropdownMenu {
on_open_change: None, on_open_change: None,
items: None, items: None,
min_width: None, min_width: None,
style: StyleRefinement::default(),
} }
} }
@@ -168,6 +171,12 @@ impl Sizable for DropdownMenu {
} }
} }
impl gpui::Styled for DropdownMenu {
fn style(&mut self) -> &mut StyleRefinement {
&mut self.style
}
}
impl RenderOnce for DropdownMenu { impl RenderOnce for DropdownMenu {
fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement { fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
let theme = cx.theme(); let theme = cx.theme();
@@ -410,6 +419,7 @@ impl RenderOnce for DropdownMenu {
div() div()
.relative() .relative()
.refine_style(&self.style)
.child( .child(
canvas( canvas(
{ {
+12 -3
View File
@@ -11,8 +11,8 @@ use gpui::{
EntityInputHandler, EventEmitter, Font, HitboxBehavior, InteractiveElement as _, IntoElement, EntityInputHandler, EventEmitter, Font, HitboxBehavior, InteractiveElement as _, IntoElement,
KeyBinding, KeyDownEvent, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, KeyBinding, KeyDownEvent, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent,
ParentElement as _, Pixels, RenderOnce, Role, ScrollDelta, ScrollEvent, SharedString, ParentElement as _, Pixels, RenderOnce, Role, ScrollDelta, ScrollEvent, SharedString,
StatefulInteractiveElement as _, Styled as _, TextAlign, TextRun, UTF16Selection, Window, StatefulInteractiveElement as _, StyleRefinement, Styled as _, TextAlign, TextRun,
WrappedLine, actions, canvas, div, fill, point, px, UTF16Selection, Window, WrappedLine, actions, canvas, div, fill, point, px,
}; };
use gpui_native_icons::IconRole; use gpui_native_icons::IconRole;
use gpui_native_theme::{ use gpui_native_theme::{
@@ -22,7 +22,7 @@ use gpui_native_theme::{
use gpui_native_utils::focus_ring; use gpui_native_utils::focus_ring;
use crate::button::{Button, ButtonVariant}; use crate::button::{Button, ButtonVariant};
use crate::common::{Sizable, h_flex}; use crate::common::{Sizable, StyledExt as _, h_flex};
/// The key context input bindings match against. /// The key context input bindings match against.
pub const INPUT_CONTEXT: &str = "Input"; pub const INPUT_CONTEXT: &str = "Input";
@@ -1884,6 +1884,7 @@ pub struct Input {
rows: usize, rows: usize,
prefix: Option<AnyElement>, prefix: Option<AnyElement>,
suffix: Option<AnyElement>, suffix: Option<AnyElement>,
style: StyleRefinement,
} }
impl Input { impl Input {
@@ -1903,6 +1904,7 @@ impl Input {
rows: DEFAULT_ROWS, rows: DEFAULT_ROWS,
prefix: None, prefix: None,
suffix: None, suffix: None,
style: StyleRefinement::default(),
} }
} }
@@ -1961,6 +1963,12 @@ impl Input {
} }
} }
impl gpui::Styled for Input {
fn style(&mut self) -> &mut StyleRefinement {
&mut self.style
}
}
impl Sizable for Input { impl Sizable for Input {
fn apply_size(&mut self, size: Size) { fn apply_size(&mut self, size: Size) {
self.size = size; self.size = size;
@@ -2151,6 +2159,7 @@ impl RenderOnce for Input {
} else { } else {
colors.input colors.input
}) })
.refine_style(&self.style)
.when(self.disabled, |input| input.opacity(0.5)) .when(self.disabled, |input| input.opacity(0.5))
.when(!self.disabled, |input| { .when(!self.disabled, |input| {
input.track_focus(&focus_handle).tab_stop(true) input.track_focus(&focus_handle).tab_stop(true)
+12 -2
View File
@@ -1,12 +1,13 @@
use gpui::prelude::FluentBuilder as _; use gpui::prelude::FluentBuilder as _;
use gpui::{ use gpui::{
App, ClickEvent, ElementId, InteractiveElement as _, IntoElement, ParentElement as _, App, ClickEvent, ElementId, InteractiveElement as _, IntoElement, ParentElement as _,
RenderOnce, Role, SharedString, StatefulInteractiveElement as _, Styled as _, Window, RenderOnce, Role, SharedString, StatefulInteractiveElement as _, StyleRefinement, Styled as _,
Window,
}; };
use gpui_native_theme::{ActiveTheme as _, Size}; use gpui_native_theme::{ActiveTheme as _, Size};
use gpui_native_utils::focus_ring; use gpui_native_utils::focus_ring;
use crate::common::{Sizable, h_flex}; use crate::common::{Sizable, StyledExt as _, h_flex};
/// The click handler. When set it replaces the default `href` opening. /// The click handler. When set it replaces the default `href` opening.
type ClickHandler = Box<dyn Fn(&ClickEvent, &mut Window, &mut App)>; type ClickHandler = Box<dyn Fn(&ClickEvent, &mut Window, &mut App)>;
@@ -22,6 +23,7 @@ pub struct Link {
disabled: bool, disabled: bool,
a11y_label: Option<SharedString>, a11y_label: Option<SharedString>,
on_click: Option<ClickHandler>, on_click: Option<ClickHandler>,
style: StyleRefinement,
} }
impl Link { impl Link {
@@ -38,6 +40,7 @@ impl Link {
disabled: false, disabled: false,
a11y_label: None, a11y_label: None,
on_click: None, on_click: None,
style: StyleRefinement::default(),
} }
} }
@@ -84,6 +87,12 @@ impl Link {
} }
} }
impl gpui::Styled for Link {
fn style(&mut self) -> &mut StyleRefinement {
&mut self.style
}
}
impl Sizable for Link { impl Sizable for Link {
fn apply_size(&mut self, size: Size) { fn apply_size(&mut self, size: Size) {
self.size = size; self.size = size;
@@ -106,6 +115,7 @@ impl RenderOnce for Link {
.text_size(metrics.text_size) .text_size(metrics.text_size)
.text_color(colors.accent) .text_color(colors.accent)
.underline() .underline()
.refine_style(&self.style)
.role(Role::Link) .role(Role::Link)
.when_some(a11y_label, |link, label| link.aria_label(label)) .when_some(a11y_label, |link, label| link.aria_label(label))
.when(self.disabled, |link| link.opacity(0.5)) .when(self.disabled, |link| link.opacity(0.5))
+12 -3
View File
@@ -8,14 +8,14 @@ use gpui::{
Animation, AnimationExt as _, AnyElement, App, Bounds, BoxShadow, DefiniteLength, Animation, AnimationExt as _, AnyElement, App, Bounds, BoxShadow, DefiniteLength,
DispatchPhase, ElementId, Entity, FocusHandle, InteractiveElement as _, IntoElement, DispatchPhase, ElementId, Entity, FocusHandle, InteractiveElement as _, IntoElement,
KeyDownEvent, MouseButton, MouseDownEvent, ParentElement as _, Pixels, Point, RenderOnce, Role, KeyDownEvent, MouseButton, MouseDownEvent, ParentElement as _, Pixels, Point, RenderOnce, Role,
ScrollHandle, SharedString, StatefulInteractiveElement as _, Styled as _, Window, anchored, ScrollHandle, SharedString, StatefulInteractiveElement as _, StyleRefinement, Styled as _,
canvas, deferred, div, ease_out_quint, point, px, relative, Window, anchored, canvas, deferred, div, ease_out_quint, point, px, relative,
}; };
use gpui_native_icons::{Icon, IconRole, icon as icon_glyph}; use gpui_native_icons::{Icon, IconRole, icon as icon_glyph};
use gpui_native_theme::{ActiveTheme as _, BORDER_WIDTH, POPUP_MAX_HEIGHT}; use gpui_native_theme::{ActiveTheme as _, BORDER_WIDTH, POPUP_MAX_HEIGHT};
use gpui_native_utils::focus_handle; use gpui_native_utils::focus_handle;
use crate::common::{OVERLAY_LAYER, v_flex}; use crate::common::{OVERLAY_LAYER, StyledExt as _, v_flex};
use crate::scroll_area::{ScrollArea, ScrollAxes}; use crate::scroll_area::{ScrollArea, ScrollAxes};
/// Runs the item's action. The menu closes itself before the handler runs. /// Runs the item's action. The menu closes itself before the handler runs.
@@ -203,6 +203,7 @@ pub struct Menu {
trigger: Option<TriggerFn>, trigger: Option<TriggerFn>,
items: Option<ItemsFn>, items: Option<ItemsFn>,
min_width: Option<DefiniteLength>, min_width: Option<DefiniteLength>,
style: StyleRefinement,
} }
impl MenuChrome { impl MenuChrome {
@@ -256,6 +257,7 @@ impl Menu {
trigger: None, trigger: None,
items: None, items: None,
min_width: None, min_width: None,
style: StyleRefinement::default(),
} }
} }
@@ -332,6 +334,12 @@ impl Menu {
} }
} }
impl gpui::Styled for Menu {
fn style(&mut self) -> &mut StyleRefinement {
&mut self.style
}
}
impl RenderOnce for Menu { impl RenderOnce for Menu {
fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement { fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
let (chrome, enter_duration) = MenuChrome::read(cx); let (chrome, enter_duration) = MenuChrome::read(cx);
@@ -367,6 +375,7 @@ impl RenderOnce for Menu {
div() div()
.relative() .relative()
.refine_style(&self.style)
.child( .child(
canvas( canvas(
{ {
+11 -2
View File
@@ -6,11 +6,11 @@ use gpui::{
Animation, AnimationExt as _, AnyElement, App, Bounds, DispatchPhase, ElementId, Animation, AnimationExt as _, AnyElement, App, Bounds, DispatchPhase, ElementId,
InteractiveElement as _, IntoElement, KeyDownEvent, MouseButton, MouseDownEvent, InteractiveElement as _, IntoElement, KeyDownEvent, MouseButton, MouseDownEvent,
ParentElement as _, Pixels, RenderOnce, Role, SharedString, StatefulInteractiveElement as _, ParentElement as _, Pixels, RenderOnce, Role, SharedString, StatefulInteractiveElement as _,
Styled as _, Window, anchored, canvas, deferred, div, ease_out_quint, point, StyleRefinement, Styled as _, Window, anchored, canvas, deferred, div, ease_out_quint, point,
}; };
use gpui_native_theme::ActiveTheme as _; use gpui_native_theme::ActiveTheme as _;
use crate::common::{OVERLAY_LAYER, v_flex}; use crate::common::{OVERLAY_LAYER, StyledExt as _, v_flex};
/// Reports the next open state of a [`Popover`]: `true` to open, `false` to close. /// Reports the next open state of a [`Popover`]: `true` to open, `false` to close.
type ChangeHandler = Rc<dyn Fn(bool, &mut Window, &mut App)>; type ChangeHandler = Rc<dyn Fn(bool, &mut Window, &mut App)>;
@@ -29,6 +29,7 @@ pub struct Popover {
on_change: Option<ChangeHandler>, on_change: Option<ChangeHandler>,
trigger: Option<TriggerFn>, trigger: Option<TriggerFn>,
content: Option<ContentFn>, content: Option<ContentFn>,
style: StyleRefinement,
} }
impl Popover { impl Popover {
@@ -44,6 +45,7 @@ impl Popover {
on_change: None, on_change: None,
trigger: None, trigger: None,
content: None, content: None,
style: StyleRefinement::default(),
} }
} }
@@ -90,6 +92,12 @@ impl Popover {
} }
} }
impl gpui::Styled for Popover {
fn style(&mut self) -> &mut StyleRefinement {
&mut self.style
}
}
impl RenderOnce for Popover { impl RenderOnce for Popover {
fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement { fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
let (colors, radius, shadows, enter_duration, panel_border, anchor_gap) = { let (colors, radius, shadows, enter_duration, panel_border, anchor_gap) = {
@@ -117,6 +125,7 @@ impl RenderOnce for Popover {
div() div()
.relative() .relative()
.refine_style(&self.style)
.child( .child(
canvas( canvas(
{ {
+11 -2
View File
@@ -4,11 +4,11 @@ use gpui::prelude::FluentBuilder as _;
use gpui::{ use gpui::{
Animation, AnimationExt as _, App, ElementId, InteractiveElement as _, IntoElement, Animation, AnimationExt as _, App, ElementId, InteractiveElement as _, IntoElement,
ParentElement as _, RenderOnce, Role, SharedString, StatefulInteractiveElement as _, ParentElement as _, RenderOnce, Role, SharedString, StatefulInteractiveElement as _,
Styled as _, Window, div, relative, StyleRefinement, Styled as _, Window, div, relative,
}; };
use gpui_native_theme::{ActiveTheme as _, PROGRESS_ANIMATION_PERIOD, Size}; use gpui_native_theme::{ActiveTheme as _, PROGRESS_ANIMATION_PERIOD, Size};
use crate::common::Sizable; use crate::common::{Sizable, StyledExt as _};
/// A progress bar. With a `value` in `0..=1` it paints a determinate fill. /// A progress bar. With a `value` in `0..=1` it paints a determinate fill.
#[derive(IntoElement)] #[derive(IntoElement)]
@@ -19,6 +19,7 @@ pub struct Progress {
indeterminate: bool, indeterminate: bool,
size: Size, size: Size,
a11y_label: Option<SharedString>, a11y_label: Option<SharedString>,
style: StyleRefinement,
} }
impl Progress { impl Progress {
@@ -33,6 +34,7 @@ impl Progress {
indeterminate: false, indeterminate: false,
size: Size::default(), size: Size::default(),
a11y_label: None, a11y_label: None,
style: StyleRefinement::default(),
} }
} }
@@ -52,6 +54,12 @@ impl Progress {
} }
} }
impl gpui::Styled for Progress {
fn style(&mut self) -> &mut StyleRefinement {
&mut self.style
}
}
impl Sizable for Progress { impl Sizable for Progress {
fn apply_size(&mut self, size: Size) { fn apply_size(&mut self, size: Size) {
self.size = size; self.size = size;
@@ -72,6 +80,7 @@ impl RenderOnce for Progress {
div() div()
.id(self.id) .id(self.id)
.w_full() .w_full()
.refine_style(&self.style)
.role(Role::ProgressIndicator) .role(Role::ProgressIndicator)
.when_some(self.a11y_label, |progress, label| { .when_some(self.a11y_label, |progress, label| {
progress.aria_label(label) progress.aria_label(label)
+15 -2
View File
@@ -1,12 +1,13 @@
use gpui::prelude::FluentBuilder; use gpui::prelude::FluentBuilder;
use gpui::{ use gpui::{
App, ElementId, InteractiveElement as _, IntoElement, ParentElement as _, RenderOnce, Role, App, ElementId, InteractiveElement as _, IntoElement, ParentElement as _, RenderOnce, Role,
SharedString, StatefulInteractiveElement as _, Styled as _, Toggled, Window, div, SharedString, StatefulInteractiveElement as _, StyleRefinement, Styled as _, Toggled, Window,
div,
}; };
use gpui_native_theme::{ActiveTheme as _, Size}; use gpui_native_theme::{ActiveTheme as _, Size};
use gpui_native_utils::focus_ring; use gpui_native_utils::focus_ring;
use crate::common::{Sizable, h_flex, v_flex}; use crate::common::{Sizable, StyledExt as _, h_flex, v_flex};
/// The group's change reporter, fired with the clicked radio's value. /// The group's change reporter, fired with the clicked radio's value.
type ChangeHandler<V> = std::rc::Rc<dyn Fn(V, &mut Window, &mut App)>; type ChangeHandler<V> = std::rc::Rc<dyn Fn(V, &mut Window, &mut App)>;
@@ -83,6 +84,7 @@ where
size: Size, size: Size,
a11y_label: Option<SharedString>, a11y_label: Option<SharedString>,
on_change: Option<ChangeHandler<V>>, on_change: Option<ChangeHandler<V>>,
style: StyleRefinement,
} }
impl<V> RadioGroup<V> impl<V> RadioGroup<V>
@@ -101,6 +103,7 @@ where
size: Size::default(), size: Size::default(),
a11y_label: None, a11y_label: None,
on_change: None, on_change: None,
style: StyleRefinement::default(),
} }
} }
@@ -144,6 +147,15 @@ where
} }
} }
impl<V> gpui::Styled for RadioGroup<V>
where
V: Clone + PartialEq + 'static,
{
fn style(&mut self) -> &mut StyleRefinement {
&mut self.style
}
}
impl<V> RenderOnce for RadioGroup<V> impl<V> RenderOnce for RadioGroup<V>
where where
V: Clone + PartialEq + 'static, V: Clone + PartialEq + 'static,
@@ -162,6 +174,7 @@ where
.id(self.id) .id(self.id)
.gap_2() .gap_2()
.text_size(metrics.text_size) .text_size(metrics.text_size)
.refine_style(&self.style)
.role(Role::RadioGroup) .role(Role::RadioGroup)
.when_some(group_label.clone(), |group, label| group.aria_label(label)) .when_some(group_label.clone(), |group, label| group.aria_label(label))
.children(self.children.into_iter().map(move |radio| { .children(self.children.into_iter().map(move |radio| {
+15 -1
View File
@@ -3,8 +3,12 @@
use std::rc::Rc; use std::rc::Rc;
use gpui::prelude::FluentBuilder as _; use gpui::prelude::FluentBuilder as _;
use gpui::{App, InteractiveElement as _, IntoElement, RenderOnce, Styled as _, Window, div}; use gpui::{
App, InteractiveElement as _, IntoElement, RenderOnce, StyleRefinement, Styled as _, Window,
div,
};
use gpui_native_theme::{ActiveTheme as _, BORDER_WIDTH}; use gpui_native_theme::{ActiveTheme as _, BORDER_WIDTH};
use gpui_native_utils::StyledExt as _;
/// Which axis the rule runs along. /// Which axis the rule runs along.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
@@ -24,6 +28,7 @@ type DebugSelector = Rc<dyn Fn() -> String>;
pub struct Separator { pub struct Separator {
orientation: SeparatorOrientation, orientation: SeparatorOrientation,
debug_selector: Option<DebugSelector>, debug_selector: Option<DebugSelector>,
style: StyleRefinement,
} }
impl Separator { impl Separator {
@@ -32,6 +37,7 @@ impl Separator {
Self { Self {
orientation: SeparatorOrientation::Horizontal, orientation: SeparatorOrientation::Horizontal,
debug_selector: None, debug_selector: None,
style: StyleRefinement::default(),
} }
} }
@@ -40,6 +46,7 @@ impl Separator {
Self { Self {
orientation: SeparatorOrientation::Vertical, orientation: SeparatorOrientation::Vertical,
debug_selector: None, debug_selector: None,
style: StyleRefinement::default(),
} }
} }
@@ -59,6 +66,12 @@ impl Separator {
} }
} }
impl gpui::Styled for Separator {
fn style(&mut self) -> &mut StyleRefinement {
&mut self.style
}
}
impl RenderOnce for Separator { impl RenderOnce for Separator {
fn render(self, _window: &mut Window, cx: &mut App) -> impl IntoElement { fn render(self, _window: &mut Window, cx: &mut App) -> impl IntoElement {
let border = cx.theme().colors.border; let border = cx.theme().colors.border;
@@ -73,5 +86,6 @@ impl RenderOnce for Separator {
SeparatorOrientation::Horizontal => rule.w_full().h(BORDER_WIDTH), SeparatorOrientation::Horizontal => rule.w_full().h(BORDER_WIDTH),
SeparatorOrientation::Vertical => rule.self_stretch().w(BORDER_WIDTH), SeparatorOrientation::Vertical => rule.self_stretch().w(BORDER_WIDTH),
}) })
.refine_style(&self.style)
} }
} }
+12 -2
View File
@@ -5,12 +5,13 @@ use gpui::prelude::FluentBuilder as _;
use gpui::{ use gpui::{
App, Bounds, DispatchPhase, ElementId, InteractiveElement as _, IntoElement, KeyDownEvent, App, Bounds, DispatchPhase, ElementId, InteractiveElement as _, IntoElement, KeyDownEvent,
MouseButton, MouseMoveEvent, MouseUpEvent, ParentElement as _, Pixels, RenderOnce, Role, MouseButton, MouseMoveEvent, MouseUpEvent, ParentElement as _, Pixels, RenderOnce, Role,
SharedString, StatefulInteractiveElement as _, Styled as _, Window, canvas, div, relative, SharedString, StatefulInteractiveElement as _, StyleRefinement, Styled as _, Window, canvas,
div, relative,
}; };
use gpui_native_theme::{ActiveTheme as _, Size}; use gpui_native_theme::{ActiveTheme as _, Size};
use gpui_native_utils::focus_ring; use gpui_native_utils::focus_ring;
use crate::common::{Sizable, h_flex}; use crate::common::{Sizable, StyledExt as _, h_flex};
/// The change reporter, fired with the next value by click, drag, and arrows. /// The change reporter, fired with the next value by click, drag, and arrows.
type ChangeHandler = Rc<dyn Fn(f32, &mut Window, &mut App)>; type ChangeHandler = Rc<dyn Fn(f32, &mut Window, &mut App)>;
@@ -46,6 +47,7 @@ pub struct Slider {
disabled: bool, disabled: bool,
a11y_label: Option<SharedString>, a11y_label: Option<SharedString>,
on_change: Option<ChangeHandler>, on_change: Option<ChangeHandler>,
style: StyleRefinement,
} }
impl Slider { impl Slider {
@@ -64,6 +66,7 @@ impl Slider {
disabled: false, disabled: false,
a11y_label: None, a11y_label: None,
on_change: None, on_change: None,
style: StyleRefinement::default(),
} }
} }
@@ -110,6 +113,12 @@ impl Slider {
} }
} }
impl gpui::Styled for Slider {
fn style(&mut self) -> &mut StyleRefinement {
&mut self.style
}
}
impl Sizable for Slider { impl Sizable for Slider {
fn apply_size(&mut self, size: Size) { fn apply_size(&mut self, size: Size) {
self.size = size; self.size = size;
@@ -169,6 +178,7 @@ impl RenderOnce for Slider {
.relative() .relative()
.w_full() .w_full()
.h(row_height) .h(row_height)
.refine_style(&self.style)
.role(Role::Slider) .role(Role::Slider)
.when_some(self.a11y_label.clone(), |slider, label| { .when_some(self.a11y_label.clone(), |slider, label| {
slider.aria_label(label) slider.aria_label(label)
+11 -2
View File
@@ -15,8 +15,8 @@ use std::sync::{Arc, Mutex};
use gpui::prelude::FluentBuilder as _; use gpui::prelude::FluentBuilder as _;
use gpui::{ use gpui::{
App, Context, ElementId, Entity, EventEmitter, InteractiveElement as _, IntoElement, App, Context, ElementId, Entity, EventEmitter, InteractiveElement as _, IntoElement,
ParentElement as _, RenderOnce, Role, SharedString, StatefulInteractiveElement as _, Styled, ParentElement as _, RenderOnce, Role, SharedString, StatefulInteractiveElement as _,
Subscription, Task, WeakEntity, Window, div, relative, StyleRefinement, Styled, Subscription, Task, WeakEntity, Window, div, relative,
}; };
use gpui_native_icons::{IconRole, icon}; use gpui_native_icons::{IconRole, icon};
use gpui_native_theme::{ActiveTheme as _, BORDER_WIDTH, Size}; use gpui_native_theme::{ActiveTheme as _, BORDER_WIDTH, Size};
@@ -654,6 +654,7 @@ pub struct SpeechButton {
size: Size, size: Size,
disabled: bool, disabled: bool,
show_when_unsupported: bool, show_when_unsupported: bool,
style: StyleRefinement,
} }
impl SpeechButton { impl SpeechButton {
@@ -664,6 +665,7 @@ impl SpeechButton {
size: Size::default(), size: Size::default(),
disabled: false, disabled: false,
show_when_unsupported: false, show_when_unsupported: false,
style: StyleRefinement::default(),
} }
} }
@@ -680,6 +682,12 @@ impl SpeechButton {
} }
} }
impl gpui::Styled for SpeechButton {
fn style(&mut self) -> &mut StyleRefinement {
&mut self.style
}
}
impl Sizable for SpeechButton { impl Sizable for SpeechButton {
fn apply_size(&mut self, size: Size) { fn apply_size(&mut self, size: Size) {
self.size = size; self.size = size;
@@ -741,6 +749,7 @@ impl RenderOnce for SpeechButton {
.rounded(theme.radius.control) .rounded(theme.radius.control)
.text_color(foreground) .text_color(foreground)
.when(capturing, |button| button.bg(colors.muted)) .when(capturing, |button| button.bg(colors.muted))
.refine_style(&self.style)
.when(disabled, |button| button.opacity(0.5)) .when(disabled, |button| button.opacity(0.5))
.aria_label(label.clone()) .aria_label(label.clone())
.tooltip(Tooltip::text(label)) .tooltip(Tooltip::text(label))
+12 -3
View File
@@ -8,13 +8,13 @@ use gpui::prelude::FluentBuilder as _;
use gpui::{ use gpui::{
Animation, AnimationElement, AnimationExt as _, App, Canvas, ElementId, Hsla, Animation, AnimationElement, AnimationExt as _, App, Canvas, ElementId, Hsla,
InteractiveElement as _, IntoElement, ParentElement as _, Path, PathBuilder, Pixels, Point, InteractiveElement as _, IntoElement, ParentElement as _, Path, PathBuilder, Pixels, Point,
RenderOnce, Role, SharedString, StatefulInteractiveElement as _, Styled as _, Window, canvas, RenderOnce, Role, SharedString, StatefulInteractiveElement as _, StyleRefinement, Styled as _,
div, point, px, Window, canvas, div, point, px,
}; };
use gpui_native_icons::{Icon, IconRole, icon}; use gpui_native_icons::{Icon, IconRole, icon};
use gpui_native_theme::{ActiveTheme as _, SPINNER_PERIOD, Size}; use gpui_native_theme::{ActiveTheme as _, SPINNER_PERIOD, Size};
use crate::common::Sizable; use crate::common::{Sizable, StyledExt as _};
/// The share of the circle the spinning arc paints. /// The share of the circle the spinning arc paints.
const SPIN_SWEEP: f32 = 0.75; const SPIN_SWEEP: f32 = 0.75;
@@ -41,6 +41,7 @@ pub struct Spinner {
size: Size, size: Size,
color: Option<Hsla>, color: Option<Hsla>,
a11y_label: Option<SharedString>, a11y_label: Option<SharedString>,
style: StyleRefinement,
} }
impl Spinner { impl Spinner {
@@ -56,6 +57,7 @@ impl Spinner {
size: Size::default(), size: Size::default(),
color: None, color: None,
a11y_label: None, a11y_label: None,
style: StyleRefinement::default(),
} }
} }
@@ -87,6 +89,12 @@ impl Spinner {
} }
} }
impl gpui::Styled for Spinner {
fn style(&mut self) -> &mut StyleRefinement {
&mut self.style
}
}
impl Sizable for Spinner { impl Sizable for Spinner {
fn apply_size(&mut self, size: Size) { fn apply_size(&mut self, size: Size) {
self.size = size; self.size = size;
@@ -106,6 +114,7 @@ impl RenderOnce for Spinner {
.id(self.id) .id(self.id)
.flex_none() .flex_none()
.size(side) .size(side)
.refine_style(&self.style)
.role(Role::ProgressIndicator) .role(Role::ProgressIndicator)
.when_some(self.a11y_label, |spinner, label| spinner.aria_label(label)) .when_some(self.a11y_label, |spinner, label| spinner.aria_label(label))
.when_some(value, |spinner, value| { .when_some(value, |spinner, value| {
+12 -3
View File
@@ -3,13 +3,13 @@
use gpui::prelude::FluentBuilder as _; use gpui::prelude::FluentBuilder as _;
use gpui::{ use gpui::{
AnimationExt as _, App, ElementId, InteractiveElement as _, IntoElement, ParentElement as _, AnimationExt as _, App, ElementId, InteractiveElement as _, IntoElement, ParentElement as _,
RenderOnce, Role, SharedString, SpringAnimation, StatefulInteractiveElement as _, Styled as _, RenderOnce, Role, SharedString, SpringAnimation, StatefulInteractiveElement as _,
Toggled, Window, div, px, StyleRefinement, Styled as _, Toggled, Window, div, px,
}; };
use gpui_native_theme::{ActiveTheme as _, CONTROL_SPRING, Size}; use gpui_native_theme::{ActiveTheme as _, CONTROL_SPRING, Size};
use gpui_native_utils::focus_ring; use gpui_native_utils::focus_ring;
use crate::common::{Sizable, h_flex}; use crate::common::{Sizable, StyledExt as _, h_flex};
/// The change reporter, fired with the next value by pointer, Enter, and Space. /// The change reporter, fired with the next value by pointer, Enter, and Space.
type ChangeHandler = Box<dyn Fn(bool, &mut Window, &mut App)>; type ChangeHandler = Box<dyn Fn(bool, &mut Window, &mut App)>;
@@ -25,6 +25,7 @@ pub struct Switch {
disabled: bool, disabled: bool,
a11y_label: Option<SharedString>, a11y_label: Option<SharedString>,
on_change: Option<ChangeHandler>, on_change: Option<ChangeHandler>,
style: StyleRefinement,
} }
impl Switch { impl Switch {
@@ -41,6 +42,7 @@ impl Switch {
disabled: false, disabled: false,
a11y_label: None, a11y_label: None,
on_change: None, on_change: None,
style: StyleRefinement::default(),
} }
} }
@@ -84,6 +86,12 @@ impl Switch {
} }
} }
impl gpui::Styled for Switch {
fn style(&mut self) -> &mut StyleRefinement {
&mut self.style
}
}
impl Sizable for Switch { impl Sizable for Switch {
fn apply_size(&mut self, size: Size) { fn apply_size(&mut self, size: Size) {
self.size = size; self.size = size;
@@ -116,6 +124,7 @@ impl RenderOnce for Switch {
.id(self.id) .id(self.id)
.gap_1p5() .gap_1p5()
.text_size(metrics.text_size) .text_size(metrics.text_size)
.refine_style(&self.style)
.role(Role::Switch) .role(Role::Switch)
.when_some(a11y_label, |switch, label| switch.aria_label(label)) .when_some(a11y_label, |switch, label| switch.aria_label(label))
.aria_toggled(Toggled::from(self.checked)) .aria_toggled(Toggled::from(self.checked))
+6 -2
View File
@@ -7,14 +7,15 @@ use gpui::prelude::FluentBuilder;
use gpui::{ use gpui::{
Animation, AnimationExt as _, App, Context, ElementId, Entity, InteractiveElement as _, Animation, AnimationExt as _, App, Context, ElementId, Entity, InteractiveElement as _,
IntoElement, ParentElement as _, RenderOnce, Role, SharedString, IntoElement, ParentElement as _, RenderOnce, Role, SharedString,
StatefulInteractiveElement as _, Styled as _, Task, Window, deferred, div, ease_out_quint, px, StatefulInteractiveElement as _, StyleRefinement, Styled as _, Task, Window, deferred, div,
ease_out_quint, px,
}; };
use gpui_native_icons::{Icon, IconRole}; use gpui_native_icons::{Icon, IconRole};
use gpui_native_theme::{ActiveTheme as _, TOAST_MAX_WIDTH}; use gpui_native_theme::{ActiveTheme as _, TOAST_MAX_WIDTH};
use gpui_native_utils::ResultLogErr as _; use gpui_native_utils::ResultLogErr as _;
use crate::button::{Button, ButtonVariant}; use crate::button::{Button, ButtonVariant};
use crate::common::{DismissHandler, Sizable as _, TOAST_LAYER}; use crate::common::{DismissHandler, Sizable as _, StyledExt as _, TOAST_LAYER};
/// The action handler of a [`Toast`]. /// The action handler of a [`Toast`].
pub type ActionHandler = Rc<dyn Fn(&mut App)>; pub type ActionHandler = Rc<dyn Fn(&mut App)>;
@@ -49,6 +50,7 @@ pub struct Toast {
action: Option<ToastAction>, action: Option<ToastAction>,
duration: Option<Duration>, duration: Option<Duration>,
on_dismiss: Option<DismissHandler>, on_dismiss: Option<DismissHandler>,
style: StyleRefinement,
} }
impl Toast { impl Toast {
@@ -66,6 +68,7 @@ impl Toast {
action: None, action: None,
duration: Some(Self::DURATION), duration: Some(Self::DURATION),
on_dismiss: None, on_dismiss: None,
style: StyleRefinement::default(),
} }
} }
@@ -300,6 +303,7 @@ impl ToastEntry {
.border_color(border) .border_color(border)
.rounded(radius) .rounded(radius)
.shadow(shadows.clone()) .shadow(shadows.clone())
.refine_style(&toast.style)
.when_some(toast.icon.clone(), |pill, icon| { .when_some(toast.icon.clone(), |pill, icon| {
pill.child( pill.child(
div() div()
+11 -2
View File
@@ -1,12 +1,12 @@
use gpui::prelude::FluentBuilder as _; use gpui::prelude::FluentBuilder as _;
use gpui::{ use gpui::{
App, ElementId, InteractiveElement as _, IntoElement, ParentElement as _, RenderOnce, Role, App, ElementId, InteractiveElement as _, IntoElement, ParentElement as _, RenderOnce, Role,
SharedString, StatefulInteractiveElement as _, Styled as _, Toggled, Window, SharedString, StatefulInteractiveElement as _, StyleRefinement, Styled as _, Toggled, Window,
}; };
use gpui_native_theme::{ActiveTheme as _, Size}; use gpui_native_theme::{ActiveTheme as _, Size};
use gpui_native_utils::focus_ring; use gpui_native_utils::focus_ring;
use crate::common::{Sizable, h_flex}; use crate::common::{Sizable, StyledExt as _, h_flex};
/// The change handler, fired with the next pressed state. /// The change handler, fired with the next pressed state.
type ChangeHandler = Box<dyn Fn(bool, &mut Window, &mut App)>; type ChangeHandler = Box<dyn Fn(bool, &mut Window, &mut App)>;
@@ -22,6 +22,7 @@ pub struct Toggle {
disabled: bool, disabled: bool,
a11y_label: Option<SharedString>, a11y_label: Option<SharedString>,
on_change: Option<ChangeHandler>, on_change: Option<ChangeHandler>,
style: StyleRefinement,
} }
impl Toggle { impl Toggle {
@@ -38,6 +39,7 @@ impl Toggle {
disabled: false, disabled: false,
a11y_label: None, a11y_label: None,
on_change: None, on_change: None,
style: StyleRefinement::default(),
} }
} }
@@ -81,6 +83,12 @@ impl Toggle {
} }
} }
impl gpui::Styled for Toggle {
fn style(&mut self) -> &mut StyleRefinement {
&mut self.style
}
}
impl Sizable for Toggle { impl Sizable for Toggle {
fn apply_size(&mut self, size: Size) { fn apply_size(&mut self, size: Size) {
self.size = size; self.size = size;
@@ -118,6 +126,7 @@ impl RenderOnce for Toggle {
.hover(|style| style.bg(colors.muted)) .hover(|style| style.bg(colors.muted))
.active(|style| style.bg(ramps.secondary.hover)) .active(|style| style.bg(ramps.secondary.hover))
}) })
.refine_style(&self.style)
.when(self.disabled, |toggle| toggle.opacity(0.5)) .when(self.disabled, |toggle| toggle.opacity(0.5))
.when(!self.disabled, |toggle| { .when(!self.disabled, |toggle| {
toggle toggle
+11 -2
View File
@@ -4,11 +4,11 @@ use gpui::prelude::FluentBuilder;
use gpui::{ use gpui::{
AnyElement, App, ElementId, FocusHandle, InteractiveElement as _, IntoElement, KeyDownEvent, AnyElement, App, ElementId, FocusHandle, InteractiveElement as _, IntoElement, KeyDownEvent,
ParentElement as _, RenderOnce, Role, SharedString, StatefulInteractiveElement as _, ParentElement as _, RenderOnce, Role, SharedString, StatefulInteractiveElement as _,
Styled as _, Window, div, StyleRefinement, Styled as _, Window, div,
}; };
use gpui_native_icons::Icon; use gpui_native_icons::Icon;
use gpui_native_theme::{ActiveTheme as _, TextRole, Typeset as _}; use gpui_native_theme::{ActiveTheme as _, TextRole, Typeset as _};
use gpui_native_utils::{nav_key, paint_selectable_row, selectable_label_color}; use gpui_native_utils::{StyledExt as _, nav_key, paint_selectable_row, selectable_label_color};
/// The change reporter, fired with the next selection by pointer and keys. /// The change reporter, fired with the next selection by pointer and keys.
type ChangeHandler = Rc<dyn Fn(Option<usize>, &mut Window, &mut App)>; type ChangeHandler = Rc<dyn Fn(Option<usize>, &mut Window, &mut App)>;
@@ -77,6 +77,7 @@ pub struct List {
a11y_label: Option<SharedString>, a11y_label: Option<SharedString>,
on_change: Option<ChangeHandler>, on_change: Option<ChangeHandler>,
items: Option<ItemsFn>, items: Option<ItemsFn>,
style: StyleRefinement,
} }
impl List { impl List {
@@ -91,6 +92,7 @@ impl List {
a11y_label: None, a11y_label: None,
on_change: None, on_change: None,
items: None, items: None,
style: StyleRefinement::default(),
} }
} }
@@ -128,6 +130,12 @@ impl List {
} }
} }
impl gpui::Styled for List {
fn style(&mut self) -> &mut StyleRefinement {
&mut self.style
}
}
impl RenderOnce for List { impl RenderOnce for List {
fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement { fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
let items = match self.items { let items = match self.items {
@@ -171,6 +179,7 @@ impl RenderOnce for List {
.flex_col() .flex_col()
.gap_0p5() .gap_0p5()
.text_size(theme.sizes.medium.text_size) .text_size(theme.sizes.medium.text_size)
.refine_style(&self.style)
.track_focus(&focus) .track_focus(&focus)
.focusable() .focusable()
.tab_stop(true) .tab_stop(true)
+12 -2
View File
@@ -8,12 +8,12 @@ use gpui::prelude::FluentBuilder;
use gpui::{ use gpui::{
AnyElement, App, ElementId, FocusHandle, InteractiveElement as _, IntoElement, KeyDownEvent, AnyElement, App, ElementId, FocusHandle, InteractiveElement as _, IntoElement, KeyDownEvent,
ParentElement as _, Pixels, RenderOnce, Role, SharedString, StatefulInteractiveElement as _, ParentElement as _, Pixels, RenderOnce, Role, SharedString, StatefulInteractiveElement as _,
Styled as _, Window, div, px, StyleRefinement, Styled as _, Window, div, px,
}; };
use gpui_native_core::grain::grain as grain_overlay; use gpui_native_core::grain::grain as grain_overlay;
use gpui_native_core::scroll_area::ScrollArea; use gpui_native_core::scroll_area::ScrollArea;
use gpui_native_theme::{ActiveTheme as _, BORDER_WIDTH, TextRole, Typeset as _}; use gpui_native_theme::{ActiveTheme as _, BORDER_WIDTH, TextRole, Typeset as _};
use gpui_native_utils::{nav_key, paint_selectable_row, selectable_label_color}; use gpui_native_utils::{StyledExt as _, nav_key, paint_selectable_row, selectable_label_color};
/// The change reporter, fired with the next selected row by pointer and keys. /// The change reporter, fired with the next selected row by pointer and keys.
type ChangeHandler = Rc<dyn Fn(Option<usize>, &mut Window, &mut App)>; type ChangeHandler = Rc<dyn Fn(Option<usize>, &mut Window, &mut App)>;
@@ -144,6 +144,7 @@ pub struct Sidebar {
a11y_label: Option<SharedString>, a11y_label: Option<SharedString>,
on_change: Option<ChangeHandler>, on_change: Option<ChangeHandler>,
entries: Option<EntriesFn>, entries: Option<EntriesFn>,
style: StyleRefinement,
} }
impl Sidebar { impl Sidebar {
@@ -163,6 +164,7 @@ impl Sidebar {
a11y_label: None, a11y_label: None,
on_change: None, on_change: None,
entries: None, entries: None,
style: StyleRefinement::default(),
} }
} }
@@ -249,6 +251,12 @@ impl Sidebar {
} }
} }
impl gpui::Styled for Sidebar {
fn style(&mut self) -> &mut StyleRefinement {
&mut self.style
}
}
impl RenderOnce for Sidebar { impl RenderOnce for Sidebar {
fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement { fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
let Self { let Self {
@@ -262,6 +270,7 @@ impl RenderOnce for Sidebar {
a11y_label, a11y_label,
on_change, on_change,
entries, entries,
style,
} = self; } = self;
let label = a11y_label.unwrap_or_else(|| SharedString::from(id.to_string())); let label = a11y_label.unwrap_or_else(|| SharedString::from(id.to_string()));
@@ -379,6 +388,7 @@ impl RenderOnce for Sidebar {
} }
}) })
.text_size(theme.sizes.medium.text_size) .text_size(theme.sizes.medium.text_size)
.refine_style(&style)
.when(border_right, |sidebar| { .when(border_right, |sidebar| {
sidebar sidebar
.border_r(BORDER_WIDTH) .border_r(BORDER_WIDTH)
+11 -2
View File
@@ -7,7 +7,7 @@ use gpui::{
AnyElement, App, AppContext as _, Bounds, ClickEvent, Context, Div, ElementId, Global, AnyElement, App, AppContext as _, Bounds, ClickEvent, Context, Div, ElementId, Global,
InteractiveElement as _, IntoElement, KeyDownEvent, MouseButton, ParentElement as _, Pixels, InteractiveElement as _, IntoElement, KeyDownEvent, MouseButton, ParentElement as _, Pixels,
Point, Render, RenderOnce, Role, SharedString, Stateful, StatefulInteractiveElement as _, Point, Render, RenderOnce, Role, SharedString, Stateful, StatefulInteractiveElement as _,
Styled as _, Window, canvas, div, px, relative, StyleRefinement, Styled as _, Window, canvas, div, px, relative,
}; };
use gpui_native_core::button::{Button, ButtonVariant}; use gpui_native_core::button::{Button, ButtonVariant};
use gpui_native_core::common::{Sizable as _, v_flex}; use gpui_native_core::common::{Sizable as _, v_flex};
@@ -17,7 +17,7 @@ use gpui_native_core::spinner::Spinner;
use gpui_native_core::tooltip::Tooltip; use gpui_native_core::tooltip::Tooltip;
use gpui_native_icons::IconRole; use gpui_native_icons::IconRole;
use gpui_native_theme::{ActiveTheme as _, POPUP_MAX_HEIGHT, Size}; use gpui_native_theme::{ActiveTheme as _, POPUP_MAX_HEIGHT, Size};
use gpui_native_utils::adjacent_selectable; use gpui_native_utils::{StyledExt as _, adjacent_selectable};
/// Reports the next selected tab by pointer and keys. /// Reports the next selected tab by pointer and keys.
type ChangeHandler = Rc<dyn Fn(usize, &mut Window, &mut App)>; type ChangeHandler = Rc<dyn Fn(usize, &mut Window, &mut App)>;
@@ -315,6 +315,7 @@ pub struct Tabs {
on_reorder: Option<ReorderHandler>, on_reorder: Option<ReorderHandler>,
on_overflow_open: Option<OpenHandler>, on_overflow_open: Option<OpenHandler>,
tabs: Option<TabsFn>, tabs: Option<TabsFn>,
style: StyleRefinement,
} }
impl Tabs { impl Tabs {
@@ -337,6 +338,7 @@ impl Tabs {
on_reorder: None, on_reorder: None,
on_overflow_open: None, on_overflow_open: None,
tabs: None, tabs: None,
style: StyleRefinement::default(),
} }
} }
@@ -713,6 +715,12 @@ impl Tabs {
} }
} }
impl gpui::Styled for Tabs {
fn style(&mut self) -> &mut StyleRefinement {
&mut self.style
}
}
impl RenderOnce for Tabs { impl RenderOnce for Tabs {
fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement { fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
let tabs = match self.tabs { let tabs = match self.tabs {
@@ -820,6 +828,7 @@ impl RenderOnce for Tabs {
.id(self.id.clone()) .id(self.id.clone())
.flex() .flex()
.text_size(medium_text_size) .text_size(medium_text_size)
.refine_style(&self.style)
.track_focus(&focus) .track_focus(&focus)
.focusable() .focusable()
.tab_stop(true) .tab_stop(true)
+11 -2
View File
@@ -4,11 +4,11 @@ use gpui::prelude::FluentBuilder;
use gpui::{ use gpui::{
AnyElement, App, ElementId, FocusHandle, InteractiveElement as _, IntoElement, KeyDownEvent, AnyElement, App, ElementId, FocusHandle, InteractiveElement as _, IntoElement, KeyDownEvent,
ParentElement as _, RenderOnce, Role, SharedString, StatefulInteractiveElement as _, ParentElement as _, RenderOnce, Role, SharedString, StatefulInteractiveElement as _,
Styled as _, Window, div, StyleRefinement, Styled as _, Window, div,
}; };
use gpui_native_icons::{Icon, IconRole, icon}; use gpui_native_icons::{Icon, IconRole, icon};
use gpui_native_theme::ActiveTheme as _; use gpui_native_theme::ActiveTheme as _;
use gpui_native_utils::{nav_key, paint_selectable_row, selectable_label_color}; use gpui_native_utils::{StyledExt as _, nav_key, paint_selectable_row, selectable_label_color};
/// The change reporter, fired with the next selection by pointer and keys. /// The change reporter, fired with the next selection by pointer and keys.
type ChangeHandler = Rc<dyn Fn(Option<usize>, &mut Window, &mut App)>; type ChangeHandler = Rc<dyn Fn(Option<usize>, &mut Window, &mut App)>;
@@ -94,6 +94,7 @@ pub struct Tree {
on_change: Option<ChangeHandler>, on_change: Option<ChangeHandler>,
on_disclosure: Option<DisclosureHandler>, on_disclosure: Option<DisclosureHandler>,
items: Option<ItemsFn>, items: Option<ItemsFn>,
style: StyleRefinement,
} }
impl Tree { impl Tree {
@@ -109,6 +110,7 @@ impl Tree {
on_change: None, on_change: None,
on_disclosure: None, on_disclosure: None,
items: None, items: None,
style: StyleRefinement::default(),
} }
} }
@@ -210,6 +212,12 @@ impl Tree {
} }
} }
impl gpui::Styled for Tree {
fn style(&mut self) -> &mut StyleRefinement {
&mut self.style
}
}
impl RenderOnce for Tree { impl RenderOnce for Tree {
fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement { fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
let items = match self.items { let items = match self.items {
@@ -258,6 +266,7 @@ impl RenderOnce for Tree {
.flex_col() .flex_col()
.gap_0p5() .gap_0p5()
.text_size(theme.sizes.medium.text_size) .text_size(theme.sizes.medium.text_size)
.refine_style(&self.style)
.track_focus(&focus) .track_focus(&focus)
.focusable() .focusable()
.tab_stop(true) .tab_stop(true)
+17 -1
View File
@@ -10,6 +10,7 @@ use gpui::{
Render, RenderOnce, SharedString, StyleRefinement, Styled as _, Window, div, rems, Render, RenderOnce, SharedString, StyleRefinement, Styled as _, Window, div, rems,
}; };
use gpui_native_theme::ActiveTheme as _; use gpui_native_theme::ActiveTheme as _;
use gpui_native_utils::StyledExt as _;
use crate::resizable::{Resizable, ResizableState}; use crate::resizable::{Resizable, ResizableState};
@@ -80,6 +81,7 @@ pub struct PanelRow {
id: ElementId, id: ElementId,
main: Option<AnyElement>, main: Option<AnyElement>,
split: Option<AnyElement>, split: Option<AnyElement>,
style: StyleRefinement,
} }
impl PanelRow { impl PanelRow {
@@ -92,6 +94,7 @@ impl PanelRow {
id: id.into(), id: id.into(),
main: None, main: None,
split: None, split: None,
style: StyleRefinement::default(),
} }
} }
@@ -114,6 +117,12 @@ impl PanelRow {
} }
} }
impl gpui::Styled for PanelRow {
fn style(&mut self) -> &mut StyleRefinement {
&mut self.style
}
}
impl RenderOnce for PanelRow { impl RenderOnce for PanelRow {
fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement { fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
let id = self.id.clone(); let id = self.id.clone();
@@ -152,6 +161,13 @@ impl RenderOnce for PanelRow {
None => div().w_full().h_full().child(main), None => div().w_full().h_full().child(main),
}; };
div().flex_1().min_w_0().h_full().p_2().pt_1().child(row) div()
.flex_1()
.min_w_0()
.h_full()
.p_2()
.pt_1()
.refine_style(&self.style)
.child(row)
} }
} }
+12 -3
View File
@@ -8,11 +8,11 @@ use gpui::{
App, Axis, Bounds, CursorStyle, DispatchPhase, ElementId, HitboxBehavior, App, Axis, Bounds, CursorStyle, DispatchPhase, ElementId, HitboxBehavior,
InteractiveElement as _, IntoElement, KeyDownEvent, MouseButton, MouseDownEvent, InteractiveElement as _, IntoElement, KeyDownEvent, MouseButton, MouseDownEvent,
MouseMoveEvent, MouseUpEvent, ParentElement as _, Pixels, Point, RenderOnce, Role, MouseMoveEvent, MouseUpEvent, ParentElement as _, Pixels, Point, RenderOnce, Role,
SharedString, StatefulInteractiveElement as _, Styled as _, Window, canvas, deferred, div, SharedString, StatefulInteractiveElement as _, StyleRefinement, Styled as _, Window, canvas,
fill, point, px, rems, deferred, div, fill, point, px, rems,
}; };
use gpui_native_theme::{ActiveTheme as _, BORDER_WIDTH, HAIRLINE_WIDTH, RESIZE_KEYBOARD_STEP}; use gpui_native_theme::{ActiveTheme as _, BORDER_WIDTH, HAIRLINE_WIDTH, RESIZE_KEYBOARD_STEP};
use gpui_native_utils::{focus_handle, focus_ring}; use gpui_native_utils::{StyledExt as _, focus_handle, focus_ring};
/// How far one keyboard arrow step moves the seam. /// How far one keyboard arrow step moves the seam.
const KEYBOARD_STEP: Pixels = RESIZE_KEYBOARD_STEP; const KEYBOARD_STEP: Pixels = RESIZE_KEYBOARD_STEP;
@@ -38,6 +38,7 @@ pub struct ResizeHandle {
accessibility_label: Option<SharedString>, accessibility_label: Option<SharedString>,
on_resize: Option<ResizeHandler>, on_resize: Option<ResizeHandler>,
on_reset: Option<ResetHandler>, on_reset: Option<ResetHandler>,
style: StyleRefinement,
} }
impl ResizeHandle { impl ResizeHandle {
@@ -53,6 +54,7 @@ impl ResizeHandle {
accessibility_label: None, accessibility_label: None,
on_resize: None, on_resize: None,
on_reset: None, on_reset: None,
style: StyleRefinement::default(),
} }
} }
@@ -96,6 +98,12 @@ impl ResizeHandle {
} }
} }
impl gpui::Styled for ResizeHandle {
fn style(&mut self) -> &mut StyleRefinement {
&mut self.style
}
}
impl RenderOnce for ResizeHandle { impl RenderOnce for ResizeHandle {
fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement { fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
let theme = cx.theme(); let theme = cx.theme();
@@ -141,6 +149,7 @@ impl RenderOnce for ResizeHandle {
.when(axis == Axis::Vertical, |handle| { .when(axis == Axis::Vertical, |handle| {
handle.w_full().h(thickness) handle.w_full().h(thickness)
}) })
.refine_style(&self.style)
.when(self.disabled, |handle| handle.opacity(0.5)) .when(self.disabled, |handle| handle.opacity(0.5))
.when(!self.disabled, |handle| { .when(!self.disabled, |handle| {
handle handle
+12 -3
View File
@@ -4,8 +4,8 @@
use gpui::prelude::FluentBuilder as _; use gpui::prelude::FluentBuilder as _;
use gpui::{ use gpui::{
AnyElement, App, ElementId, Entity, IntoElement, ParentElement as _, RenderOnce, Styled as _, AnyElement, App, ElementId, Entity, IntoElement, ParentElement as _, RenderOnce,
Window, div, StyleRefinement, Styled as _, Window, div,
}; };
#[cfg(feature = "alert")] #[cfg(feature = "alert")]
use gpui_native_core::alert::{Alerts, AlertsView}; use gpui_native_core::alert::{Alerts, AlertsView};
@@ -13,7 +13,7 @@ use gpui_native_core::grain::grain as grain_overlay;
#[cfg(feature = "toast")] #[cfg(feature = "toast")]
use gpui_native_core::toast::{Toasts, ToastsView}; use gpui_native_core::toast::{Toasts, ToastsView};
use gpui_native_theme::ActiveTheme as _; use gpui_native_theme::ActiveTheme as _;
use gpui_native_utils::v_flex; use gpui_native_utils::{StyledExt as _, v_flex};
use crate::titlebar::Titlebar; use crate::titlebar::Titlebar;
use crate::window_frame::frame; use crate::window_frame::frame;
@@ -31,6 +31,7 @@ pub struct Shell {
toasts: Option<Entity<Toasts>>, toasts: Option<Entity<Toasts>>,
#[cfg(feature = "alert")] #[cfg(feature = "alert")]
alerts: Option<Entity<Alerts>>, alerts: Option<Entity<Alerts>>,
style: StyleRefinement,
} }
impl Shell { impl Shell {
@@ -49,6 +50,7 @@ impl Shell {
toasts: None, toasts: None,
#[cfg(feature = "alert")] #[cfg(feature = "alert")]
alerts: None, alerts: None,
style: StyleRefinement::default(),
} }
} }
@@ -94,6 +96,12 @@ impl Shell {
} }
} }
impl gpui::Styled for Shell {
fn style(&mut self) -> &mut StyleRefinement {
&mut self.style
}
}
impl RenderOnce for Shell { impl RenderOnce for Shell {
fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement { fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
let id = self.id.clone(); let id = self.id.clone();
@@ -110,6 +118,7 @@ impl RenderOnce for Shell {
.h_full() .h_full()
.overflow_hidden() .overflow_hidden()
.bg(background) .bg(background)
.refine_style(&self.style)
.when(self.transparent && self.grain, |layout| { .when(self.transparent && self.grain, |layout| {
layout.child(grain_overlay()) layout.child(grain_overlay())
}); });
+11 -2
View File
@@ -7,10 +7,10 @@
use gpui::prelude::FluentBuilder as _; use gpui::prelude::FluentBuilder as _;
use gpui::{ use gpui::{
AnyElement, App, ElementId, InteractiveElement as _, IntoElement, ParentElement, RenderOnce, AnyElement, App, ElementId, InteractiveElement as _, IntoElement, ParentElement, RenderOnce,
SharedString, Styled as _, Window, SharedString, StyleRefinement, Styled as _, Window,
}; };
use gpui_native_theme::{ActiveTheme as _, Size, TRAFFIC_LIGHT_PAD}; use gpui_native_theme::{ActiveTheme as _, Size, TRAFFIC_LIGHT_PAD};
use gpui_native_utils::h_flex; use gpui_native_utils::{StyledExt as _, h_flex};
use crate::window_controls::{WindowControls, titlebar_strip}; use crate::window_controls::{WindowControls, titlebar_strip};
@@ -23,6 +23,7 @@ pub struct Titlebar {
tab_bar: Option<AnyElement>, tab_bar: Option<AnyElement>,
suffix: Vec<AnyElement>, suffix: Vec<AnyElement>,
transparent: bool, transparent: bool,
style: StyleRefinement,
} }
impl Titlebar { impl Titlebar {
@@ -37,6 +38,7 @@ impl Titlebar {
tab_bar: None, tab_bar: None,
suffix: Vec::new(), suffix: Vec::new(),
transparent: false, transparent: false,
style: StyleRefinement::default(),
} }
} }
@@ -66,6 +68,12 @@ impl Titlebar {
} }
} }
impl gpui::Styled for Titlebar {
fn style(&mut self) -> &mut StyleRefinement {
&mut self.style
}
}
impl ParentElement for Titlebar { impl ParentElement for Titlebar {
fn extend(&mut self, elements: impl IntoIterator<Item = AnyElement>) { fn extend(&mut self, elements: impl IntoIterator<Item = AnyElement>) {
self.prefix.extend(elements); self.prefix.extend(elements);
@@ -91,6 +99,7 @@ impl RenderOnce for Titlebar {
.gap_2() .gap_2()
.when(!self.transparent, |bar| bar.bg(theme.colors.muted)) .when(!self.transparent, |bar| bar.bg(theme.colors.muted))
.px(padding_x) .px(padding_x)
.refine_style(&self.style)
.when(cfg!(target_os = "macos"), |bar| bar.pl(TRAFFIC_LIGHT_PAD)) .when(cfg!(target_os = "macos"), |bar| bar.pl(TRAFFIC_LIGHT_PAD))
.when(!self.prefix.is_empty(), |bar| { .when(!self.prefix.is_empty(), |bar| {
bar.child( bar.child(