mirror of
https://github.com/Zedfrigg/ironbar.git
synced 2025-08-16 14:21:03 +02:00
feat(custom): add halign and valign options to box widget (#988)
This commit is contained in:
parent
e4c0a1ba92
commit
b13c725f67
2 changed files with 45 additions and 1 deletions
|
@ -47,6 +47,8 @@ A container to place nested widgets inside.
|
||||||
|---------------|------------------------------------------------------------|----------------|-------------------------------------------------------------------|
|
|---------------|------------------------------------------------------------|----------------|-------------------------------------------------------------------|
|
||||||
| `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 modules/widgets to add to this box. |
|
| `widgets` | `(Module or Widget)[]` | `[]` | List of modules/widgets to add to this box. |
|
||||||
|
| `halign` | `'start'` or `'center'` or `'end'` or `'fill'` | `'fill'` | The horizontal alignment of the box within its parent container. |
|
||||||
|
| `valign` | `'start'` or `'center'` or `'end'` or `'fill'` | `'fill'` | The vertical alignment of the box within its parent container. |
|
||||||
|
|
||||||
#### Label
|
#### Label
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,31 @@ use crate::modules::custom::WidgetConfig;
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize, Clone)]
|
||||||
|
#[serde(rename_all = "lowercase")]
|
||||||
|
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
|
||||||
|
pub enum ModuleAlignment {
|
||||||
|
/// Align widget to the start (left for horizontal, top for vertical).
|
||||||
|
Start,
|
||||||
|
/// Align widget to the center.
|
||||||
|
Center,
|
||||||
|
/// Align widget to the end (right for horizontal, bottom for vertical).
|
||||||
|
End,
|
||||||
|
/// Stretch widget to fill available space.
|
||||||
|
Fill,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<ModuleAlignment> for gtk::Align {
|
||||||
|
fn from(align: ModuleAlignment) -> Self {
|
||||||
|
match align {
|
||||||
|
ModuleAlignment::Start => gtk::Align::Start,
|
||||||
|
ModuleAlignment::Center => gtk::Align::Center,
|
||||||
|
ModuleAlignment::End => gtk::Align::End,
|
||||||
|
ModuleAlignment::Fill => gtk::Align::Fill,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Clone)]
|
#[derive(Debug, Deserialize, Clone)]
|
||||||
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
|
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
|
||||||
pub struct BoxWidget {
|
pub struct BoxWidget {
|
||||||
|
@ -21,10 +46,21 @@ pub struct BoxWidget {
|
||||||
/// Whether child widgets should be horizontally or vertically added.
|
/// Whether child widgets should be horizontally or vertically added.
|
||||||
///
|
///
|
||||||
/// **Valid options**: `horizontal`, `vertical`, `h`, `v`
|
/// **Valid options**: `horizontal`, `vertical`, `h`, `v`
|
||||||
/// <br />
|
|
||||||
/// **Default**: `horizontal`
|
/// **Default**: `horizontal`
|
||||||
orientation: Option<ModuleOrientation>,
|
orientation: Option<ModuleOrientation>,
|
||||||
|
|
||||||
|
/// Horizontal alignment of the box relative to its parent.
|
||||||
|
///
|
||||||
|
/// **Valid options**: `start`, `center`, `end`, `fill`
|
||||||
|
/// **Default**: `fill`
|
||||||
|
halign: Option<ModuleAlignment>,
|
||||||
|
|
||||||
|
/// Vertical alignment of the box relative to its parent.
|
||||||
|
///
|
||||||
|
/// **Valid options**: `start`, `center`, `end`, `fill`
|
||||||
|
/// **Default**: `fill`
|
||||||
|
valign: Option<ModuleAlignment>,
|
||||||
|
|
||||||
/// Modules and widgets to add to this box.
|
/// Modules and widgets to add to this box.
|
||||||
///
|
///
|
||||||
/// **Default**: `null`
|
/// **Default**: `null`
|
||||||
|
@ -47,6 +83,12 @@ impl CustomWidget for BoxWidget {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let horizontal_alignment = self.halign.unwrap_or(ModuleAlignment::Fill);
|
||||||
|
let vertical_alignment = self.valign.unwrap_or(ModuleAlignment::Fill);
|
||||||
|
|
||||||
|
container.set_halign(horizontal_alignment.into());
|
||||||
|
container.set_valign(vertical_alignment.into());
|
||||||
|
|
||||||
container
|
container
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue