zed/crates/ui2/src/components/stack.rs

32 lines
631 B
Rust
Raw Normal View History

use gpui::{div, Div};
use crate::prelude::*;
2023-10-17 11:32:49 +00:00
pub trait Stack: Styled + Sized {
/// Horizontally stacks elements.
fn h_stack(self) -> Self {
self.flex().flex_row().items_center()
}
/// Vertically stacks elements.
fn v_stack(self) -> Self {
self.flex().flex_col()
}
}
2023-10-26 13:54:43 +00:00
impl<V: 'static> Stack for Div<V> {}
/// Horizontally stacks elements.
///
/// Sets `flex()`, `flex_row()`, `items_center()`
2023-10-26 13:54:43 +00:00
pub fn h_stack<V: 'static>() -> Div<V> {
div().h_stack()
}
/// Vertically stacks elements.
///
/// Sets `flex()`, `flex_col()`
2023-10-26 13:54:43 +00:00
pub fn v_stack<V: 'static>() -> Div<V> {
div().v_stack()
}