mirror of
https://github.com/Zedfrigg/ironbar.git
synced 2025-08-16 22:31:03 +02:00
feat: justify property for clock and custom label
This commit is contained in:
parent
5136637752
commit
708118d266
6 changed files with 52 additions and 9 deletions
|
@ -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. |
|
| `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). |
|
| `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. |
|
| `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: <https://docs.rs/chrono/latest/chrono/format/strftime/index.html>
|
> Detail on available tokens can be found here: <https://docs.rs/chrono/latest/chrono/format/strftime/index.html>
|
||||||
|
|
||||||
|
|
|
@ -54,10 +54,11 @@ A text label. Pango markup is supported.
|
||||||
|
|
||||||
> Type `label`
|
> Type `label`
|
||||||
|
|
||||||
| Name | Type | Default | Description |
|
| Name | Type | Default | Description |
|
||||||
|---------|-------------------------------------------------|---------|---------------------------------------------------------------------|
|
|---------------|------------------------------------------------------------|----------------|----------------------------------------------------------------------|
|
||||||
| `label` | [Dynamic String](dynamic-values#dynamic-string) | `null` | Widget text label. Pango markup and embedded scripts are supported. |
|
| `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. |
|
| `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
|
#### Button
|
||||||
|
|
||||||
|
@ -425,4 +426,4 @@ The following top-level selectors are always available:
|
||||||
| `.custom` | Custom widget container. |
|
| `.custom` | Custom widget container. |
|
||||||
| `.popup-custom` | Custom widget popup container. |
|
| `.popup-custom` | Custom widget popup container. |
|
||||||
|
|
||||||
For more information on styling, please see the [styling guide](styling-guide).
|
For more information on styling, please see the [styling guide](styling-guide).
|
||||||
|
|
|
@ -3,7 +3,7 @@ use crate::script::{Script, ScriptInput};
|
||||||
use glib::Propagation;
|
use glib::Propagation;
|
||||||
use gtk::gdk::ScrollDirection;
|
use gtk::gdk::ScrollDirection;
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
use gtk::{EventBox, Orientation, Revealer, RevealerTransitionType};
|
use gtk::{EventBox, Justification, Orientation, Revealer, RevealerTransitionType};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use tracing::trace;
|
use tracing::trace;
|
||||||
|
|
||||||
|
@ -198,6 +198,28 @@ impl From<ModuleOrientation> 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<ModuleJustification> 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 {
|
impl TransitionType {
|
||||||
pub const fn to_revealer_transition_type(
|
pub const fn to_revealer_transition_type(
|
||||||
&self,
|
&self,
|
||||||
|
|
|
@ -45,7 +45,7 @@ use std::collections::HashMap;
|
||||||
#[cfg(feature = "schema")]
|
#[cfg(feature = "schema")]
|
||||||
use schemars::JsonSchema;
|
use schemars::JsonSchema;
|
||||||
|
|
||||||
pub use self::common::{CommonConfig, ModuleOrientation, TransitionType};
|
pub use self::common::{CommonConfig, ModuleJustification, ModuleOrientation, TransitionType};
|
||||||
pub use self::truncate::{EllipsizeMode, TruncateMode};
|
pub use self::truncate::{EllipsizeMode, TruncateMode};
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Clone)]
|
#[derive(Debug, Deserialize, Clone)]
|
||||||
|
|
|
@ -8,7 +8,7 @@ use serde::Deserialize;
|
||||||
use tokio::sync::{broadcast, mpsc};
|
use tokio::sync::{broadcast, mpsc};
|
||||||
use tokio::time::sleep;
|
use tokio::time::sleep;
|
||||||
|
|
||||||
use crate::config::{CommonConfig, ModuleOrientation};
|
use crate::config::{CommonConfig, ModuleJustification, ModuleOrientation};
|
||||||
use crate::gtk_helpers::IronbarGtkExt;
|
use crate::gtk_helpers::IronbarGtkExt;
|
||||||
use crate::modules::{
|
use crate::modules::{
|
||||||
Module, ModuleInfo, ModuleParts, ModulePopup, ModuleUpdateEvent, PopupButton, WidgetContext,
|
Module, ModuleInfo, ModuleParts, ModulePopup, ModuleUpdateEvent, PopupButton, WidgetContext,
|
||||||
|
@ -61,6 +61,14 @@ pub struct ClockModule {
|
||||||
/// See [common options](module-level-options#common-options).
|
/// See [common options](module-level-options#common-options).
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
pub common: Option<CommonConfig>,
|
pub common: Option<CommonConfig>,
|
||||||
|
|
||||||
|
/// The justification (alignment) of the date/time shown on the bar.
|
||||||
|
///
|
||||||
|
/// **Valid options**: `left`, `right`, `center`, `fill`
|
||||||
|
/// <br>
|
||||||
|
/// **Default**: `left`
|
||||||
|
#[serde(default)]
|
||||||
|
justify: ModuleJustification
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for ClockModule {
|
impl Default for ClockModule {
|
||||||
|
@ -71,6 +79,7 @@ impl Default for ClockModule {
|
||||||
locale: default_locale(),
|
locale: default_locale(),
|
||||||
orientation: ModuleOrientation::Horizontal,
|
orientation: ModuleOrientation::Horizontal,
|
||||||
common: Some(CommonConfig::default()),
|
common: Some(CommonConfig::default()),
|
||||||
|
justify: ModuleJustification::Left
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -129,6 +138,7 @@ impl Module<Button> for ClockModule {
|
||||||
let label = Label::builder()
|
let label = Label::builder()
|
||||||
.angle(self.orientation.to_angle())
|
.angle(self.orientation.to_angle())
|
||||||
.use_markup(true)
|
.use_markup(true)
|
||||||
|
.justify(self.justify.into())
|
||||||
.build();
|
.build();
|
||||||
button.add(&label);
|
button.add(&label);
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ use serde::Deserialize;
|
||||||
|
|
||||||
use super::{CustomWidget, CustomWidgetContext};
|
use super::{CustomWidget, CustomWidgetContext};
|
||||||
use crate::build;
|
use crate::build;
|
||||||
use crate::config::ModuleOrientation;
|
use crate::config::{ModuleJustification, ModuleOrientation};
|
||||||
use crate::dynamic_value::dynamic_string;
|
use crate::dynamic_value::dynamic_string;
|
||||||
use crate::gtk_helpers::IronbarLabelExt;
|
use crate::gtk_helpers::IronbarLabelExt;
|
||||||
|
|
||||||
|
@ -36,6 +36,14 @@ pub struct LabelWidget {
|
||||||
/// **Default**: `horizontal`
|
/// **Default**: `horizontal`
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
orientation: ModuleOrientation,
|
orientation: ModuleOrientation,
|
||||||
|
|
||||||
|
/// The justification (alignment) of the label text.
|
||||||
|
///
|
||||||
|
/// **Valid options**: `left`, `right`, `center`, `fill`
|
||||||
|
/// <br>
|
||||||
|
/// **Default**: `left`
|
||||||
|
#[serde(default)]
|
||||||
|
justify: ModuleJustification
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CustomWidget for LabelWidget {
|
impl CustomWidget for LabelWidget {
|
||||||
|
@ -45,6 +53,7 @@ impl CustomWidget for LabelWidget {
|
||||||
let label = build!(self, Self::Widget);
|
let label = build!(self, Self::Widget);
|
||||||
|
|
||||||
label.set_angle(self.orientation.to_angle());
|
label.set_angle(self.orientation.to_angle());
|
||||||
|
label.set_justify(self.justify.into());
|
||||||
label.set_use_markup(true);
|
label.set_use_markup(true);
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue