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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
use crate::TextAlignment;
use super::implz::Platform;
use uniui_gui::prelude::*;
pub struct Label {
text: String,
platform: Platform,
slot_set_text: SlotImpl<String>,
text_alignment: Property<TextAlignment>,
}
impl Label {
pub fn new(text: String) -> Label {
return Label {
text,
platform: Platform::new(),
slot_set_text: SlotImpl::new(),
text_alignment: Property::new(TextAlignment::Start),
};
}
pub fn slot_set_text(&self) -> &dyn Slot<String> {
return &self.slot_set_text;
}
pub fn slot_set_text_alignment(&self) -> &dyn Slot<TextAlignment> {
return self.text_alignment.slot();
}
fn set_text(
&mut self,
s: String,
) {
self.text = s;
self.platform.set_text(&self.text);
}
}
impl Widget for Label {
fn to_native(
&mut self,
widget_generator: &mut dyn WidgetGenerator,
) -> Result<NativeWidget, ()> {
return self.platform.to_native(widget_generator, &self.text);
}
}
impl DataProcessor for Label {
fn process_data(
&mut self,
_: i64,
_: &mut dyn Application,
) {
if let Some(text) = self.slot_set_text.data_iter().last() {
self.set_text(text);
}
if self.text_alignment.try_update() {
self.platform.update_alignment(self.text_alignment.as_ref());
}
}
}