Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add lines and wrap-mode properties to label widget #1278

Merged
merged 3 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
vaporii marked this conversation as resolved.
Show resolved Hide resolved
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
Loading