Add .when
to Element
s
This commit is contained in:
parent
77feecc623
commit
45d08c70f0
4 changed files with 32 additions and 12 deletions
|
@ -1,10 +1,12 @@
|
||||||
mod children;
|
mod children;
|
||||||
mod components;
|
mod components;
|
||||||
|
mod element_ext;
|
||||||
mod elements;
|
mod elements;
|
||||||
pub mod prelude;
|
pub mod prelude;
|
||||||
mod tokens;
|
mod tokens;
|
||||||
|
|
||||||
pub use children::*;
|
pub use children::*;
|
||||||
pub use components::*;
|
pub use components::*;
|
||||||
|
pub use element_ext::*;
|
||||||
pub use elements::*;
|
pub use elements::*;
|
||||||
pub use tokens::*;
|
pub use tokens::*;
|
||||||
|
|
|
@ -111,16 +111,16 @@ impl<S: 'static + Send + Sync + Clone> ListHeader<S> {
|
||||||
.flex_1()
|
.flex_1()
|
||||||
.w_full()
|
.w_full()
|
||||||
.fill(background_color)
|
.fill(background_color)
|
||||||
// .when(self.state == InteractionState::Focused, |this| {
|
.when(self.state == InteractionState::Focused, |this| {
|
||||||
// this.border()
|
this.border()
|
||||||
// .border_color(theme.lowest.accent.default.border)
|
.border_color(theme.lowest.accent.default.border)
|
||||||
// })
|
})
|
||||||
.relative()
|
.relative()
|
||||||
.py_1()
|
.py_1()
|
||||||
.child(
|
.child(
|
||||||
div()
|
div()
|
||||||
.h_6()
|
.h_6()
|
||||||
// .when(self.variant == ListItemVariant::Inset, |this| this.px_2())
|
.when(self.variant == ListItemVariant::Inset, |this| this.px_2())
|
||||||
.flex()
|
.flex()
|
||||||
.flex_1()
|
.flex_1()
|
||||||
.w_full()
|
.w_full()
|
||||||
|
@ -178,7 +178,7 @@ impl<S: 'static + Send + Sync + Clone> ListSubHeader<S> {
|
||||||
h_stack().flex_1().w_full().relative().py_1().child(
|
h_stack().flex_1().w_full().relative().py_1().child(
|
||||||
div()
|
div()
|
||||||
.h_6()
|
.h_6()
|
||||||
// .when(self.variant == ListItemVariant::Inset, |this| this.px_2())
|
.when(self.variant == ListItemVariant::Inset, |this| this.px_2())
|
||||||
.flex()
|
.flex()
|
||||||
.flex_1()
|
.flex_1()
|
||||||
.w_full()
|
.w_full()
|
||||||
|
@ -412,15 +412,15 @@ impl<S: 'static + Send + Sync + Clone> ListEntry<S> {
|
||||||
|
|
||||||
div()
|
div()
|
||||||
.fill(background_color)
|
.fill(background_color)
|
||||||
// .when(self.state == InteractionState::Focused, |this| {
|
.when(self.state == InteractionState::Focused, |this| {
|
||||||
// this.border()
|
this.border()
|
||||||
// .border_color(theme.lowest.accent.default.border)
|
.border_color(theme.lowest.accent.default.border)
|
||||||
// })
|
})
|
||||||
.relative()
|
.relative()
|
||||||
.py_1()
|
.py_1()
|
||||||
.child(
|
.child(
|
||||||
sized_item
|
sized_item
|
||||||
// .when(self.variant == ListItemVariant::Inset, |this| this.px_2())
|
.when(self.variant == ListItemVariant::Inset, |this| this.px_2())
|
||||||
// .ml(rems(0.75 * self.indent_level as f32))
|
// .ml(rems(0.75 * self.indent_level as f32))
|
||||||
.children((0..self.indent_level).map(|_| {
|
.children((0..self.indent_level).map(|_| {
|
||||||
div()
|
div()
|
||||||
|
|
18
crates/storybook2/src/ui/element_ext.rs
Normal file
18
crates/storybook2/src/ui/element_ext.rs
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
use gpui3::Element;
|
||||||
|
|
||||||
|
pub trait ElementExt<S: 'static + Send + Sync>: Element<State = S> {
|
||||||
|
/// Applies a given function `then` to the current element if `condition` is true.
|
||||||
|
/// This function is used to conditionally modify the element based on a given condition.
|
||||||
|
/// If `condition` is false, it just returns the current element as it is.
|
||||||
|
fn when(mut self, condition: bool, then: impl FnOnce(Self) -> Self) -> Self
|
||||||
|
where
|
||||||
|
Self: Sized,
|
||||||
|
{
|
||||||
|
if condition {
|
||||||
|
self = then(self);
|
||||||
|
}
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<S: 'static + Send + Sync, E: Element<State = S>> ElementExt<S> for E {}
|
|
@ -3,7 +3,7 @@ pub use gpui3::{
|
||||||
WindowContext,
|
WindowContext,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub use crate::ui::{HackyChildren, HackyChildrenPayload};
|
pub use crate::ui::{HackyChildren, HackyChildrenPayload, ElementExt};
|
||||||
|
|
||||||
use gpui3::{hsla, rgb, Hsla};
|
use gpui3::{hsla, rgb, Hsla};
|
||||||
use strum::EnumIter;
|
use strum::EnumIter;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue