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 -7
View File
@@ -9,7 +9,7 @@ use gpui::{
StatefulInteractiveElement as _, Styled as _, Window, anchored, canvas, deferred, div,
ease_out_quint, point, px, relative,
};
use gpui_native_icons::{IconRole, icon as icon_glyph};
use gpui_native_icons::{Icon, IconRole, icon as icon_glyph};
use gpui_native_theme::{ActiveTheme as _, POPUP_MAX_HEIGHT};
use crate::common::v_flex;
@@ -30,7 +30,7 @@ type ItemsFn = Box<dyn Fn(&mut Window, &mut App) -> Vec<MenuItem>>;
pub struct MenuItem {
kind: MenuItemKind,
label: SharedString,
icon: Option<IconRole>,
icon: Option<Icon>,
shortcut: Option<SharedString>,
handler: Option<ItemHandler>,
disabled: bool,
@@ -86,8 +86,11 @@ impl MenuItem {
}
/// Shows an icon before 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
}
@@ -526,7 +529,7 @@ fn render_item(
let destructive = item.destructive;
let checked = item.checked;
let shortcut = item.shortcut.clone();
let icon_role = item.icon;
let icon = item.icon.clone();
div()
.id(("menu-item", index))
@@ -576,8 +579,8 @@ fn render_item(
}
}
})
.when_some(icon_role, |row, role| {
row.child(icon_glyph(role).size(chrome.icon_size).color(label_color))
.when_some(icon, |row, icon| {
row.child(icon.size(chrome.icon_size).color(label_color))
})
.child(
div()