use crate::{Borderable, Color, Colorable, FontSize, Labelable};
use crate::position::{self, Align, Scalar};
use crate::text;
use crate::widget::{self};
#[derive(Clone, WidgetCommon_)]
pub struct TitleBar<'a> {
#[carbide(common_builder)]
pub common: widget::CommonBuilder,
pub style: Style,
pub label: &'a str,
}
pub struct State {
ids: Ids,
}
widget_ids! {
struct Ids {
rectangle,
label,
}
}
#[derive(Copy, Clone, Debug, Default, PartialEq, WidgetStyle_)]
pub struct Style {
#[carbide(default = "theme.background_color")]
pub color: Option<Color>,
#[carbide(default = "theme.border_width")]
pub border: Option<Scalar>,
#[carbide(default = "theme.border_color")]
pub border_color: Option<Color>,
#[carbide(default = "theme.label_color")]
pub text_color: Option<Color>,
#[carbide(default = "theme.font_size_medium")]
pub font_size: Option<FontSize>,
#[carbide(default = "Some(widget::text::Wrap::Whitespace)")]
pub maybe_wrap: Option<Option<widget::text::Wrap>>,
#[carbide(default = "1.0")]
pub line_spacing: Option<Scalar>,
#[carbide(default = "text::Justify::Center")]
pub justify: Option<text::Justify>,
#[carbide(default = "position::Relative::Align(Align::Middle)")]
pub label_x: Option<position::Relative>,
#[carbide(default = "position::Relative::Align(Align::Middle)")]
pub label_y: Option<position::Relative>,
#[carbide(default = "theme.font_id")]
pub font_id: Option<Option<text::font::Id>>,
}
const LABEL_PADDING: f64 = 4.0;
impl<'a> TitleBar<'a> {
pub fn new(label: &'a str, _id: widget::Id) -> Self {
TitleBar {
common: widget::CommonBuilder::default(),
style: Style::default(),
label: label,
} }
pub fn left_justify_label(mut self) -> Self {
self.style.justify = Some(text::Justify::Left);
self
}
pub fn center_justify_label(mut self) -> Self {
self.style.justify = Some(text::Justify::Center);
self
}
pub fn right_justify_label(mut self) -> Self {
self.style.justify = Some(text::Justify::Right);
self
}
pub fn label_x(mut self, x: position::Relative) -> Self {
self.style.label_x = Some(x);
self
}
pub fn label_y(mut self, y: position::Relative) -> Self {
self.style.label_y = Some(y);
self
}
pub fn font_id(mut self, font_id: text::font::Id) -> Self {
self.style.font_id = Some(Some(font_id));
self
}
builder_methods!{
pub line_spacing { style.line_spacing = Some(Scalar) }
}
}
pub fn calc_height(font_size: FontSize) -> Scalar {
font_size as Scalar + LABEL_PADDING * 2.0
}
impl<'a> Colorable for TitleBar<'a> {
builder_method!(color { style.color = Some(Color) });
}
impl<'a> Borderable for TitleBar<'a> {
builder_methods!{
border { style.border = Some(Scalar) }
border_color { style.border_color = Some(Color) }
}
}
impl<'a> Labelable<'a> for TitleBar<'a> {
builder_methods!{
label { label = &'a str }
label_color { style.text_color = Some(Color) }
label_font_size { style.font_size = Some(FontSize) }
}
}