1
0
Fork 0
mirror of https://github.com/Zedfrigg/ironbar.git synced 2025-08-17 14:51:04 +02:00
ironbar/src/modules/custom/label.rs

60 lines
1.5 KiB
Rust
Raw Normal View History

use gtk::prelude::*;
use gtk::Label;
use serde::Deserialize;
2024-10-15 22:10:37 +01:00
use super::{CustomWidget, CustomWidgetContext};
use crate::build;
use crate::config::ModuleOrientation;
use crate::dynamic_value::dynamic_string;
2024-10-15 22:10:37 +01:00
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,
}
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_use_markup(true);
{
let label = label.clone();
dynamic_string(&self.label, move |string| {
2024-10-15 22:10:37 +01:00
label.set_label_escaped(&string);
});
}
label
}
}