mirror of
https://github.com/Zedfrigg/ironbar.git
synced 2025-08-17 14:51:04 +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
|
@ -5,6 +5,31 @@ use crate::modules::custom::WidgetConfig;
|
|||
use gtk::prelude::*;
|
||||
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)]
|
||||
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
|
||||
pub struct BoxWidget {
|
||||
|
@ -21,10 +46,21 @@ pub struct BoxWidget {
|
|||
/// Whether child widgets should be horizontally or vertically added.
|
||||
///
|
||||
/// **Valid options**: `horizontal`, `vertical`, `h`, `v`
|
||||
/// <br />
|
||||
/// **Default**: `horizontal`
|
||||
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.
|
||||
///
|
||||
/// **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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue