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
@@ -6,7 +6,7 @@ use gpui::{
RenderOnce, Role, SharedString, StatefulInteractiveElement as _, Styled as _, Window, canvas,
relative, transparent_black,
};
use gpui_native_icons::{IconRole, icon};
use gpui_native_icons::Icon;
use gpui_native_theme::{ActiveTheme as _, BORDER_WIDTH, Size};
use gpui_native_utils::{focus_ring, record_anchor_bounds};
use std::rc::Rc;
@@ -38,7 +38,7 @@ pub enum ButtonVariant {
pub struct Button {
id: ElementId,
label: Option<SharedString>,
icon: Option<IconRole>,
icon: Option<Icon>,
variant: ButtonVariant,
size: Size,
disabled: bool,
@@ -82,8 +82,11 @@ impl Button {
}
/// 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
}
@@ -236,8 +239,8 @@ impl RenderOnce for Button {
)
})
.when(!self.loading, |button| {
button.when_some(self.icon, |button, role| {
button.child(icon(role).size(metrics.icon_size).color(foreground))
button.when_some(self.icon, |button, icon| {
button.child(icon.size(metrics.icon_size).color(foreground))
})
})
.when_some(self.label, |button, label| button.child(label))