use crate::{
graphics::{colours::RGBA, shapes, Shape, Size},
Align, DebugWidget, ToAny, Widget,
};
use super::{Button, Label};
#[derive(Debug)]
pub struct ToolBar {
pub title: Option<Label>,
pub title_align: Align,
pub actions: Vec<Button>,
pub actions_align: Align,
pub colour: RGBA,
}
crate::dynamic_widget!(ToolBar);
impl Widget for ToolBar {
fn shape(&self, size: Option<Size>) -> Shape {
assert!(size != None);
shapes::Builder::new()
.rectangle(size.unwrap(), None)
.fill(self.colour)
.finish()
}
}
impl Default for ToolBar {
fn default() -> Self {
ToolBar {
title: None,
title_align: Align::Center,
actions: vec![],
actions_align: Align::Right,
colour: RGBA::default(),
}
}
}
impl ToolBar {
pub fn new(
title: Label,
title_align: Align,
actions: Vec<Button>,
actions_align: Align,
colour: RGBA,
) -> Self {
Self {
title: Some(title),
title_align,
actions,
actions_align,
colour,
}
}
pub fn simple(actions: Vec<Button>, colour: RGBA) -> Self {
Self {
actions,
colour,
..Self::default()
}
}
pub fn titled(title: Label, actions: Vec<Button>) -> Self {
Self {
title: Some(title),
actions,
..Self::default()
}
}
pub fn coloured(actions: Vec<Button>, colour: RGBA) -> Self {
Self {
actions,
colour,
..Self::default()
}
}
}