refactor(custom): reduce a lot of repeated code

This commit is contained in:
Jake Stanger
2023-04-10 13:51:07 +01:00
parent a9d1233909
commit 3613aef5c5
8 changed files with 85 additions and 97 deletions

View File

@@ -1,4 +1,5 @@
use super::{try_get_orientation, CustomWidget, CustomWidgetContext, Widget};
use crate::build;
use gtk::prelude::*;
use gtk::Orientation;
use serde::Deserialize;
@@ -15,21 +16,12 @@ 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);
}
let container = build!(self, Self::Widget);
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);
container.set_orientation(
try_get_orientation(&orientation).unwrap_or(Orientation::Horizontal),
)
}
if let Some(widgets) = self.widgets {