gpui: Make style macros more composable (#14007)
This PR begins the process of breaking up the `style_helpers!` macro into smaller macros that can be used to generate methods for a related subset of styles. The style method macros also now accept an optional `visibility` parameter to control the visibility of the generated methods. This allows for adding these methods to a struct instead of a just a trait. For example, to expose just the padding styles on a `Facepile` we can do this: ```rs impl Facepile { fn style(&mut self) -> &mut StyleRefinement { self.base.style() } gpui::padding_style_methods!({ visibility: pub }); } ``` Release Notes: - N/A
This commit is contained in:
parent
8203b6875b
commit
3cdd465226
4 changed files with 335 additions and 203 deletions
|
@ -1,9 +1,10 @@
|
|||
use crate::{
|
||||
self as gpui, hsla, point, px, relative, rems, AbsoluteLength, AlignItems, CursorStyle,
|
||||
DefiniteLength, Fill, FlexDirection, FlexWrap, Font, FontStyle, FontWeight, Hsla,
|
||||
JustifyContent, Length, Position, SharedString, StyleRefinement, Visibility, WhiteSpace,
|
||||
JustifyContent, Length, SharedString, StyleRefinement, Visibility, WhiteSpace,
|
||||
};
|
||||
use crate::{BoxShadow, TextStyleRefinement};
|
||||
pub use gpui_macros::{margin_style_methods, padding_style_methods, position_style_methods};
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
use taffy::style::{AlignContent, Display, Overflow};
|
||||
|
||||
|
@ -14,20 +15,9 @@ pub trait Styled: Sized {
|
|||
fn style(&mut self) -> &mut StyleRefinement;
|
||||
|
||||
gpui_macros::style_helpers!();
|
||||
|
||||
/// Sets the position of the element to `relative`.
|
||||
/// [Docs](https://tailwindcss.com/docs/position)
|
||||
fn relative(mut self) -> Self {
|
||||
self.style().position = Some(Position::Relative);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the position of the element to `absolute`.
|
||||
/// [Docs](https://tailwindcss.com/docs/position)
|
||||
fn absolute(mut self) -> Self {
|
||||
self.style().position = Some(Position::Absolute);
|
||||
self
|
||||
}
|
||||
gpui_macros::margin_style_methods!();
|
||||
gpui_macros::padding_style_methods!();
|
||||
gpui_macros::position_style_methods!();
|
||||
|
||||
/// Sets the display type of the element to `block`.
|
||||
/// [Docs](https://tailwindcss.com/docs/display)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue