From d8e64f28fbc34f655b7392c92983d6fd5e373505 Mon Sep 17 00:00:00 2001 From: Alexander Mohr Date: Tue, 15 Apr 2025 22:47:26 +0200 Subject: [PATCH] add support for wrapping labels --- README.md | 11 +++++-- src/lib/gui.rs | 32 ++++++++++++++++++--- styles/{compact.css => compact/style.css} | 0 styles/launcher/config.toml | 8 ++++++ styles/{launcher.css => launcher/style.css} | 11 +++++++ 5 files changed, 56 insertions(+), 6 deletions(-) rename styles/{compact.css => compact/style.css} (100%) create mode 100644 styles/launcher/config.toml rename styles/{launcher.css => launcher/style.css} (88%) diff --git a/README.md b/README.md index fd79220..a221feb 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,15 @@ layerrule = blur, worf ## Additional functionality compared to Wofi (planed) * Support passing 'hidden' parameters that are not visible in the launcher but will be returned to the application * Window switcher for hyprland +* All arguments expect show are supported by config and args + +### New config / command line options +* fuzzy-length: Defines how long a string must be to be considered for fuzzy match +* row-box-orientation: Allows aligning values vertically to place the label below the icon + +### New Styling options +* `label`: Allows styling the label +* `row`: Allows styling to row, mainly used to disable hover effects ## Breaking changes to Wofi * Runtime behaviour is not guaranteed to be the same and won't ever be, this includes error messages and themes. @@ -28,8 +37,6 @@ layerrule = blur, worf * stylesheet -> use style instead * color / colors -> GTK4 does not support color files -## New options -* --fuzzy-length: Defines how long a string must be be ## Not supported diff --git a/src/lib/gui.rs b/src/lib/gui.rs index f59d490..1ef39e7 100644 --- a/src/lib/gui.rs +++ b/src/lib/gui.rs @@ -6,7 +6,7 @@ use crossbeam::channel::Sender; use gdk4::gio::{File, Menu}; use gdk4::glib::{GString, Propagation, Unichar}; use gdk4::prelude::{Cast, DisplayExt, ListModelExtManual, MonitorExt}; -use gdk4::{Display, Key}; +use gdk4::{pango, Display, Key}; use gtk4::prelude::{ ApplicationExt, ApplicationExtManual, BoxExt, ButtonExt, EditableExt, EntryExt, FileChooserExt, FlowBoxChildExt, GestureSingleExt, GtkWindowExt, ListBoxRowExt, NativeExt, OrientableExt, @@ -143,8 +143,6 @@ fn build_ui( inner_box.set_vexpand(false); if let Some(halign) = config.halign { inner_box.set_halign(halign.into()); - } else { - inner_box.set_halign(Align::Fill); } if let Some(valign) = config.valign { @@ -435,8 +433,11 @@ fn create_menu_row( row_box.append(&image); } - let label = Label::new(Some(&menu_item.label)); + // todo make max length configurable + let label = Label::new(Some(&wrap_text(&menu_item.label, 15))); label.set_hexpand(true); + label.set_widget_name("label"); + label.set_wrap(true); row_box.append(&label); if config.content_halign.unwrap() == config::Align::Start @@ -547,3 +548,26 @@ pub fn initialize_sort_scores(items: &mut Vec) { } } } + +fn wrap_text(text: &str, line_length: usize) -> String { + let mut result = String::new(); + let mut line = String::new(); + + for word in text.split_whitespace() { + if line.len() + word.len() + 1 > line_length { + if !line.is_empty() { + result.push_str(&line.trim_end()); + result.push('\n'); + line.clear(); + } + } + line.push_str(word); + line.push(' '); + } + + if !line.is_empty() { + result.push_str(&line.trim_end()); + } + + result +} diff --git a/styles/compact.css b/styles/compact/style.css similarity index 100% rename from styles/compact.css rename to styles/compact/style.css diff --git a/styles/launcher/config.toml b/styles/launcher/config.toml new file mode 100644 index 0000000..bae4b84 --- /dev/null +++ b/styles/launcher/config.toml @@ -0,0 +1,8 @@ +image_size=64 +columns=6 +orientation="Vertical" +row_bow_orientation="Vertical" +content_halign="Center" +height="70%" +width="60%" +valign="Start" diff --git a/styles/launcher.css b/styles/launcher/style.css similarity index 88% rename from styles/launcher.css rename to styles/launcher/style.css index d4c075e..141b141 100644 --- a/styles/launcher.css +++ b/styles/launcher/style.css @@ -45,15 +45,21 @@ padding: 1rem; margin: 1rem; border-radius: 0.5rem; + border-bottom: 5px solid rgba(32, 32, 32, 0.1); + } #window #outer-box #scroll #inner-box #entry #img { width: 1rem; margin-right: 0.5rem; } + #window #outer-box #scroll #inner-box #entry:selected { color: #fff; background-color: rgba(255, 255, 255, 0.1); outline: none; + border-bottom: 5px solid rgba(214, 174, 0, 1); + border-bottom-left-radius: 0; + border-bottom-right-radius: 0; } #row:hover { @@ -67,3 +73,8 @@ outline: inherit; outline-color: inherit; } + +#label { + margin-top: 1rem; + margin-bottom: 0; +}