feat: support app-defined icon sets

This commit is contained in:
2026-11-09 20:35:04 +07:00
parent 1c091db699
commit ec906839ed
17 changed files with 274 additions and 173 deletions
+10 -11
View File
@@ -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;
use gpui_native_theme::ActiveTheme as _;
use gpui_native_utils::{nav_key, paint_selectable_row, selectable_label_color};
@@ -17,7 +17,7 @@ type ItemsFn = Box<dyn Fn(&mut Window, &mut App) -> Vec<ListItem>>;
/// One row of a [`List`].
pub struct ListItem {
label: SharedString,
icon: Option<IconRole>,
icon: Option<Icon>,
detail: Option<SharedString>,
disabled: bool,
}
@@ -36,9 +36,12 @@ impl ListItem {
}
}
/// Shows an icon leading the label.
pub fn icon(mut self, role: IconRole) -> Self {
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>,
{
self.icon = Some(icon.into());
self
}
@@ -222,12 +225,8 @@ fn render_row(
}
})
})
.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()
+11 -12
View File
@@ -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()));
+15 -12
View File
@@ -10,7 +10,7 @@ use gpui_native_core::button::{Button, ButtonVariant};
use gpui_native_core::common::Sizable as _;
use gpui_native_core::spinner::Spinner;
use gpui_native_core::tooltip::Tooltip;
use gpui_native_icons::{IconRole, icon};
use gpui_native_icons::{Icon, IconRole};
use gpui_native_theme::{ActiveTheme as _, Size};
use gpui_native_utils::adjacent_selectable;
@@ -35,7 +35,7 @@ pub struct Tab {
/// The stable identity for element state; must survive reordering.
key: ElementId,
label: SharedString,
icon: Option<IconRole>,
icon: Option<Icon>,
lead: Option<AnyElement>,
busy: bool,
disabled: bool,
@@ -63,8 +63,11 @@ impl Tab {
}
/// 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
}
@@ -344,18 +347,18 @@ fn render_tab(
};
let lead = tab.lead.take();
let icon = tab.icon.take();
strip_tab = match lead {
Some(lead) => strip_tab.child(lead),
None => match variant {
TabsVariant::Underline => strip_tab.child(div().flex_none().pb_0p5().when_some(
tab.icon,
|slot, role| {
slot.child(icon(role).size(metrics.dense_icon_size).color(label_color))
},
)),
TabsVariant::Pill => strip_tab.when_some(tab.icon, |strip_tab, role| {
strip_tab.child(icon(role).size(metrics.dense_icon_size).color(label_color))
TabsVariant::Underline => {
strip_tab.child(div().flex_none().pb_0p5().when_some(icon, |slot, icon| {
slot.child(icon.size(metrics.dense_icon_size).color(label_color))
}))
}
TabsVariant::Pill => strip_tab.when_some(icon, |strip_tab, icon| {
strip_tab.child(icon.size(metrics.dense_icon_size).color(label_color))
}),
},
};
+9 -10
View File
@@ -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()