diff --git a/examples/worf-hyprswitch/images/worf-warden.png b/examples/worf-hyprswitch/images/worf-warden.png deleted file mode 100644 index b3dfe4d..0000000 Binary files a/examples/worf-hyprswitch/images/worf-warden.png and /dev/null differ diff --git a/styles/launcher/config.toml b/styles/launcher/config.toml index b8471ad..4643c41 100644 --- a/styles/launcher/config.toml +++ b/styles/launcher/config.toml @@ -6,3 +6,5 @@ content_halign="Center" height="70%" width="60%" valign="Start" +#line_wrap="Word" +line_max_chars=32 diff --git a/worf/src/lib/config.rs b/worf/src/lib/config.rs index cd3b86c..bbae244 100644 --- a/worf/src/lib/config.rs +++ b/worf/src/lib/config.rs @@ -94,7 +94,7 @@ pub enum Layer { Background, Bottom, Top, - Overlay + Overlay, } impl FromStr for Layer { @@ -387,13 +387,28 @@ pub struct Config { #[clap(long = "row-box-orientation")] row_box_orientation: Option, + /// Defines if lines should wrap. + /// Can be None, Inherit, Word + /// Defaults to None #[clap(long = "line-wrap")] line_wrap: Option, + /// Truncate labels after reaching this amount of chars. + #[clap(long = "line-max-chars")] + line_max_chars: Option, + + /// Defines the maximum width of a label in chars. + /// After reaching this, lines will break into a new line. + /// Does not truncate. + #[clap(long = "line-max-width-chars")] + line_max_width_chars: Option, + /// Display only icon in emoji mode #[clap(long = "emoji-hide-string")] emoji_hide_label: Option, + /// Defines the key detection type. + /// See `KeyDetectionType` for details. #[clap(long = "key-detection-type")] key_detection_type: Option, } @@ -515,6 +530,16 @@ impl Config { self.line_wrap.clone().unwrap_or(WrapMode::None) } + #[must_use] + pub fn line_max_chars(&self) -> Option { + self.line_max_chars + } + + #[must_use] + pub fn line_max_width_chars(&self) -> Option { + self.line_max_width_chars + } + #[must_use] pub fn term(&self) -> Option { self.term.clone().or_else(|| { diff --git a/worf/src/lib/gui.rs b/worf/src/lib/gui.rs index 77b383a..ab6c9ba 100644 --- a/worf/src/lib/gui.rs +++ b/worf/src/lib/gui.rs @@ -485,7 +485,7 @@ fn modifiers_from_mask(mask: gdk4::ModifierType) -> HashSet { modifiers } -impl From for gtk4_layer_shell::Layer{ +impl From for gtk4_layer_shell::Layer { fn from(value: config::Layer) -> Self { match value { config::Layer::Background => gtk4_layer_shell::Layer::Background, @@ -1395,6 +1395,22 @@ fn create_menu_row( label.set_hexpand(true); label.set_widget_name("text"); label.set_wrap(true); + if let Some(max_width_chars) = meta.config.line_max_width_chars() { + label.set_max_width_chars(max_width_chars); + } + + if let Some(max_len) = meta.config.line_max_chars() { + if let Some(text) = label_text.as_ref() { + if text.chars().count() > max_len { + let end = text + .char_indices() + .nth(max_len) + .map_or(text.len(), |(idx, _)| idx); + label.set_text(&format!("{}...", &text[..end])); + } + } + } + row_box.append(&label); if meta.config.content_halign().eq(&config::Align::Start)