Add ui::Divider component
Co-Authored-By: Marshall Bowers <1486634+maxdeviant@users.noreply.github.com>
This commit is contained in:
parent
5dca5caf9f
commit
3d66ba35a3
2 changed files with 48 additions and 0 deletions
|
@ -3,6 +3,7 @@ mod button;
|
||||||
mod checkbox;
|
mod checkbox;
|
||||||
mod context_menu;
|
mod context_menu;
|
||||||
mod details;
|
mod details;
|
||||||
|
mod divider;
|
||||||
mod elevated_surface;
|
mod elevated_surface;
|
||||||
mod facepile;
|
mod facepile;
|
||||||
mod icon;
|
mod icon;
|
||||||
|
@ -31,6 +32,7 @@ pub use button::*;
|
||||||
pub use checkbox::*;
|
pub use checkbox::*;
|
||||||
pub use context_menu::*;
|
pub use context_menu::*;
|
||||||
pub use details::*;
|
pub use details::*;
|
||||||
|
pub use divider::*;
|
||||||
pub use elevated_surface::*;
|
pub use elevated_surface::*;
|
||||||
pub use facepile::*;
|
pub use facepile::*;
|
||||||
pub use icon::*;
|
pub use icon::*;
|
||||||
|
|
46
crates/ui2/src/components/divider.rs
Normal file
46
crates/ui2/src/components/divider.rs
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
use crate::prelude::*;
|
||||||
|
|
||||||
|
enum DividerDirection {
|
||||||
|
Horizontal,
|
||||||
|
Vertical,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
pub struct Divider {
|
||||||
|
direction: DividerDirection,
|
||||||
|
inset: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Divider {
|
||||||
|
pub fn horizontal() -> Self {
|
||||||
|
Self {
|
||||||
|
direction: DividerDirection::Horizontal,
|
||||||
|
inset: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn vertical() -> Self {
|
||||||
|
Self {
|
||||||
|
direction: DividerDirection::Vertical,
|
||||||
|
inset: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn inset(mut self) -> Self {
|
||||||
|
self.inset = true;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
|
||||||
|
div()
|
||||||
|
.map(|this| match self.direction {
|
||||||
|
DividerDirection::Horizontal => {
|
||||||
|
this.h_px().w_full().when(self.inset, |this| this.mx_1p5())
|
||||||
|
}
|
||||||
|
DividerDirection::Vertical => {
|
||||||
|
this.w_px().h_full().when(self.inset, |this| this.my_1p5())
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.bg(cx.theme().colors().border_variant)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue