1
0
Fork 0
mirror of https://github.com/Zedfrigg/ironbar.git synced 2025-07-02 11:11:04 +02:00

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
No known key found for this signature in database
GPG key ID: C51FC8F9CB0BEA61
8 changed files with 85 additions and 97 deletions

View file

@ -1,9 +1,10 @@
use super::{try_get_orientation, CustomWidget, CustomWidgetContext, ExecEvent};
use crate::modules::custom::set_length;
use crate::popup::Popup;
use crate::script::{OutputStream, Script, ScriptInput};
use crate::{send, try_send};
use crate::{build, send, try_send};
use gtk::prelude::*;
use gtk::{Orientation, Scale};
use gtk::Scale;
use serde::Deserialize;
use std::cell::Cell;
use tokio::spawn;
@ -35,33 +36,20 @@ impl CustomWidget for SliderWidget {
type Widget = Scale;
fn into_widget(self, context: CustomWidgetContext) -> Self::Widget {
let mut builder = Scale::builder();
if let Some(name) = self.name {
builder = builder.name(name);
}
let scale = build!(self, Self::Widget);
if let Some(orientation) = self.orientation {
builder = builder
.orientation(try_get_orientation(&orientation).unwrap_or(context.bar_orientation));
scale.set_orientation(
try_get_orientation(&orientation).unwrap_or(context.bar_orientation),
);
}
if let Some(length) = self.length {
builder = match context.bar_orientation {
Orientation::Horizontal => builder.width_request(length),
Orientation::Vertical => builder.height_request(length),
_ => builder,
}
set_length(&scale, length, context.bar_orientation);
}
let scale = builder.build();
scale.set_range(self.min, self.max);
if let Some(class) = self.class {
scale.style_context().add_class(&class);
}
if let Some(on_change) = self.on_change {
let min = self.min;
let max = self.max;