add lines and wrap-mode properties to label widget (#1278)
* add :lines property to label widget * add :lines property and fix some other little stuff * quick documentation fix
This commit is contained in:
parent
593a4f4666
commit
e7b95688a7
2 changed files with 18 additions and 1 deletions
|
@ -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)
|
- Add keyboard support for button presses (By: julianschuler)
|
||||||
- Support empty string for safe access operator (By: ModProg)
|
- Support empty string for safe access operator (By: ModProg)
|
||||||
- Add `log` function calls to simplexpr (By: topongo)
|
- 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)
|
## [0.6.0] (21.04.2024)
|
||||||
|
|
||||||
|
|
|
@ -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 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 limit-width - maximum count of characters to display
|
||||||
// @prop truncate-left - whether to truncate on the left side
|
// @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) {
|
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 {
|
if (truncate || limit_width != i32::MAX) && show_truncated {
|
||||||
// gtk does weird thing if we set max_width_chars to i32::MAX
|
// 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<gtk::Label> {
|
||||||
prop(justify: as_string = "left") {
|
prop(justify: as_string = "left") {
|
||||||
gtk_widget.set_justify(parse_justification(&justify)?);
|
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)
|
Ok(gtk_widget)
|
||||||
}
|
}
|
||||||
|
@ -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.
|
/// 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) {
|
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));
|
let signal_handler_id = std::rc::Rc::new(std::cell::RefCell::new(None));
|
||||||
|
|
Loading…
Add table
Reference in a new issue