add sizable trait
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
use gpui::{Div, Styled as _, div};
|
||||
|
||||
pub use gpui_native_theme::Size;
|
||||
|
||||
/// A row whose children center on the cross axis.
|
||||
pub fn h_flex() -> Div {
|
||||
div().flex().flex_row().items_center()
|
||||
@@ -11,3 +13,31 @@ pub fn h_flex() -> Div {
|
||||
pub fn v_flex() -> Div {
|
||||
div().flex().flex_col()
|
||||
}
|
||||
|
||||
/// A component that can be told which size to render at.
|
||||
pub trait Sizable: Sized {
|
||||
/// Sets the size.
|
||||
fn with_size(mut self, size: Size) -> Self {
|
||||
self.apply_size(size);
|
||||
self
|
||||
}
|
||||
|
||||
/// Applies the size to the component's fields.
|
||||
fn apply_size(&mut self, size: Size);
|
||||
|
||||
/// Sets `Size::Small`.
|
||||
fn small(self) -> Self
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
self.with_size(Size::Small)
|
||||
}
|
||||
|
||||
/// Sets `Size::Large`.
|
||||
fn large(self) -> Self
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
self.with_size(Size::Large)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user