forked from reya/gpui-native-kit
feat: support app-defined icon sets
This commit is contained in:
+11
-12
@@ -10,7 +10,7 @@ use gpui::{
|
||||
Styled as _, Window, div,
|
||||
};
|
||||
use gpui_native_core::scroll_area::ScrollArea;
|
||||
use gpui_native_icons::{IconRole, icon};
|
||||
use gpui_native_icons::Icon;
|
||||
use gpui_native_theme::ActiveTheme as _;
|
||||
use gpui_native_utils::{nav_key, paint_selectable_row, selectable_label_color};
|
||||
|
||||
@@ -26,7 +26,7 @@ pub enum SidebarEntry {
|
||||
/// A selectable row.
|
||||
Row {
|
||||
label: SharedString,
|
||||
icon: Option<IconRole>,
|
||||
icon: Option<Icon>,
|
||||
detail: Option<SharedString>,
|
||||
disabled: bool,
|
||||
},
|
||||
@@ -56,10 +56,13 @@ impl SidebarEntry {
|
||||
}
|
||||
}
|
||||
|
||||
/// Shows an icon leading the label.
|
||||
pub fn icon(mut self, role: IconRole) -> Self {
|
||||
if let Self::Row { icon, .. } = &mut self {
|
||||
*icon = Some(role);
|
||||
/// Shows an icon leading the label, a role or any custom [`IconNamed`].
|
||||
pub fn icon<I>(mut self, icon: I) -> Self
|
||||
where
|
||||
I: Into<Icon>,
|
||||
{
|
||||
if let Self::Row { icon: slot, .. } = &mut self {
|
||||
*slot = Some(icon.into());
|
||||
}
|
||||
self
|
||||
}
|
||||
@@ -337,12 +340,8 @@ fn render_entry(
|
||||
});
|
||||
}
|
||||
|
||||
row = row.when_some(*row_icon, |row, role| {
|
||||
row.child(
|
||||
icon(role)
|
||||
.size(theme.sizes.medium.icon_size)
|
||||
.color(label_color),
|
||||
)
|
||||
row = row.when_some(row_icon.clone(), |row, icon| {
|
||||
row.child(icon.size(theme.sizes.medium.icon_size).color(label_color))
|
||||
});
|
||||
|
||||
row = row.child(div().flex_1().text_color(label_color).child(label.clone()));
|
||||
|
||||
Reference in New Issue
Block a user