Skip to content

Commit

Permalink
add gravity property to label widget (#949)
Browse files Browse the repository at this point in the history
  • Loading branch information
Elekrisk authored Feb 17, 2024
1 parent e95d3af commit 8c97789
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions crates/eww/src/widgets/widget_definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,10 @@ fn build_gtk_label(bargs: &mut BuilderArgs) -> Result<gtk::Label> {
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)
Expand Down Expand Up @@ -1148,6 +1152,17 @@ fn parse_justification(j: &str) -> Result<gtk::Justification> {
}
}

/// @var gravity - "south", "east", "west", "north", "auto"
fn parse_gravity(g: &str) -> Result<gtk::pango::Gravity> {
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<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));
Expand Down

0 comments on commit 8c97789

Please sign in to comment.