Skip to content

Commit 998e5ce

Browse files
authored
Merge pull request #829 from BowDown097/master
feat: justify property for clock and custom label
2 parents db6b46a + 59b5ddc commit 998e5ce

File tree

6 files changed

+52
-9
lines changed

6 files changed

+52
-9
lines changed

Diff for: docs/modules/Clock.md

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Clicking on the widget opens a popup with the time and a calendar.
1414
| `format_popup` | `string` | `%H:%M:%S` | Date/time format string to display in the popup header. Pango markup is supported. |
1515
| `locale` | `string` | `$LC_TIME` or `$LANG` or `'POSIX'` | Locale to use (eg `en_GB`). Defaults to the system language (reading from env var). |
1616
| `orientation` | `'horizontal'` or `'vertical'` (shorthand: `'h'` or `'v'`) | `'horizontal'` | Orientation of the time on the clock button. |
17+
| `justify` | `'left'`', `'right'`, `'center'`, or `'fill'` | `'left'` | Justification (alignment) of the date/time shown on the bar. |
1718

1819
> Detail on available tokens can be found here: <https://docs.rs/chrono/latest/chrono/format/strftime/index.html>
1920

Diff for: docs/modules/Custom.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,11 @@ A text label. Pango markup is supported.
5454

5555
> Type `label`
5656
57-
| Name | Type | Default | Description |
58-
|---------|-------------------------------------------------|---------|---------------------------------------------------------------------|
59-
| `label` | [Dynamic String](dynamic-values#dynamic-string) | `null` | Widget text label. Pango markup and embedded scripts are supported. |
60-
| `orientation` | `'horizontal'` or `'vertical'` (shorthand: `'h'` or `'v'`) | `'horizontal'` | Orientation of the label. |
57+
| Name | Type | Default | Description |
58+
|---------------|------------------------------------------------------------|----------------|----------------------------------------------------------------------|
59+
| `label` | [Dynamic String](dynamic-values#dynamic-string) | `null` | Widget text label. Pango markup and embedded scripts are supported. |
60+
| `orientation` | `'horizontal'` or `'vertical'` (shorthand: `'h'` or `'v'`) | `'horizontal'` | Orientation of the label text. |
61+
| `justify` | `'left'`, `'right'`, `'center'`, or `'fill'` | `'left'` | Justification (alignment) of the label text. |
6162

6263
#### Button
6364

@@ -425,4 +426,4 @@ The following top-level selectors are always available:
425426
| `.custom` | Custom widget container. |
426427
| `.popup-custom` | Custom widget popup container. |
427428

428-
For more information on styling, please see the [styling guide](styling-guide).
429+
For more information on styling, please see the [styling guide](styling-guide).

Diff for: src/config/common.rs

+23-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::script::{Script, ScriptInput};
33
use glib::Propagation;
44
use gtk::gdk::ScrollDirection;
55
use gtk::prelude::*;
6-
use gtk::{EventBox, Orientation, Revealer, RevealerTransitionType};
6+
use gtk::{EventBox, Justification, Orientation, Revealer, RevealerTransitionType};
77
use serde::Deserialize;
88
use tracing::trace;
99

@@ -198,6 +198,28 @@ impl From<ModuleOrientation> for Orientation {
198198
}
199199
}
200200

201+
#[derive(Debug, Default, Deserialize, Clone, Copy)]
202+
#[serde(rename_all = "snake_case")]
203+
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
204+
pub enum ModuleJustification {
205+
#[default]
206+
Left,
207+
Right,
208+
Center,
209+
Fill,
210+
}
211+
212+
impl From<ModuleJustification> for Justification {
213+
fn from(o: ModuleJustification) -> Self {
214+
match o {
215+
ModuleJustification::Left => Self::Left,
216+
ModuleJustification::Right => Self::Right,
217+
ModuleJustification::Center => Self::Center,
218+
ModuleJustification::Fill => Self::Fill,
219+
}
220+
}
221+
}
222+
201223
impl TransitionType {
202224
pub const fn to_revealer_transition_type(
203225
&self,

Diff for: src/config/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ use std::collections::HashMap;
4545
#[cfg(feature = "schema")]
4646
use schemars::JsonSchema;
4747

48-
pub use self::common::{CommonConfig, ModuleOrientation, TransitionType};
48+
pub use self::common::{CommonConfig, ModuleJustification, ModuleOrientation, TransitionType};
4949
pub use self::truncate::{EllipsizeMode, TruncateMode};
5050

5151
#[derive(Debug, Deserialize, Clone)]

Diff for: src/modules/clock.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use serde::Deserialize;
88
use tokio::sync::{broadcast, mpsc};
99
use tokio::time::sleep;
1010

11-
use crate::config::{CommonConfig, ModuleOrientation};
11+
use crate::config::{CommonConfig, ModuleJustification, ModuleOrientation};
1212
use crate::gtk_helpers::IronbarGtkExt;
1313
use crate::modules::{
1414
Module, ModuleInfo, ModuleParts, ModulePopup, ModuleUpdateEvent, PopupButton, WidgetContext,
@@ -58,6 +58,14 @@ pub struct ClockModule {
5858
#[serde(default)]
5959
orientation: ModuleOrientation,
6060

61+
/// The justification (alignment) of the date/time shown on the bar.
62+
///
63+
/// **Valid options**: `left`, `right`, `center`, `fill`
64+
/// <br>
65+
/// **Default**: `left`
66+
#[serde(default)]
67+
justify: ModuleJustification,
68+
6169
/// See [common options](module-level-options#common-options).
6270
#[serde(flatten)]
6371
pub common: Option<CommonConfig>,
@@ -71,6 +79,7 @@ impl Default for ClockModule {
7179
locale: default_locale(),
7280
orientation: ModuleOrientation::Horizontal,
7381
common: Some(CommonConfig::default()),
82+
justify: ModuleJustification::Left,
7483
}
7584
}
7685
}
@@ -129,6 +138,7 @@ impl Module<Button> for ClockModule {
129138
let label = Label::builder()
130139
.angle(self.orientation.to_angle())
131140
.use_markup(true)
141+
.justify(self.justify.into())
132142
.build();
133143
button.add(&label);
134144

Diff for: src/modules/custom/label.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use serde::Deserialize;
44

55
use super::{CustomWidget, CustomWidgetContext};
66
use crate::build;
7-
use crate::config::ModuleOrientation;
7+
use crate::config::{ModuleJustification, ModuleOrientation};
88
use crate::dynamic_value::dynamic_string;
99
use crate::gtk_helpers::IronbarLabelExt;
1010

@@ -36,6 +36,14 @@ pub struct LabelWidget {
3636
/// **Default**: `horizontal`
3737
#[serde(default)]
3838
orientation: ModuleOrientation,
39+
40+
/// The justification (alignment) of the label text.
41+
///
42+
/// **Valid options**: `left`, `right`, `center`, `fill`
43+
/// <br>
44+
/// **Default**: `left`
45+
#[serde(default)]
46+
justify: ModuleJustification,
3947
}
4048

4149
impl CustomWidget for LabelWidget {
@@ -45,6 +53,7 @@ impl CustomWidget for LabelWidget {
4553
let label = build!(self, Self::Widget);
4654

4755
label.set_angle(self.orientation.to_angle());
56+
label.set_justify(self.justify.into());
4857
label.set_use_markup(true);
4958

5059
{

0 commit comments

Comments
 (0)