use crate::{Borderable, Color, Colorable, FontSize};
use crate::position::Scalar;
use crate::text;
use crate::widget;
#[derive(WidgetCommon_)]
pub struct TextBox<'a> {
#[carbide(common_builder)]
common: widget::CommonBuilder,
text: &'a str,
style: Style,
}
#[derive(Copy, Clone, Debug, Default, PartialEq, WidgetStyle_)]
pub struct Style {
#[carbide(default = "5.0")]
pub text_padding: Option<Scalar>,
#[carbide(default = "theme.shape_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 = "text::Justify::Left")]
pub justify: Option<text::Justify>,
#[carbide(default = "theme.font_id")]
pub font_id: Option<Option<text::font::Id>>,
}
widget_ids! {
struct Ids {
text_edit,
rectangle,
}
}
pub struct State {
ids: Ids,
}
impl<'a> TextBox<'a> {
pub fn new(text: &'a str) -> Self {
TextBox {
common: widget::CommonBuilder::default(),
style: Style::default(),
text: text,
}
}
pub fn left_justify(self) -> Self {
self.justify(text::Justify::Left)
}
pub fn center_justify(self) -> Self {
self.justify(text::Justify::Center)
}
pub fn right_justify(self) -> Self {
self.justify(text::Justify::Right)
}
pub fn font_id(mut self, font_id: text::font::Id) -> Self {
self.style.font_id = Some(Some(font_id));
self
}
builder_methods!{
pub text_color { style.text_color = Some(Color) }
pub font_size { style.font_size = Some(FontSize) }
pub justify { style.justify = Some(text::Justify) }
pub pad_text { style.text_padding = Some(Scalar) }
}
}
#[derive(Clone, Debug)]
pub enum Event {
Update(String),
Enter,
}
impl<'a> Borderable for TextBox<'a> {
builder_methods!{
border { style.border = Some(Scalar) }
border_color { style.border_color = Some(Color) }
}
}
impl<'a> Colorable for TextBox<'a> {
builder_method!(color { style.color = Some(Color) });
}