From 708118d2664969cb239e1e769c08902510fbfd66 Mon Sep 17 00:00:00 2001 From: BowDown097 Date: Wed, 1 Jan 2025 12:07:42 -0800 Subject: [PATCH 1/3] feat: justify property for clock and custom label --- docs/modules/Clock.md | 1 + docs/modules/Custom.md | 11 ++++++----- src/config/common.rs | 24 +++++++++++++++++++++++- src/config/mod.rs | 2 +- src/modules/clock.rs | 12 +++++++++++- src/modules/custom/label.rs | 11 ++++++++++- 6 files changed, 52 insertions(+), 9 deletions(-) diff --git a/docs/modules/Clock.md b/docs/modules/Clock.md index a191763..2581460 100644 --- a/docs/modules/Clock.md +++ b/docs/modules/Clock.md @@ -14,6 +14,7 @@ Clicking on the widget opens a popup with the time and a calendar. | `format_popup` | `string` | `%H:%M:%S` | Date/time format string to display in the popup header. Pango markup is supported. | | `locale` | `string` | `$LC_TIME` or `$LANG` or `'POSIX'` | Locale to use (eg `en_GB`). Defaults to the system language (reading from env var). | | `orientation` | `'horizontal'` or `'vertical'` (shorthand: `'h'` or `'v'`) | `'horizontal'` | Orientation of the time on the clock button. | +| `justify` | `'left'`', `'right'`, `'center'`, or `'fill'` | `'left'` | Justification (alignment) of the date/time shown on the bar. | > Detail on available tokens can be found here: diff --git a/docs/modules/Custom.md b/docs/modules/Custom.md index f9e718f..f7d2510 100644 --- a/docs/modules/Custom.md +++ b/docs/modules/Custom.md @@ -54,10 +54,11 @@ A text label. Pango markup is supported. > Type `label` -| Name | Type | Default | Description | -|---------|-------------------------------------------------|---------|---------------------------------------------------------------------| -| `label` | [Dynamic String](dynamic-values#dynamic-string) | `null` | Widget text label. Pango markup and embedded scripts are supported. | -| `orientation` | `'horizontal'` or `'vertical'` (shorthand: `'h'` or `'v'`) | `'horizontal'` | Orientation of the label. | +| Name | Type | Default | Description | +|---------------|------------------------------------------------------------|----------------|----------------------------------------------------------------------| +| `label` | [Dynamic String](dynamic-values#dynamic-string) | `null` | Widget text label. Pango markup and embedded scripts are supported. | +| `orientation` | `'horizontal'` or `'vertical'` (shorthand: `'h'` or `'v'`) | `'horizontal'` | Orientation of the label text. | +| `justify` | `'left'`, `'right'`, `'center'`, or `'fill'` | `'left'` | Justification (alignment) of the label text. | #### Button @@ -425,4 +426,4 @@ The following top-level selectors are always available: | `.custom` | Custom widget container. | | `.popup-custom` | Custom widget popup container. | -For more information on styling, please see the [styling guide](styling-guide). \ No newline at end of file +For more information on styling, please see the [styling guide](styling-guide). diff --git a/src/config/common.rs b/src/config/common.rs index d987e85..1b66318 100644 --- a/src/config/common.rs +++ b/src/config/common.rs @@ -3,7 +3,7 @@ use crate::script::{Script, ScriptInput}; use glib::Propagation; use gtk::gdk::ScrollDirection; use gtk::prelude::*; -use gtk::{EventBox, Orientation, Revealer, RevealerTransitionType}; +use gtk::{EventBox, Justification, Orientation, Revealer, RevealerTransitionType}; use serde::Deserialize; use tracing::trace; @@ -198,6 +198,28 @@ impl From for Orientation { } } +#[derive(Debug, Default, Deserialize, Clone, Copy)] +#[serde(rename_all = "snake_case")] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] +pub enum ModuleJustification { + #[default] + Left, + Right, + Center, + Fill +} + +impl From for Justification { + fn from(o: ModuleJustification) -> Self { + match o { + ModuleJustification::Left => Self::Left, + ModuleJustification::Right => Self::Right, + ModuleJustification::Center => Self::Center, + ModuleJustification::Fill => Self::Fill + } + } +} + impl TransitionType { pub const fn to_revealer_transition_type( &self, diff --git a/src/config/mod.rs b/src/config/mod.rs index b3bda4f..b4d7371 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -45,7 +45,7 @@ use std::collections::HashMap; #[cfg(feature = "schema")] use schemars::JsonSchema; -pub use self::common::{CommonConfig, ModuleOrientation, TransitionType}; +pub use self::common::{CommonConfig, ModuleJustification, ModuleOrientation, TransitionType}; pub use self::truncate::{EllipsizeMode, TruncateMode}; #[derive(Debug, Deserialize, Clone)] diff --git a/src/modules/clock.rs b/src/modules/clock.rs index 6af5e88..fc14df5 100644 --- a/src/modules/clock.rs +++ b/src/modules/clock.rs @@ -8,7 +8,7 @@ use serde::Deserialize; use tokio::sync::{broadcast, mpsc}; use tokio::time::sleep; -use crate::config::{CommonConfig, ModuleOrientation}; +use crate::config::{CommonConfig, ModuleJustification, ModuleOrientation}; use crate::gtk_helpers::IronbarGtkExt; use crate::modules::{ Module, ModuleInfo, ModuleParts, ModulePopup, ModuleUpdateEvent, PopupButton, WidgetContext, @@ -61,6 +61,14 @@ pub struct ClockModule { /// See [common options](module-level-options#common-options). #[serde(flatten)] pub common: Option, + + /// The justification (alignment) of the date/time shown on the bar. + /// + /// **Valid options**: `left`, `right`, `center`, `fill` + ///
+ /// **Default**: `left` + #[serde(default)] + justify: ModuleJustification } impl Default for ClockModule { @@ -71,6 +79,7 @@ impl Default for ClockModule { locale: default_locale(), orientation: ModuleOrientation::Horizontal, common: Some(CommonConfig::default()), + justify: ModuleJustification::Left } } } @@ -129,6 +138,7 @@ impl Module