raui_core/widget/component/
text_box.rs1use crate::{
2 PropsData,
3 widget::{
4 component::WidgetAlpha,
5 context::WidgetContext,
6 node::WidgetNode,
7 unit::text::{
8 TextBoxDirection, TextBoxFont, TextBoxHorizontalAlign, TextBoxNode, TextBoxSizeValue,
9 TextBoxVerticalAlign,
10 },
11 utils::{Color, Transform},
12 },
13};
14use serde::{Deserialize, Serialize};
15
16#[derive(PropsData, Debug, Default, Clone, Serialize, Deserialize)]
17#[props_data(crate::props::PropsData)]
18#[prefab(crate::Prefab)]
19pub struct TextBoxProps {
20 #[serde(default)]
21 pub text: String,
22 #[serde(default)]
23 pub width: TextBoxSizeValue,
24 #[serde(default)]
25 pub height: TextBoxSizeValue,
26 #[serde(default)]
27 pub horizontal_align: TextBoxHorizontalAlign,
28 #[serde(default)]
29 pub vertical_align: TextBoxVerticalAlign,
30 #[serde(default)]
31 pub direction: TextBoxDirection,
32 #[serde(default)]
33 pub font: TextBoxFont,
34 #[serde(default)]
35 pub color: Color,
36 #[serde(default)]
37 pub transform: Transform,
38}
39
40pub fn text_box(context: WidgetContext) -> WidgetNode {
41 let WidgetContext {
42 id,
43 props,
44 shared_props,
45 ..
46 } = context;
47
48 let TextBoxProps {
49 width,
50 height,
51 text,
52 horizontal_align,
53 vertical_align,
54 direction,
55 font,
56 mut color,
57 transform,
58 } = props.read_cloned_or_default();
59
60 let alpha = shared_props.read_cloned_or_default::<WidgetAlpha>().0;
61 color.a *= alpha;
62
63 TextBoxNode {
64 id: id.to_owned(),
65 props: props.clone(),
66 text,
67 width,
68 height,
69 horizontal_align,
70 vertical_align,
71 direction,
72 font,
73 color,
74 transform,
75 }
76 .into()
77}