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::{
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<SharedString>,
message: Option<SharedString>,
severity: AlertSeverity,
style: AlertStyle,
presentation: AlertStyle,
icon: Option<Icon>,
on_dismiss: Option<DismissHandler>,
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()
+12 -3
View File
@@ -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<SharedString>,
tooltip: Option<TooltipBuilder>,
on_click: Option<ClickHandler>,
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()
+11 -2
View File
@@ -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<dyn Fn(bool, &mut Window, &mut App)>;
@@ -28,6 +28,7 @@ pub struct Checkbox {
debug_selector: Option<Rc<dyn Fn() -> String>>,
a11y_label: Option<SharedString>,
on_change: Option<ChangeHandler>,
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())
})
+6 -3
View File
@@ -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<SharedString>,
tooltip: Option<TooltipBuilder>,
on_copied: Option<CopiedHandler>,
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| {
+8 -3
View File
@@ -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<Command>,
matcher: CommandMatcher,
on_execute: Option<CommandHandler>,
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<Command>,
matcher: CommandMatcher,
on_execute: Option<CommandHandler>,
style: StyleRefinement,
query: Entity<InputState>,
/// The commands the matcher returned for the query, in display order.
matches: Vec<Command>,
@@ -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();
+5 -1
View File
@@ -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<TargetFn>,
items: Option<ItemsFn>,
a11y_label: Option<SharedString>,
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)
})
+12 -3
View File
@@ -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<ActionsFn>,
min_width: Option<DefiniteLength>,
height: Option<DefiniteLength>,
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()),
+12 -2
View File
@@ -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<ChangeHandler>,
items: Option<ItemsFn>,
min_width: Option<DefiniteLength>,
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(
{
+12 -3
View File
@@ -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<AnyElement>,
suffix: Option<AnyElement>,
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)
+12 -2
View File
@@ -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<dyn Fn(&ClickEvent, &mut Window, &mut App)>;
@@ -22,6 +23,7 @@ pub struct Link {
disabled: bool,
a11y_label: Option<SharedString>,
on_click: Option<ClickHandler>,
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))
+12 -3
View File
@@ -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<TriggerFn>,
items: Option<ItemsFn>,
min_width: Option<DefiniteLength>,
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(
{
+11 -2
View File
@@ -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<dyn Fn(bool, &mut Window, &mut App)>;
@@ -29,6 +29,7 @@ pub struct Popover {
on_change: Option<ChangeHandler>,
trigger: Option<TriggerFn>,
content: Option<ContentFn>,
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(
{
+11 -2
View File
@@ -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<SharedString>,
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)
+15 -2
View File
@@ -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<V> = std::rc::Rc<dyn Fn(V, &mut Window, &mut App)>;
@@ -83,6 +84,7 @@ where
size: Size,
a11y_label: Option<SharedString>,
on_change: Option<ChangeHandler<V>>,
style: StyleRefinement,
}
impl<V> RadioGroup<V>
@@ -101,6 +103,7 @@ where
size: Size::default(),
a11y_label: 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>
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| {
+15 -1
View File
@@ -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<dyn Fn() -> String>;
pub struct Separator {
orientation: SeparatorOrientation,
debug_selector: Option<DebugSelector>,
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)
}
}
+12 -2
View File
@@ -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<dyn Fn(f32, &mut Window, &mut App)>;
@@ -46,6 +47,7 @@ pub struct Slider {
disabled: bool,
a11y_label: Option<SharedString>,
on_change: Option<ChangeHandler>,
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)
+11 -2
View File
@@ -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))
+12 -3
View File
@@ -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<Hsla>,
a11y_label: Option<SharedString>,
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| {
+12 -3
View File
@@ -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<dyn Fn(bool, &mut Window, &mut App)>;
@@ -25,6 +25,7 @@ pub struct Switch {
disabled: bool,
a11y_label: Option<SharedString>,
on_change: Option<ChangeHandler>,
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))
+6 -2
View File
@@ -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<dyn Fn(&mut App)>;
@@ -49,6 +50,7 @@ pub struct Toast {
action: Option<ToastAction>,
duration: Option<Duration>,
on_dismiss: Option<DismissHandler>,
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()
+11 -2
View File
@@ -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<dyn Fn(bool, &mut Window, &mut App)>;
@@ -22,6 +22,7 @@ pub struct Toggle {
disabled: bool,
a11y_label: Option<SharedString>,
on_change: Option<ChangeHandler>,
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
+11 -2
View File
@@ -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<dyn Fn(Option<usize>, &mut Window, &mut App)>;
@@ -77,6 +77,7 @@ pub struct List {
a11y_label: Option<SharedString>,
on_change: Option<ChangeHandler>,
items: Option<ItemsFn>,
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)
+12 -2
View File
@@ -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<dyn Fn(Option<usize>, &mut Window, &mut App)>;
@@ -144,6 +144,7 @@ pub struct Sidebar {
a11y_label: Option<SharedString>,
on_change: Option<ChangeHandler>,
entries: Option<EntriesFn>,
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)
+11 -2
View File
@@ -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<dyn Fn(usize, &mut Window, &mut App)>;
@@ -315,6 +315,7 @@ pub struct Tabs {
on_reorder: Option<ReorderHandler>,
on_overflow_open: Option<OpenHandler>,
tabs: Option<TabsFn>,
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)
+11 -2
View File
@@ -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<dyn Fn(Option<usize>, &mut Window, &mut App)>;
@@ -94,6 +94,7 @@ pub struct Tree {
on_change: Option<ChangeHandler>,
on_disclosure: Option<DisclosureHandler>,
items: Option<ItemsFn>,
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)
+17 -1
View File
@@ -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<AnyElement>,
split: Option<AnyElement>,
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)
}
}
+12 -3
View File
@@ -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<SharedString>,
on_resize: Option<ResizeHandler>,
on_reset: Option<ResetHandler>,
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
+12 -3
View File
@@ -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<Entity<Toasts>>,
#[cfg(feature = "alert")]
alerts: Option<Entity<Alerts>>,
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())
});
+11 -2
View File
@@ -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<AnyElement>,
suffix: Vec<AnyElement>,
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<Item = AnyElement>) {
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(