Skip to content

Commit 3d66ba3

Browse files
Add ui::Divider component
Co-Authored-By: Marshall Bowers <1486634+maxdeviant@users.noreply.github.com>
1 parent 5dca5ca commit 3d66ba3

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

crates/ui2/src/components.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ mod button;
33
mod checkbox;
44
mod context_menu;
55
mod details;
6+
mod divider;
67
mod elevated_surface;
78
mod facepile;
89
mod icon;
@@ -31,6 +32,7 @@ pub use button::*;
3132
pub use checkbox::*;
3233
pub use context_menu::*;
3334
pub use details::*;
35+
pub use divider::*;
3436
pub use elevated_surface::*;
3537
pub use facepile::*;
3638
pub use icon::*;

crates/ui2/src/components/divider.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
use crate::prelude::*;
2+
3+
enum DividerDirection {
4+
Horizontal,
5+
Vertical,
6+
}
7+
8+
#[derive(Component)]
9+
pub struct Divider {
10+
direction: DividerDirection,
11+
inset: bool,
12+
}
13+
14+
impl Divider {
15+
pub fn horizontal() -> Self {
16+
Self {
17+
direction: DividerDirection::Horizontal,
18+
inset: false,
19+
}
20+
}
21+
22+
pub fn vertical() -> Self {
23+
Self {
24+
direction: DividerDirection::Vertical,
25+
inset: false,
26+
}
27+
}
28+
29+
pub fn inset(mut self) -> Self {
30+
self.inset = true;
31+
self
32+
}
33+
34+
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
35+
div()
36+
.map(|this| match self.direction {
37+
DividerDirection::Horizontal => {
38+
this.h_px().w_full().when(self.inset, |this| this.mx_1p5())
39+
}
40+
DividerDirection::Vertical => {
41+
this.w_px().h_full().when(self.inset, |this| this.my_1p5())
42+
}
43+
})
44+
.bg(cx.theme().colors().border_variant)
45+
}
46+
}

0 commit comments

Comments
 (0)