feat: support app-defined icon sets
This commit is contained in:
+15
-10
@@ -6,7 +6,7 @@ use gpui::{
|
||||
IntoElement, ParentElement as _, RenderOnce, SharedString, StatefulInteractiveElement as _,
|
||||
Styled as _, 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 _, Size};
|
||||
|
||||
use crate::common::DismissHandler;
|
||||
@@ -33,7 +33,7 @@ pub struct Alert {
|
||||
title: Option<SharedString>,
|
||||
message: Option<SharedString>,
|
||||
severity: AlertSeverity,
|
||||
icon: Option<IconRole>,
|
||||
icon: Option<Icon>,
|
||||
show_icon: bool,
|
||||
on_dismiss: Option<DismissHandler>,
|
||||
}
|
||||
@@ -78,9 +78,12 @@ impl Alert {
|
||||
self
|
||||
}
|
||||
|
||||
/// Overrides the severity-derived icon with this glyph.
|
||||
pub fn icon(mut self, role: IconRole) -> Self {
|
||||
self.icon = Some(role);
|
||||
/// Overrides the severity-derived icon.
|
||||
pub fn icon<I>(mut self, icon: I) -> Self
|
||||
where
|
||||
I: Into<Icon>,
|
||||
{
|
||||
self.icon = Some(icon.into());
|
||||
self
|
||||
}
|
||||
|
||||
@@ -116,10 +119,12 @@ impl RenderOnce for Alert {
|
||||
AlertSeverity::Danger => theme.ramps.destructive,
|
||||
};
|
||||
|
||||
let icon_role = self.icon.unwrap_or(match self.severity {
|
||||
AlertSeverity::Info => IconRole::Info,
|
||||
AlertSeverity::Success => IconRole::Check,
|
||||
AlertSeverity::Warning | AlertSeverity::Danger => IconRole::Warning,
|
||||
let icon_glyph = self.icon.unwrap_or_else(|| {
|
||||
icon(match self.severity {
|
||||
AlertSeverity::Info => IconRole::Info,
|
||||
AlertSeverity::Success => IconRole::Check,
|
||||
AlertSeverity::Warning | AlertSeverity::Danger => IconRole::Warning,
|
||||
})
|
||||
});
|
||||
|
||||
let foreground = theme.colors.foreground;
|
||||
@@ -158,7 +163,7 @@ impl RenderOnce for Alert {
|
||||
.flex()
|
||||
.items_center()
|
||||
.h(window.line_height())
|
||||
.child(icon(icon_role).size(icon_size).color(ramp.base)),
|
||||
.child(icon_glyph.size(icon_size).color(ramp.base)),
|
||||
)
|
||||
})
|
||||
.child(
|
||||
|
||||
Reference in New Issue
Block a user