From 8c977892d489c753760085a40f26639b0e06b3e8 Mon Sep 17 00:00:00 2001 From: Elekrisk Date: Sat, 17 Feb 2024 10:42:29 +0100 Subject: [PATCH] add `gravity` property to `label` widget (#949) --- CHANGELOG.md | 1 + crates/eww/src/widgets/widget_definitions.rs | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 91796d3..8c3aea4 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 - Add `:namespace` window option - Default to building with x11 and wayland support simultaneously - Add `truncate-left` property on `label` widgets (By: kawaki-san) +- Add `gravity` property on `label` widgets (By: Elekrisk) - Add support for safe access (`?.`) in simplexpr (By: oldwomanjosiah) - Allow floating-point numbers in percentages for window-geometry - Add support for safe access with index (`?.[n]`) (By: ModProg) diff --git a/crates/eww/src/widgets/widget_definitions.rs b/crates/eww/src/widgets/widget_definitions.rs index fb2b128..0468fb1 100644 --- a/crates/eww/src/widgets/widget_definitions.rs +++ b/crates/eww/src/widgets/widget_definitions.rs @@ -861,6 +861,10 @@ fn build_gtk_label(bargs: &mut BuilderArgs) -> Result { 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 gravity - the gravity of the string (south, east, west, north, auto). Text will want to face the direction of gravity. + prop(gravity: as_string = "south") { + gtk_widget.pango_context().set_base_gravity(parse_gravity(&gravity)?); + }, // @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) @@ -1148,6 +1152,17 @@ fn parse_justification(j: &str) -> Result { } } +/// @var gravity - "south", "east", "west", "north", "auto" +fn parse_gravity(g: &str) -> Result { + enum_parse! { "gravity", g, + "south" => gtk::pango::Gravity::South, + "east" => gtk::pango::Gravity::East, + "west" => gtk::pango::Gravity::West, + "north" => gtk::pango::Gravity::North, + "auto" => gtk::pango::Gravity::Auto, + } +} + /// 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));