From 745a01d7af41ba656c5d2f6f633482e51cb6fd5c Mon Sep 17 00:00:00 2001 From: Ren Amamiya Date: Mon, 16 Nov 2026 14:02:33 +0700 Subject: [PATCH] utils: add shared StyledExt styling helper --- crates/core/src/alert.rs | 22 +++++++++++++++++----- crates/core/src/button.rs | 15 ++++++++++++--- crates/core/src/checkbox.rs | 13 +++++++++++-- crates/core/src/clipboard.rs | 9 ++++++--- crates/core/src/command_palette.rs | 11 ++++++++--- crates/core/src/context_menu.rs | 6 +++++- crates/core/src/dialog.rs | 15 ++++++++++++--- crates/core/src/dropdown_menu.rs | 14 ++++++++++++-- crates/core/src/input.rs | 15 ++++++++++++--- crates/core/src/link.rs | 14 ++++++++++++-- crates/core/src/menu.rs | 15 ++++++++++++--- crates/core/src/popover.rs | 13 +++++++++++-- crates/core/src/progress.rs | 13 +++++++++++-- crates/core/src/radio.rs | 17 +++++++++++++++-- crates/core/src/separator.rs | 16 +++++++++++++++- crates/core/src/slider.rs | 14 ++++++++++++-- crates/core/src/speech.rs | 13 +++++++++++-- crates/core/src/spinner.rs | 15 ++++++++++++--- crates/core/src/switch.rs | 15 ++++++++++++--- crates/core/src/toast.rs | 8 ++++++-- crates/core/src/toggle.rs | 13 +++++++++++-- crates/data/src/list.rs | 13 +++++++++++-- crates/data/src/sidebar.rs | 14 ++++++++++++-- crates/data/src/tabs.rs | 13 +++++++++++-- crates/data/src/tree.rs | 13 +++++++++++-- crates/layout/src/panel.rs | 18 +++++++++++++++++- crates/layout/src/resize_handle.rs | 15 ++++++++++++--- crates/layout/src/shell.rs | 15 ++++++++++++--- crates/layout/src/titlebar.rs | 13 +++++++++++-- 29 files changed, 332 insertions(+), 68 deletions(-) diff --git a/crates/core/src/alert.rs b/crates/core/src/alert.rs index 9ff1e87..ae6dca5 100644 --- a/crates/core/src/alert.rs +++ b/crates/core/src/alert.rs @@ -4,7 +4,8 @@ use gpui::prelude::FluentBuilder as _; use gpui::{ Animation, AnimationExt as _, App, Context, ElementId, Entity, InteractiveElement as _, 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_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::common::DismissHandler; use crate::common::Sizable as _; +use crate::common::StyledExt as _; use crate::common::TOAST_LAYER; use crate::common::v_flex; @@ -48,9 +50,10 @@ pub struct Alert { title: Option, message: Option, severity: AlertSeverity, - style: AlertStyle, + presentation: AlertStyle, icon: Option, on_dismiss: Option, + style: StyleRefinement, } impl Alert { @@ -63,9 +66,10 @@ impl Alert { title: None, message: None, severity: AlertSeverity::Info, - style: AlertStyle::default(), + presentation: AlertStyle::default(), icon: None, on_dismiss: None, + style: StyleRefinement::default(), } } @@ -95,7 +99,7 @@ impl Alert { /// Sets how the alert presents. pub fn style(mut self, style: AlertStyle) -> Self { - self.style = style; + self.presentation = style; 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 { fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement { let theme = cx.theme(); @@ -176,7 +186,7 @@ impl RenderOnce for Alert { .on_click(move |_, _window, cx| on_dismiss(cx)) }); - match self.style { + match self.presentation { AlertStyle::Overlay => { let surface = theme.colors.surface; let border = if theme.borders.overlays { @@ -199,6 +209,7 @@ impl RenderOnce for Alert { .border_1() .border_color(border) .shadow(theme.elevations.popover.shadows()) + .refine_style(&self.style) .when_some(self.icon.clone(), |alert, icon_glyph| { alert.child( div() @@ -219,6 +230,7 @@ impl RenderOnce for Alert { .flex() .overflow_hidden() .bg(ramp.subtle) + .refine_style(&self.style) .child(div().flex_none().w_1p5().self_stretch().bg(ramp.base)) .child( div() diff --git a/crates/core/src/button.rs b/crates/core/src/button.rs index 55160d6..e435da0 100644 --- a/crates/core/src/button.rs +++ b/crates/core/src/button.rs @@ -3,15 +3,15 @@ use gpui::prelude::FluentBuilder as _; use gpui::{ AnyElement, AnyView, App, ClickEvent, ElementId, InteractiveElement as _, IntoElement, - ParentElement, RenderOnce, Role, SharedString, StatefulInteractiveElement as _, Styled as _, - Window, canvas, relative, transparent_black, + ParentElement, RenderOnce, Role, SharedString, StatefulInteractiveElement as _, + StyleRefinement, Styled as _, Window, canvas, relative, transparent_black, }; use gpui_native_icons::Icon; use gpui_native_theme::{ActiveTheme as _, BORDER_WIDTH, Size}; use gpui_native_utils::{focus_ring, record_anchor_bounds}; use std::rc::Rc; -use crate::common::{Sizable, h_flex}; +use crate::common::{Sizable, StyledExt as _, h_flex}; use crate::spinner::Spinner; /// The single activation handler, shared by pointer, Enter, and Space. @@ -64,6 +64,7 @@ pub struct Button { a11y_label: Option, tooltip: Option, on_click: Option, + style: StyleRefinement, } impl Button { @@ -88,6 +89,7 @@ impl Button { a11y_label: None, tooltip: 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 { fn apply_size(&mut self, size: Size) { self.size = size; @@ -277,6 +285,7 @@ impl RenderOnce for Button { .border_color(border) .when_some(background, |button, background| button.bg(background)) .text_color(foreground) + .refine_style(&self.style) .when_some(a11y_label, |button, label| button.aria_label(label)) .child( h_flex() diff --git a/crates/core/src/checkbox.rs b/crates/core/src/checkbox.rs index ebcecb0..f8b5705 100644 --- a/crates/core/src/checkbox.rs +++ b/crates/core/src/checkbox.rs @@ -5,13 +5,13 @@ use std::rc::Rc; use gpui::prelude::FluentBuilder as _; use gpui::{ 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_theme::{ActiveTheme as _, Size}; 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. type ChangeHandler = Box; @@ -28,6 +28,7 @@ pub struct Checkbox { debug_selector: Option String>>, a11y_label: Option, on_change: Option, + style: StyleRefinement, } impl Checkbox { @@ -45,6 +46,7 @@ impl Checkbox { debug_selector: None, a11y_label: 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 { fn apply_size(&mut self, size: Size) { self.size = size; @@ -117,6 +125,7 @@ impl RenderOnce for Checkbox { .id(self.id) .gap_1p5() .text_size(metrics.text_size) + .refine_style(&self.style) .when_some(self.debug_selector, |checkbox, selector| { checkbox.debug_selector(move || selector()) }) diff --git a/crates/core/src/clipboard.rs b/crates/core/src/clipboard.rs index 4c2dc59..55056b0 100644 --- a/crates/core/src/clipboard.rs +++ b/crates/core/src/clipboard.rs @@ -5,15 +5,15 @@ use std::time::Duration; use gpui::prelude::FluentBuilder as _; use gpui::{ - AnyView, App, ClipboardItem, ElementId, Entity, IntoElement, RenderOnce, SharedString, Task, - Window, + AnyView, App, ClipboardItem, ElementId, Entity, IntoElement, RenderOnce, SharedString, + StyleRefinement, Task, Window, }; use gpui_native_icons::IconRole; use gpui_native_theme::Size; use gpui_native_utils::ResultLogErr as _; 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. pub const COPIED_DURATION: Duration = Duration::from_secs(1); @@ -35,6 +35,7 @@ pub struct ClipboardButton { a11y_label: Option, tooltip: Option, on_copied: Option, + style: StyleRefinement, } impl ClipboardButton { @@ -52,6 +53,7 @@ impl ClipboardButton { a11y_label: None, tooltip: None, on_copied: None, + style: StyleRefinement::default(), } } @@ -127,6 +129,7 @@ impl RenderOnce for ClipboardButton { .variant(ButtonVariant::Ghost) .with_size(self.size) .disabled(self.disabled) + .refine_style(&self.style) .debug_selector(move || selector.to_string()) .accessibility_label(self.a11y_label.unwrap_or_else(|| "Copy".into())) .when_some(self.tooltip, |button, tooltip| { diff --git a/crates/core/src/command_palette.rs b/crates/core/src/command_palette.rs index 267c599..5d03204 100644 --- a/crates/core/src/command_palette.rs +++ b/crates/core/src/command_palette.rs @@ -6,13 +6,13 @@ use gpui::prelude::FluentBuilder; use gpui::{ AnyElement, App, Context, ElementId, Entity, InteractiveElement as _, IntoElement, KeyBinding, MouseButton, ParentElement as _, Render, Role, ScrollHandle, SharedString, - StatefulInteractiveElement as _, Styled as _, Subscription, Window, actions, canvas, deferred, - div, relative, + StatefulInteractiveElement as _, StyleRefinement, Styled as _, Subscription, Window, actions, + canvas, deferred, div, relative, }; use gpui_native_icons::Icon; 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::scroll_area::{ScrollArea, ScrollAxes}; @@ -104,6 +104,7 @@ pub struct CommandPalette { commands: Vec, matcher: CommandMatcher, on_execute: Option, + style: StyleRefinement, } impl CommandPalette { @@ -120,6 +121,7 @@ impl CommandPalette { commands, matcher: Rc::new(matcher), on_execute: None, + style: StyleRefinement::default(), } } @@ -162,6 +164,7 @@ pub struct CommandPaletteState { commands: Vec, matcher: CommandMatcher, on_execute: Option, + style: StyleRefinement, query: Entity, /// The commands the matcher returned for the query, in display order. matches: Vec, @@ -191,6 +194,7 @@ impl CommandPaletteState { commands: palette.commands, matcher: palette.matcher, on_execute: palette.on_execute, + style: palette.style, query, matches, highlight: None, @@ -451,6 +455,7 @@ impl Render for CommandPaletteState { .border_color(panel_border) .shadow(shadows) .overflow_hidden() + .refine_style(&self.style) .on_mouse_down(MouseButton::Left, |_, _, cx| cx.stop_propagation()) .on_action({ let state = state.clone(); diff --git a/crates/core/src/context_menu.rs b/crates/core/src/context_menu.rs index 14e9f24..2ef1fb0 100644 --- a/crates/core/src/context_menu.rs +++ b/crates/core/src/context_menu.rs @@ -1,9 +1,10 @@ use gpui::prelude::FluentBuilder as _; use gpui::{ 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}; /// Builds the element that opens the menu on right-click. @@ -21,6 +22,7 @@ pub struct ContextMenu { target: Option, items: Option, a11y_label: Option, + style: StyleRefinement, } impl ContextMenu { @@ -34,6 +36,7 @@ impl ContextMenu { target: None, items: None, a11y_label: None, + style: StyleRefinement::default(), } } @@ -116,6 +119,7 @@ impl RenderOnce for ContextMenu { .trigger_button(MouseButton::Right) .trigger(trigger) .items(items) + .refine_style(&self.style) .when_some(self.a11y_label.clone(), |menu, label| { menu.accessibility_label(label) }) diff --git a/crates/core/src/dialog.rs b/crates/core/src/dialog.rs index 5f0019e..63359cd 100644 --- a/crates/core/src/dialog.rs +++ b/crates/core/src/dialog.rs @@ -4,14 +4,14 @@ use std::rc::Rc; use gpui::{ Animation, AnimationExt as _, AnyElement, App, DefiniteLength, ElementId, InteractiveElement as _, IntoElement, KeyDownEvent, MouseButton, ParentElement as _, - RenderOnce, Role, ScrollHandle, SharedString, StatefulInteractiveElement as _, Styled as _, - Window, canvas, deferred, div, ease_out_quint, relative, + RenderOnce, Role, ScrollHandle, SharedString, StatefulInteractiveElement as _, StyleRefinement, + Styled as _, Window, canvas, deferred, div, ease_out_quint, relative, }; use gpui_native_icons::IconRole; use gpui_native_theme::{ActiveTheme as _, TextRole, Typeset as _}; 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::scroll_area::ScrollArea; @@ -35,6 +35,7 @@ pub struct Dialog { actions: Option, min_width: Option, height: Option, + style: StyleRefinement, } impl Dialog { @@ -55,6 +56,7 @@ impl Dialog { actions: None, min_width: 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 { fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement { let root = div().absolute().inset_0(); @@ -307,6 +315,7 @@ impl RenderOnce for Dialog { .items_center() .justify_center() .p_4() + .refine_style(&self.style) .child(scrim.with_animation( "dialog-scrim-enter", Animation::new(enter_duration).with_easing(ease_out_quint()), diff --git a/crates/core/src/dropdown_menu.rs b/crates/core/src/dropdown_menu.rs index 40bbc52..ae2fe99 100644 --- a/crates/core/src/dropdown_menu.rs +++ b/crates/core/src/dropdown_menu.rs @@ -7,14 +7,15 @@ use gpui::prelude::FluentBuilder as _; use gpui::{ App, ClickEvent, DefiniteLength, DispatchPhase, ElementId, InteractiveElement as _, 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_theme::{ActiveTheme as _, BORDER_WIDTH, Size}; use gpui_native_utils::{focus_handle, focus_ring}; use crate::button::ButtonVariant; -use crate::common::{Sizable, h_flex}; +use crate::common::{Sizable, StyledExt as _, h_flex}; use crate::menu::{ ChangeHandler, MenuChrome, MenuItem, MenuPanelSpec, TriggerBoundsCell, anchored_menu_panel, }; @@ -42,6 +43,7 @@ pub struct DropdownMenu { on_open_change: Option, items: Option, min_width: Option, + style: StyleRefinement, } impl DropdownMenu { @@ -65,6 +67,7 @@ impl DropdownMenu { on_open_change: None, items: 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 { fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement { let theme = cx.theme(); @@ -410,6 +419,7 @@ impl RenderOnce for DropdownMenu { div() .relative() + .refine_style(&self.style) .child( canvas( { diff --git a/crates/core/src/input.rs b/crates/core/src/input.rs index dc30797..c9edfc1 100644 --- a/crates/core/src/input.rs +++ b/crates/core/src/input.rs @@ -11,8 +11,8 @@ use gpui::{ EntityInputHandler, EventEmitter, Font, HitboxBehavior, InteractiveElement as _, IntoElement, KeyBinding, KeyDownEvent, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, ParentElement as _, Pixels, RenderOnce, Role, ScrollDelta, ScrollEvent, SharedString, - StatefulInteractiveElement as _, Styled as _, TextAlign, TextRun, UTF16Selection, Window, - WrappedLine, actions, canvas, div, fill, point, px, + StatefulInteractiveElement as _, StyleRefinement, Styled as _, TextAlign, TextRun, + UTF16Selection, Window, WrappedLine, actions, canvas, div, fill, point, px, }; use gpui_native_icons::IconRole; use gpui_native_theme::{ @@ -22,7 +22,7 @@ use gpui_native_theme::{ use gpui_native_utils::focus_ring; 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. pub const INPUT_CONTEXT: &str = "Input"; @@ -1884,6 +1884,7 @@ pub struct Input { rows: usize, prefix: Option, suffix: Option, + style: StyleRefinement, } impl Input { @@ -1903,6 +1904,7 @@ impl Input { rows: DEFAULT_ROWS, prefix: 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 { fn apply_size(&mut self, size: Size) { self.size = size; @@ -2151,6 +2159,7 @@ impl RenderOnce for Input { } else { colors.input }) + .refine_style(&self.style) .when(self.disabled, |input| input.opacity(0.5)) .when(!self.disabled, |input| { input.track_focus(&focus_handle).tab_stop(true) diff --git a/crates/core/src/link.rs b/crates/core/src/link.rs index 8614790..4ce6ba8 100644 --- a/crates/core/src/link.rs +++ b/crates/core/src/link.rs @@ -1,12 +1,13 @@ use gpui::prelude::FluentBuilder as _; use gpui::{ 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_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. type ClickHandler = Box; @@ -22,6 +23,7 @@ pub struct Link { disabled: bool, a11y_label: Option, on_click: Option, + style: StyleRefinement, } impl Link { @@ -38,6 +40,7 @@ impl Link { disabled: false, a11y_label: 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 { fn apply_size(&mut self, size: Size) { self.size = size; @@ -106,6 +115,7 @@ impl RenderOnce for Link { .text_size(metrics.text_size) .text_color(colors.accent) .underline() + .refine_style(&self.style) .role(Role::Link) .when_some(a11y_label, |link, label| link.aria_label(label)) .when(self.disabled, |link| link.opacity(0.5)) diff --git a/crates/core/src/menu.rs b/crates/core/src/menu.rs index c59dda5..6085a85 100644 --- a/crates/core/src/menu.rs +++ b/crates/core/src/menu.rs @@ -8,14 +8,14 @@ use gpui::{ Animation, AnimationExt as _, AnyElement, App, Bounds, BoxShadow, DefiniteLength, DispatchPhase, ElementId, Entity, FocusHandle, InteractiveElement as _, IntoElement, KeyDownEvent, MouseButton, MouseDownEvent, ParentElement as _, Pixels, Point, RenderOnce, Role, - ScrollHandle, SharedString, StatefulInteractiveElement as _, Styled as _, Window, anchored, - canvas, deferred, div, ease_out_quint, point, px, relative, + ScrollHandle, SharedString, StatefulInteractiveElement as _, StyleRefinement, Styled as _, + Window, anchored, canvas, deferred, div, ease_out_quint, point, px, relative, }; use gpui_native_icons::{Icon, IconRole, icon as icon_glyph}; use gpui_native_theme::{ActiveTheme as _, BORDER_WIDTH, POPUP_MAX_HEIGHT}; 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}; /// Runs the item's action. The menu closes itself before the handler runs. @@ -203,6 +203,7 @@ pub struct Menu { trigger: Option, items: Option, min_width: Option, + style: StyleRefinement, } impl MenuChrome { @@ -256,6 +257,7 @@ impl Menu { trigger: None, items: 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 { fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement { let (chrome, enter_duration) = MenuChrome::read(cx); @@ -367,6 +375,7 @@ impl RenderOnce for Menu { div() .relative() + .refine_style(&self.style) .child( canvas( { diff --git a/crates/core/src/popover.rs b/crates/core/src/popover.rs index fef0033..d08e796 100644 --- a/crates/core/src/popover.rs +++ b/crates/core/src/popover.rs @@ -6,11 +6,11 @@ use gpui::{ Animation, AnimationExt as _, AnyElement, App, Bounds, DispatchPhase, ElementId, InteractiveElement as _, IntoElement, KeyDownEvent, MouseButton, MouseDownEvent, 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 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. type ChangeHandler = Rc; @@ -29,6 +29,7 @@ pub struct Popover { on_change: Option, trigger: Option, content: Option, + style: StyleRefinement, } impl Popover { @@ -44,6 +45,7 @@ impl Popover { on_change: None, trigger: 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 { fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement { let (colors, radius, shadows, enter_duration, panel_border, anchor_gap) = { @@ -117,6 +125,7 @@ impl RenderOnce for Popover { div() .relative() + .refine_style(&self.style) .child( canvas( { diff --git a/crates/core/src/progress.rs b/crates/core/src/progress.rs index db2c621..b7ae118 100644 --- a/crates/core/src/progress.rs +++ b/crates/core/src/progress.rs @@ -4,11 +4,11 @@ use gpui::prelude::FluentBuilder as _; use gpui::{ Animation, AnimationExt as _, App, ElementId, InteractiveElement as _, IntoElement, 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 crate::common::Sizable; +use crate::common::{Sizable, StyledExt as _}; /// A progress bar. With a `value` in `0..=1` it paints a determinate fill. #[derive(IntoElement)] @@ -19,6 +19,7 @@ pub struct Progress { indeterminate: bool, size: Size, a11y_label: Option, + style: StyleRefinement, } impl Progress { @@ -33,6 +34,7 @@ impl Progress { indeterminate: false, size: Size::default(), 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 { fn apply_size(&mut self, size: Size) { self.size = size; @@ -72,6 +80,7 @@ impl RenderOnce for Progress { div() .id(self.id) .w_full() + .refine_style(&self.style) .role(Role::ProgressIndicator) .when_some(self.a11y_label, |progress, label| { progress.aria_label(label) diff --git a/crates/core/src/radio.rs b/crates/core/src/radio.rs index 1c4137a..d848e0b 100644 --- a/crates/core/src/radio.rs +++ b/crates/core/src/radio.rs @@ -1,12 +1,13 @@ use gpui::prelude::FluentBuilder; use gpui::{ 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_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. type ChangeHandler = std::rc::Rc; @@ -83,6 +84,7 @@ where size: Size, a11y_label: Option, on_change: Option>, + style: StyleRefinement, } impl RadioGroup @@ -101,6 +103,7 @@ where size: Size::default(), a11y_label: None, on_change: None, + style: StyleRefinement::default(), } } @@ -144,6 +147,15 @@ where } } +impl gpui::Styled for RadioGroup +where + V: Clone + PartialEq + 'static, +{ + fn style(&mut self) -> &mut StyleRefinement { + &mut self.style + } +} + impl RenderOnce for RadioGroup where V: Clone + PartialEq + 'static, @@ -162,6 +174,7 @@ where .id(self.id) .gap_2() .text_size(metrics.text_size) + .refine_style(&self.style) .role(Role::RadioGroup) .when_some(group_label.clone(), |group, label| group.aria_label(label)) .children(self.children.into_iter().map(move |radio| { diff --git a/crates/core/src/separator.rs b/crates/core/src/separator.rs index 038a674..054dc37 100644 --- a/crates/core/src/separator.rs +++ b/crates/core/src/separator.rs @@ -3,8 +3,12 @@ use std::rc::Rc; 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_utils::StyledExt as _; /// Which axis the rule runs along. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] @@ -24,6 +28,7 @@ type DebugSelector = Rc String>; pub struct Separator { orientation: SeparatorOrientation, debug_selector: Option, + style: StyleRefinement, } impl Separator { @@ -32,6 +37,7 @@ impl Separator { Self { orientation: SeparatorOrientation::Horizontal, debug_selector: None, + style: StyleRefinement::default(), } } @@ -40,6 +46,7 @@ impl Separator { Self { orientation: SeparatorOrientation::Vertical, 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 { fn render(self, _window: &mut Window, cx: &mut App) -> impl IntoElement { let border = cx.theme().colors.border; @@ -73,5 +86,6 @@ impl RenderOnce for Separator { SeparatorOrientation::Horizontal => rule.w_full().h(BORDER_WIDTH), SeparatorOrientation::Vertical => rule.self_stretch().w(BORDER_WIDTH), }) + .refine_style(&self.style) } } diff --git a/crates/core/src/slider.rs b/crates/core/src/slider.rs index a29ab97..c3ebfaa 100644 --- a/crates/core/src/slider.rs +++ b/crates/core/src/slider.rs @@ -5,12 +5,13 @@ use gpui::prelude::FluentBuilder as _; use gpui::{ App, Bounds, DispatchPhase, ElementId, InteractiveElement as _, IntoElement, KeyDownEvent, 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_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. type ChangeHandler = Rc; @@ -46,6 +47,7 @@ pub struct Slider { disabled: bool, a11y_label: Option, on_change: Option, + style: StyleRefinement, } impl Slider { @@ -64,6 +66,7 @@ impl Slider { disabled: false, a11y_label: 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 { fn apply_size(&mut self, size: Size) { self.size = size; @@ -169,6 +178,7 @@ impl RenderOnce for Slider { .relative() .w_full() .h(row_height) + .refine_style(&self.style) .role(Role::Slider) .when_some(self.a11y_label.clone(), |slider, label| { slider.aria_label(label) diff --git a/crates/core/src/speech.rs b/crates/core/src/speech.rs index 2f9edde..8d996f4 100644 --- a/crates/core/src/speech.rs +++ b/crates/core/src/speech.rs @@ -15,8 +15,8 @@ use std::sync::{Arc, Mutex}; use gpui::prelude::FluentBuilder as _; use gpui::{ App, Context, ElementId, Entity, EventEmitter, InteractiveElement as _, IntoElement, - ParentElement as _, RenderOnce, Role, SharedString, StatefulInteractiveElement as _, Styled, - Subscription, Task, WeakEntity, Window, div, relative, + ParentElement as _, RenderOnce, Role, SharedString, StatefulInteractiveElement as _, + StyleRefinement, Styled, Subscription, Task, WeakEntity, Window, div, relative, }; use gpui_native_icons::{IconRole, icon}; use gpui_native_theme::{ActiveTheme as _, BORDER_WIDTH, Size}; @@ -654,6 +654,7 @@ pub struct SpeechButton { size: Size, disabled: bool, show_when_unsupported: bool, + style: StyleRefinement, } impl SpeechButton { @@ -664,6 +665,7 @@ impl SpeechButton { size: Size::default(), disabled: 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 { fn apply_size(&mut self, size: Size) { self.size = size; @@ -741,6 +749,7 @@ impl RenderOnce for SpeechButton { .rounded(theme.radius.control) .text_color(foreground) .when(capturing, |button| button.bg(colors.muted)) + .refine_style(&self.style) .when(disabled, |button| button.opacity(0.5)) .aria_label(label.clone()) .tooltip(Tooltip::text(label)) diff --git a/crates/core/src/spinner.rs b/crates/core/src/spinner.rs index b2a2d10..d822fc8 100644 --- a/crates/core/src/spinner.rs +++ b/crates/core/src/spinner.rs @@ -8,13 +8,13 @@ use gpui::prelude::FluentBuilder as _; use gpui::{ Animation, AnimationElement, AnimationExt as _, App, Canvas, ElementId, Hsla, InteractiveElement as _, IntoElement, ParentElement as _, Path, PathBuilder, Pixels, Point, - RenderOnce, Role, SharedString, StatefulInteractiveElement as _, Styled as _, Window, canvas, - div, point, px, + RenderOnce, Role, SharedString, StatefulInteractiveElement as _, StyleRefinement, Styled as _, + Window, canvas, div, point, px, }; use gpui_native_icons::{Icon, IconRole, icon}; 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. const SPIN_SWEEP: f32 = 0.75; @@ -41,6 +41,7 @@ pub struct Spinner { size: Size, color: Option, a11y_label: Option, + style: StyleRefinement, } impl Spinner { @@ -56,6 +57,7 @@ impl Spinner { size: Size::default(), color: 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 { fn apply_size(&mut self, size: Size) { self.size = size; @@ -106,6 +114,7 @@ impl RenderOnce for Spinner { .id(self.id) .flex_none() .size(side) + .refine_style(&self.style) .role(Role::ProgressIndicator) .when_some(self.a11y_label, |spinner, label| spinner.aria_label(label)) .when_some(value, |spinner, value| { diff --git a/crates/core/src/switch.rs b/crates/core/src/switch.rs index 1876a53..b9ac546 100644 --- a/crates/core/src/switch.rs +++ b/crates/core/src/switch.rs @@ -3,13 +3,13 @@ use gpui::prelude::FluentBuilder as _; use gpui::{ AnimationExt as _, App, ElementId, InteractiveElement as _, IntoElement, ParentElement as _, - RenderOnce, Role, SharedString, SpringAnimation, StatefulInteractiveElement as _, Styled as _, - Toggled, Window, div, px, + RenderOnce, Role, SharedString, SpringAnimation, StatefulInteractiveElement as _, + StyleRefinement, Styled as _, Toggled, Window, div, px, }; use gpui_native_theme::{ActiveTheme as _, CONTROL_SPRING, Size}; 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. type ChangeHandler = Box; @@ -25,6 +25,7 @@ pub struct Switch { disabled: bool, a11y_label: Option, on_change: Option, + style: StyleRefinement, } impl Switch { @@ -41,6 +42,7 @@ impl Switch { disabled: false, a11y_label: 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 { fn apply_size(&mut self, size: Size) { self.size = size; @@ -116,6 +124,7 @@ impl RenderOnce for Switch { .id(self.id) .gap_1p5() .text_size(metrics.text_size) + .refine_style(&self.style) .role(Role::Switch) .when_some(a11y_label, |switch, label| switch.aria_label(label)) .aria_toggled(Toggled::from(self.checked)) diff --git a/crates/core/src/toast.rs b/crates/core/src/toast.rs index ff998cd..7fe02bb 100644 --- a/crates/core/src/toast.rs +++ b/crates/core/src/toast.rs @@ -7,14 +7,15 @@ use gpui::prelude::FluentBuilder; use gpui::{ Animation, AnimationExt as _, App, Context, ElementId, Entity, InteractiveElement as _, 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_theme::{ActiveTheme as _, TOAST_MAX_WIDTH}; use gpui_native_utils::ResultLogErr as _; 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`]. pub type ActionHandler = Rc; @@ -49,6 +50,7 @@ pub struct Toast { action: Option, duration: Option, on_dismiss: Option, + style: StyleRefinement, } impl Toast { @@ -66,6 +68,7 @@ impl Toast { action: None, duration: Some(Self::DURATION), on_dismiss: None, + style: StyleRefinement::default(), } } @@ -300,6 +303,7 @@ impl ToastEntry { .border_color(border) .rounded(radius) .shadow(shadows.clone()) + .refine_style(&toast.style) .when_some(toast.icon.clone(), |pill, icon| { pill.child( div() diff --git a/crates/core/src/toggle.rs b/crates/core/src/toggle.rs index 2ac016f..8aaba45 100644 --- a/crates/core/src/toggle.rs +++ b/crates/core/src/toggle.rs @@ -1,12 +1,12 @@ use gpui::prelude::FluentBuilder as _; use gpui::{ 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_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. type ChangeHandler = Box; @@ -22,6 +22,7 @@ pub struct Toggle { disabled: bool, a11y_label: Option, on_change: Option, + style: StyleRefinement, } impl Toggle { @@ -38,6 +39,7 @@ impl Toggle { disabled: false, a11y_label: 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 { fn apply_size(&mut self, size: Size) { self.size = size; @@ -118,6 +126,7 @@ impl RenderOnce for Toggle { .hover(|style| style.bg(colors.muted)) .active(|style| style.bg(ramps.secondary.hover)) }) + .refine_style(&self.style) .when(self.disabled, |toggle| toggle.opacity(0.5)) .when(!self.disabled, |toggle| { toggle diff --git a/crates/data/src/list.rs b/crates/data/src/list.rs index f91b708..02880ce 100644 --- a/crates/data/src/list.rs +++ b/crates/data/src/list.rs @@ -4,11 +4,11 @@ use gpui::prelude::FluentBuilder; use gpui::{ AnyElement, App, ElementId, FocusHandle, InteractiveElement as _, IntoElement, KeyDownEvent, ParentElement as _, RenderOnce, Role, SharedString, StatefulInteractiveElement as _, - Styled as _, Window, div, + StyleRefinement, Styled as _, Window, div, }; use gpui_native_icons::Icon; 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. type ChangeHandler = Rc, &mut Window, &mut App)>; @@ -77,6 +77,7 @@ pub struct List { a11y_label: Option, on_change: Option, items: Option, + style: StyleRefinement, } impl List { @@ -91,6 +92,7 @@ impl List { a11y_label: None, on_change: 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 { fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement { let items = match self.items { @@ -171,6 +179,7 @@ impl RenderOnce for List { .flex_col() .gap_0p5() .text_size(theme.sizes.medium.text_size) + .refine_style(&self.style) .track_focus(&focus) .focusable() .tab_stop(true) diff --git a/crates/data/src/sidebar.rs b/crates/data/src/sidebar.rs index f0d0814..0bc306b 100644 --- a/crates/data/src/sidebar.rs +++ b/crates/data/src/sidebar.rs @@ -8,12 +8,12 @@ use gpui::prelude::FluentBuilder; use gpui::{ AnyElement, App, ElementId, FocusHandle, InteractiveElement as _, IntoElement, KeyDownEvent, 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::scroll_area::ScrollArea; 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. type ChangeHandler = Rc, &mut Window, &mut App)>; @@ -144,6 +144,7 @@ pub struct Sidebar { a11y_label: Option, on_change: Option, entries: Option, + style: StyleRefinement, } impl Sidebar { @@ -163,6 +164,7 @@ impl Sidebar { a11y_label: None, on_change: 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 { fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement { let Self { @@ -262,6 +270,7 @@ impl RenderOnce for Sidebar { a11y_label, on_change, entries, + style, } = self; 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) + .refine_style(&style) .when(border_right, |sidebar| { sidebar .border_r(BORDER_WIDTH) diff --git a/crates/data/src/tabs.rs b/crates/data/src/tabs.rs index 0eeb42b..0da8738 100644 --- a/crates/data/src/tabs.rs +++ b/crates/data/src/tabs.rs @@ -7,7 +7,7 @@ use gpui::{ AnyElement, App, AppContext as _, Bounds, ClickEvent, Context, Div, ElementId, Global, InteractiveElement as _, IntoElement, KeyDownEvent, MouseButton, ParentElement as _, Pixels, 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::common::{Sizable as _, v_flex}; @@ -17,7 +17,7 @@ use gpui_native_core::spinner::Spinner; use gpui_native_core::tooltip::Tooltip; use gpui_native_icons::IconRole; 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. type ChangeHandler = Rc; @@ -315,6 +315,7 @@ pub struct Tabs { on_reorder: Option, on_overflow_open: Option, tabs: Option, + style: StyleRefinement, } impl Tabs { @@ -337,6 +338,7 @@ impl Tabs { on_reorder: None, on_overflow_open: 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 { fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement { let tabs = match self.tabs { @@ -820,6 +828,7 @@ impl RenderOnce for Tabs { .id(self.id.clone()) .flex() .text_size(medium_text_size) + .refine_style(&self.style) .track_focus(&focus) .focusable() .tab_stop(true) diff --git a/crates/data/src/tree.rs b/crates/data/src/tree.rs index ca67467..e043c22 100644 --- a/crates/data/src/tree.rs +++ b/crates/data/src/tree.rs @@ -4,11 +4,11 @@ use gpui::prelude::FluentBuilder; use gpui::{ AnyElement, App, ElementId, FocusHandle, InteractiveElement as _, IntoElement, KeyDownEvent, 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_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. type ChangeHandler = Rc, &mut Window, &mut App)>; @@ -94,6 +94,7 @@ pub struct Tree { on_change: Option, on_disclosure: Option, items: Option, + style: StyleRefinement, } impl Tree { @@ -109,6 +110,7 @@ impl Tree { on_change: None, on_disclosure: 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 { fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement { let items = match self.items { @@ -258,6 +266,7 @@ impl RenderOnce for Tree { .flex_col() .gap_0p5() .text_size(theme.sizes.medium.text_size) + .refine_style(&self.style) .track_focus(&focus) .focusable() .tab_stop(true) diff --git a/crates/layout/src/panel.rs b/crates/layout/src/panel.rs index d9116cc..a886d1e 100644 --- a/crates/layout/src/panel.rs +++ b/crates/layout/src/panel.rs @@ -10,6 +10,7 @@ use gpui::{ Render, RenderOnce, SharedString, StyleRefinement, Styled as _, Window, div, rems, }; use gpui_native_theme::ActiveTheme as _; +use gpui_native_utils::StyledExt as _; use crate::resizable::{Resizable, ResizableState}; @@ -80,6 +81,7 @@ pub struct PanelRow { id: ElementId, main: Option, split: Option, + style: StyleRefinement, } impl PanelRow { @@ -92,6 +94,7 @@ impl PanelRow { id: id.into(), main: 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 { fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement { let id = self.id.clone(); @@ -152,6 +161,13 @@ impl RenderOnce for PanelRow { 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) } } diff --git a/crates/layout/src/resize_handle.rs b/crates/layout/src/resize_handle.rs index a0b9422..f33bb63 100644 --- a/crates/layout/src/resize_handle.rs +++ b/crates/layout/src/resize_handle.rs @@ -8,11 +8,11 @@ use gpui::{ App, Axis, Bounds, CursorStyle, DispatchPhase, ElementId, HitboxBehavior, InteractiveElement as _, IntoElement, KeyDownEvent, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, ParentElement as _, Pixels, Point, RenderOnce, Role, - SharedString, StatefulInteractiveElement as _, Styled as _, Window, canvas, deferred, div, - fill, point, px, rems, + SharedString, StatefulInteractiveElement as _, StyleRefinement, Styled as _, Window, canvas, + deferred, div, fill, point, px, rems, }; 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. const KEYBOARD_STEP: Pixels = RESIZE_KEYBOARD_STEP; @@ -38,6 +38,7 @@ pub struct ResizeHandle { accessibility_label: Option, on_resize: Option, on_reset: Option, + style: StyleRefinement, } impl ResizeHandle { @@ -53,6 +54,7 @@ impl ResizeHandle { accessibility_label: None, on_resize: 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 { fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement { let theme = cx.theme(); @@ -141,6 +149,7 @@ impl RenderOnce for ResizeHandle { .when(axis == Axis::Vertical, |handle| { handle.w_full().h(thickness) }) + .refine_style(&self.style) .when(self.disabled, |handle| handle.opacity(0.5)) .when(!self.disabled, |handle| { handle diff --git a/crates/layout/src/shell.rs b/crates/layout/src/shell.rs index a9435a4..bc11ee0 100644 --- a/crates/layout/src/shell.rs +++ b/crates/layout/src/shell.rs @@ -4,8 +4,8 @@ use gpui::prelude::FluentBuilder as _; use gpui::{ - AnyElement, App, ElementId, Entity, IntoElement, ParentElement as _, RenderOnce, Styled as _, - Window, div, + AnyElement, App, ElementId, Entity, IntoElement, ParentElement as _, RenderOnce, + StyleRefinement, Styled as _, Window, div, }; #[cfg(feature = "alert")] use gpui_native_core::alert::{Alerts, AlertsView}; @@ -13,7 +13,7 @@ use gpui_native_core::grain::grain as grain_overlay; #[cfg(feature = "toast")] use gpui_native_core::toast::{Toasts, ToastsView}; 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::window_frame::frame; @@ -31,6 +31,7 @@ pub struct Shell { toasts: Option>, #[cfg(feature = "alert")] alerts: Option>, + style: StyleRefinement, } impl Shell { @@ -49,6 +50,7 @@ impl Shell { toasts: None, #[cfg(feature = "alert")] 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 { fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement { let id = self.id.clone(); @@ -110,6 +118,7 @@ impl RenderOnce for Shell { .h_full() .overflow_hidden() .bg(background) + .refine_style(&self.style) .when(self.transparent && self.grain, |layout| { layout.child(grain_overlay()) }); diff --git a/crates/layout/src/titlebar.rs b/crates/layout/src/titlebar.rs index 2d9d35d..cf615d1 100644 --- a/crates/layout/src/titlebar.rs +++ b/crates/layout/src/titlebar.rs @@ -7,10 +7,10 @@ use gpui::prelude::FluentBuilder as _; use gpui::{ 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_utils::h_flex; +use gpui_native_utils::{StyledExt as _, h_flex}; use crate::window_controls::{WindowControls, titlebar_strip}; @@ -23,6 +23,7 @@ pub struct Titlebar { tab_bar: Option, suffix: Vec, transparent: bool, + style: StyleRefinement, } impl Titlebar { @@ -37,6 +38,7 @@ impl Titlebar { tab_bar: None, suffix: Vec::new(), 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 { fn extend(&mut self, elements: impl IntoIterator) { self.prefix.extend(elements); @@ -91,6 +99,7 @@ impl RenderOnce for Titlebar { .gap_2() .when(!self.transparent, |bar| bar.bg(theme.colors.muted)) .px(padding_x) + .refine_style(&self.style) .when(cfg!(target_os = "macos"), |bar| bar.pl(TRAFFIC_LIGHT_PAD)) .when(!self.prefix.is_empty(), |bar| { bar.child(