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
@@ -7,7 +7,7 @@ use gpui::{
SpringConfig, StatefulInteractiveElement as _, StyleRefinement, Styled as _, Toggled, Window,
canvas, div,
};
use gpui_native_icons::{IconRole, icon};
use gpui_native_icons::Icon;
use gpui_native_theme::{ActiveTheme as _, Size};
use gpui_native_utils::{focus_handle, focus_ring};
@@ -21,7 +21,7 @@ type ChangeHandler<T> = Rc<dyn Fn(T, &mut Window, &mut App)>;
pub struct SegmentedOption<T> {
value: T,
label: SharedString,
icon: Option<IconRole>,
icon: Option<Icon>,
}
impl<T> SegmentedOption<T> {
@@ -38,8 +38,11 @@ impl<T> SegmentedOption<T> {
}
/// Sets a leading icon for the segment.
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
}
}
@@ -226,8 +229,8 @@ where
.role(Role::RadioButton)
.aria_label(segment.label.clone())
.aria_toggled(Toggled::from(is_selected))
.when_some(segment.icon, |segment, role| {
segment.child(icon(role).size(icon_size).color(content_color))
.when_some(segment.icon.clone(), |segment, icon| {
segment.child(icon.size(icon_size).color(content_color))
})
.child(segment.label.clone())
.child(