forked from reya/gpui-native-kit
feat: support app-defined icon sets
This commit is contained in:
+9
-10
@@ -6,7 +6,7 @@ use gpui::{
|
||||
ParentElement as _, RenderOnce, Role, SharedString, StatefulInteractiveElement as _,
|
||||
Styled as _, Window, div,
|
||||
};
|
||||
use gpui_native_icons::{IconRole, icon};
|
||||
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};
|
||||
|
||||
@@ -20,7 +20,7 @@ type ItemsFn = Box<dyn Fn(&mut Window, &mut App) -> Vec<TreeItem>>;
|
||||
#[derive(Clone)]
|
||||
pub struct TreeItem {
|
||||
label: SharedString,
|
||||
icon: Option<IconRole>,
|
||||
icon: Option<Icon>,
|
||||
depth: usize,
|
||||
expandable: bool,
|
||||
expanded: bool,
|
||||
@@ -44,8 +44,11 @@ impl TreeItem {
|
||||
}
|
||||
|
||||
/// Shows an icon leading the label.
|
||||
pub fn icon(mut self, role: IconRole) -> Self {
|
||||
self.icon = Some(role);
|
||||
pub fn icon<I>(mut self, icon: I) -> Self
|
||||
where
|
||||
I: Into<Icon>,
|
||||
{
|
||||
self.icon = Some(icon.into());
|
||||
self
|
||||
}
|
||||
|
||||
@@ -317,12 +320,8 @@ fn render_row(
|
||||
selected,
|
||||
on_disclosure,
|
||||
))
|
||||
.when_some(item.icon, |row, role| {
|
||||
row.child(
|
||||
icon(role)
|
||||
.size(theme.sizes.medium.icon_size)
|
||||
.color(label_color),
|
||||
)
|
||||
.when_some(item.icon.clone(), |row, icon| {
|
||||
row.child(icon.size(theme.sizes.medium.icon_size).color(label_color))
|
||||
})
|
||||
.child(
|
||||
div()
|
||||
|
||||
Reference in New Issue
Block a user