From 607f4411d3af9ab5d903829459bf988be9a5221b Mon Sep 17 00:00:00 2001 From: nativerv <70909425+nativerv@users.noreply.github.com> Date: Sat, 17 Feb 2024 14:15:05 +0300 Subject: [PATCH] add `:unindent` property (#804) --- CHANGELOG.md | 1 + crates/eww/src/widgets/widget_definitions.rs | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c3aea4..86a57d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ All notable changes to eww will be listed here, starting at changes since versio - Add support for referring to monitor with `` - Add support for multiple matchers in `monitor` field - Add `stack` widget (By: vladaviedov) +- Add `unindent` property to the label widget, allowing to disable removal of leading spaces (By: nrv) ## [0.4.0] (04.09.2022) diff --git a/crates/eww/src/widgets/widget_definitions.rs b/crates/eww/src/widgets/widget_definitions.rs index 0468fb1..20b1f9a 100644 --- a/crates/eww/src/widgets/widget_definitions.rs +++ b/crates/eww/src/widgets/widget_definitions.rs @@ -2,7 +2,7 @@ use super::{build_widget::BuilderArgs, circular_progressbar::*, run_command, transform::*}; use crate::{ def_widget, enum_parse, error_handling_ctx, - util::{list_difference, unindent}, + util::{self, list_difference}, widgets::build_widget::build_gtk_widget, }; use anyhow::{anyhow, Context, Result}; @@ -830,7 +830,8 @@ fn build_gtk_label(bargs: &mut BuilderArgs) -> Result { // @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 truncated - prop(text: as_string, limit_width: as_i32 = i32::MAX, truncate_left: as_bool = false, show_truncated: as_bool = true) { + // @prop unindent - whether to remove leading spaces + prop(text: as_string, limit_width: as_i32 = i32::MAX, truncate_left: as_bool = false, show_truncated: as_bool = true, unindent: as_bool = true) { let limit_width = limit_width as usize; let char_count = text.chars().count(); let text = if char_count > limit_width { @@ -852,7 +853,7 @@ fn build_gtk_label(bargs: &mut BuilderArgs) -> Result { }; let text = unescape::unescape(&text).context(format!("Failed to unescape label text {}", &text))?; - let text = unindent(&text); + let text = if unindent { util::unindent(&text) } else { text }; gtk_widget.set_text(&text); }, // @prop markup - Pango markup to display