mirror of
https://github.com/Zedfrigg/ironbar.git
synced 2025-07-01 10:41:03 +02:00
feat(custom): support common options in widgets
This commit is contained in:
parent
9d09855fce
commit
4a09b70854
3 changed files with 41 additions and 17 deletions
|
@ -15,7 +15,8 @@ It is well worth looking at the examples.
|
||||||
There are many widget types, each with their own config options.
|
There are many widget types, each with their own config options.
|
||||||
You can think of these like HTML elements and their attributes.
|
You can think of these like HTML elements and their attributes.
|
||||||
|
|
||||||
Every widget has the following options available; `type` is mandatory.
|
Every widget has the following options available; `type` is mandatory.
|
||||||
|
You can also add common [module-level options](https://github.com/JakeStanger/ironbar/wiki/configuration-guide#32-module-level-options) on a widget.
|
||||||
|
|
||||||
| Name | Type | Default | Description |
|
| Name | Type | Default | Description |
|
||||||
|---------|-------------------------------------------------------------------|---------|-------------------------------|
|
|---------|-------------------------------------------------------------------|---------|-------------------------------|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use super::{try_get_orientation, CustomWidget, CustomWidgetContext, Widget};
|
use super::{try_get_orientation, CustomWidget, CustomWidgetContext};
|
||||||
use crate::build;
|
use crate::build;
|
||||||
|
use crate::modules::custom::WidgetConfig;
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
use gtk::Orientation;
|
use gtk::Orientation;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
@ -9,7 +10,7 @@ pub struct BoxWidget {
|
||||||
name: Option<String>,
|
name: Option<String>,
|
||||||
class: Option<String>,
|
class: Option<String>,
|
||||||
orientation: Option<String>,
|
orientation: Option<String>,
|
||||||
widgets: Option<Vec<Widget>>,
|
widgets: Option<Vec<WidgetConfig>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CustomWidget for BoxWidget {
|
impl CustomWidget for BoxWidget {
|
||||||
|
@ -26,7 +27,7 @@ impl CustomWidget for BoxWidget {
|
||||||
|
|
||||||
if let Some(widgets) = self.widgets {
|
if let Some(widgets) = self.widgets {
|
||||||
for widget in widgets {
|
for widget in widgets {
|
||||||
widget.add_to(&container, context);
|
widget.widget.add_to(&container, context, widget.common);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,9 @@ use self::slider::SliderWidget;
|
||||||
use crate::config::CommonConfig;
|
use crate::config::CommonConfig;
|
||||||
use crate::modules::custom::button::ButtonWidget;
|
use crate::modules::custom::button::ButtonWidget;
|
||||||
use crate::modules::custom::progress::ProgressWidget;
|
use crate::modules::custom::progress::ProgressWidget;
|
||||||
use crate::modules::{Module, ModuleInfo, ModuleUpdateEvent, ModuleWidget, WidgetContext};
|
use crate::modules::{
|
||||||
|
wrap_widget, Module, ModuleInfo, ModuleUpdateEvent, ModuleWidget, WidgetContext,
|
||||||
|
};
|
||||||
use crate::popup::WidgetGeometry;
|
use crate::popup::WidgetGeometry;
|
||||||
use crate::script::Script;
|
use crate::script::Script;
|
||||||
use crate::send_async;
|
use crate::send_async;
|
||||||
|
@ -29,14 +31,22 @@ pub struct CustomModule {
|
||||||
/// Container class name
|
/// Container class name
|
||||||
class: Option<String>,
|
class: Option<String>,
|
||||||
/// Widgets to add to the bar container
|
/// Widgets to add to the bar container
|
||||||
bar: Vec<Widget>,
|
bar: Vec<WidgetConfig>,
|
||||||
/// Widgets to add to the popup container
|
/// Widgets to add to the popup container
|
||||||
popup: Option<Vec<Widget>>,
|
popup: Option<Vec<WidgetConfig>>,
|
||||||
|
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
pub common: Option<CommonConfig>,
|
pub common: Option<CommonConfig>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize, Clone)]
|
||||||
|
pub struct WidgetConfig {
|
||||||
|
#[serde(flatten)]
|
||||||
|
widget: Widget,
|
||||||
|
#[serde(flatten)]
|
||||||
|
common: CommonConfig,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Clone)]
|
#[derive(Debug, Deserialize, Clone)]
|
||||||
#[serde(tag = "type", rename_all = "snake_case")]
|
#[serde(tag = "type", rename_all = "snake_case")]
|
||||||
pub enum Widget {
|
pub enum Widget {
|
||||||
|
@ -107,15 +117,23 @@ fn try_get_orientation(orientation: &str) -> Result<Orientation> {
|
||||||
|
|
||||||
impl Widget {
|
impl Widget {
|
||||||
/// Creates this widget and adds it to the parent container
|
/// Creates this widget and adds it to the parent container
|
||||||
fn add_to(self, parent: >k::Box, context: CustomWidgetContext) {
|
fn add_to(self, parent: >k::Box, context: CustomWidgetContext, common: CommonConfig) {
|
||||||
match self {
|
macro_rules! create {
|
||||||
Self::Box(widget) => parent.add(&widget.into_widget(context)),
|
($widget:expr) => {
|
||||||
Self::Label(widget) => parent.add(&widget.into_widget(context)),
|
wrap_widget(&$widget.into_widget(context), common)
|
||||||
Self::Button(widget) => parent.add(&widget.into_widget(context)),
|
};
|
||||||
Self::Image(widget) => parent.add(&widget.into_widget(context)),
|
|
||||||
Self::Slider(widget) => parent.add(&widget.into_widget(context)),
|
|
||||||
Self::Progress(widget) => parent.add(&widget.into_widget(context)),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let event_box = match self {
|
||||||
|
Self::Box(widget) => create!(widget),
|
||||||
|
Self::Label(widget) => create!(widget),
|
||||||
|
Self::Button(widget) => create!(widget),
|
||||||
|
Self::Image(widget) => create!(widget),
|
||||||
|
Self::Slider(widget) => create!(widget),
|
||||||
|
Self::Progress(widget) => create!(widget),
|
||||||
|
};
|
||||||
|
|
||||||
|
parent.add(&event_box);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -186,7 +204,9 @@ impl Module<gtk::Box> for CustomModule {
|
||||||
};
|
};
|
||||||
|
|
||||||
self.bar.clone().into_iter().for_each(|widget| {
|
self.bar.clone().into_iter().for_each(|widget| {
|
||||||
widget.add_to(&container, custom_context);
|
widget
|
||||||
|
.widget
|
||||||
|
.add_to(&container, custom_context, widget.common);
|
||||||
});
|
});
|
||||||
|
|
||||||
let popup = self.into_popup(context.controller_tx, context.popup_rx, info);
|
let popup = self.into_popup(context.controller_tx, context.popup_rx, info);
|
||||||
|
@ -222,7 +242,9 @@ impl Module<gtk::Box> for CustomModule {
|
||||||
};
|
};
|
||||||
|
|
||||||
for widget in popup {
|
for widget in popup {
|
||||||
widget.add_to(&container, custom_context);
|
widget
|
||||||
|
.widget
|
||||||
|
.add_to(&container, custom_context, widget.common);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue