utils: add shared StyledExt styling helper
This commit is contained in:
@@ -10,6 +10,7 @@ use gpui::{
|
||||
Render, RenderOnce, SharedString, StyleRefinement, Styled as _, Window, div, rems,
|
||||
};
|
||||
use gpui_native_theme::ActiveTheme as _;
|
||||
use gpui_native_utils::StyledExt as _;
|
||||
|
||||
use crate::resizable::{Resizable, ResizableState};
|
||||
|
||||
@@ -80,6 +81,7 @@ pub struct PanelRow {
|
||||
id: ElementId,
|
||||
main: Option<AnyElement>,
|
||||
split: Option<AnyElement>,
|
||||
style: StyleRefinement,
|
||||
}
|
||||
|
||||
impl PanelRow {
|
||||
@@ -92,6 +94,7 @@ impl PanelRow {
|
||||
id: id.into(),
|
||||
main: None,
|
||||
split: None,
|
||||
style: StyleRefinement::default(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,6 +117,12 @@ impl PanelRow {
|
||||
}
|
||||
}
|
||||
|
||||
impl gpui::Styled for PanelRow {
|
||||
fn style(&mut self) -> &mut StyleRefinement {
|
||||
&mut self.style
|
||||
}
|
||||
}
|
||||
|
||||
impl RenderOnce for PanelRow {
|
||||
fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
|
||||
let id = self.id.clone();
|
||||
@@ -152,6 +161,13 @@ impl RenderOnce for PanelRow {
|
||||
None => div().w_full().h_full().child(main),
|
||||
};
|
||||
|
||||
div().flex_1().min_w_0().h_full().p_2().pt_1().child(row)
|
||||
div()
|
||||
.flex_1()
|
||||
.min_w_0()
|
||||
.h_full()
|
||||
.p_2()
|
||||
.pt_1()
|
||||
.refine_style(&self.style)
|
||||
.child(row)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,11 +8,11 @@ use gpui::{
|
||||
App, Axis, Bounds, CursorStyle, DispatchPhase, ElementId, HitboxBehavior,
|
||||
InteractiveElement as _, IntoElement, KeyDownEvent, MouseButton, MouseDownEvent,
|
||||
MouseMoveEvent, MouseUpEvent, ParentElement as _, Pixels, Point, RenderOnce, Role,
|
||||
SharedString, StatefulInteractiveElement as _, Styled as _, Window, canvas, deferred, div,
|
||||
fill, point, px, rems,
|
||||
SharedString, StatefulInteractiveElement as _, StyleRefinement, Styled as _, Window, canvas,
|
||||
deferred, div, fill, point, px, rems,
|
||||
};
|
||||
use gpui_native_theme::{ActiveTheme as _, BORDER_WIDTH, HAIRLINE_WIDTH, RESIZE_KEYBOARD_STEP};
|
||||
use gpui_native_utils::{focus_handle, focus_ring};
|
||||
use gpui_native_utils::{StyledExt as _, focus_handle, focus_ring};
|
||||
|
||||
/// How far one keyboard arrow step moves the seam.
|
||||
const KEYBOARD_STEP: Pixels = RESIZE_KEYBOARD_STEP;
|
||||
@@ -38,6 +38,7 @@ pub struct ResizeHandle {
|
||||
accessibility_label: Option<SharedString>,
|
||||
on_resize: Option<ResizeHandler>,
|
||||
on_reset: Option<ResetHandler>,
|
||||
style: StyleRefinement,
|
||||
}
|
||||
|
||||
impl ResizeHandle {
|
||||
@@ -53,6 +54,7 @@ impl ResizeHandle {
|
||||
accessibility_label: None,
|
||||
on_resize: None,
|
||||
on_reset: None,
|
||||
style: StyleRefinement::default(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,6 +98,12 @@ impl ResizeHandle {
|
||||
}
|
||||
}
|
||||
|
||||
impl gpui::Styled for ResizeHandle {
|
||||
fn style(&mut self) -> &mut StyleRefinement {
|
||||
&mut self.style
|
||||
}
|
||||
}
|
||||
|
||||
impl RenderOnce for ResizeHandle {
|
||||
fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
|
||||
let theme = cx.theme();
|
||||
@@ -141,6 +149,7 @@ impl RenderOnce for ResizeHandle {
|
||||
.when(axis == Axis::Vertical, |handle| {
|
||||
handle.w_full().h(thickness)
|
||||
})
|
||||
.refine_style(&self.style)
|
||||
.when(self.disabled, |handle| handle.opacity(0.5))
|
||||
.when(!self.disabled, |handle| {
|
||||
handle
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
|
||||
use gpui::prelude::FluentBuilder as _;
|
||||
use gpui::{
|
||||
AnyElement, App, ElementId, Entity, IntoElement, ParentElement as _, RenderOnce, Styled as _,
|
||||
Window, div,
|
||||
AnyElement, App, ElementId, Entity, IntoElement, ParentElement as _, RenderOnce,
|
||||
StyleRefinement, Styled as _, Window, div,
|
||||
};
|
||||
#[cfg(feature = "alert")]
|
||||
use gpui_native_core::alert::{Alerts, AlertsView};
|
||||
@@ -13,7 +13,7 @@ use gpui_native_core::grain::grain as grain_overlay;
|
||||
#[cfg(feature = "toast")]
|
||||
use gpui_native_core::toast::{Toasts, ToastsView};
|
||||
use gpui_native_theme::ActiveTheme as _;
|
||||
use gpui_native_utils::v_flex;
|
||||
use gpui_native_utils::{StyledExt as _, v_flex};
|
||||
|
||||
use crate::titlebar::Titlebar;
|
||||
use crate::window_frame::frame;
|
||||
@@ -31,6 +31,7 @@ pub struct Shell {
|
||||
toasts: Option<Entity<Toasts>>,
|
||||
#[cfg(feature = "alert")]
|
||||
alerts: Option<Entity<Alerts>>,
|
||||
style: StyleRefinement,
|
||||
}
|
||||
|
||||
impl Shell {
|
||||
@@ -49,6 +50,7 @@ impl Shell {
|
||||
toasts: None,
|
||||
#[cfg(feature = "alert")]
|
||||
alerts: None,
|
||||
style: StyleRefinement::default(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,6 +96,12 @@ impl Shell {
|
||||
}
|
||||
}
|
||||
|
||||
impl gpui::Styled for Shell {
|
||||
fn style(&mut self) -> &mut StyleRefinement {
|
||||
&mut self.style
|
||||
}
|
||||
}
|
||||
|
||||
impl RenderOnce for Shell {
|
||||
fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
|
||||
let id = self.id.clone();
|
||||
@@ -110,6 +118,7 @@ impl RenderOnce for Shell {
|
||||
.h_full()
|
||||
.overflow_hidden()
|
||||
.bg(background)
|
||||
.refine_style(&self.style)
|
||||
.when(self.transparent && self.grain, |layout| {
|
||||
layout.child(grain_overlay())
|
||||
});
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
use gpui::prelude::FluentBuilder as _;
|
||||
use gpui::{
|
||||
AnyElement, App, ElementId, InteractiveElement as _, IntoElement, ParentElement, RenderOnce,
|
||||
SharedString, Styled as _, Window,
|
||||
SharedString, StyleRefinement, Styled as _, Window,
|
||||
};
|
||||
use gpui_native_theme::{ActiveTheme as _, Size, TRAFFIC_LIGHT_PAD};
|
||||
use gpui_native_utils::h_flex;
|
||||
use gpui_native_utils::{StyledExt as _, h_flex};
|
||||
|
||||
use crate::window_controls::{WindowControls, titlebar_strip};
|
||||
|
||||
@@ -23,6 +23,7 @@ pub struct Titlebar {
|
||||
tab_bar: Option<AnyElement>,
|
||||
suffix: Vec<AnyElement>,
|
||||
transparent: bool,
|
||||
style: StyleRefinement,
|
||||
}
|
||||
|
||||
impl Titlebar {
|
||||
@@ -37,6 +38,7 @@ impl Titlebar {
|
||||
tab_bar: None,
|
||||
suffix: Vec::new(),
|
||||
transparent: false,
|
||||
style: StyleRefinement::default(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,6 +68,12 @@ impl Titlebar {
|
||||
}
|
||||
}
|
||||
|
||||
impl gpui::Styled for Titlebar {
|
||||
fn style(&mut self) -> &mut StyleRefinement {
|
||||
&mut self.style
|
||||
}
|
||||
}
|
||||
|
||||
impl ParentElement for Titlebar {
|
||||
fn extend(&mut self, elements: impl IntoIterator<Item = AnyElement>) {
|
||||
self.prefix.extend(elements);
|
||||
@@ -91,6 +99,7 @@ impl RenderOnce for Titlebar {
|
||||
.gap_2()
|
||||
.when(!self.transparent, |bar| bar.bg(theme.colors.muted))
|
||||
.px(padding_x)
|
||||
.refine_style(&self.style)
|
||||
.when(cfg!(target_os = "macos"), |bar| bar.pl(TRAFFIC_LIGHT_PAD))
|
||||
.when(!self.prefix.is_empty(), |bar| {
|
||||
bar.child(
|
||||
|
||||
Reference in New Issue
Block a user