mirror of
https://github.com/Zedfrigg/ironbar.git
synced 2025-04-19 19:34:24 +02:00
Merge pull request #527 from JakeStanger/feat/custom-button-box
feat(custom): ability to add modules/widgets to buttons
This commit is contained in:
commit
10b3b01e5b
2 changed files with 18 additions and 8 deletions
|
@ -46,7 +46,7 @@ A container to place nested widgets inside.
|
||||||
| Name | Type | Default | Description |
|
| Name | Type | Default | Description |
|
||||||
|---------------|------------------------------------------------------------|----------------|-------------------------------------------------------------------|
|
|---------------|------------------------------------------------------------|----------------|-------------------------------------------------------------------|
|
||||||
| `orientation` | `'horizontal'` or `'vertical'` (shorthand: `'h'` or `'v'`) | `'horizontal'` | Whether child widgets should be horizontally or vertically added. |
|
| `orientation` | `'horizontal'` or `'vertical'` (shorthand: `'h'` or `'v'`) | `'horizontal'` | Whether child widgets should be horizontally or vertically added. |
|
||||||
| `widgets` | `(Module or Widget)[]` | `[]` | List of widgets to add to this box. |
|
| `widgets` | `(Module or Widget)[]` | `[]` | List of modules/widgets to add to this box. |
|
||||||
|
|
||||||
#### Label
|
#### Label
|
||||||
|
|
||||||
|
@ -64,10 +64,11 @@ A clickable button, which can run a command when clicked.
|
||||||
|
|
||||||
> Type `button`
|
> Type `button`
|
||||||
|
|
||||||
| Name | Type | Default | Description |
|
| Name | Type | Default | Description |
|
||||||
|------------|-------------------------------------------------|---------|---------------------------------------------------------------------|
|
|------------|-------------------------------------------------|---------|--------------------------------------------------------------------------------------------------|
|
||||||
| `label` | [Dynamic String](dynamic-values#dynamic-string) | `null` | Widget text label. Pango markup and embedded scripts are supported. |
|
| `label` | [Dynamic String](dynamic-values#dynamic-string) | `null` | Widget text label. Pango markup and embedded scripts are supported. Ignored if `widgets` is set. |
|
||||||
| `on_click` | `string [command]` | `null` | Command to execute. More on this [below](#commands). |
|
| `widgets` | `(Module or Widget)[]` | `[]` | List of modules/widgets to add to this button. |
|
||||||
|
| `on_click` | `string [command]` | `null` | Command to execute. More on this [below](#commands). |
|
||||||
|
|
||||||
#### Image
|
#### Image
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
use gtk::{Button, Label};
|
use gtk::{Button, Label, Orientation};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
use crate::dynamic_value::dynamic_string;
|
use crate::dynamic_value::dynamic_string;
|
||||||
use crate::modules::PopupButton;
|
use crate::modules::PopupButton;
|
||||||
use crate::{build, try_send};
|
use crate::{build, try_send};
|
||||||
|
|
||||||
use super::{CustomWidget, CustomWidgetContext, ExecEvent};
|
use super::{CustomWidget, CustomWidgetContext, ExecEvent, WidgetConfig};
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Clone)]
|
#[derive(Debug, Deserialize, Clone)]
|
||||||
pub struct ButtonWidget {
|
pub struct ButtonWidget {
|
||||||
|
@ -14,6 +14,7 @@ pub struct ButtonWidget {
|
||||||
class: Option<String>,
|
class: Option<String>,
|
||||||
label: Option<String>,
|
label: Option<String>,
|
||||||
on_click: Option<String>,
|
on_click: Option<String>,
|
||||||
|
widgets: Option<Vec<WidgetConfig>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CustomWidget for ButtonWidget {
|
impl CustomWidget for ButtonWidget {
|
||||||
|
@ -23,7 +24,15 @@ impl CustomWidget for ButtonWidget {
|
||||||
let button = build!(self, Self::Widget);
|
let button = build!(self, Self::Widget);
|
||||||
context.popup_buttons.borrow_mut().push(button.clone());
|
context.popup_buttons.borrow_mut().push(button.clone());
|
||||||
|
|
||||||
if let Some(text) = self.label {
|
if let Some(widgets) = self.widgets {
|
||||||
|
let container = gtk::Box::new(Orientation::Horizontal, 0);
|
||||||
|
|
||||||
|
for widget in widgets {
|
||||||
|
widget.widget.add_to(&container, &context, widget.common);
|
||||||
|
}
|
||||||
|
|
||||||
|
button.add(&container);
|
||||||
|
} else if let Some(text) = self.label {
|
||||||
let label = Label::new(None);
|
let label = Label::new(None);
|
||||||
label.set_use_markup(true);
|
label.set_use_markup(true);
|
||||||
button.add(&label);
|
button.add(&label);
|
||||||
|
|
Loading…
Add table
Reference in a new issue