From 34d929f097d812baece71ef097e5ae1a67828d87 Mon Sep 17 00:00:00 2001 From: Alessio <35380179+AlecsFerra@users.noreply.github.com> Date: Fri, 29 Apr 2022 12:06:20 +0000 Subject: [PATCH] Added support to label text alignment. (#412) * Added support to label text alignment. Since labels in gtk can't be aligned via css (I still don't know why) and can be only aligned using code, this patch adds support for this functionality by adding the properties :xalign and :yalign to the label expression. The exact behavior is described by the docs. * Updated changelog with :xalign and :yalign for labels --- CHANGELOG.md | 1 + crates/eww/src/widgets/widget_definitions.rs | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c7d3967..68a20a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ All notable changes to eww will be listed here, starting at changes since versio - Add support for `:hover` css selectors for eventbox (By: druskus20) - Add `eww get` subcommand (By: druskus20) - Add circular progress widget (By: druskus20) +- Add `:xalign` and `:yalign` to labels (By: alecsferra) - Add graph widget (By: druskus20) - Add `>=` and `<=` operators to simplexpr (By: viandoxdev) - Add `desktop` window type (By: Alvaro Lopez) diff --git a/crates/eww/src/widgets/widget_definitions.rs b/crates/eww/src/widgets/widget_definitions.rs index 4b98eff..97b8443 100644 --- a/crates/eww/src/widgets/widget_definitions.rs +++ b/crates/eww/src/widgets/widget_definitions.rs @@ -736,7 +736,11 @@ fn build_gtk_label(bargs: &mut BuilderArgs) -> Result { // @prop wrap - Wrap the text. This mainly makes sense if you set the width of this widget. prop(wrap: as_bool) { gtk_widget.set_line_wrap(wrap) }, // @prop angle - the angle of rotation for the label (between 0 - 360) - prop(angle: as_f64 = 0) { gtk_widget.set_angle(angle) } + prop(angle: as_f64 = 0) { gtk_widget.set_angle(angle) }, + // @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) } }); Ok(gtk_widget) }