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

refactor(custom): split into enum with separate file per widget

This commit is contained in:
Jake Stanger 2023-04-07 20:22:31 +01:00
parent 4b4f1ffc21
commit 2ab06f044e
No known key found for this signature in database
GPG key ID: C51FC8F9CB0BEA61
6 changed files with 371 additions and 309 deletions

View file

@ -0,0 +1,42 @@
use super::{CustomWidget, CustomWidgetContext};
use crate::dynamic_string::DynamicString;
use gtk::prelude::*;
use gtk::Label;
use serde::Deserialize;
#[derive(Debug, Deserialize, Clone)]
pub struct LabelWidget {
name: Option<String>,
class: Option<String>,
label: Option<String>,
}
impl CustomWidget for LabelWidget {
type Widget = Label;
fn into_widget(self, _context: CustomWidgetContext) -> Self::Widget {
let mut builder = Label::builder().use_markup(true);
if let Some(name) = self.name {
builder = builder.name(name);
}
let label = builder.build();
if let Some(class) = self.class {
label.style_context().add_class(&class);
}
let text = self.label.map_or_else(String::new, |text| text);
{
let label = label.clone();
DynamicString::new(&text, move |string| {
label.set_label(&string);
Continue(true)
});
}
label
}
}