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
+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)