diff --git a/CHANGELOG.md b/CHANGELOG.md index 96154b33..e5acadd5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,7 @@ All notable changes to eww will be listed here, starting at changes since versio - Add keyboard support for button presses (By: julianschuler) - Support empty string for safe access operator (By: ModProg) - Add `log` function calls to simplexpr (By: topongo) +- Add `:lines` and `:wrap-mode` properties to label widget (By: vaporii) ## [0.6.0] (21.04.2024) diff --git a/crates/eww/src/widgets/widget_definitions.rs b/crates/eww/src/widgets/widget_definitions.rs index 29c14a08..c5158ea0 100644 --- a/crates/eww/src/widgets/widget_definitions.rs +++ b/crates/eww/src/widgets/widget_definitions.rs @@ -1013,7 +1013,7 @@ fn build_gtk_label(bargs: &mut BuilderArgs) -> Result { // @prop truncate - whether to truncate text (or pango markup). If `show-truncated` is `false`, or if `limit-width` has a value, this property has no effect and truncation is enabled. // @prop limit-width - maximum count of characters to display // @prop truncate-left - whether to truncate on the left side - // @prop show-truncated - show whether the text was truncatedd. Disabling it will also disable dynamic truncation (the labels won't be truncated more than `limit-width`, even if there is not enough space for them), and will completly disable truncation on pango markup. + // @prop show-truncated - show whether the text was truncated. Disabling it will also disable dynamic truncation (the labels won't be truncated more than `limit-width`, even if there is not enough space for them), and will completly disable truncation on pango markup. prop(markup: as_string, truncate: as_bool = false, limit_width: as_i32 = i32::MAX, truncate_left: as_bool = false, show_truncated: as_bool = true) { if (truncate || limit_width != i32::MAX) && show_truncated { // gtk does weird thing if we set max_width_chars to i32::MAX @@ -1050,6 +1050,14 @@ fn build_gtk_label(bargs: &mut BuilderArgs) -> Result { prop(justify: as_string = "left") { gtk_widget.set_justify(parse_justification(&justify)?); }, + // @prop wrap-mode - how text is wrapped. possible options: $wrap-mode + prop(wrap_mode: as_string = "word") { + gtk_widget.set_wrap_mode(parse_wrap_mode(&wrap_mode)?); + }, + // @prop lines - maximum number of lines to display (only works when `limit-width` has a value). A value of -1 (default) disables the limit. + prop(lines: as_i32 = -1) { + gtk_widget.set_lines(lines); + } }); Ok(gtk_widget) } @@ -1384,6 +1392,14 @@ fn parse_gravity(g: &str) -> Result { } } +/// @var wrap-mode - "word", "char" +fn parse_wrap_mode(w: &str) -> Result { + enum_parse! { "wrap-mode", w, + "word" => gtk::pango::WrapMode::Word, + "char" => gtk::pango::WrapMode::Char + } +} + /// 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));