utils: add shared StyledExt styling helper
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -3,15 +3,15 @@
|
||||
use gpui::prelude::FluentBuilder as _;
|
||||
use gpui::{
|
||||
AnyElement, AnyView, App, ClickEvent, ElementId, InteractiveElement as _, IntoElement,
|
||||
ParentElement, RenderOnce, Role, SharedString, StatefulInteractiveElement as _, Styled as _,
|
||||
Window, canvas, relative, transparent_black,
|
||||
ParentElement, RenderOnce, Role, SharedString, StatefulInteractiveElement as _,
|
||||
StyleRefinement, Styled as _, Window, canvas, relative, transparent_black,
|
||||
};
|
||||
use gpui_native_icons::Icon;
|
||||
use gpui_native_theme::{ActiveTheme as _, BORDER_WIDTH, Size};
|
||||
use gpui_native_utils::{focus_ring, record_anchor_bounds};
|
||||
use std::rc::Rc;
|
||||
|
||||
use crate::common::{Sizable, h_flex};
|
||||
use crate::common::{Sizable, StyledExt as _, h_flex};
|
||||
use crate::spinner::Spinner;
|
||||
|
||||
/// The single activation handler, shared by pointer, Enter, and Space.
|
||||
@@ -64,6 +64,7 @@ pub struct Button {
|
||||
a11y_label: Option<SharedString>,
|
||||
tooltip: Option<TooltipBuilder>,
|
||||
on_click: Option<ClickHandler>,
|
||||
style: StyleRefinement,
|
||||
}
|
||||
|
||||
impl Button {
|
||||
@@ -88,6 +89,7 @@ impl Button {
|
||||
a11y_label: None,
|
||||
tooltip: None,
|
||||
on_click: None,
|
||||
style: StyleRefinement::default(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,6 +190,12 @@ impl ParentElement for Button {
|
||||
}
|
||||
}
|
||||
|
||||
impl gpui::Styled for Button {
|
||||
fn style(&mut self) -> &mut StyleRefinement {
|
||||
&mut self.style
|
||||
}
|
||||
}
|
||||
|
||||
impl Sizable for Button {
|
||||
fn apply_size(&mut self, size: Size) {
|
||||
self.size = size;
|
||||
@@ -277,6 +285,7 @@ impl RenderOnce for Button {
|
||||
.border_color(border)
|
||||
.when_some(background, |button, background| button.bg(background))
|
||||
.text_color(foreground)
|
||||
.refine_style(&self.style)
|
||||
.when_some(a11y_label, |button, label| button.aria_label(label))
|
||||
.child(
|
||||
h_flex()
|
||||
|
||||
@@ -5,13 +5,13 @@ use std::rc::Rc;
|
||||
use gpui::prelude::FluentBuilder as _;
|
||||
use gpui::{
|
||||
App, ElementId, InteractiveElement as _, IntoElement, ParentElement as _, RenderOnce, Role,
|
||||
SharedString, StatefulInteractiveElement as _, Styled as _, Toggled, Window,
|
||||
SharedString, StatefulInteractiveElement as _, StyleRefinement, Styled as _, Toggled, Window,
|
||||
};
|
||||
use gpui_native_icons::{IconRole, icon};
|
||||
use gpui_native_theme::{ActiveTheme as _, Size};
|
||||
use gpui_native_utils::focus_ring;
|
||||
|
||||
use crate::common::{Sizable, h_flex};
|
||||
use crate::common::{Sizable, StyledExt as _, h_flex};
|
||||
|
||||
/// The change reporter, fired with the next value by pointer, Enter, and Space.
|
||||
type ChangeHandler = Box<dyn Fn(bool, &mut Window, &mut App)>;
|
||||
@@ -28,6 +28,7 @@ pub struct Checkbox {
|
||||
debug_selector: Option<Rc<dyn Fn() -> String>>,
|
||||
a11y_label: Option<SharedString>,
|
||||
on_change: Option<ChangeHandler>,
|
||||
style: StyleRefinement,
|
||||
}
|
||||
|
||||
impl Checkbox {
|
||||
@@ -45,6 +46,7 @@ impl Checkbox {
|
||||
debug_selector: None,
|
||||
a11y_label: None,
|
||||
on_change: None,
|
||||
style: StyleRefinement::default(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,6 +99,12 @@ impl Checkbox {
|
||||
}
|
||||
}
|
||||
|
||||
impl gpui::Styled for Checkbox {
|
||||
fn style(&mut self) -> &mut StyleRefinement {
|
||||
&mut self.style
|
||||
}
|
||||
}
|
||||
|
||||
impl Sizable for Checkbox {
|
||||
fn apply_size(&mut self, size: Size) {
|
||||
self.size = size;
|
||||
@@ -117,6 +125,7 @@ impl RenderOnce for Checkbox {
|
||||
.id(self.id)
|
||||
.gap_1p5()
|
||||
.text_size(metrics.text_size)
|
||||
.refine_style(&self.style)
|
||||
.when_some(self.debug_selector, |checkbox, selector| {
|
||||
checkbox.debug_selector(move || selector())
|
||||
})
|
||||
|
||||
@@ -5,15 +5,15 @@ use std::time::Duration;
|
||||
|
||||
use gpui::prelude::FluentBuilder as _;
|
||||
use gpui::{
|
||||
AnyView, App, ClipboardItem, ElementId, Entity, IntoElement, RenderOnce, SharedString, Task,
|
||||
Window,
|
||||
AnyView, App, ClipboardItem, ElementId, Entity, IntoElement, RenderOnce, SharedString,
|
||||
StyleRefinement, Task, Window,
|
||||
};
|
||||
use gpui_native_icons::IconRole;
|
||||
use gpui_native_theme::Size;
|
||||
use gpui_native_utils::ResultLogErr as _;
|
||||
|
||||
use crate::button::{Button, ButtonVariant};
|
||||
use crate::common::Sizable;
|
||||
use crate::common::{Sizable, StyledExt as _};
|
||||
|
||||
/// How long the check mark shows before reverting to the copy icon.
|
||||
pub const COPIED_DURATION: Duration = Duration::from_secs(1);
|
||||
@@ -35,6 +35,7 @@ pub struct ClipboardButton {
|
||||
a11y_label: Option<SharedString>,
|
||||
tooltip: Option<TooltipBuilder>,
|
||||
on_copied: Option<CopiedHandler>,
|
||||
style: StyleRefinement,
|
||||
}
|
||||
|
||||
impl ClipboardButton {
|
||||
@@ -52,6 +53,7 @@ impl ClipboardButton {
|
||||
a11y_label: None,
|
||||
tooltip: None,
|
||||
on_copied: None,
|
||||
style: StyleRefinement::default(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,6 +129,7 @@ impl RenderOnce for ClipboardButton {
|
||||
.variant(ButtonVariant::Ghost)
|
||||
.with_size(self.size)
|
||||
.disabled(self.disabled)
|
||||
.refine_style(&self.style)
|
||||
.debug_selector(move || selector.to_string())
|
||||
.accessibility_label(self.a11y_label.unwrap_or_else(|| "Copy".into()))
|
||||
.when_some(self.tooltip, |button, tooltip| {
|
||||
|
||||
@@ -6,13 +6,13 @@ use gpui::prelude::FluentBuilder;
|
||||
use gpui::{
|
||||
AnyElement, App, Context, ElementId, Entity, InteractiveElement as _, IntoElement, KeyBinding,
|
||||
MouseButton, ParentElement as _, Render, Role, ScrollHandle, SharedString,
|
||||
StatefulInteractiveElement as _, Styled as _, Subscription, Window, actions, canvas, deferred,
|
||||
div, relative,
|
||||
StatefulInteractiveElement as _, StyleRefinement, Styled as _, Subscription, Window, actions,
|
||||
canvas, deferred, div, relative,
|
||||
};
|
||||
use gpui_native_icons::Icon;
|
||||
use gpui_native_theme::{ActiveTheme as _, POPUP_MAX_HEIGHT, Size};
|
||||
|
||||
use crate::common::{DIALOG_LAYER, h_flex, v_flex};
|
||||
use crate::common::{DIALOG_LAYER, StyledExt as _, h_flex, v_flex};
|
||||
use crate::input::{Input, InputState, InputStateEvent};
|
||||
use crate::scroll_area::{ScrollArea, ScrollAxes};
|
||||
|
||||
@@ -104,6 +104,7 @@ pub struct CommandPalette {
|
||||
commands: Vec<Command>,
|
||||
matcher: CommandMatcher,
|
||||
on_execute: Option<CommandHandler>,
|
||||
style: StyleRefinement,
|
||||
}
|
||||
|
||||
impl CommandPalette {
|
||||
@@ -120,6 +121,7 @@ impl CommandPalette {
|
||||
commands,
|
||||
matcher: Rc::new(matcher),
|
||||
on_execute: None,
|
||||
style: StyleRefinement::default(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,6 +164,7 @@ pub struct CommandPaletteState {
|
||||
commands: Vec<Command>,
|
||||
matcher: CommandMatcher,
|
||||
on_execute: Option<CommandHandler>,
|
||||
style: StyleRefinement,
|
||||
query: Entity<InputState>,
|
||||
/// The commands the matcher returned for the query, in display order.
|
||||
matches: Vec<Command>,
|
||||
@@ -191,6 +194,7 @@ impl CommandPaletteState {
|
||||
commands: palette.commands,
|
||||
matcher: palette.matcher,
|
||||
on_execute: palette.on_execute,
|
||||
style: palette.style,
|
||||
query,
|
||||
matches,
|
||||
highlight: None,
|
||||
@@ -451,6 +455,7 @@ impl Render for CommandPaletteState {
|
||||
.border_color(panel_border)
|
||||
.shadow(shadows)
|
||||
.overflow_hidden()
|
||||
.refine_style(&self.style)
|
||||
.on_mouse_down(MouseButton::Left, |_, _, cx| cx.stop_propagation())
|
||||
.on_action({
|
||||
let state = state.clone();
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
use gpui::prelude::FluentBuilder as _;
|
||||
use gpui::{
|
||||
App, ElementId, InteractiveElement as _, IntoElement, MouseButton, MouseDownEvent,
|
||||
ParentElement as _, RenderOnce, SharedString, Window, div,
|
||||
ParentElement as _, RenderOnce, SharedString, StyleRefinement, Window, div,
|
||||
};
|
||||
|
||||
use crate::common::StyledExt as _;
|
||||
use crate::menu::{Menu, MenuItem};
|
||||
|
||||
/// Builds the element that opens the menu on right-click.
|
||||
@@ -21,6 +22,7 @@ pub struct ContextMenu {
|
||||
target: Option<TargetFn>,
|
||||
items: Option<ItemsFn>,
|
||||
a11y_label: Option<SharedString>,
|
||||
style: StyleRefinement,
|
||||
}
|
||||
|
||||
impl ContextMenu {
|
||||
@@ -34,6 +36,7 @@ impl ContextMenu {
|
||||
target: None,
|
||||
items: None,
|
||||
a11y_label: None,
|
||||
style: StyleRefinement::default(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,6 +119,7 @@ impl RenderOnce for ContextMenu {
|
||||
.trigger_button(MouseButton::Right)
|
||||
.trigger(trigger)
|
||||
.items(items)
|
||||
.refine_style(&self.style)
|
||||
.when_some(self.a11y_label.clone(), |menu, label| {
|
||||
menu.accessibility_label(label)
|
||||
})
|
||||
|
||||
@@ -4,14 +4,14 @@ use std::rc::Rc;
|
||||
use gpui::{
|
||||
Animation, AnimationExt as _, AnyElement, App, DefiniteLength, ElementId,
|
||||
InteractiveElement as _, IntoElement, KeyDownEvent, MouseButton, ParentElement as _,
|
||||
RenderOnce, Role, ScrollHandle, SharedString, StatefulInteractiveElement as _, Styled as _,
|
||||
Window, canvas, deferred, div, ease_out_quint, relative,
|
||||
RenderOnce, Role, ScrollHandle, SharedString, StatefulInteractiveElement as _, StyleRefinement,
|
||||
Styled as _, Window, canvas, deferred, div, ease_out_quint, relative,
|
||||
};
|
||||
use gpui_native_icons::IconRole;
|
||||
use gpui_native_theme::{ActiveTheme as _, TextRole, Typeset as _};
|
||||
|
||||
use crate::button::{Button, ButtonVariant};
|
||||
use crate::common::{DIALOG_LAYER, Sizable, v_flex};
|
||||
use crate::common::{DIALOG_LAYER, Sizable, StyledExt as _, v_flex};
|
||||
use crate::grain::grain;
|
||||
use crate::scroll_area::ScrollArea;
|
||||
|
||||
@@ -35,6 +35,7 @@ pub struct Dialog {
|
||||
actions: Option<ActionsFn>,
|
||||
min_width: Option<DefiniteLength>,
|
||||
height: Option<DefiniteLength>,
|
||||
style: StyleRefinement,
|
||||
}
|
||||
|
||||
impl Dialog {
|
||||
@@ -55,6 +56,7 @@ impl Dialog {
|
||||
actions: None,
|
||||
min_width: None,
|
||||
height: None,
|
||||
style: StyleRefinement::default(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,6 +142,12 @@ impl Dialog {
|
||||
}
|
||||
}
|
||||
|
||||
impl gpui::Styled for Dialog {
|
||||
fn style(&mut self) -> &mut StyleRefinement {
|
||||
&mut self.style
|
||||
}
|
||||
}
|
||||
|
||||
impl RenderOnce for Dialog {
|
||||
fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
|
||||
let root = div().absolute().inset_0();
|
||||
@@ -307,6 +315,7 @@ impl RenderOnce for Dialog {
|
||||
.items_center()
|
||||
.justify_center()
|
||||
.p_4()
|
||||
.refine_style(&self.style)
|
||||
.child(scrim.with_animation(
|
||||
"dialog-scrim-enter",
|
||||
Animation::new(enter_duration).with_easing(ease_out_quint()),
|
||||
|
||||
@@ -7,14 +7,15 @@ use gpui::prelude::FluentBuilder as _;
|
||||
use gpui::{
|
||||
App, ClickEvent, DefiniteLength, DispatchPhase, ElementId, InteractiveElement as _,
|
||||
IntoElement, KeyDownEvent, MouseButton, MouseDownEvent, ParentElement as _, RenderOnce, Role,
|
||||
SharedString, StatefulInteractiveElement as _, Styled as _, Window, canvas, div, relative,
|
||||
SharedString, StatefulInteractiveElement as _, StyleRefinement, Styled as _, Window, canvas,
|
||||
div, relative,
|
||||
};
|
||||
use gpui_native_icons::{Icon, IconRole, icon};
|
||||
use gpui_native_theme::{ActiveTheme as _, BORDER_WIDTH, Size};
|
||||
use gpui_native_utils::{focus_handle, focus_ring};
|
||||
|
||||
use crate::button::ButtonVariant;
|
||||
use crate::common::{Sizable, h_flex};
|
||||
use crate::common::{Sizable, StyledExt as _, h_flex};
|
||||
use crate::menu::{
|
||||
ChangeHandler, MenuChrome, MenuItem, MenuPanelSpec, TriggerBoundsCell, anchored_menu_panel,
|
||||
};
|
||||
@@ -42,6 +43,7 @@ pub struct DropdownMenu {
|
||||
on_open_change: Option<ChangeHandler>,
|
||||
items: Option<ItemsFn>,
|
||||
min_width: Option<DefiniteLength>,
|
||||
style: StyleRefinement,
|
||||
}
|
||||
|
||||
impl DropdownMenu {
|
||||
@@ -65,6 +67,7 @@ impl DropdownMenu {
|
||||
on_open_change: None,
|
||||
items: None,
|
||||
min_width: None,
|
||||
style: StyleRefinement::default(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,6 +171,12 @@ impl Sizable for DropdownMenu {
|
||||
}
|
||||
}
|
||||
|
||||
impl gpui::Styled for DropdownMenu {
|
||||
fn style(&mut self) -> &mut StyleRefinement {
|
||||
&mut self.style
|
||||
}
|
||||
}
|
||||
|
||||
impl RenderOnce for DropdownMenu {
|
||||
fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
|
||||
let theme = cx.theme();
|
||||
@@ -410,6 +419,7 @@ impl RenderOnce for DropdownMenu {
|
||||
|
||||
div()
|
||||
.relative()
|
||||
.refine_style(&self.style)
|
||||
.child(
|
||||
canvas(
|
||||
{
|
||||
|
||||
@@ -11,8 +11,8 @@ use gpui::{
|
||||
EntityInputHandler, EventEmitter, Font, HitboxBehavior, InteractiveElement as _, IntoElement,
|
||||
KeyBinding, KeyDownEvent, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent,
|
||||
ParentElement as _, Pixels, RenderOnce, Role, ScrollDelta, ScrollEvent, SharedString,
|
||||
StatefulInteractiveElement as _, Styled as _, TextAlign, TextRun, UTF16Selection, Window,
|
||||
WrappedLine, actions, canvas, div, fill, point, px,
|
||||
StatefulInteractiveElement as _, StyleRefinement, Styled as _, TextAlign, TextRun,
|
||||
UTF16Selection, Window, WrappedLine, actions, canvas, div, fill, point, px,
|
||||
};
|
||||
use gpui_native_icons::IconRole;
|
||||
use gpui_native_theme::{
|
||||
@@ -22,7 +22,7 @@ use gpui_native_theme::{
|
||||
use gpui_native_utils::focus_ring;
|
||||
|
||||
use crate::button::{Button, ButtonVariant};
|
||||
use crate::common::{Sizable, h_flex};
|
||||
use crate::common::{Sizable, StyledExt as _, h_flex};
|
||||
|
||||
/// The key context input bindings match against.
|
||||
pub const INPUT_CONTEXT: &str = "Input";
|
||||
@@ -1884,6 +1884,7 @@ pub struct Input {
|
||||
rows: usize,
|
||||
prefix: Option<AnyElement>,
|
||||
suffix: Option<AnyElement>,
|
||||
style: StyleRefinement,
|
||||
}
|
||||
|
||||
impl Input {
|
||||
@@ -1903,6 +1904,7 @@ impl Input {
|
||||
rows: DEFAULT_ROWS,
|
||||
prefix: None,
|
||||
suffix: None,
|
||||
style: StyleRefinement::default(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1961,6 +1963,12 @@ impl Input {
|
||||
}
|
||||
}
|
||||
|
||||
impl gpui::Styled for Input {
|
||||
fn style(&mut self) -> &mut StyleRefinement {
|
||||
&mut self.style
|
||||
}
|
||||
}
|
||||
|
||||
impl Sizable for Input {
|
||||
fn apply_size(&mut self, size: Size) {
|
||||
self.size = size;
|
||||
@@ -2151,6 +2159,7 @@ impl RenderOnce for Input {
|
||||
} else {
|
||||
colors.input
|
||||
})
|
||||
.refine_style(&self.style)
|
||||
.when(self.disabled, |input| input.opacity(0.5))
|
||||
.when(!self.disabled, |input| {
|
||||
input.track_focus(&focus_handle).tab_stop(true)
|
||||
|
||||
+12
-2
@@ -1,12 +1,13 @@
|
||||
use gpui::prelude::FluentBuilder as _;
|
||||
use gpui::{
|
||||
App, ClickEvent, ElementId, InteractiveElement as _, IntoElement, ParentElement as _,
|
||||
RenderOnce, Role, SharedString, StatefulInteractiveElement as _, Styled as _, Window,
|
||||
RenderOnce, Role, SharedString, StatefulInteractiveElement as _, StyleRefinement, Styled as _,
|
||||
Window,
|
||||
};
|
||||
use gpui_native_theme::{ActiveTheme as _, Size};
|
||||
use gpui_native_utils::focus_ring;
|
||||
|
||||
use crate::common::{Sizable, h_flex};
|
||||
use crate::common::{Sizable, StyledExt as _, h_flex};
|
||||
|
||||
/// The click handler. When set it replaces the default `href` opening.
|
||||
type ClickHandler = Box<dyn Fn(&ClickEvent, &mut Window, &mut App)>;
|
||||
@@ -22,6 +23,7 @@ pub struct Link {
|
||||
disabled: bool,
|
||||
a11y_label: Option<SharedString>,
|
||||
on_click: Option<ClickHandler>,
|
||||
style: StyleRefinement,
|
||||
}
|
||||
|
||||
impl Link {
|
||||
@@ -38,6 +40,7 @@ impl Link {
|
||||
disabled: false,
|
||||
a11y_label: None,
|
||||
on_click: None,
|
||||
style: StyleRefinement::default(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,6 +87,12 @@ impl Link {
|
||||
}
|
||||
}
|
||||
|
||||
impl gpui::Styled for Link {
|
||||
fn style(&mut self) -> &mut StyleRefinement {
|
||||
&mut self.style
|
||||
}
|
||||
}
|
||||
|
||||
impl Sizable for Link {
|
||||
fn apply_size(&mut self, size: Size) {
|
||||
self.size = size;
|
||||
@@ -106,6 +115,7 @@ impl RenderOnce for Link {
|
||||
.text_size(metrics.text_size)
|
||||
.text_color(colors.accent)
|
||||
.underline()
|
||||
.refine_style(&self.style)
|
||||
.role(Role::Link)
|
||||
.when_some(a11y_label, |link, label| link.aria_label(label))
|
||||
.when(self.disabled, |link| link.opacity(0.5))
|
||||
|
||||
+12
-3
@@ -8,14 +8,14 @@ use gpui::{
|
||||
Animation, AnimationExt as _, AnyElement, App, Bounds, BoxShadow, DefiniteLength,
|
||||
DispatchPhase, ElementId, Entity, FocusHandle, InteractiveElement as _, IntoElement,
|
||||
KeyDownEvent, MouseButton, MouseDownEvent, ParentElement as _, Pixels, Point, RenderOnce, Role,
|
||||
ScrollHandle, SharedString, StatefulInteractiveElement as _, Styled as _, Window, anchored,
|
||||
canvas, deferred, div, ease_out_quint, point, px, relative,
|
||||
ScrollHandle, SharedString, StatefulInteractiveElement as _, StyleRefinement, Styled as _,
|
||||
Window, anchored, canvas, deferred, div, ease_out_quint, point, px, relative,
|
||||
};
|
||||
use gpui_native_icons::{Icon, IconRole, icon as icon_glyph};
|
||||
use gpui_native_theme::{ActiveTheme as _, BORDER_WIDTH, POPUP_MAX_HEIGHT};
|
||||
use gpui_native_utils::focus_handle;
|
||||
|
||||
use crate::common::{OVERLAY_LAYER, v_flex};
|
||||
use crate::common::{OVERLAY_LAYER, StyledExt as _, v_flex};
|
||||
use crate::scroll_area::{ScrollArea, ScrollAxes};
|
||||
|
||||
/// Runs the item's action. The menu closes itself before the handler runs.
|
||||
@@ -203,6 +203,7 @@ pub struct Menu {
|
||||
trigger: Option<TriggerFn>,
|
||||
items: Option<ItemsFn>,
|
||||
min_width: Option<DefiniteLength>,
|
||||
style: StyleRefinement,
|
||||
}
|
||||
|
||||
impl MenuChrome {
|
||||
@@ -256,6 +257,7 @@ impl Menu {
|
||||
trigger: None,
|
||||
items: None,
|
||||
min_width: None,
|
||||
style: StyleRefinement::default(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -332,6 +334,12 @@ impl Menu {
|
||||
}
|
||||
}
|
||||
|
||||
impl gpui::Styled for Menu {
|
||||
fn style(&mut self) -> &mut StyleRefinement {
|
||||
&mut self.style
|
||||
}
|
||||
}
|
||||
|
||||
impl RenderOnce for Menu {
|
||||
fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
|
||||
let (chrome, enter_duration) = MenuChrome::read(cx);
|
||||
@@ -367,6 +375,7 @@ impl RenderOnce for Menu {
|
||||
|
||||
div()
|
||||
.relative()
|
||||
.refine_style(&self.style)
|
||||
.child(
|
||||
canvas(
|
||||
{
|
||||
|
||||
@@ -6,11 +6,11 @@ use gpui::{
|
||||
Animation, AnimationExt as _, AnyElement, App, Bounds, DispatchPhase, ElementId,
|
||||
InteractiveElement as _, IntoElement, KeyDownEvent, MouseButton, MouseDownEvent,
|
||||
ParentElement as _, Pixels, RenderOnce, Role, SharedString, StatefulInteractiveElement as _,
|
||||
Styled as _, Window, anchored, canvas, deferred, div, ease_out_quint, point,
|
||||
StyleRefinement, Styled as _, Window, anchored, canvas, deferred, div, ease_out_quint, point,
|
||||
};
|
||||
use gpui_native_theme::ActiveTheme as _;
|
||||
|
||||
use crate::common::{OVERLAY_LAYER, v_flex};
|
||||
use crate::common::{OVERLAY_LAYER, StyledExt as _, v_flex};
|
||||
|
||||
/// Reports the next open state of a [`Popover`]: `true` to open, `false` to close.
|
||||
type ChangeHandler = Rc<dyn Fn(bool, &mut Window, &mut App)>;
|
||||
@@ -29,6 +29,7 @@ pub struct Popover {
|
||||
on_change: Option<ChangeHandler>,
|
||||
trigger: Option<TriggerFn>,
|
||||
content: Option<ContentFn>,
|
||||
style: StyleRefinement,
|
||||
}
|
||||
|
||||
impl Popover {
|
||||
@@ -44,6 +45,7 @@ impl Popover {
|
||||
on_change: None,
|
||||
trigger: None,
|
||||
content: None,
|
||||
style: StyleRefinement::default(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,6 +92,12 @@ impl Popover {
|
||||
}
|
||||
}
|
||||
|
||||
impl gpui::Styled for Popover {
|
||||
fn style(&mut self) -> &mut StyleRefinement {
|
||||
&mut self.style
|
||||
}
|
||||
}
|
||||
|
||||
impl RenderOnce for Popover {
|
||||
fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
|
||||
let (colors, radius, shadows, enter_duration, panel_border, anchor_gap) = {
|
||||
@@ -117,6 +125,7 @@ impl RenderOnce for Popover {
|
||||
|
||||
div()
|
||||
.relative()
|
||||
.refine_style(&self.style)
|
||||
.child(
|
||||
canvas(
|
||||
{
|
||||
|
||||
@@ -4,11 +4,11 @@ use gpui::prelude::FluentBuilder as _;
|
||||
use gpui::{
|
||||
Animation, AnimationExt as _, App, ElementId, InteractiveElement as _, IntoElement,
|
||||
ParentElement as _, RenderOnce, Role, SharedString, StatefulInteractiveElement as _,
|
||||
Styled as _, Window, div, relative,
|
||||
StyleRefinement, Styled as _, Window, div, relative,
|
||||
};
|
||||
use gpui_native_theme::{ActiveTheme as _, PROGRESS_ANIMATION_PERIOD, Size};
|
||||
|
||||
use crate::common::Sizable;
|
||||
use crate::common::{Sizable, StyledExt as _};
|
||||
|
||||
/// A progress bar. With a `value` in `0..=1` it paints a determinate fill.
|
||||
#[derive(IntoElement)]
|
||||
@@ -19,6 +19,7 @@ pub struct Progress {
|
||||
indeterminate: bool,
|
||||
size: Size,
|
||||
a11y_label: Option<SharedString>,
|
||||
style: StyleRefinement,
|
||||
}
|
||||
|
||||
impl Progress {
|
||||
@@ -33,6 +34,7 @@ impl Progress {
|
||||
indeterminate: false,
|
||||
size: Size::default(),
|
||||
a11y_label: None,
|
||||
style: StyleRefinement::default(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,6 +54,12 @@ impl Progress {
|
||||
}
|
||||
}
|
||||
|
||||
impl gpui::Styled for Progress {
|
||||
fn style(&mut self) -> &mut StyleRefinement {
|
||||
&mut self.style
|
||||
}
|
||||
}
|
||||
|
||||
impl Sizable for Progress {
|
||||
fn apply_size(&mut self, size: Size) {
|
||||
self.size = size;
|
||||
@@ -72,6 +80,7 @@ impl RenderOnce for Progress {
|
||||
div()
|
||||
.id(self.id)
|
||||
.w_full()
|
||||
.refine_style(&self.style)
|
||||
.role(Role::ProgressIndicator)
|
||||
.when_some(self.a11y_label, |progress, label| {
|
||||
progress.aria_label(label)
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
use gpui::prelude::FluentBuilder;
|
||||
use gpui::{
|
||||
App, ElementId, InteractiveElement as _, IntoElement, ParentElement as _, RenderOnce, Role,
|
||||
SharedString, StatefulInteractiveElement as _, Styled as _, Toggled, Window, div,
|
||||
SharedString, StatefulInteractiveElement as _, StyleRefinement, Styled as _, Toggled, Window,
|
||||
div,
|
||||
};
|
||||
use gpui_native_theme::{ActiveTheme as _, Size};
|
||||
use gpui_native_utils::focus_ring;
|
||||
|
||||
use crate::common::{Sizable, h_flex, v_flex};
|
||||
use crate::common::{Sizable, StyledExt as _, h_flex, v_flex};
|
||||
|
||||
/// The group's change reporter, fired with the clicked radio's value.
|
||||
type ChangeHandler<V> = std::rc::Rc<dyn Fn(V, &mut Window, &mut App)>;
|
||||
@@ -83,6 +84,7 @@ where
|
||||
size: Size,
|
||||
a11y_label: Option<SharedString>,
|
||||
on_change: Option<ChangeHandler<V>>,
|
||||
style: StyleRefinement,
|
||||
}
|
||||
|
||||
impl<V> RadioGroup<V>
|
||||
@@ -101,6 +103,7 @@ where
|
||||
size: Size::default(),
|
||||
a11y_label: None,
|
||||
on_change: None,
|
||||
style: StyleRefinement::default(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,6 +147,15 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<V> gpui::Styled for RadioGroup<V>
|
||||
where
|
||||
V: Clone + PartialEq + 'static,
|
||||
{
|
||||
fn style(&mut self) -> &mut StyleRefinement {
|
||||
&mut self.style
|
||||
}
|
||||
}
|
||||
|
||||
impl<V> RenderOnce for RadioGroup<V>
|
||||
where
|
||||
V: Clone + PartialEq + 'static,
|
||||
@@ -162,6 +174,7 @@ where
|
||||
.id(self.id)
|
||||
.gap_2()
|
||||
.text_size(metrics.text_size)
|
||||
.refine_style(&self.style)
|
||||
.role(Role::RadioGroup)
|
||||
.when_some(group_label.clone(), |group, label| group.aria_label(label))
|
||||
.children(self.children.into_iter().map(move |radio| {
|
||||
|
||||
@@ -3,8 +3,12 @@
|
||||
use std::rc::Rc;
|
||||
|
||||
use gpui::prelude::FluentBuilder as _;
|
||||
use gpui::{App, InteractiveElement as _, IntoElement, RenderOnce, Styled as _, Window, div};
|
||||
use gpui::{
|
||||
App, InteractiveElement as _, IntoElement, RenderOnce, StyleRefinement, Styled as _, Window,
|
||||
div,
|
||||
};
|
||||
use gpui_native_theme::{ActiveTheme as _, BORDER_WIDTH};
|
||||
use gpui_native_utils::StyledExt as _;
|
||||
|
||||
/// Which axis the rule runs along.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
@@ -24,6 +28,7 @@ type DebugSelector = Rc<dyn Fn() -> String>;
|
||||
pub struct Separator {
|
||||
orientation: SeparatorOrientation,
|
||||
debug_selector: Option<DebugSelector>,
|
||||
style: StyleRefinement,
|
||||
}
|
||||
|
||||
impl Separator {
|
||||
@@ -32,6 +37,7 @@ impl Separator {
|
||||
Self {
|
||||
orientation: SeparatorOrientation::Horizontal,
|
||||
debug_selector: None,
|
||||
style: StyleRefinement::default(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,6 +46,7 @@ impl Separator {
|
||||
Self {
|
||||
orientation: SeparatorOrientation::Vertical,
|
||||
debug_selector: None,
|
||||
style: StyleRefinement::default(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,6 +66,12 @@ impl Separator {
|
||||
}
|
||||
}
|
||||
|
||||
impl gpui::Styled for Separator {
|
||||
fn style(&mut self) -> &mut StyleRefinement {
|
||||
&mut self.style
|
||||
}
|
||||
}
|
||||
|
||||
impl RenderOnce for Separator {
|
||||
fn render(self, _window: &mut Window, cx: &mut App) -> impl IntoElement {
|
||||
let border = cx.theme().colors.border;
|
||||
@@ -73,5 +86,6 @@ impl RenderOnce for Separator {
|
||||
SeparatorOrientation::Horizontal => rule.w_full().h(BORDER_WIDTH),
|
||||
SeparatorOrientation::Vertical => rule.self_stretch().w(BORDER_WIDTH),
|
||||
})
|
||||
.refine_style(&self.style)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,12 +5,13 @@ use gpui::prelude::FluentBuilder as _;
|
||||
use gpui::{
|
||||
App, Bounds, DispatchPhase, ElementId, InteractiveElement as _, IntoElement, KeyDownEvent,
|
||||
MouseButton, MouseMoveEvent, MouseUpEvent, ParentElement as _, Pixels, RenderOnce, Role,
|
||||
SharedString, StatefulInteractiveElement as _, Styled as _, Window, canvas, div, relative,
|
||||
SharedString, StatefulInteractiveElement as _, StyleRefinement, Styled as _, Window, canvas,
|
||||
div, relative,
|
||||
};
|
||||
use gpui_native_theme::{ActiveTheme as _, Size};
|
||||
use gpui_native_utils::focus_ring;
|
||||
|
||||
use crate::common::{Sizable, h_flex};
|
||||
use crate::common::{Sizable, StyledExt as _, h_flex};
|
||||
|
||||
/// The change reporter, fired with the next value by click, drag, and arrows.
|
||||
type ChangeHandler = Rc<dyn Fn(f32, &mut Window, &mut App)>;
|
||||
@@ -46,6 +47,7 @@ pub struct Slider {
|
||||
disabled: bool,
|
||||
a11y_label: Option<SharedString>,
|
||||
on_change: Option<ChangeHandler>,
|
||||
style: StyleRefinement,
|
||||
}
|
||||
|
||||
impl Slider {
|
||||
@@ -64,6 +66,7 @@ impl Slider {
|
||||
disabled: false,
|
||||
a11y_label: None,
|
||||
on_change: None,
|
||||
style: StyleRefinement::default(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,6 +113,12 @@ impl Slider {
|
||||
}
|
||||
}
|
||||
|
||||
impl gpui::Styled for Slider {
|
||||
fn style(&mut self) -> &mut StyleRefinement {
|
||||
&mut self.style
|
||||
}
|
||||
}
|
||||
|
||||
impl Sizable for Slider {
|
||||
fn apply_size(&mut self, size: Size) {
|
||||
self.size = size;
|
||||
@@ -169,6 +178,7 @@ impl RenderOnce for Slider {
|
||||
.relative()
|
||||
.w_full()
|
||||
.h(row_height)
|
||||
.refine_style(&self.style)
|
||||
.role(Role::Slider)
|
||||
.when_some(self.a11y_label.clone(), |slider, label| {
|
||||
slider.aria_label(label)
|
||||
|
||||
@@ -15,8 +15,8 @@ use std::sync::{Arc, Mutex};
|
||||
use gpui::prelude::FluentBuilder as _;
|
||||
use gpui::{
|
||||
App, Context, ElementId, Entity, EventEmitter, InteractiveElement as _, IntoElement,
|
||||
ParentElement as _, RenderOnce, Role, SharedString, StatefulInteractiveElement as _, Styled,
|
||||
Subscription, Task, WeakEntity, Window, div, relative,
|
||||
ParentElement as _, RenderOnce, Role, SharedString, StatefulInteractiveElement as _,
|
||||
StyleRefinement, Styled, Subscription, Task, WeakEntity, Window, div, relative,
|
||||
};
|
||||
use gpui_native_icons::{IconRole, icon};
|
||||
use gpui_native_theme::{ActiveTheme as _, BORDER_WIDTH, Size};
|
||||
@@ -654,6 +654,7 @@ pub struct SpeechButton {
|
||||
size: Size,
|
||||
disabled: bool,
|
||||
show_when_unsupported: bool,
|
||||
style: StyleRefinement,
|
||||
}
|
||||
|
||||
impl SpeechButton {
|
||||
@@ -664,6 +665,7 @@ impl SpeechButton {
|
||||
size: Size::default(),
|
||||
disabled: false,
|
||||
show_when_unsupported: false,
|
||||
style: StyleRefinement::default(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -680,6 +682,12 @@ impl SpeechButton {
|
||||
}
|
||||
}
|
||||
|
||||
impl gpui::Styled for SpeechButton {
|
||||
fn style(&mut self) -> &mut StyleRefinement {
|
||||
&mut self.style
|
||||
}
|
||||
}
|
||||
|
||||
impl Sizable for SpeechButton {
|
||||
fn apply_size(&mut self, size: Size) {
|
||||
self.size = size;
|
||||
@@ -741,6 +749,7 @@ impl RenderOnce for SpeechButton {
|
||||
.rounded(theme.radius.control)
|
||||
.text_color(foreground)
|
||||
.when(capturing, |button| button.bg(colors.muted))
|
||||
.refine_style(&self.style)
|
||||
.when(disabled, |button| button.opacity(0.5))
|
||||
.aria_label(label.clone())
|
||||
.tooltip(Tooltip::text(label))
|
||||
|
||||
@@ -8,13 +8,13 @@ use gpui::prelude::FluentBuilder as _;
|
||||
use gpui::{
|
||||
Animation, AnimationElement, AnimationExt as _, App, Canvas, ElementId, Hsla,
|
||||
InteractiveElement as _, IntoElement, ParentElement as _, Path, PathBuilder, Pixels, Point,
|
||||
RenderOnce, Role, SharedString, StatefulInteractiveElement as _, Styled as _, Window, canvas,
|
||||
div, point, px,
|
||||
RenderOnce, Role, SharedString, StatefulInteractiveElement as _, StyleRefinement, Styled as _,
|
||||
Window, canvas, div, point, px,
|
||||
};
|
||||
use gpui_native_icons::{Icon, IconRole, icon};
|
||||
use gpui_native_theme::{ActiveTheme as _, SPINNER_PERIOD, Size};
|
||||
|
||||
use crate::common::Sizable;
|
||||
use crate::common::{Sizable, StyledExt as _};
|
||||
|
||||
/// The share of the circle the spinning arc paints.
|
||||
const SPIN_SWEEP: f32 = 0.75;
|
||||
@@ -41,6 +41,7 @@ pub struct Spinner {
|
||||
size: Size,
|
||||
color: Option<Hsla>,
|
||||
a11y_label: Option<SharedString>,
|
||||
style: StyleRefinement,
|
||||
}
|
||||
|
||||
impl Spinner {
|
||||
@@ -56,6 +57,7 @@ impl Spinner {
|
||||
size: Size::default(),
|
||||
color: None,
|
||||
a11y_label: None,
|
||||
style: StyleRefinement::default(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,6 +89,12 @@ impl Spinner {
|
||||
}
|
||||
}
|
||||
|
||||
impl gpui::Styled for Spinner {
|
||||
fn style(&mut self) -> &mut StyleRefinement {
|
||||
&mut self.style
|
||||
}
|
||||
}
|
||||
|
||||
impl Sizable for Spinner {
|
||||
fn apply_size(&mut self, size: Size) {
|
||||
self.size = size;
|
||||
@@ -106,6 +114,7 @@ impl RenderOnce for Spinner {
|
||||
.id(self.id)
|
||||
.flex_none()
|
||||
.size(side)
|
||||
.refine_style(&self.style)
|
||||
.role(Role::ProgressIndicator)
|
||||
.when_some(self.a11y_label, |spinner, label| spinner.aria_label(label))
|
||||
.when_some(value, |spinner, value| {
|
||||
|
||||
@@ -3,13 +3,13 @@
|
||||
use gpui::prelude::FluentBuilder as _;
|
||||
use gpui::{
|
||||
AnimationExt as _, App, ElementId, InteractiveElement as _, IntoElement, ParentElement as _,
|
||||
RenderOnce, Role, SharedString, SpringAnimation, StatefulInteractiveElement as _, Styled as _,
|
||||
Toggled, Window, div, px,
|
||||
RenderOnce, Role, SharedString, SpringAnimation, StatefulInteractiveElement as _,
|
||||
StyleRefinement, Styled as _, Toggled, Window, div, px,
|
||||
};
|
||||
use gpui_native_theme::{ActiveTheme as _, CONTROL_SPRING, Size};
|
||||
use gpui_native_utils::focus_ring;
|
||||
|
||||
use crate::common::{Sizable, h_flex};
|
||||
use crate::common::{Sizable, StyledExt as _, h_flex};
|
||||
|
||||
/// The change reporter, fired with the next value by pointer, Enter, and Space.
|
||||
type ChangeHandler = Box<dyn Fn(bool, &mut Window, &mut App)>;
|
||||
@@ -25,6 +25,7 @@ pub struct Switch {
|
||||
disabled: bool,
|
||||
a11y_label: Option<SharedString>,
|
||||
on_change: Option<ChangeHandler>,
|
||||
style: StyleRefinement,
|
||||
}
|
||||
|
||||
impl Switch {
|
||||
@@ -41,6 +42,7 @@ impl Switch {
|
||||
disabled: false,
|
||||
a11y_label: None,
|
||||
on_change: None,
|
||||
style: StyleRefinement::default(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,6 +86,12 @@ impl Switch {
|
||||
}
|
||||
}
|
||||
|
||||
impl gpui::Styled for Switch {
|
||||
fn style(&mut self) -> &mut StyleRefinement {
|
||||
&mut self.style
|
||||
}
|
||||
}
|
||||
|
||||
impl Sizable for Switch {
|
||||
fn apply_size(&mut self, size: Size) {
|
||||
self.size = size;
|
||||
@@ -116,6 +124,7 @@ impl RenderOnce for Switch {
|
||||
.id(self.id)
|
||||
.gap_1p5()
|
||||
.text_size(metrics.text_size)
|
||||
.refine_style(&self.style)
|
||||
.role(Role::Switch)
|
||||
.when_some(a11y_label, |switch, label| switch.aria_label(label))
|
||||
.aria_toggled(Toggled::from(self.checked))
|
||||
|
||||
@@ -7,14 +7,15 @@ use gpui::prelude::FluentBuilder;
|
||||
use gpui::{
|
||||
Animation, AnimationExt as _, App, Context, ElementId, Entity, InteractiveElement as _,
|
||||
IntoElement, ParentElement as _, RenderOnce, Role, SharedString,
|
||||
StatefulInteractiveElement as _, Styled as _, Task, Window, deferred, div, ease_out_quint, px,
|
||||
StatefulInteractiveElement as _, StyleRefinement, Styled as _, Task, Window, deferred, div,
|
||||
ease_out_quint, px,
|
||||
};
|
||||
use gpui_native_icons::{Icon, IconRole};
|
||||
use gpui_native_theme::{ActiveTheme as _, TOAST_MAX_WIDTH};
|
||||
use gpui_native_utils::ResultLogErr as _;
|
||||
|
||||
use crate::button::{Button, ButtonVariant};
|
||||
use crate::common::{DismissHandler, Sizable as _, TOAST_LAYER};
|
||||
use crate::common::{DismissHandler, Sizable as _, StyledExt as _, TOAST_LAYER};
|
||||
|
||||
/// The action handler of a [`Toast`].
|
||||
pub type ActionHandler = Rc<dyn Fn(&mut App)>;
|
||||
@@ -49,6 +50,7 @@ pub struct Toast {
|
||||
action: Option<ToastAction>,
|
||||
duration: Option<Duration>,
|
||||
on_dismiss: Option<DismissHandler>,
|
||||
style: StyleRefinement,
|
||||
}
|
||||
|
||||
impl Toast {
|
||||
@@ -66,6 +68,7 @@ impl Toast {
|
||||
action: None,
|
||||
duration: Some(Self::DURATION),
|
||||
on_dismiss: None,
|
||||
style: StyleRefinement::default(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -300,6 +303,7 @@ impl ToastEntry {
|
||||
.border_color(border)
|
||||
.rounded(radius)
|
||||
.shadow(shadows.clone())
|
||||
.refine_style(&toast.style)
|
||||
.when_some(toast.icon.clone(), |pill, icon| {
|
||||
pill.child(
|
||||
div()
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
use gpui::prelude::FluentBuilder as _;
|
||||
use gpui::{
|
||||
App, ElementId, InteractiveElement as _, IntoElement, ParentElement as _, RenderOnce, Role,
|
||||
SharedString, StatefulInteractiveElement as _, Styled as _, Toggled, Window,
|
||||
SharedString, StatefulInteractiveElement as _, StyleRefinement, Styled as _, Toggled, Window,
|
||||
};
|
||||
use gpui_native_theme::{ActiveTheme as _, Size};
|
||||
use gpui_native_utils::focus_ring;
|
||||
|
||||
use crate::common::{Sizable, h_flex};
|
||||
use crate::common::{Sizable, StyledExt as _, h_flex};
|
||||
|
||||
/// The change handler, fired with the next pressed state.
|
||||
type ChangeHandler = Box<dyn Fn(bool, &mut Window, &mut App)>;
|
||||
@@ -22,6 +22,7 @@ pub struct Toggle {
|
||||
disabled: bool,
|
||||
a11y_label: Option<SharedString>,
|
||||
on_change: Option<ChangeHandler>,
|
||||
style: StyleRefinement,
|
||||
}
|
||||
|
||||
impl Toggle {
|
||||
@@ -38,6 +39,7 @@ impl Toggle {
|
||||
disabled: false,
|
||||
a11y_label: None,
|
||||
on_change: None,
|
||||
style: StyleRefinement::default(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,6 +83,12 @@ impl Toggle {
|
||||
}
|
||||
}
|
||||
|
||||
impl gpui::Styled for Toggle {
|
||||
fn style(&mut self) -> &mut StyleRefinement {
|
||||
&mut self.style
|
||||
}
|
||||
}
|
||||
|
||||
impl Sizable for Toggle {
|
||||
fn apply_size(&mut self, size: Size) {
|
||||
self.size = size;
|
||||
@@ -118,6 +126,7 @@ impl RenderOnce for Toggle {
|
||||
.hover(|style| style.bg(colors.muted))
|
||||
.active(|style| style.bg(ramps.secondary.hover))
|
||||
})
|
||||
.refine_style(&self.style)
|
||||
.when(self.disabled, |toggle| toggle.opacity(0.5))
|
||||
.when(!self.disabled, |toggle| {
|
||||
toggle
|
||||
|
||||
Reference in New Issue
Block a user