Components / overlay
NotificationCenter view
The list of notifications a window has accumulated.
A view survives a frame. Hold it in an Entity with cx.new(..) and reach it with .update(..).
use gpui_kit::overlay::NotificationCenter;
Reviewed in notification-center.
Construct
new(ident: impl Into<Ident>, cx: &mut Context<Self>) -> Self
Options
Chain onto the value.
capacity(capacity: usize) -> Self
Commands
Need a Context, so they need a view.
set_capacity(capacity: usize, cx: &mut Context<Self>)
set_control_size(size: ControlSize, cx: &mut Context<Self>)
show(notification: Notification, window: &Window, cx: &mut Context<Self>) -> bool
record(notification: Notification, cx: &mut Context<Self>)
mark_read(id: &str, cx: &mut Context<Self>) -> bool
mark_all_read(cx: &mut Context<Self>)
dismiss(id: &str, cx: &mut Context<Self>) -> bool
clear(cx: &mut Context<Self>)
Queries
Only answer; they change nothing.
len() -> usize
is_empty() -> bool
holds(id: &str) -> bool
is_read(id: &str) -> Option<bool>
unread() -> UnreadCount
Reports
The variants of the event it emits. It never applies the change itself.
- Read
- Dismissed
- Cleared
- ActionTaken
Example · notification-center
fn notification_center(_window: &mut Window, cx: &mut App) -> AnyElement {
if !cx.has_global::<SceneNotifications>() {
let centre = cx.new(|cx| NotificationCenter::new("scene.notifications", cx));
centre.update(cx, |centre, cx| {
centre.record(
Notification::new("scene.notify.exported", "Theme exported to disk")
.tone(Tone::Success)
.at("9:41")
.read(true),
cx,
);
centre.record(
Notification::new("scene.notify.stale", "Refreshing the model catalog failed")
.tone(Tone::Warning)
.detail("The last verified catalog is still shown.")
.at("9:44"),
cx,
);
centre.record(
Notification::new(
"scene.notify.refused",
"The host refused to publish this run",
)
.tone(Tone::Warning)
.detail("Approval is required for this workspace.")
.at("9:46")
.action("Request approval", |_, _| {}),
cx,
);
});
cx.set_global(SceneNotifications { centre });
}
let centre = cx.global::<SceneNotifications>().centre.clone();
let theme = cx.theme().clone();
stack(&theme)
.w(px(520.0))
// The same three reports the toast scene shows, after their toasts
// have gone.
.child(caption(
&theme,
"what the toasts said, still here once they timed out",
))
.child(centre)
.into_any_element()
}