Add vertical line

This commit is contained in:
Kenny Levinsen
2023-02-14 00:28:40 +01:00
parent b09f642fd6
commit 8202963a6f
2 changed files with 42 additions and 22 deletions
+27 -17
View File
@@ -31,7 +31,8 @@ pub enum Widget {
HorizontalLayout(Vec<Widget>), HorizontalLayout(Vec<Widget>),
InvertedHorizontalLayout(Vec<Widget>), InvertedHorizontalLayout(Vec<Widget>),
VerticalLayout(Vec<Widget>), VerticalLayout(Vec<Widget>),
Line(u32), HorizontalLine(u32),
VerticalLine(u32),
Clock { Clock {
font: Option<String>, font: Option<String>,
font_size: f32, font_size: f32,
@@ -219,15 +220,19 @@ impl Config {
}, },
Widget::VerticalLayout(bars), Widget::VerticalLayout(bars),
]), ]),
Widget::Line(1), Widget::HorizontalLine(1),
Widget::InvertedHorizontalLayout(vec![ Widget::InvertedHorizontalLayout(vec![
Widget::Calendar { Widget::Margin {
font_primary: None, margins: (16, 8, 16, 0),
font_secondary: None, widget: Box::new(Widget::Calendar {
font_size: 24., font_primary: None,
sections_x: 1, font_secondary: None,
sections_y: -1, font_size: 24.,
sections_x: 1,
sections_y: if clay { -1 } else { 3 },
}),
}, },
Widget::VerticalLine(1),
Widget::Launcher { Widget::Launcher {
font: None, font: None,
font_size: 32., font_size: 32.,
@@ -246,7 +251,7 @@ impl Config {
mode: if clay { mode: if clay {
OperationMode::XdgToplevel OperationMode::XdgToplevel
} else { } else {
OperationMode::LayerSurface((1024, 768)) OperationMode::LayerSurface((1024, 1))
}, },
} }
} }
@@ -299,15 +304,19 @@ impl Default for Widget {
}, },
]), ]),
]), ]),
Widget::Line(1), Widget::HorizontalLine(1),
Widget::InvertedHorizontalLayout(vec![ Widget::InvertedHorizontalLayout(vec![
Widget::Calendar { Widget::Margin {
font_primary: None, margins: (16, 8, 16, 0),
font_secondary: None, widget: Box::new(Widget::Calendar {
font_size: 24., font_primary: None,
sections_x: 1, font_secondary: None,
sections_y: -1, font_size: 24.,
sections_x: 1,
sections_y: -1,
}),
}, },
Widget::VerticalLine(1),
Widget::Launcher { Widget::Launcher {
font: None, font: None,
font_size: 32., font_size: 32.,
@@ -335,7 +344,8 @@ impl Widget {
Widget::VerticalLayout(widgets) => widgets Widget::VerticalLayout(widgets) => widgets
.into_iter() .into_iter()
.for_each(|w| w.construct_widgets(v, fm, events)), .for_each(|w| w.construct_widgets(v, fm, events)),
Widget::Line(width) => v.push(Box::new(Line::new(width))), Widget::HorizontalLine(width) => v.push(Box::new(Line::new(width, false))),
Widget::VerticalLine(width) => v.push(Box::new(Line::new(width, true))),
Widget::Clock { font, font_size } => v.push(Box::new(Clock::new( Widget::Clock { font, font_size } => v.push(Box::new(Clock::new(
&mut fm, &mut fm,
leak_or_default(font, "sans"), leak_or_default(font, "sans"),
+15 -5
View File
@@ -10,13 +10,15 @@ use crate::{
pub struct Line { pub struct Line {
geometry: Geometry, geometry: Geometry,
thickness: u32, thickness: u32,
vertical: bool,
} }
impl Line { impl Line {
pub fn new(thickness: u32) -> Line { pub fn new(thickness: u32, vertical: bool) -> Line {
Line { Line {
geometry: Default::default(), geometry: Default::default(),
thickness, thickness,
vertical,
} }
} }
} }
@@ -35,8 +37,16 @@ impl Widget for Line {
self.geometry = Geometry { self.geometry = Geometry {
x: geometry.x, x: geometry.x,
y: geometry.y, y: geometry.y,
width: geometry.width, width: if self.vertical {
height: self.thickness, self.thickness
} else {
geometry.width
},
height: if self.vertical {
geometry.height
} else {
self.thickness
},
}; };
self.geometry self.geometry
} }
@@ -45,8 +55,8 @@ impl Widget for Line {
Geometry { Geometry {
x: 0, x: 0,
y: 0, y: 0,
width: 0, width: if self.vertical { self.thickness } else { 1 },
height: self.thickness, height: if self.vertical { 1 } else { self.thickness },
} }
} }
} }