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
6 changed files with 371 additions and 309 deletions

43
src/modules/custom/box.rs Normal file
View File

@@ -0,0 +1,43 @@
use super::{try_get_orientation, CustomWidget, CustomWidgetContext, Widget};
use gtk::prelude::*;
use gtk::Orientation;
use serde::Deserialize;
#[derive(Debug, Deserialize, Clone)]
pub struct BoxWidget {
name: Option<String>,
class: Option<String>,
orientation: Option<String>,
widgets: Option<Vec<Widget>>,
}
impl CustomWidget for BoxWidget {
type Widget = gtk::Box;
fn into_widget(self, context: CustomWidgetContext) -> Self::Widget {
let mut builder = gtk::Box::builder();
if let Some(name) = self.name {
builder = builder.name(&name);
}
if let Some(orientation) = self.orientation {
builder = builder
.orientation(try_get_orientation(&orientation).unwrap_or(Orientation::Horizontal));
}
let container = builder.build();
if let Some(class) = self.class {
container.style_context().add_class(&class);
}
if let Some(widgets) = self.widgets {
for widget in widgets {
widget.add_to(&container, context);
}
}
container
}
}