1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
use crate::{ widget::{unit::WidgetUnitData, utils::Color, WidgetId}, Scalar, }; use serde::{Deserialize, Serialize}; #[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum TextBoxAlignment { Left, Center, Right, } impl Default for TextBoxAlignment { fn default() -> Self { Self::Left } } #[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum TextBoxDirection { HorizontalLeftToRight, HorizontalRightToLeft, VerticalTopToBottom, VerticalBottomToTop, } impl Default for TextBoxDirection { fn default() -> Self { Self::HorizontalLeftToRight } } impl TextBoxDirection { pub fn is_horizontal(&self) -> bool { *self == Self::HorizontalLeftToRight || *self == Self::HorizontalRightToLeft } pub fn is_vertical(&self) -> bool { *self == Self::VerticalTopToBottom || *self == Self::VerticalBottomToTop } pub fn is_order_ascending(&self) -> bool { *self == Self::HorizontalLeftToRight || *self == Self::VerticalTopToBottom } pub fn is_order_descending(&self) -> bool { *self == Self::HorizontalRightToLeft || *self == Self::VerticalBottomToTop } } #[derive(Debug, Default, Clone, Serialize, Deserialize)] pub struct TextBoxFont { #[serde(default)] pub name: String, #[serde(default)] pub size: Scalar, #[serde(default)] pub bold: bool, #[serde(default)] pub italic: bool, } #[derive(Debug, Copy, Clone, Serialize, Deserialize)] pub enum TextBoxSizeValue { Fill, Exact(Scalar), } impl Default for TextBoxSizeValue { fn default() -> Self { Self::Fill } } #[derive(Debug, Default, Clone, Serialize, Deserialize)] pub struct TextBox { #[serde(default)] pub id: WidgetId, #[serde(default)] pub text: String, #[serde(default)] pub width: TextBoxSizeValue, #[serde(default)] pub height: TextBoxSizeValue, #[serde(default)] pub alignment: TextBoxAlignment, #[serde(default)] pub direction: TextBoxDirection, #[serde(default)] pub font: TextBoxFont, #[serde(default)] pub color: Color, } impl WidgetUnitData for TextBox { fn id(&self) -> &WidgetId { &self.id } }