utils: add shared StyledExt styling helper
This commit is contained in:
+11
-2
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user