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
+9 -6
View File
@@ -9,7 +9,7 @@ use gpui::{
MouseButton, MouseDownEvent, ParentElement as _, RenderOnce, Role, SharedString,
StatefulInteractiveElement as _, Styled as _, Window, canvas, div, relative,
};
use gpui_native_icons::{IconRole, icon};
use gpui_native_icons::{Icon, IconRole, icon};
use gpui_native_theme::{ActiveTheme as _, BORDER_WIDTH, Size};
use gpui_native_utils::{focus_handle, focus_ring};
@@ -27,7 +27,7 @@ type ItemsFn = Box<dyn Fn(&mut Window, &mut App) -> Vec<MenuItem>>;
pub struct DropdownMenu {
id: ElementId,
label: Option<SharedString>,
icon: Option<IconRole>,
icon: Option<Icon>,
variant: ButtonVariant,
size: Size,
disabled: bool,
@@ -73,8 +73,11 @@ impl DropdownMenu {
}
/// Shows an icon beside 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
}
@@ -267,8 +270,8 @@ impl RenderOnce for DropdownMenu {
)
})
.when(!self.loading, |zone| {
zone.when_some(self.icon, |zone, role| {
zone.child(icon(role).size(metrics.icon_size).color(foreground))
zone.when_some(self.icon, |zone, icon| {
zone.child(icon.size(metrics.icon_size).color(foreground))
})
})
.when_some(self.label, |zone, label| zone.child(label));