2023-04-07 20:22:31 +01:00
|
|
|
use gtk::prelude::*;
|
|
|
|
use gtk::Label;
|
|
|
|
use serde::Deserialize;
|
|
|
|
|
2023-07-16 18:57:00 +01:00
|
|
|
use crate::build;
|
2024-04-04 16:12:45 -04:00
|
|
|
use crate::config::ModuleOrientation;
|
2023-07-16 18:57:00 +01:00
|
|
|
use crate::dynamic_value::dynamic_string;
|
|
|
|
|
|
|
|
use super::{CustomWidget, CustomWidgetContext};
|
|
|
|
|
2023-04-07 20:22:31 +01:00
|
|
|
#[derive(Debug, Deserialize, Clone)]
|
|
|
|
pub struct LabelWidget {
|
|
|
|
name: Option<String>,
|
|
|
|
class: Option<String>,
|
2023-04-10 13:51:07 +01:00
|
|
|
label: String,
|
2024-04-04 16:12:45 -04:00
|
|
|
#[serde(default)]
|
|
|
|
orientation: ModuleOrientation,
|
2023-04-07 20:22:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
impl CustomWidget for LabelWidget {
|
|
|
|
type Widget = Label;
|
|
|
|
|
|
|
|
fn into_widget(self, _context: CustomWidgetContext) -> Self::Widget {
|
2023-04-10 13:51:07 +01:00
|
|
|
let label = build!(self, Self::Widget);
|
2023-04-07 20:22:31 +01:00
|
|
|
|
2024-04-05 13:28:47 -04:00
|
|
|
label.set_angle(self.orientation.to_angle());
|
2024-04-04 16:12:45 -04:00
|
|
|
|
2023-04-10 13:51:07 +01:00
|
|
|
label.set_use_markup(true);
|
2023-04-07 20:22:31 +01:00
|
|
|
|
|
|
|
{
|
|
|
|
let label = label.clone();
|
2023-06-22 23:07:40 +01:00
|
|
|
dynamic_string(&self.label, move |string| {
|
2023-04-10 13:51:07 +01:00
|
|
|
label.set_markup(&string);
|
2023-04-07 20:22:31 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
label
|
|
|
|
}
|
|
|
|
}
|