feat: add justify property

This commit is contained in:
n3oney 2023-03-07 23:38:08 +01:00 committed by ElKowar
parent fba770255d
commit c72b881c3f
2 changed files with 16 additions and 1 deletions

View file

@ -12,6 +12,7 @@ All notable changes to eww will be listed here, starting at changes since versio
- Made `and`, `or` and `?:` lazily evaluated in simplexpr (By: ModProg) - Made `and`, `or` and `?:` lazily evaluated in simplexpr (By: ModProg)
- Add Vanilla CSS support (By: Ezequiel Ramis) - Add Vanilla CSS support (By: Ezequiel Ramis)
- Add `jq` function, offering jq-style json processing - Add `jq` function, offering jq-style json processing
- Add `justify` property to the label widget, allowing text justification (By: n3oney)
## [0.4.0] (04.09.2022) ## [0.4.0] (04.09.2022)

View file

@ -841,7 +841,11 @@ fn build_gtk_label(bargs: &mut BuilderArgs) -> Result<gtk::Label> {
// @prop xalign - the alignment of the label text on the x axis (between 0 - 1, 0 -> left, 0.5 -> center, 1 -> right) // @prop xalign - the alignment of the label text on the x axis (between 0 - 1, 0 -> left, 0.5 -> center, 1 -> right)
prop(xalign: as_f64 = 0.5) { gtk_widget.set_xalign(xalign as f32) }, prop(xalign: as_f64 = 0.5) { gtk_widget.set_xalign(xalign as f32) },
// @prop yalign - the alignment of the label text on the y axis (between 0 - 1, 0 -> bottom, 0.5 -> center, 1 -> top) // @prop yalign - the alignment of the label text on the y axis (between 0 - 1, 0 -> bottom, 0.5 -> center, 1 -> top)
prop(yalign: as_f64 = 0.5) { gtk_widget.set_yalign(yalign as f32) } prop(yalign: as_f64 = 0.5) { gtk_widget.set_yalign(yalign as f32) },
// @prop justify - the justification of the label text (left, right, center, fill)
prop(justify: as_string = "left") {
gtk_widget.set_justify(parse_justification(&justify)?);
},
}); });
Ok(gtk_widget) Ok(gtk_widget)
} }
@ -1061,6 +1065,16 @@ fn parse_align(o: &str) -> Result<gtk::Align> {
} }
} }
/// @var justification - "left", "right", "center", "fill"
fn parse_justification(j: &str) -> Result<gtk::Justification> {
enum_parse! { "justification", j,
"left" => gtk::Justification::Left,
"right" => gtk::Justification::Right,
"center" => gtk::Justification::Center,
"fill" => gtk::Justification::Fill,
}
}
/// Connect a function to the first map event of a widget. After that first map, the handler will get disconnected. /// Connect a function to the first map event of a widget. After that first map, the handler will get disconnected.
fn connect_first_map<W: IsA<gtk::Widget>, F: Fn(&W) + 'static>(widget: &W, func: F) { fn connect_first_map<W: IsA<gtk::Widget>, F: Fn(&W) + 'static>(widget: &W, func: F) {
let signal_handler_id = std::rc::Rc::new(std::cell::RefCell::new(None)); let signal_handler_id = std::rc::Rc::new(std::cell::RefCell::new(None));