diff --git a/CHANGELOG.md b/CHANGELOG.md index 628c693..24ef038 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) - Add Vanilla CSS support (By: Ezequiel Ramis) - 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) diff --git a/crates/eww/src/widgets/widget_definitions.rs b/crates/eww/src/widgets/widget_definitions.rs index aa222fd..91662ff 100644 --- a/crates/eww/src/widgets/widget_definitions.rs +++ b/crates/eww/src/widgets/widget_definitions.rs @@ -841,7 +841,11 @@ fn build_gtk_label(bargs: &mut BuilderArgs) -> Result { // @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 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) } @@ -1061,6 +1065,16 @@ fn parse_align(o: &str) -> Result { } } +/// @var justification - "left", "right", "center", "fill" +fn parse_justification(j: &str) -> Result { + 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. fn connect_first_map, F: Fn(&W) + 'static>(widget: &W, func: F) { let signal_handler_id = std::rc::Rc::new(std::cell::RefCell::new(None));