mirror of
https://github.com/Zedfrigg/ironbar.git
synced 2025-08-16 22:31:03 +02:00
68 lines
1.8 KiB
Rust
68 lines
1.8 KiB
Rust
use gtk::prelude::*;
|
|
use gtk::Label;
|
|
use serde::Deserialize;
|
|
|
|
use super::{CustomWidget, CustomWidgetContext};
|
|
use crate::build;
|
|
use crate::config::{ModuleJustification, ModuleOrientation};
|
|
use crate::dynamic_value::dynamic_string;
|
|
use crate::gtk_helpers::IronbarLabelExt;
|
|
|
|
#[derive(Debug, Deserialize, Clone)]
|
|
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
|
|
pub struct LabelWidget {
|
|
/// Widget name.
|
|
///
|
|
/// **Default**: `null`
|
|
name: Option<String>,
|
|
|
|
/// Widget class name.
|
|
///
|
|
/// **Default**: `null`
|
|
class: Option<String>,
|
|
|
|
/// Widget text label. Pango markup and embedded scripts are supported.
|
|
///
|
|
/// This is a [Dynamic String](dynamic-values#dynamic-string).
|
|
///
|
|
/// **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,
|
|
}
|
|
|
|
impl CustomWidget for LabelWidget {
|
|
type Widget = Label;
|
|
|
|
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());
|
|
label.set_use_markup(true);
|
|
|
|
{
|
|
let label = label.clone();
|
|
dynamic_string(&self.label, move |string| {
|
|
label.set_label_escaped(&string);
|
|
});
|
|
}
|
|
|
|
label
|
|
}
|
|
}
|