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, /// Widget class name. /// /// **Default**: `null` class: Option, /// 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` ///
/// **Default**: `horizontal` #[serde(default)] orientation: ModuleOrientation, /// The justification (alignment) of the label text. /// /// **Valid options**: `left`, `right`, `center`, `fill` ///
/// **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 } }