1
0
Fork 0
mirror of https://github.com/Zedfrigg/ironbar.git synced 2025-08-17 23:01:04 +02:00

feat: fully implement orientation/justify options

Adds `orientation` and `justify` options to all modules and custom
widgets where it makes sense to do so.

Any modules without support document this. Widgets fully document the
options inline where present for now.

Resolves #296
This commit is contained in:
Jake Stanger 2025-03-22 19:19:47 +00:00
parent 0855039bce
commit c20feb77b7
No known key found for this signature in database
GPG key ID: C51FC8F9CB0BEA61
29 changed files with 317 additions and 161 deletions

View file

@ -4,7 +4,7 @@ use serde::Deserialize;
use super::{CustomWidget, CustomWidgetContext};
use crate::build;
use crate::config::{ModuleJustification, ModuleOrientation, TruncateMode};
use crate::config::{LayoutConfig, TruncateMode};
use crate::dynamic_value::dynamic_string;
use crate::gtk_helpers::IronbarLabelExt;
@ -28,22 +28,9 @@ pub struct LabelWidget {
/// **Required**
label: String,
/// Orientation of the label.
/// Setting to vertical will rotate text 90 degrees.
///
/// **Valid options**: `horizontal`, `vertical`, `h`, `v`
/// <br />
/// **Default**: `horizontal`
#[serde(default)]
orientation: ModuleOrientation,
/// The justification (alignment) of the label text.
///
/// **Valid options**: `left`, `right`, `center`, `fill`
/// <br>
/// **Default**: `left`
#[serde(default)]
justify: ModuleJustification,
/// See [layout options](module-level-options#layout)
#[serde(default, flatten)]
layout: LayoutConfig,
/// See [truncate options](module-level-options#truncate-mode).
///
@ -54,11 +41,14 @@ pub struct LabelWidget {
impl CustomWidget for LabelWidget {
type Widget = Label;
fn into_widget(self, _context: CustomWidgetContext) -> Self::Widget {
fn into_widget(self, context: CustomWidgetContext) -> Self::Widget {
let label = build!(self, Self::Widget);
label.set_angle(self.orientation.to_angle());
label.set_justify(self.justify.into());
if !context.is_popup {
label.set_angle(self.layout.angle(context.info));
}
label.set_justify(self.layout.justify.into());
label.set_use_markup(true);
if let Some(truncate) = self.truncate {