utils: add shared StyledExt styling helper

This commit is contained in:
2026-11-16 14:02:33 +07:00
parent d7e4047070
commit 745a01d7af
29 changed files with 332 additions and 68 deletions
+17 -5
View File
@@ -4,7 +4,8 @@ use gpui::prelude::FluentBuilder as _;
use gpui::{
Animation, AnimationExt as _, App, Context, ElementId, Entity, InteractiveElement as _,
IntoElement, ParentElement as _, RenderOnce, Role, SharedString,
StatefulInteractiveElement as _, Styled as _, Window, deferred, div, ease_out_quint,
StatefulInteractiveElement as _, StyleRefinement, Styled as _, Window, deferred, div,
ease_out_quint,
};
use gpui_native_icons::{Icon, IconRole};
use gpui_native_theme::{ActiveTheme as _, ENTER_SLIDE_DISTANCE, Size, TextRole, Typeset as _};
@@ -13,6 +14,7 @@ use gpui_native_utils::ResultLogErr as _;
use crate::button::{Button, ButtonVariant};
use crate::common::DismissHandler;
use crate::common::Sizable as _;
use crate::common::StyledExt as _;
use crate::common::TOAST_LAYER;
use crate::common::v_flex;
@@ -48,9 +50,10 @@ pub struct Alert {
title: Option<SharedString>,
message: Option<SharedString>,
severity: AlertSeverity,
style: AlertStyle,
presentation: AlertStyle,
icon: Option<Icon>,
on_dismiss: Option<DismissHandler>,
style: StyleRefinement,
}
impl Alert {
@@ -63,9 +66,10 @@ impl Alert {
title: None,
message: None,
severity: AlertSeverity::Info,
style: AlertStyle::default(),
presentation: AlertStyle::default(),
icon: None,
on_dismiss: None,
style: StyleRefinement::default(),
}
}
@@ -95,7 +99,7 @@ impl Alert {
/// Sets how the alert presents.
pub fn style(mut self, style: AlertStyle) -> Self {
self.style = style;
self.presentation = style;
self
}
@@ -123,6 +127,12 @@ impl Alert {
}
}
impl gpui::Styled for Alert {
fn style(&mut self) -> &mut StyleRefinement {
&mut self.style
}
}
impl RenderOnce for Alert {
fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
let theme = cx.theme();
@@ -176,7 +186,7 @@ impl RenderOnce for Alert {
.on_click(move |_, _window, cx| on_dismiss(cx))
});
match self.style {
match self.presentation {
AlertStyle::Overlay => {
let surface = theme.colors.surface;
let border = if theme.borders.overlays {
@@ -199,6 +209,7 @@ impl RenderOnce for Alert {
.border_1()
.border_color(border)
.shadow(theme.elevations.popover.shadows())
.refine_style(&self.style)
.when_some(self.icon.clone(), |alert, icon_glyph| {
alert.child(
div()
@@ -219,6 +230,7 @@ impl RenderOnce for Alert {
.flex()
.overflow_hidden()
.bg(ramp.subtle)
.refine_style(&self.style)
.child(div().flex_none().w_1p5().self_stretch().bg(ramp.base))
.child(
div()