Skip to content

Commit

Permalink
add lines and wrap-mode properties to label widget (#1278)
Browse files Browse the repository at this point in the history
* add :lines property to label widget

* add :lines property and fix some other little stuff

* quick documentation fix
  • Loading branch information
vaporii authored Feb 5, 2025
1 parent 593a4f4 commit e7b9568
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
18 changes: 17 additions & 1 deletion crates/eww/src/widgets/widget_definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,7 @@ fn build_gtk_label(bargs: &mut BuilderArgs) -> Result<gtk::Label> {
// @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
Expand Down Expand Up @@ -1050,6 +1050,14 @@ fn build_gtk_label(bargs: &mut BuilderArgs) -> Result<gtk::Label> {
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)
}
Expand Down Expand Up @@ -1384,6 +1392,14 @@ fn parse_gravity(g: &str) -> Result<gtk::pango::Gravity> {
}
}

/// @var wrap-mode - "word", "char"
fn parse_wrap_mode(w: &str) -> Result<gtk::pango::WrapMode> {
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<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 e7b9568

Please sign in to comment.