ohos_arkui_binding/component/built_in_component/
time_picker.rs1#[derive(Clone, Debug, PartialEq)]
4pub struct TimePickerTextStyleObject {
6 pub font_color: String,
7 pub font_size: f32,
8 pub font_weight: String,
9 pub font_family: String,
10 pub font_style: String,
11}
12
13impl TimePickerTextStyleObject {
14 pub fn new<C, W, F, S>(
15 font_color: C,
16 font_size: f32,
17 font_weight: W,
18 font_family: F,
19 font_style: S,
20 ) -> Self
21 where
22 C: Into<String>,
23 W: Into<String>,
24 F: Into<String>,
25 S: Into<String>,
26 {
27 Self {
28 font_color: font_color.into(),
29 font_size,
30 font_weight: font_weight.into(),
31 font_family: font_family.into(),
32 font_style: font_style.into(),
33 }
34 }
35
36 pub fn to_attribute_string(&self) -> String {
37 format!(
38 "{};{};{};{};{}",
39 self.font_color, self.font_size, self.font_weight, self.font_family, self.font_style
40 )
41 }
42
43 pub fn from_attribute_string(raw: &str) -> Option<Self> {
44 let mut parts = raw.splitn(5, ';');
45 let font_color = parts.next()?.to_string();
46 let font_size = parts.next()?.parse::<f32>().ok()?;
47 let font_weight = parts.next()?.to_string();
48 let font_family = parts.next()?.to_string();
49 let font_style = parts.next()?.to_string();
50 Some(Self {
51 font_color,
52 font_size,
53 font_weight,
54 font_family,
55 font_style,
56 })
57 }
58}
59
60impl super::TimePicker {
61 pub fn set_time_picker_disappear_text_style_object(
62 &self,
63 style: &TimePickerTextStyleObject,
64 ) -> crate::ArkUIResult<()> {
65 <Self as crate::ArkUICommonAttribute>::set_attribute(
66 self,
67 crate::ArkUINodeAttributeType::TimePickerDisappearTextStyle,
68 crate::ArkUINodeAttributeItem::String(style.to_attribute_string()),
69 )
70 }
71
72 pub fn get_time_picker_disappear_text_style_object(
73 &self,
74 ) -> crate::ArkUIResult<Option<TimePickerTextStyleObject>> {
75 match <Self as crate::ArkUICommonAttribute>::get_attribute(
76 self,
77 crate::ArkUINodeAttributeType::TimePickerDisappearTextStyle,
78 )? {
79 crate::ArkUINodeAttributeItem::String(raw) => {
80 Ok(TimePickerTextStyleObject::from_attribute_string(&raw))
81 }
82 _ => Ok(None),
83 }
84 }
85
86 pub fn set_time_picker_text_style_object(
87 &self,
88 style: &TimePickerTextStyleObject,
89 ) -> crate::ArkUIResult<()> {
90 <Self as crate::ArkUICommonAttribute>::set_attribute(
91 self,
92 crate::ArkUINodeAttributeType::TimePickerTextStyle,
93 crate::ArkUINodeAttributeItem::String(style.to_attribute_string()),
94 )
95 }
96
97 pub fn get_time_picker_text_style_object(
98 &self,
99 ) -> crate::ArkUIResult<Option<TimePickerTextStyleObject>> {
100 match <Self as crate::ArkUICommonAttribute>::get_attribute(
101 self,
102 crate::ArkUINodeAttributeType::TimePickerTextStyle,
103 )? {
104 crate::ArkUINodeAttributeItem::String(raw) => {
105 Ok(TimePickerTextStyleObject::from_attribute_string(&raw))
106 }
107 _ => Ok(None),
108 }
109 }
110
111 pub fn set_time_picker_selected_text_style_object(
112 &self,
113 style: &TimePickerTextStyleObject,
114 ) -> crate::ArkUIResult<()> {
115 <Self as crate::ArkUICommonAttribute>::set_attribute(
116 self,
117 crate::ArkUINodeAttributeType::TimePickerSelectedTextStyle,
118 crate::ArkUINodeAttributeItem::String(style.to_attribute_string()),
119 )
120 }
121
122 pub fn get_time_picker_selected_text_style_object(
123 &self,
124 ) -> crate::ArkUIResult<Option<TimePickerTextStyleObject>> {
125 match <Self as crate::ArkUICommonAttribute>::get_attribute(
126 self,
127 crate::ArkUINodeAttributeType::TimePickerSelectedTextStyle,
128 )? {
129 crate::ArkUINodeAttributeItem::String(raw) => {
130 Ok(TimePickerTextStyleObject::from_attribute_string(&raw))
131 }
132 _ => Ok(None),
133 }
134 }
135}
136
137impl super::TimePicker {
139 pub fn set_time_picker_selected<T: Into<crate::ArkUINodeAttributeItem>>(
140 &self,
141 value: T,
142 ) -> crate::ArkUIResult<()> {
143 <Self as crate::ArkUICommonAttribute>::set_attribute(
144 self,
145 crate::ArkUINodeAttributeType::TimePickerSelected,
146 value.into(),
147 )
148 }
149
150 pub fn get_time_picker_selected(&self) -> crate::ArkUIResult<crate::ArkUINodeAttributeItem> {
151 <Self as crate::ArkUICommonAttribute>::get_attribute(
152 self,
153 crate::ArkUINodeAttributeType::TimePickerSelected,
154 )
155 }
156
157 pub fn set_time_picker_use_military_time<T: Into<crate::ArkUINodeAttributeItem>>(
158 &self,
159 value: T,
160 ) -> crate::ArkUIResult<()> {
161 <Self as crate::ArkUICommonAttribute>::set_attribute(
162 self,
163 crate::ArkUINodeAttributeType::TimePickerUseMilitaryTime,
164 value.into(),
165 )
166 }
167
168 pub fn get_time_picker_use_military_time(
169 &self,
170 ) -> crate::ArkUIResult<crate::ArkUINodeAttributeItem> {
171 <Self as crate::ArkUICommonAttribute>::get_attribute(
172 self,
173 crate::ArkUINodeAttributeType::TimePickerUseMilitaryTime,
174 )
175 }
176
177 pub fn set_time_picker_disappear_text_style<T: Into<crate::ArkUINodeAttributeItem>>(
178 &self,
179 value: T,
180 ) -> crate::ArkUIResult<()> {
181 <Self as crate::ArkUICommonAttribute>::set_attribute(
182 self,
183 crate::ArkUINodeAttributeType::TimePickerDisappearTextStyle,
184 value.into(),
185 )
186 }
187
188 pub fn get_time_picker_disappear_text_style(
189 &self,
190 ) -> crate::ArkUIResult<crate::ArkUINodeAttributeItem> {
191 <Self as crate::ArkUICommonAttribute>::get_attribute(
192 self,
193 crate::ArkUINodeAttributeType::TimePickerDisappearTextStyle,
194 )
195 }
196
197 pub fn set_time_picker_text_style<T: Into<crate::ArkUINodeAttributeItem>>(
198 &self,
199 value: T,
200 ) -> crate::ArkUIResult<()> {
201 <Self as crate::ArkUICommonAttribute>::set_attribute(
202 self,
203 crate::ArkUINodeAttributeType::TimePickerTextStyle,
204 value.into(),
205 )
206 }
207
208 pub fn get_time_picker_text_style(&self) -> crate::ArkUIResult<crate::ArkUINodeAttributeItem> {
209 <Self as crate::ArkUICommonAttribute>::get_attribute(
210 self,
211 crate::ArkUINodeAttributeType::TimePickerTextStyle,
212 )
213 }
214
215 pub fn set_time_picker_selected_text_style<T: Into<crate::ArkUINodeAttributeItem>>(
216 &self,
217 value: T,
218 ) -> crate::ArkUIResult<()> {
219 <Self as crate::ArkUICommonAttribute>::set_attribute(
220 self,
221 crate::ArkUINodeAttributeType::TimePickerSelectedTextStyle,
222 value.into(),
223 )
224 }
225
226 pub fn get_time_picker_selected_text_style(
227 &self,
228 ) -> crate::ArkUIResult<crate::ArkUINodeAttributeItem> {
229 <Self as crate::ArkUICommonAttribute>::get_attribute(
230 self,
231 crate::ArkUINodeAttributeType::TimePickerSelectedTextStyle,
232 )
233 }
234
235 #[cfg(feature = "api-18")]
236 pub fn set_time_picker_enable_cascade<T: Into<crate::ArkUINodeAttributeItem>>(
237 &self,
238 value: T,
239 ) -> crate::ArkUIResult<()> {
240 <Self as crate::ArkUICommonAttribute>::set_attribute(
241 self,
242 crate::ArkUINodeAttributeType::TimePickerEnableCascade,
243 value.into(),
244 )
245 }
246
247 #[cfg(feature = "api-18")]
248 pub fn get_time_picker_enable_cascade(
249 &self,
250 ) -> crate::ArkUIResult<crate::ArkUINodeAttributeItem> {
251 <Self as crate::ArkUICommonAttribute>::get_attribute(
252 self,
253 crate::ArkUINodeAttributeType::TimePickerEnableCascade,
254 )
255 }
256
257 #[cfg(feature = "api-18")]
258 pub fn set_time_picker_end<T: Into<crate::ArkUINodeAttributeItem>>(
259 &self,
260 value: T,
261 ) -> crate::ArkUIResult<()> {
262 <Self as crate::ArkUICommonAttribute>::set_attribute(
263 self,
264 crate::ArkUINodeAttributeType::TimePickerEnd,
265 value.into(),
266 )
267 }
268
269 #[cfg(feature = "api-18")]
270 pub fn get_time_picker_end(&self) -> crate::ArkUIResult<crate::ArkUINodeAttributeItem> {
271 <Self as crate::ArkUICommonAttribute>::get_attribute(
272 self,
273 crate::ArkUINodeAttributeType::TimePickerEnd,
274 )
275 }
276
277 #[cfg(feature = "api-18")]
278 pub fn set_time_picker_start<T: Into<crate::ArkUINodeAttributeItem>>(
279 &self,
280 value: T,
281 ) -> crate::ArkUIResult<()> {
282 <Self as crate::ArkUICommonAttribute>::set_attribute(
283 self,
284 crate::ArkUINodeAttributeType::TimePickerStart,
285 value.into(),
286 )
287 }
288
289 #[cfg(feature = "api-18")]
290 pub fn get_time_picker_start(&self) -> crate::ArkUIResult<crate::ArkUINodeAttributeItem> {
291 <Self as crate::ArkUICommonAttribute>::get_attribute(
292 self,
293 crate::ArkUINodeAttributeType::TimePickerStart,
294 )
295 }
296}
297#[derive(Clone, Copy, Debug, PartialEq, Eq)]
300pub struct TimePickerChangeEvent {
302 pub hour: i32,
303 pub minute: i32,
304}
305
306impl super::TimePicker {
307 pub fn on_time_picker_change<T: Fn(TimePickerChangeEvent) + 'static>(&mut self, cb: T) {
308 crate::ArkUIEvent::on_event(
309 self,
310 crate::NodeEventType::TimePickerEventOnChange,
311 move |event| {
312 cb(TimePickerChangeEvent {
313 hour: event.i32_value(0).unwrap_or_default(),
314 minute: event.i32_value(1).unwrap_or_default(),
315 });
316 },
317 );
318 }
319}