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::{
IntoElement, ParentElement as _, RenderOnce, SharedString, StatefulInteractiveElement as _,
Styled as _, Task, Window, deferred, div, ease_out_quint, px,
};
use gpui_native_icons::{IconRole, icon};
use gpui_native_icons::{Icon, IconRole, icon};
use gpui_native_theme::ActiveTheme as _;
use crate::button::{Button, ButtonVariant};
@@ -43,7 +43,7 @@ impl ToastAction {
#[derive(Clone)]
pub struct Toast {
message: SharedString,
icon: Option<IconRole>,
icon: Option<Icon>,
action: Option<ToastAction>,
duration: Option<Duration>,
on_dismiss: Option<DismissHandler>,
@@ -68,8 +68,11 @@ impl Toast {
}
/// Shows this glyph before the content.
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
}
@@ -285,14 +288,14 @@ fn pill(entry: &ToastEntry, toasts: &Entity<Toasts>, cx: &App) -> gpui::Stateful
.border_color(border)
.rounded(radius)
.shadow(shadows.clone())
.when_some(toast.icon, |pill, icon_role| {
.when_some(toast.icon.clone(), |pill, icon| {
pill.child(
div()
.flex_none()
.mr_2()
.flex()
.items_center()
.child(icon(icon_role).size(icon_size).color(foreground)),
.child(icon.size(icon_size).color(foreground)),
)
})
.child(