add more formatting and wrapping options

This commit is contained in:
Alexander Mohr 2025-05-31 22:57:12 +02:00
parent 578594636a
commit 0f89e367a8
4 changed files with 45 additions and 2 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 167 KiB

View file

@ -6,3 +6,5 @@ content_halign="Center"
height="70%" height="70%"
width="60%" width="60%"
valign="Start" valign="Start"
#line_wrap="Word"
line_max_chars=32

View file

@ -94,7 +94,7 @@ pub enum Layer {
Background, Background,
Bottom, Bottom,
Top, Top,
Overlay Overlay,
} }
impl FromStr for Layer { impl FromStr for Layer {
@ -387,13 +387,28 @@ pub struct Config {
#[clap(long = "row-box-orientation")] #[clap(long = "row-box-orientation")]
row_box_orientation: Option<Orientation>, row_box_orientation: Option<Orientation>,
/// Defines if lines should wrap.
/// Can be None, Inherit, Word
/// Defaults to None
#[clap(long = "line-wrap")] #[clap(long = "line-wrap")]
line_wrap: Option<WrapMode>, line_wrap: Option<WrapMode>,
/// Truncate labels after reaching this amount of chars.
#[clap(long = "line-max-chars")]
line_max_chars: Option<usize>,
/// 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<i32>,
/// Display only icon in emoji mode /// Display only icon in emoji mode
#[clap(long = "emoji-hide-string")] #[clap(long = "emoji-hide-string")]
emoji_hide_label: Option<bool>, emoji_hide_label: Option<bool>,
/// Defines the key detection type.
/// See `KeyDetectionType` for details.
#[clap(long = "key-detection-type")] #[clap(long = "key-detection-type")]
key_detection_type: Option<KeyDetectionType>, key_detection_type: Option<KeyDetectionType>,
} }
@ -515,6 +530,16 @@ impl Config {
self.line_wrap.clone().unwrap_or(WrapMode::None) self.line_wrap.clone().unwrap_or(WrapMode::None)
} }
#[must_use]
pub fn line_max_chars(&self) -> Option<usize> {
self.line_max_chars
}
#[must_use]
pub fn line_max_width_chars(&self) -> Option<i32> {
self.line_max_width_chars
}
#[must_use] #[must_use]
pub fn term(&self) -> Option<String> { pub fn term(&self) -> Option<String> {
self.term.clone().or_else(|| { self.term.clone().or_else(|| {

View file

@ -485,7 +485,7 @@ fn modifiers_from_mask(mask: gdk4::ModifierType) -> HashSet<Modifier> {
modifiers modifiers
} }
impl From<config::Layer> for gtk4_layer_shell::Layer{ impl From<config::Layer> for gtk4_layer_shell::Layer {
fn from(value: config::Layer) -> Self { fn from(value: config::Layer) -> Self {
match value { match value {
config::Layer::Background => gtk4_layer_shell::Layer::Background, config::Layer::Background => gtk4_layer_shell::Layer::Background,
@ -1395,6 +1395,22 @@ fn create_menu_row<T: Clone + 'static + Send>(
label.set_hexpand(true); label.set_hexpand(true);
label.set_widget_name("text"); label.set_widget_name("text");
label.set_wrap(true); 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); row_box.append(&label);
if meta.config.content_halign().eq(&config::Align::Start) if meta.config.content_halign().eq(&config::Align::Start)