1use std::any::Any;
5use std::fmt;
6
7use crate::align::{Align, Anchors, SelfAlign};
8use crate::canvas::Canvas;
9use crate::error::{Error, Result};
10use crate::event::{EventArgs, EventCtx, KeyEvent, PointerEvent, WheelEvent};
11use crate::geometry::{Bounds, PointF, RectF, SizeF};
12use crate::paint::PaintCtx;
13use crate::platform::CursorShape;
14use crate::prop::{PropInfo, PropKind, PropValue};
15
16#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
21pub struct ComponentId {
22 pub(crate) index: u32,
23 pub(crate) generation: u32,
24}
25
26impl ComponentId {
27 pub fn to_u64(self) -> u64 {
29 (self.generation as u64) << 32 | self.index as u64
30 }
31
32 pub fn from_u64(value: u64) -> Self {
34 Self { index: value as u32, generation: (value >> 32) as u32 }
35 }
36}
37
38impl fmt::Display for ComponentId {
39 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
40 write!(f, "#{}v{}", self.index, self.generation)
41 }
42}
43
44#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
46pub struct ControlState {
47 pub hover: bool,
48 pub pressed: bool,
49 pub focused: bool,
50 pub checked: bool,
51 pub disabled: bool,
53}
54
55#[derive(Clone, Debug, PartialEq)]
57pub enum ClipShape {
58 RoundRect(f32),
60 Corners(crate::Bounds),
63 Ellipse,
65 Path(std::sync::Arc<crate::Path>),
68}
69
70impl ClipShape {
71 pub fn from_corners(c: crate::Bounds) -> ClipShape {
74 if c.left == c.top && c.top == c.right && c.right == c.bottom && c.left >= 0.0 {
75 ClipShape::RoundRect(c.left)
76 } else {
77 ClipShape::Corners(c)
78 }
79 }
80
81 pub fn radius(&self, rect: crate::RectF) -> f32 {
84 let limit = rect.width.min(rect.height) / 2.0;
85 match self {
86 ClipShape::RoundRect(r) => r.clamp(0.0, limit),
87 ClipShape::Corners(c) => c.left.max(c.top).max(c.right).max(c.bottom).clamp(0.0, limit),
88 ClipShape::Ellipse => limit,
89 ClipShape::Path(_) => 0.0,
90 }
91 }
92
93 pub fn outline(&self, rect: crate::RectF) -> crate::Path {
95 let mut path = crate::Path::new();
96 match self {
97 ClipShape::RoundRect(_) => {
98 path.rect(rect, self.radius(rect));
99 }
100 ClipShape::Corners(c) => path = crate::Path::corners(rect, *c),
101 ClipShape::Ellipse => {
102 path.ellipse(rect);
103 }
104 ClipShape::Path(p) => {
105 let b = p.bounds();
106 let sx = if b.width > 0.0 { rect.width / b.width } else { 1.0 };
107 let sy = if b.height > 0.0 { rect.height / b.height } else { 1.0 };
108 path = p.map_points(|q| crate::PointF::new(rect.x + (q.x - b.x) * sx, rect.y + (q.y - b.y) * sy));
109 }
110 }
111 path
112 }
113
114 pub fn fill(&self, canvas: &mut dyn crate::Canvas, rect: crate::RectF, brush: &crate::Brush) {
116 match self {
117 ClipShape::RoundRect(_) => canvas.fill_rect(rect, self.radius(rect), brush),
118 ClipShape::Ellipse => canvas.fill_ellipse(rect, brush),
119 _ => canvas.fill_path(&self.outline(rect), brush),
120 }
121 }
122
123 pub fn clip(&self, canvas: &mut dyn crate::Canvas, rect: crate::RectF) {
125 match self {
126 ClipShape::RoundRect(_) => canvas.clip_round_rect(rect, self.radius(rect)),
127 _ => canvas.clip_path(&self.outline(rect), false),
128 }
129 }
130}
131
132pub trait Component: Any {
163 fn class_name(&self) -> &'static str;
166
167 fn inner(&self) -> Option<&dyn Component> {
169 None
170 }
171
172 fn inner_mut(&mut self) -> Option<&mut dyn Component> {
173 None
174 }
175
176 fn class_chain(&self, out: &mut Vec<&'static str>) {
179 out.push(self.class_name());
180 if let Some(inner) = self.inner() {
181 inner.class_chain(out);
182 }
183 }
184
185 fn control(&self) -> Option<&ControlBase> {
187 self.inner().and_then(|i| i.control())
188 }
189
190 fn control_mut(&mut self) -> Option<&mut ControlBase> {
191 self.inner_mut().and_then(|i| i.control_mut())
192 }
193
194 fn props(&self) -> &'static [PropInfo] {
197 &[]
198 }
199
200 fn default_event(&self) -> Option<&'static str> {
204 self.inner().and_then(|c| c.default_event())
205 }
206
207 fn get_prop(&self, _name: &str) -> Option<PropValue> {
209 None
210 }
211
212 fn set_prop(&mut self, name: &str, _value: PropValue) -> Result<()> {
215 Err(Error::UnknownProperty(name.to_string()))
216 }
217
218 fn notification(&mut self, freed: ComponentId) {
221 if let Some(inner) = self.inner_mut() {
222 inner.notification(freed);
223 }
224 }
225
226 fn paint(&self, canvas: &mut dyn Canvas, ctx: &PaintCtx<'_>) {
228 if let Some(inner) = self.inner() {
229 inner.paint(canvas, ctx);
230 }
231 }
232
233 fn transparent_background(&self) -> bool {
237 self.inner().is_some_and(|i| i.transparent_background())
238 }
239
240 fn opaque(&self, style: &crate::theme::ResolvedStyle) -> bool {
245 self.inner().is_some_and(|i| i.opaque(style))
246 }
247
248 fn clip_shape(&self) -> Option<ClipShape> {
252 self.inner().and_then(|i| i.clip_shape())
253 }
254
255 fn painted_shape(&self) -> Option<ClipShape> {
260 self.clip_shape().or_else(|| self.inner().and_then(|i| i.painted_shape()))
261 }
262
263 fn paint_after(&self, canvas: &mut dyn Canvas, ctx: &PaintCtx<'_>) {
265 if let Some(inner) = self.inner() {
266 inner.paint_after(canvas, ctx);
267 }
268 }
269
270 fn paint_is_pure(&self) -> bool {
277 false
278 }
279
280 fn provided(&self) -> Option<crate::providers::Provided<'_>> {
283 None
284 }
285
286 fn resized(&mut self, ctx: &mut EventCtx<'_>) {
288 if let Some(inner) = self.inner_mut() {
289 inner.resized(ctx);
290 }
291 }
292
293 fn click(&mut self, ctx: &mut EventCtx<'_>) {
295 match self.inner_mut() {
296 Some(inner) => inner.click(ctx),
297 None => ctx.fire("on_click", EventArgs::None),
298 }
299 }
300
301 fn pointer_down(&mut self, ctx: &mut EventCtx<'_>, event: &PointerEvent) {
302 if let Some(inner) = self.inner_mut() {
303 inner.pointer_down(ctx, event);
304 }
305 }
306
307 fn pointer_up(&mut self, ctx: &mut EventCtx<'_>, event: &PointerEvent) {
308 if let Some(inner) = self.inner_mut() {
309 inner.pointer_up(ctx, event);
310 }
311 }
312
313 fn pointer_move(&mut self, ctx: &mut EventCtx<'_>, event: &PointerEvent) {
314 if let Some(inner) = self.inner_mut() {
315 inner.pointer_move(ctx, event);
316 }
317 }
318
319 fn pointer_enter(&mut self, ctx: &mut EventCtx<'_>) {
320 if let Some(inner) = self.inner_mut() {
321 inner.pointer_enter(ctx);
322 }
323 }
324
325 fn pointer_leave(&mut self, ctx: &mut EventCtx<'_>) {
326 if let Some(inner) = self.inner_mut() {
327 inner.pointer_leave(ctx);
328 }
329 }
330
331 fn wheel(&mut self, ctx: &mut EventCtx<'_>, event: &WheelEvent) {
332 if let Some(inner) = self.inner_mut() {
333 inner.wheel(ctx, event);
334 }
335 }
336
337 fn gesture(&mut self, ctx: &mut EventCtx<'_>, event: &crate::event::GestureEvent) {
340 if let Some(inner) = self.inner_mut() {
341 inner.gesture(ctx, event);
342 }
343 }
344
345 fn swipe(&mut self, ctx: &mut EventCtx<'_>, event: &crate::event::SwipeEvent) {
348 if let Some(inner) = self.inner_mut() {
349 inner.swipe(ctx, event);
350 }
351 }
352
353 fn touch_end(&mut self, ctx: &mut EventCtx<'_>) {
357 if let Some(inner) = self.inner_mut() {
358 inner.touch_end(ctx);
359 }
360 }
361
362 fn edge_swipe(&mut self, ctx: &mut EventCtx<'_>, event: &crate::event::SwipeEvent) -> bool {
365 match self.inner_mut() {
366 Some(inner) => inner.edge_swipe(ctx, event),
367 None => false,
368 }
369 }
370
371 fn context_menu(&mut self, ctx: &mut EventCtx<'_>, at: PointF, touch: bool) -> bool {
376 match self.inner_mut() {
377 Some(inner) => inner.context_menu(ctx, at, touch),
378 None => false,
379 }
380 }
381
382 fn key_down(&mut self, ctx: &mut EventCtx<'_>, event: &KeyEvent) {
383 if let Some(inner) = self.inner_mut() {
384 inner.key_down(ctx, event);
385 }
386 }
387
388 fn key_up(&mut self, ctx: &mut EventCtx<'_>, event: &KeyEvent) {
389 if let Some(inner) = self.inner_mut() {
390 inner.key_up(ctx, event);
391 }
392 }
393
394 fn shortcut(&mut self, ctx: &mut EventCtx<'_>, event: &KeyEvent) {
398 if let Some(inner) = self.inner_mut() {
399 inner.shortcut(ctx, event);
400 }
401 }
402
403 fn platform_hooks(&self) -> Option<&dyn PlatformHooks> {
406 self.inner().and_then(|i| i.platform_hooks())
407 }
408
409 fn platform_hooks_mut(&mut self) -> Option<&mut dyn PlatformHooks> {
410 self.inner_mut().and_then(|i| i.platform_hooks_mut())
411 }
412
413 fn design_hooks(&self) -> Option<&dyn DesignHooks> {
416 self.inner().and_then(|i| i.design_hooks())
417 }
418
419 fn design_hooks_mut(&mut self) -> Option<&mut dyn DesignHooks> {
420 self.inner_mut().and_then(|i| i.design_hooks_mut())
421 }
422
423 fn contains_point(&self, local: PointF, size: SizeF) -> bool {
426 self.inner().map_or(true, |i| i.contains_point(local, size))
427 }
428
429 fn hit_slop(&self) -> f32 {
433 self.inner().map_or(0.0, |i| i.hit_slop())
434 }
435
436 fn scroll_axes(&self) -> (bool, bool) {
439 self.inner().map_or((false, false), |i| i.scroll_axes())
440 }
441
442 fn drag_drop(&self) -> Option<&dyn DragDrop> {
445 None
446 }
447
448 fn drag_drop_mut(&mut self) -> Option<&mut dyn DragDrop> {
449 None
450 }
451
452 fn accepts_text(&self) -> bool {
453 self.inner().is_some_and(|i| i.accepts_text())
454 }
455
456 fn captures_key(&self, event: &KeyEvent) -> bool {
459 self.inner().is_some_and(|i| i.captures_key(event))
460 }
461
462 fn mnemonic_text(&self) -> Option<&str> {
465 self.inner().and_then(|i| i.mnemonic_text())
466 }
467
468 fn mnemonic_focuses_child(&self) -> bool {
470 self.inner().is_some_and(|i| i.mnemonic_focuses_child())
471 }
472
473 fn text_input(&mut self, ctx: &mut EventCtx<'_>, text: &str) {
475 if let Some(inner) = self.inner_mut() {
476 inner.text_input(ctx, text);
477 }
478 }
479
480 fn focus_enter(&mut self, ctx: &mut EventCtx<'_>) {
481 if let Some(inner) = self.inner_mut() {
482 inner.focus_enter(ctx);
483 }
484 }
485
486 fn focus_exit(&mut self, ctx: &mut EventCtx<'_>) {
487 if let Some(inner) = self.inner_mut() {
488 inner.focus_exit(ctx);
489 }
490 }
491
492 fn property_changed(&mut self, ctx: &mut EventCtx<'_>, name: &str) {
496 if let Some(inner) = self.inner_mut() {
497 inner.property_changed(ctx, name);
498 }
499 }
500
501 fn checked_state(&self) -> Option<bool> {
504 self.inner().and_then(|i| i.checked_state())
505 }
506
507 fn change_args(&self, name: &str, value: &PropValue) -> Option<EventArgs> {
514 match self.inner() {
515 Some(inner) => inner.change_args(name, value),
516 None => Some(EventArgs::Value(value.clone())),
517 }
518 }
519
520 fn paint_only_property(&self, name: &str) -> bool {
525 self.inner().is_some_and(|inner| inner.paint_only_property(name))
526 }
527
528 fn timed(&self) -> Option<&dyn Timed> {
530 self.inner().and_then(|i| i.timed())
531 }
532
533 fn timed_mut(&mut self) -> Option<&mut dyn Timed> {
534 self.inner_mut().and_then(|i| i.timed_mut())
535 }
536
537 fn layout_hooks(&self) -> Option<&dyn LayoutHooks> {
540 self.inner().and_then(|i| i.layout_hooks())
541 }
542
543 fn child_pointer_mut(&mut self) -> Option<&mut dyn ChildPointer> {
546 self.inner_mut().and_then(|i| i.child_pointer_mut())
547 }
548
549 fn popup(&self) -> Option<&dyn Popup> {
552 self.inner().and_then(|i| i.popup())
553 }
554
555 fn popup_mut(&mut self) -> Option<&mut dyn Popup> {
556 self.inner_mut().and_then(|i| i.popup_mut())
557 }
558
559 fn accessible_items(&self) -> Option<&dyn AccessibleItems> {
562 self.inner().and_then(|i| i.accessible_items())
563 }
564
565 fn accessible_items_mut(&mut self) -> Option<&mut dyn AccessibleItems> {
566 self.inner_mut().and_then(|i| i.accessible_items_mut())
567 }
568
569 fn attach(&self) -> Option<(ComponentId, f32, f32)> {
573 self.inner().and_then(|i| i.attach())
574 }
575
576 fn event_info(&self, event: &str) -> Vec<(&'static str, String)> {
580 self.inner().map(|i| i.event_info(event)).unwrap_or_default()
581 }
582
583 fn message(&mut self, ctx: &mut EventCtx<'_>, message: &dyn Any) {
587 if let Some(inner) = self.inner_mut() {
588 inner.message(ctx, message);
589 }
590 }
591
592 fn methods(&self) -> &'static [MethodInfo] {
595 &[]
596 }
597
598 fn invoke(&mut self, ctx: &mut EventCtx<'_>, method: &str, args: &[PropValue]) -> std::result::Result<PropValue, String> {
602 let class = self.class_name();
603 match self.inner_mut() {
604 Some(inner) => inner.invoke(ctx, method, args),
605 None => Err(format!("{class} não tem o método '{method}'")),
606 }
607 }
608
609}
610
611pub trait AccessibleItems {
616 fn access_items(&self, _ui: &crate::Ui, _id: ComponentId) -> Vec<crate::automation::AccessItem> {
619 Vec::new()
620 }
621
622 fn access_action(&mut self, _ctx: &mut EventCtx<'_>, _index: usize, _action: crate::automation::ItemAction) -> bool {
625 false
626 }
627
628 fn access_table_size(&self, _ui: &crate::Ui) -> Option<(usize, usize)> {
632 None
633 }
634}
635
636pub trait Popup {
641 fn closes_on_outside_press(&self) -> bool {
648 false
649 }
650
651 fn dismissed(&mut self, _ctx: &mut EventCtx<'_>) -> bool {
657 false
658 }
659
660 fn dies_with(&self) -> Option<ComponentId> {
664 None
665 }
666}
667
668pub trait LayoutHooks {
672 fn arrange(&self, _area: RectF, _children: &[ArrangeItem]) -> Option<Vec<RectF>> {
677 None
678 }
679
680 fn baseline(&self, _ui: &crate::Ui, _id: ComponentId, _height: f32) -> Option<f32> {
684 None
685 }
686
687 fn dock_gap(&self) -> f32 {
690 0.0
691 }
692
693 fn auto_height(&self, _ui: &crate::Ui, _id: ComponentId, _width: f32) -> Option<f32> {
697 None
698 }
699
700 fn auto_width(&self, _ui: &crate::Ui, _id: ComponentId) -> Option<f32> {
704 None
705 }
706}
707
708pub trait Timed {
713 fn timer_interval(&self) -> Option<f64> {
716 None
717 }
718
719 fn timer_precision(&self) -> crate::TimerPrecision {
721 crate::TimerPrecision::default()
722 }
723
724 fn timer_background(&self) -> bool {
727 false
728 }
729
730 fn timer_late(&mut self, _late: f64) {}
732
733 fn frame(&mut self, _ctx: &mut EventCtx<'_>) -> bool {
737 false
738 }
739
740 fn timer(&mut self, ctx: &mut EventCtx<'_>) {
743 ctx.fire("on_timer", EventArgs::None);
744 }
745}
746
747pub trait ChildPointer {
758 fn child_pressed(&mut self, ctx: &mut EventCtx<'_>, child: ComponentId, event: &PointerEvent);
761 fn child_clicked(&mut self, ctx: &mut EventCtx<'_>, child: ComponentId);
763}
764
765pub trait DragDrop {
766 fn drag_item(&self, _ui: &crate::Ui) -> Option<(String, String)> {
771 None
772 }
773
774 fn drag_visual(&self, _ui: &crate::Ui, _source: ComponentId) -> Option<crate::DragVisual> {
777 None
778 }
779
780 fn drop_accepts(&self, _ui: &crate::Ui, _id: ComponentId, _data: &str) -> bool {
785 false
786 }
787
788 fn drop_hover(&mut self, _ctx: &mut EventCtx<'_>, _data: &str, _position: PointF) {}
791
792 fn drop_leave(&mut self, _ctx: &mut EventCtx<'_>) {}
794
795 fn drop_receive(&mut self, _ctx: &mut EventCtx<'_>, _data: &str, _position: PointF) {}
797
798 fn drag_ended(&mut self, _ctx: &mut EventCtx<'_>, _data: &str, _end: crate::DragEnd) {}
800}
801
802pub trait PlatformHooks {
806 fn taskbar(&self) -> Option<crate::taskbar::TaskbarSpec> {
808 None
809 }
810
811 fn tray(&self) -> Option<crate::tray::TraySpec> {
813 None
814 }
815
816 fn native_view(&self) -> Option<NativeView> {
820 None
821 }
822
823 fn take_native_commands(&self) -> Vec<NativeCommand> {
825 Vec::new()
826 }
827
828 fn connection(&self) -> Option<Connection> {
832 None
833 }
834
835 fn files_dropped(&mut self, _ctx: &mut EventCtx<'_>, _paths: &[String]) -> bool {
838 false
839 }
840
841 fn files_hovering(&mut self, _ctx: &mut EventCtx<'_>, _paths: Option<&[String]>) -> bool {
844 false
845 }
846}
847
848pub trait DesignHooks {
852 fn design_grip(&self, _local: PointF) -> Option<usize> {
855 None
856 }
857
858 fn design_drag(&mut self, _grip: usize, _delta: PointF, _begin: bool) -> Option<(Option<ComponentId>, &'static str, PropValue)> {
862 None
863 }
864}
865
866#[derive(Clone, Copy, Debug, PartialEq)]
868pub struct ArrangeItem {
869 pub id: ComponentId,
870 pub size: SizeF,
871 pub margins: Bounds,
873 pub span: u32,
875 pub row_span: u32,
877 pub cell: Option<(u32, u32)>,
879 pub grow: f32,
881 pub baseline: Option<f32>,
883 pub spacing: f32,
886}
887
888impl ArrangeItem {
889 pub fn of(id: ComponentId, cb: &ControlBase) -> Self {
891 ArrangeItem {
892 id,
893 size: SizeF::new(cb.width(), cb.height()),
894 margins: cb.margins(),
895 span: cb.column_span(),
896 row_span: cb.row_span(),
897 cell: cb.grid_cell(),
898 grow: cb.grow(),
899 baseline: None,
900 spacing: cb.spacing_scale(),
901 }
902 }
903}
904
905#[derive(Clone, Debug, PartialEq)]
907pub enum NativeView {
908 Web { url: String, html: String, generation: u64, navigation: Vec<String>, sandbox: String, background: Option<crate::Color>, data_dir: String, browser_args: String },
917}
918
919#[derive(Clone, Debug, PartialEq)]
923pub struct WebMessage {
924 pub text: String,
925 pub url: String,
926}
927
928pub fn navigation_allowed(allowed: &[String], url: &str) -> bool {
932 allowed.is_empty()
933 || url.starts_with("about:")
934 || url.starts_with("data:")
935 || allowed.iter().any(|a| {
936 let a = a.trim_end_matches('/');
937 url == a || url.starts_with(&format!("{a}/")) || url.starts_with(&format!("{a}?")) || (a.matches('/').count() <= 2 && url_origin(url) == url_origin(a))
938 })
939}
940
941pub fn url_origin(url: &str) -> String {
943 let Some((scheme, rest)) = url.split_once("://") else { return url.to_string() };
944 let host = rest.split(['/', '?', '#']).next().unwrap_or_default();
945 format!("{}://{}", scheme.to_ascii_lowercase(), host.to_ascii_lowercase())
946}
947
948#[derive(Clone, Copy, Debug, PartialEq)]
951pub struct MethodInfo {
952 pub name: &'static str,
953 pub args: &'static [PropKind],
954 pub returns: Option<PropKind>,
955 pub params: &'static [&'static str],
958 pub arg_types: &'static [&'static str],
961 pub returns_type: &'static str,
962}
963
964impl MethodInfo {
965 pub const fn new(name: &'static str, args: &'static [PropKind], returns: Option<PropKind>) -> Self {
966 Self { name, args, returns, params: &[], arg_types: &[], returns_type: "" }
967 }
968
969 pub const fn types(self, args: &'static [&'static str], returns: &'static str) -> Self {
971 Self { arg_types: args, returns_type: returns, ..self }
972 }
973
974 pub const fn params(self, names: &'static [&'static str]) -> Self {
977 Self { params: names, ..self }
978 }
979}
980
981#[derive(Clone, Debug, PartialEq)]
983pub enum NativeCommand {
984 Eval(String),
986 Back,
987 Forward,
988 Reload,
989}
990
991#[derive(Clone, Debug, PartialEq)]
993pub struct NativeViewSlot {
994 pub id: ComponentId,
995 pub rect: crate::RectF,
996 pub clip: Option<crate::RectF>,
999 pub visible: bool,
1000 pub view: NativeView,
1001 pub commands: Vec<NativeCommand>,
1002}
1003
1004pub fn prop_infos_of(component: &dyn Component) -> Vec<PropInfo> {
1010 let mut out: Vec<PropInfo> = Vec::new();
1011 let mut seen = std::collections::HashSet::new();
1014 let mut push = |info: &PropInfo| {
1015 if seen.insert(info.name) {
1016 out.push(*info);
1017 }
1018 };
1019 let mut layer = Some(component);
1020 while let Some(l) = layer {
1021 l.props().iter().for_each(&mut push);
1022 layer = l.inner();
1023 }
1024 if component.control().is_some() {
1025 ControlBase::PROPS.iter().for_each(&mut push);
1026 }
1027 out
1028}
1029
1030pub fn prop_info_of(component: &dyn Component, name: &str) -> Option<PropInfo> {
1033 let mut layer = Some(component);
1034 while let Some(l) = layer {
1035 if let Some(info) = l.props().iter().find(|p| p.name == name) {
1036 return Some(*info);
1037 }
1038 layer = l.inner();
1039 }
1040 if component.control().is_some() {
1041 return ControlBase::PROPS.iter().find(|p| p.name == name).copied();
1042 }
1043 None
1044}
1045
1046pub const VALUE_PROPERTIES: [&str; 19] = [
1051 "text", "checked", "value", "item_index", "selected", "date", "end_date", "time", "color", "files", "html", "index", "page", "hotkey",
1052 "angle", "pressed", "position", "low", "high",
1053];
1054
1055pub fn is_value_property(info: &PropInfo) -> bool {
1059 match info.name {
1060 "tab_index" | "expanded" => true,
1061 name => matches!(info.category, "Data" | "Runtime") && VALUE_PROPERTIES.contains(&name),
1062 }
1063}
1064
1065pub fn read_prop(component: &dyn Component, name: &str) -> Option<PropValue> {
1066 let mut layer = Some(component);
1067 while let Some(l) = layer {
1068 if let Some(v) = l.get_prop(name) {
1069 return Some(v);
1070 }
1071 layer = l.inner();
1072 }
1073 component.control().and_then(|cb| cb.get_prop(name))
1074}
1075
1076#[derive(Clone, Copy, Debug, PartialEq)]
1079pub(crate) struct AnchorRef {
1080 pub(crate) parent: SizeF,
1081 pub(crate) rect: RectF,
1082}
1083
1084#[derive(Clone, Debug)]
1089pub struct ControlBase {
1090 left: f32,
1092 top: f32,
1094 width: f32,
1096 height: f32,
1098 margins: Bounds,
1100 padding: Bounds,
1102 align: Align,
1104 anchors: Anchors,
1106 visible: bool,
1108 enabled: bool,
1110 hit_test: bool,
1112 clip_children: bool,
1114 inherit_state: bool,
1117 translatable: bool,
1121 captures_wheel: bool,
1124 captures_gesture: bool,
1127 can_focus: bool,
1129 draggable: bool,
1131 accepts_drops: bool,
1133 drag: Option<Box<DragDecl>>,
1136 tab_stop: bool,
1138 pan_on_touch: bool,
1140 hover_within: bool,
1143 pub(crate) popup_menu: Option<ComponentId>,
1145 cursor: CursorShape,
1147 opacity: f32,
1149 blend_mode: crate::BlendMode,
1152 rotation: f32,
1154 scale: f32,
1159 translate: PointF,
1161 cache_layer: bool,
1164 aspect_ratio: f32,
1166 max_width: f32,
1168 min_width: f32,
1170 min_height: f32,
1172 max_height: f32,
1174 self_align: SelfAlign,
1176 auto_size: bool,
1178 column_span: u32,
1180 grid_row: i16,
1183 grid_column: i16,
1185 row_span: u16,
1187 grow: f32,
1190 pub(crate) text_scale: f32,
1193 pub(crate) spacing_scale: f32,
1194 shadow: Option<crate::canvas::Shadow>,
1196 tag: i64,
1198 rare: Option<Box<RareTexts>>,
1201 style: String,
1203 theme: String,
1205 hint: String,
1207 state: ControlState,
1208 pub(crate) bounds: RectF,
1209 pub(crate) anchor_ref: Option<AnchorRef>,
1210 pub(crate) follow: Option<(ComponentId, Option<PointF>)>,
1213 pub(crate) design_hidden: bool,
1216 pub(crate) design_only: bool,
1218 pub(crate) keep_left_to_right: bool,
1221 pub(crate) colors: ColorOverride,
1223 pub(crate) font: FontOverride,
1225 scroll_offset: PointF,
1227 pub(crate) laid_out_scroll: PointF,
1230 pub(crate) safe_area: Bounds,
1232 pub(crate) content_size: SizeF,
1234}
1235
1236impl Default for ControlBase {
1237 fn default() -> Self {
1238 Self::new(100.0, 100.0)
1239 }
1240}
1241
1242impl ControlBase {
1243 pub const PROPS: &'static [PropInfo] = &[
1245 PropInfo::new("left", PropKind::Float, "Layout"),
1246 PropInfo::new("top", PropKind::Float, "Layout"),
1247 PropInfo::new("width", PropKind::Float, "Layout"),
1248 PropInfo::new("height", PropKind::Float, "Layout"),
1249 PropInfo::new("align", PropKind::Enum(<Align as crate::prop::PropEnum>::NAMES), "Layout").rust_type("Align"),
1250 PropInfo::new("anchors", PropKind::Set(&Anchors::NAMES), "Layout").rust_type("Anchors"),
1251 PropInfo::new("margins", PropKind::Bounds, "Layout"),
1252 PropInfo::new("padding", PropKind::Bounds, "Layout"),
1253 PropInfo::new("visible", PropKind::Bool, "Behavior"),
1254 PropInfo::new("enabled", PropKind::Bool, "Behavior"),
1255 PropInfo::new("hit_test", PropKind::Bool, "Behavior"),
1256 PropInfo::new("clip_children", PropKind::Bool, "Behavior"),
1257 PropInfo::new("inherit_state", PropKind::Bool, "Appearance"),
1258 PropInfo::new("translate", PropKind::Bool, "Behavior"),
1259 PropInfo::new("captures_wheel", PropKind::Bool, "Behavior"),
1260 PropInfo::new("captures_gesture", PropKind::Bool, "Behavior"),
1261 PropInfo::new("can_focus", PropKind::Bool, "Behavior"),
1262 PropInfo::new("draggable", PropKind::Bool, "Behavior"),
1263 PropInfo::new("accepts_drops", PropKind::Bool, "Behavior"),
1264 PropInfo::new("drag_data", PropKind::String, "Behavior"),
1265 PropInfo::new("drag_label", PropKind::String, "Behavior"),
1266 PropInfo::new("drag_image", PropKind::Component, "Behavior"),
1267 PropInfo::new("drop_types", PropKind::String, "Behavior"),
1268 PropInfo::new("tab_stop", PropKind::Bool, "Behavior"),
1269 PropInfo::new("cursor", PropKind::Enum(<CursorShape as crate::prop::PropEnum>::NAMES), "Behavior").rust_type("CursorShape"),
1270 PropInfo::new("opacity", PropKind::Float, "Appearance"),
1271 PropInfo::new("blend_mode", PropKind::Enum(<crate::BlendMode as crate::prop::PropEnum>::NAMES), "Appearance").rust_type("BlendMode"),
1272 PropInfo::new("cache_layer", PropKind::Bool, "Appearance"),
1273 PropInfo::new("rotation", PropKind::Angle, "Layout"),
1274 PropInfo::new("scale", PropKind::Float, "Layout"),
1275 PropInfo::new("translate_x", PropKind::Float, "Appearance"),
1276 PropInfo::new("translate_y", PropKind::Float, "Appearance"),
1277 PropInfo::new("aspect_ratio", PropKind::Float, "Layout"),
1278 PropInfo::new("max_width", PropKind::Float, "Layout"),
1279 PropInfo::new("min_width", PropKind::Float, "Layout"),
1280 PropInfo::new("min_height", PropKind::Float, "Layout"),
1281 PropInfo::new("max_height", PropKind::Float, "Layout"),
1282 PropInfo::new("self_align", PropKind::Enum(<SelfAlign as crate::prop::PropEnum>::NAMES), "Layout").rust_type("SelfAlign"),
1283 PropInfo::new("auto_size", PropKind::Bool, "Layout"),
1284 PropInfo::new("column_span", PropKind::Int, "Layout"),
1285 PropInfo::new("grid_row", PropKind::Int, "Layout"),
1286 PropInfo::new("grid_column", PropKind::Int, "Layout"),
1287 PropInfo::new("row_span", PropKind::Int, "Layout"),
1288 PropInfo::new("grow", PropKind::Float, "Layout"),
1289 PropInfo::new("shadow", PropKind::Shadow, "Appearance"),
1290 PropInfo::new("style", PropKind::StyleName, "Appearance"),
1291 PropInfo::new("theme", PropKind::ThemeName, "Appearance"),
1292 PropInfo::new("fill", PropKind::Color, "Appearance"),
1293 PropInfo::new("border_color", PropKind::Color, "Appearance"),
1294 PropInfo::new("text_color", PropKind::Color, "Appearance"),
1295 PropInfo::new("accent_color", PropKind::Color, "Appearance"),
1296 PropInfo::new("success_color", PropKind::Color, "Appearance"),
1297 PropInfo::new("warning_color", PropKind::Color, "Appearance"),
1298 PropInfo::new("danger_color", PropKind::Color, "Appearance"),
1299 PropInfo::new("font_family", PropKind::String, "Font"),
1300 PropInfo::new("font_size", PropKind::Float, "Font"),
1301 PropInfo::new("font_weight", PropKind::Enum(&FONT_WEIGHTS), "Font"),
1302 PropInfo::new("font_italic", PropKind::Bool, "Font"),
1303 PropInfo::new("font_underline", PropKind::Bool, "Font"),
1304 PropInfo::new("font_strikeout", PropKind::Bool, "Font"),
1305 PropInfo::new("hint", PropKind::String, "Behavior"),
1306 PropInfo::new("tag", PropKind::Int, "Misc"),
1307 PropInfo::new("tag_string", PropKind::String, "Misc"),
1308 PropInfo::new("accessible_name", PropKind::String, "Behavior"),
1309 PropInfo::new("popup_menu", PropKind::Component, "Behavior"),
1310 PropInfo::new("on_click", PropKind::Event, "Events").event_arg(crate::EventArg::None),
1311 PropInfo::new("on_dbl_click", PropKind::Event, "Events").event_arg(crate::EventArg::Pointer),
1312 PropInfo::new("on_long_press", PropKind::Event, "Events").event_arg(crate::EventArg::Pointer),
1313 PropInfo::new("on_pointer_down", PropKind::Event, "Events").event_arg(crate::EventArg::Pointer),
1314 PropInfo::new("on_pointer_up", PropKind::Event, "Events").event_arg(crate::EventArg::Pointer),
1315 PropInfo::new("on_pointer_move", PropKind::Event, "Events").event_arg(crate::EventArg::Pointer),
1316 PropInfo::new("on_pointer_enter", PropKind::Event, "Events").event_arg(crate::EventArg::None),
1317 PropInfo::new("on_pointer_leave", PropKind::Event, "Events").event_arg(crate::EventArg::None),
1318 PropInfo::new("on_wheel", PropKind::Event, "Events").event_arg(crate::EventArg::Wheel),
1319 PropInfo::new("on_gesture", PropKind::Event, "Events").event_arg(crate::EventArg::Gesture),
1320 PropInfo::new("on_swipe", PropKind::Event, "Events").event_arg(crate::EventArg::Swipe),
1321 PropInfo::new("on_key_down", PropKind::Event, "Events").event_arg(crate::EventArg::Key),
1324 PropInfo::new("on_key_press", PropKind::Event, "Events"),
1325 PropInfo::new("on_key_up", PropKind::Event, "Events").event_arg(crate::EventArg::Key),
1326 PropInfo::new("on_enter", PropKind::Event, "Events").event_arg(crate::EventArg::None),
1327 PropInfo::new("on_exit", PropKind::Event, "Events").event_arg(crate::EventArg::None),
1328 PropInfo::new("on_resize", PropKind::Event, "Events").event_arg(crate::EventArg::None),
1329 PropInfo::new("on_drag_start", PropKind::Event, "Events"),
1330 PropInfo::new("on_drag_over", PropKind::Event, "Events"),
1331 PropInfo::new("on_drag_move", PropKind::Event, "Events").event_arg(crate::EventArg::Pointer),
1332 PropInfo::new("on_drag_leave", PropKind::Event, "Events").event_arg(crate::EventArg::Value(PropKind::String)),
1333 PropInfo::new("on_drag_drop", PropKind::Event, "Events").event_arg(crate::EventArg::Value(PropKind::String)),
1334 PropInfo::new("on_drag_end", PropKind::Event, "Events").event_arg(crate::EventArg::Value(PropKind::Bool)),
1335 ];
1336
1337 pub fn new(width: f32, height: f32) -> Self {
1338 Self {
1339 left: 0.0,
1340 top: 0.0,
1341 width,
1342 height,
1343 margins: Bounds::ZERO,
1344 padding: Bounds::ZERO,
1345 align: Align::None,
1346 anchors: Anchors::default(),
1347 visible: true,
1348 enabled: true,
1349 hit_test: true,
1350 clip_children: false,
1351 inherit_state: false,
1352 translatable: true,
1353 captures_wheel: false,
1354 captures_gesture: false,
1355 can_focus: false,
1356 draggable: false,
1357 accepts_drops: false,
1358 drag: None,
1359 tab_stop: true,
1360 pan_on_touch: true,
1361 hover_within: false,
1362 popup_menu: None,
1363 cursor: CursorShape::Default,
1364 opacity: 1.0,
1365 blend_mode: crate::BlendMode::Normal,
1366 rotation: 0.0,
1367 scale: 1.0,
1368 translate: PointF::ZERO,
1369 cache_layer: false,
1370 aspect_ratio: 0.0,
1371 max_width: 0.0,
1372 min_width: 0.0,
1373 min_height: 0.0,
1374 max_height: 0.0,
1375 self_align: SelfAlign::Stretch,
1376 auto_size: false,
1377 column_span: 1,
1378 grid_row: -1,
1379 grid_column: -1,
1380 row_span: 1,
1381 grow: 0.0,
1382 text_scale: 1.0,
1383 spacing_scale: 1.0,
1384 shadow: None,
1385 tag: 0,
1386 rare: None,
1387 style: String::new(),
1388 theme: String::new(),
1389 hint: String::new(),
1390 state: ControlState::default(),
1391 bounds: RectF::new(0.0, 0.0, width, height),
1392 anchor_ref: None,
1393 follow: None,
1394 design_hidden: false,
1395 design_only: false,
1396 keep_left_to_right: false,
1397 colors: ColorOverride::default(),
1398 font: FontOverride::default(),
1399 scroll_offset: PointF::ZERO,
1400 laid_out_scroll: PointF::ZERO,
1401 content_size: SizeF::ZERO,
1402 safe_area: Bounds::default(),
1403 }
1404 }
1405
1406 pub fn left(&self) -> f32 {
1409 self.left
1410 }
1411
1412 pub fn top(&self) -> f32 {
1413 self.top
1414 }
1415
1416 pub fn width(&self) -> f32 {
1417 self.width
1418 }
1419
1420 pub fn height(&self) -> f32 {
1421 self.height
1422 }
1423
1424 pub fn position(&self) -> PointF {
1425 PointF::new(self.left, self.top)
1426 }
1427
1428 pub fn size(&self) -> SizeF {
1429 SizeF::new(self.width, self.height)
1430 }
1431
1432 pub fn margins(&self) -> Bounds {
1435 if self.spacing_scale == 1.0 { self.margins } else { self.margins.scaled(self.spacing_scale) }
1436 }
1437
1438 pub fn padding(&self) -> Bounds {
1440 if self.spacing_scale == 1.0 { self.padding } else { self.padding.scaled(self.spacing_scale) }
1441 }
1442
1443 pub fn align(&self) -> Align {
1444 self.align
1445 }
1446
1447 pub fn anchors(&self) -> Anchors {
1448 self.anchors
1449 }
1450
1451 pub fn visible(&self) -> bool {
1452 self.visible
1453 }
1454
1455 pub fn design_only(&self) -> bool {
1457 self.design_only
1458 }
1459
1460 pub fn colors(&self) -> ColorOverride {
1462 self.colors
1463 }
1464
1465 pub fn set_colors(&mut self, colors: ColorOverride) -> &mut Self {
1466 self.colors = colors;
1467 self
1468 }
1469
1470 pub fn set_design_only(&mut self, on: bool) -> &mut Self {
1471 self.design_only = on;
1472 self
1473 }
1474
1475 pub fn keep_left_to_right(&self) -> bool {
1477 self.keep_left_to_right
1478 }
1479
1480 pub fn set_keep_left_to_right(&mut self, on: bool) -> &mut Self {
1481 self.keep_left_to_right = on;
1482 self
1483 }
1484
1485 pub fn enabled(&self) -> bool {
1486 self.enabled
1487 }
1488
1489 pub fn hit_test(&self) -> bool {
1490 self.hit_test
1491 }
1492
1493 pub fn translatable(&self) -> bool {
1494 self.translatable
1495 }
1496
1497 pub fn set_translatable(&mut self, v: bool) -> &mut Self {
1498 self.translatable = v;
1499 self
1500 }
1501
1502 pub fn inherit_state(&self) -> bool {
1503 self.inherit_state
1504 }
1505
1506 pub fn set_inherit_state(&mut self, v: bool) -> &mut Self {
1507 self.inherit_state = v;
1508 self
1509 }
1510
1511 pub fn clip_children(&self) -> bool {
1512 self.clip_children
1513 }
1514
1515 pub fn captures_wheel(&self) -> bool {
1516 self.captures_wheel
1517 }
1518
1519 pub fn captures_gesture(&self) -> bool {
1520 self.captures_gesture
1521 }
1522
1523 pub fn draggable(&self) -> bool {
1528 self.draggable
1529 }
1530
1531 pub fn set_draggable(&mut self, v: bool) -> &mut Self {
1532 self.draggable = v;
1533 self
1534 }
1535
1536 pub fn accepts_drops(&self) -> bool {
1539 self.accepts_drops
1540 }
1541
1542 pub fn set_accepts_drops(&mut self, v: bool) -> &mut Self {
1543 self.accepts_drops = v;
1544 self
1545 }
1546
1547 pub fn drag_data(&self) -> &str {
1549 self.drag.as_ref().map_or("", |d| d.data.as_str())
1550 }
1551
1552 pub fn drag_label(&self) -> &str {
1553 self.drag.as_ref().map_or("", |d| d.label.as_str())
1554 }
1555
1556 pub fn drag_image(&self) -> Option<ComponentId> {
1558 self.drag.as_ref().and_then(|d| d.image)
1559 }
1560
1561 pub(crate) fn forget_drag_image(&mut self, doomed: &[ComponentId]) {
1563 if let Some(d) = self.drag.as_mut().filter(|d| d.image.is_some_and(|i| doomed.contains(&i))) {
1564 d.image = None;
1565 }
1566 }
1567
1568 pub fn drop_types(&self) -> &str {
1570 self.drag.as_ref().map_or("", |d| d.drop_types.as_str())
1571 }
1572
1573 fn drag_decl(&mut self) -> &mut DragDecl {
1574 self.drag.get_or_insert_with(Default::default)
1575 }
1576
1577 pub fn can_focus(&self) -> bool {
1578 self.can_focus
1579 }
1580
1581 pub fn tab_stop(&self) -> bool {
1583 self.tab_stop
1584 }
1585
1586 pub fn popup_menu(&self) -> Option<ComponentId> {
1588 self.popup_menu
1589 }
1590
1591 pub fn set_popup_menu(&mut self, menu: Option<ComponentId>) -> &mut Self {
1592 self.popup_menu = menu;
1593 self
1594 }
1595
1596 pub fn pan_on_touch(&self) -> bool {
1598 self.pan_on_touch
1599 }
1600
1601 pub fn hover_within(&self) -> bool {
1603 self.hover_within
1604 }
1605
1606 pub fn set_hover_within(&mut self, v: bool) -> &mut Self {
1610 self.hover_within = v;
1611 self
1612 }
1613
1614 pub fn cursor(&self) -> CursorShape {
1616 self.cursor
1617 }
1618
1619 pub fn opacity(&self) -> f32 {
1620 self.opacity
1621 }
1622
1623 pub fn blend_mode(&self) -> crate::BlendMode {
1625 self.blend_mode
1626 }
1627
1628 pub fn set_blend_mode(&mut self, mode: crate::BlendMode) -> &mut Self {
1629 self.blend_mode = mode;
1630 self
1631 }
1632
1633 pub fn cache_layer(&self) -> bool {
1635 self.cache_layer
1636 }
1637
1638 pub fn set_cache_layer(&mut self, on: bool) -> &mut Self {
1639 self.cache_layer = on;
1640 self
1641 }
1642
1643 pub fn rotation(&self) -> f32 {
1646 self.rotation
1647 }
1648
1649 pub fn scale(&self) -> f32 {
1651 self.scale
1652 }
1653
1654 pub fn inner_size(&self) -> SizeF {
1657 let s = self.scale;
1658 if s == 1.0 { self.bounds.size() } else { SizeF::new(self.bounds.width / s, self.bounds.height / s) }
1659 }
1660
1661 pub fn shadow(&self) -> Option<crate::canvas::Shadow> {
1662 self.shadow
1663 }
1664
1665 pub fn aspect_ratio(&self) -> f32 {
1669 self.aspect_ratio
1670 }
1671
1672 pub fn set_aspect_ratio(&mut self, ratio: f32) -> &mut Self {
1673 self.aspect_ratio = if ratio.is_finite() { ratio.max(0.0) } else { 0.0 };
1674 self
1675 }
1676
1677 pub fn max_width(&self) -> f32 {
1681 self.max_width
1682 }
1683
1684 pub fn set_max_width(&mut self, width: f32) -> &mut Self {
1685 self.max_width = if width.is_finite() { width.max(0.0) } else { 0.0 };
1686 self
1687 }
1688
1689 pub fn min_width(&self) -> f32 {
1694 self.min_width
1695 }
1696
1697 pub fn set_min_width(&mut self, width: f32) -> &mut Self {
1698 self.min_width = if width.is_finite() { width.max(0.0) } else { 0.0 };
1699 self
1700 }
1701
1702 pub fn min_height(&self) -> f32 {
1704 self.min_height
1705 }
1706
1707 pub fn set_min_height(&mut self, height: f32) -> &mut Self {
1708 self.min_height = if height.is_finite() { height.max(0.0) } else { 0.0 };
1709 self
1710 }
1711
1712 pub fn max_height(&self) -> f32 {
1714 self.max_height
1715 }
1716
1717 pub fn set_max_height(&mut self, height: f32) -> &mut Self {
1718 self.max_height = if height.is_finite() { height.max(0.0) } else { 0.0 };
1719 self
1720 }
1721
1722 pub fn clamp_width(&self, available: f32) -> f32 {
1725 let w = if self.max_width > 0.0 { available.min(self.max_width) } else { available };
1726 w.max(self.min_width)
1727 }
1728
1729 pub fn clamp_height(&self, height: f32) -> f32 {
1731 let h = if self.max_height > 0.0 { height.min(self.max_height) } else { height };
1732 h.max(self.min_height)
1733 }
1734
1735 pub fn self_align(&self) -> SelfAlign {
1738 self.self_align
1739 }
1740
1741 pub fn set_self_align(&mut self, align: SelfAlign) -> &mut Self {
1742 self.self_align = align;
1743 self
1744 }
1745
1746 pub fn band_width(&self, available: f32) -> f32 {
1750 match self.self_align {
1751 SelfAlign::Stretch => self.clamp_width(available),
1752 _ if self.max_width > 0.0 => self.clamp_width(available),
1753 _ => self.clamp_width(self.width),
1754 }
1755 }
1756
1757 pub fn band_height(&self, available: f32) -> f32 {
1760 match self.self_align {
1761 SelfAlign::Stretch => self.clamp_height(available),
1762 _ if self.max_height > 0.0 => self.clamp_height(available),
1763 _ => self.clamp_height(self.height),
1764 }
1765 }
1766
1767 pub fn band_offset(&self, available: f32, size: f32) -> f32 {
1770 let spare = (available - size).max(0.0);
1771 match self.self_align {
1772 SelfAlign::Start => 0.0,
1773 SelfAlign::End => spare,
1774 SelfAlign::Stretch | SelfAlign::Center => spare / 2.0,
1775 }
1776 }
1777
1778 pub fn auto_size(&self) -> bool {
1783 self.auto_size
1784 }
1785
1786 pub fn set_auto_size(&mut self, on: bool) -> &mut Self {
1787 self.auto_size = on;
1788 self
1789 }
1790
1791 pub fn column_span(&self) -> u32 {
1794 self.column_span.max(1)
1795 }
1796
1797 pub fn grid_cell(&self) -> Option<(u32, u32)> {
1799 (self.grid_row >= 0 && self.grid_column >= 0).then(|| (self.grid_row as u32, self.grid_column as u32))
1800 }
1801
1802 pub fn set_grid_cell(&mut self, cell: Option<(u32, u32)>) -> &mut Self {
1803 let (r, c) = cell.map_or((-1, -1), |(r, c)| (r.min(i16::MAX as u32) as i16, c.min(i16::MAX as u32) as i16));
1804 self.grid_row = r;
1805 self.grid_column = c;
1806 self
1807 }
1808
1809 pub fn row_span(&self) -> u32 {
1811 u32::from(self.row_span.max(1))
1812 }
1813
1814 pub fn set_row_span(&mut self, span: u32) -> &mut Self {
1815 self.row_span = span.clamp(1, 64) as u16;
1816 self
1817 }
1818
1819 pub fn grow(&self) -> f32 {
1820 self.grow
1821 }
1822
1823 pub fn set_grow(&mut self, grow: f32) -> &mut Self {
1824 self.grow = grow.max(0.0);
1825 self
1826 }
1827
1828 pub fn set_column_span(&mut self, span: u32) -> &mut Self {
1829 self.column_span = span.max(1);
1830 self
1831 }
1832
1833 pub fn text_scale(&self) -> f32 {
1835 self.text_scale
1836 }
1837
1838 pub fn spacing_scale(&self) -> f32 {
1840 self.spacing_scale
1841 }
1842
1843 pub fn tag(&self) -> i64 {
1844 self.tag
1845 }
1846
1847 pub fn accessible_name(&self) -> &str {
1850 self.rare.as_ref().map_or("", |r| &r.accessible_name)
1851 }
1852
1853 pub fn set_accessible_name(&mut self, v: &str) -> &mut Self {
1854 self.rare_mut(|r| r.accessible_name = v.into());
1855 self
1856 }
1857
1858 fn rare_mut(&mut self, change: impl FnOnce(&mut RareTexts)) {
1859 let rare = self.rare.get_or_insert_with(Default::default);
1860 change(rare);
1861 if rare.tag_string.is_empty() && rare.accessible_name.is_empty() {
1862 self.rare = None;
1863 }
1864 }
1865
1866 pub fn tag_string(&self) -> &str {
1867 self.rare.as_ref().map_or("", |r| &r.tag_string)
1868 }
1869
1870 pub fn style(&self) -> &str {
1872 &self.style
1873 }
1874
1875 pub fn theme_name(&self) -> &str {
1877 &self.theme
1878 }
1879
1880 pub fn set_theme_name(&mut self, v: impl Into<String>) -> &mut Self {
1881 self.theme = v.into();
1882 self
1883 }
1884
1885 pub fn hint(&self) -> &str {
1887 &self.hint
1888 }
1889
1890 pub fn set_hint(&mut self, v: impl Into<String>) -> &mut Self {
1891 self.hint = v.into();
1892 self
1893 }
1894
1895 pub fn state(&self) -> ControlState {
1896 self.state
1897 }
1898
1899 pub fn bounds(&self) -> RectF {
1901 self.bounds
1902 }
1903
1904 pub fn scroll_offset(&self) -> PointF {
1906 self.scroll_offset
1907 }
1908
1909 pub fn laid_out_scroll(&self) -> PointF {
1912 self.laid_out_scroll
1913 }
1914
1915 pub fn set_scroll_offset(&mut self, offset: PointF) -> &mut Self {
1918 self.scroll_offset = offset;
1919 self
1920 }
1921
1922 pub fn content_size(&self) -> SizeF {
1925 self.content_size
1926 }
1927
1928 pub fn set_left(&mut self, v: f32) -> &mut Self {
1935 if self.left != v {
1936 self.left = v;
1937 self.anchor_ref = None;
1938 }
1939 self
1940 }
1941
1942 pub fn set_top(&mut self, v: f32) -> &mut Self {
1943 if self.top != v {
1944 self.top = v;
1945 self.anchor_ref = None;
1946 }
1947 self
1948 }
1949
1950 pub fn set_position(&mut self, left: f32, top: f32) -> &mut Self {
1951 self.set_left(left).set_top(top)
1952 }
1953
1954 pub fn set_width(&mut self, v: f32) -> &mut Self {
1955 if self.width != v.max(0.0) {
1956 self.width = v.max(0.0);
1957 self.anchor_ref = None;
1958 }
1959 self
1960 }
1961
1962 pub fn set_height(&mut self, v: f32) -> &mut Self {
1963 if self.height != v.max(0.0) {
1964 self.height = v.max(0.0);
1965 self.anchor_ref = None;
1966 }
1967 self
1968 }
1969
1970 pub(crate) fn set_measured_width(&mut self, v: f32) {
1972 self.width = v.max(0.0);
1973 if let Some(r) = self.anchor_ref.as_mut() {
1974 r.rect.width = self.width;
1975 }
1976 }
1977
1978 pub(crate) fn set_measured_height(&mut self, v: f32) {
1981 self.height = v.max(0.0);
1982 if let Some(r) = self.anchor_ref.as_mut() {
1983 r.rect.height = self.height;
1984 }
1985 }
1986
1987 pub fn set_size(&mut self, width: f32, height: f32) -> &mut Self {
1988 self.set_width(width).set_height(height)
1989 }
1990
1991 pub fn set_rect(&mut self, left: f32, top: f32, width: f32, height: f32) -> &mut Self {
1993 self.set_position(left, top).set_size(width, height)
1994 }
1995
1996 pub fn set_margins(&mut self, v: impl Into<Bounds>) -> &mut Self {
1997 self.margins = v.into();
1998 self
1999 }
2000
2001 pub fn set_padding(&mut self, v: impl Into<Bounds>) -> &mut Self {
2002 self.padding = v.into();
2003 self
2004 }
2005
2006 pub fn set_align(&mut self, v: Align) -> &mut Self {
2007 self.align = v;
2008 self.anchor_ref = None;
2009 self
2010 }
2011
2012 pub fn set_anchors(&mut self, v: Anchors) -> &mut Self {
2013 self.anchors = v;
2014 self.anchor_ref = None;
2015 self
2016 }
2017
2018 pub fn set_visible(&mut self, v: bool) -> &mut Self {
2019 self.visible = v;
2020 self
2021 }
2022
2023 pub fn set_enabled(&mut self, v: bool) -> &mut Self {
2024 self.enabled = v;
2025 self
2026 }
2027
2028 pub fn set_hit_test(&mut self, v: bool) -> &mut Self {
2029 self.hit_test = v;
2030 self
2031 }
2032
2033 pub fn set_clip_children(&mut self, v: bool) -> &mut Self {
2034 self.clip_children = v;
2035 self
2036 }
2037
2038 pub fn set_captures_wheel(&mut self, v: bool) -> &mut Self {
2039 self.captures_wheel = v;
2040 self
2041 }
2042
2043 pub fn set_captures_gesture(&mut self, v: bool) -> &mut Self {
2044 self.captures_gesture = v;
2045 self
2046 }
2047
2048 pub fn set_can_focus(&mut self, v: bool) -> &mut Self {
2049 self.can_focus = v;
2050 self
2051 }
2052
2053 pub fn set_pan_on_touch(&mut self, v: bool) -> &mut Self {
2057 self.pan_on_touch = v;
2058 self
2059 }
2060
2061 pub fn set_tab_stop(&mut self, v: bool) -> &mut Self {
2062 self.tab_stop = v;
2063 self
2064 }
2065
2066 pub fn set_cursor(&mut self, v: CursorShape) -> &mut Self {
2067 self.cursor = v;
2068 self
2069 }
2070
2071 pub fn set_opacity(&mut self, v: f32) -> &mut Self {
2072 self.opacity = v.clamp(0.0, 1.0);
2073 self
2074 }
2075
2076 pub fn translate(&self) -> PointF {
2078 self.translate
2079 }
2080
2081 pub fn set_translate(&mut self, offset: PointF) -> &mut Self {
2082 self.translate = if offset.x.is_finite() && offset.y.is_finite() { offset } else { PointF::ZERO };
2083 self
2084 }
2085
2086 pub fn set_scale(&mut self, scale: f32) -> &mut Self {
2088 self.scale = if scale.is_finite() && scale > 0.0 { scale.clamp(0.05, 20.0) } else { 1.0 };
2089 self
2090 }
2091
2092 pub fn set_rotation(&mut self, degrees: f32) -> &mut Self {
2093 self.rotation = if degrees.is_finite() { degrees % 360.0 } else { 0.0 };
2094 self
2095 }
2096
2097 pub fn set_shadow(&mut self, shadow: Option<crate::canvas::Shadow>) -> &mut Self {
2098 self.shadow = shadow;
2099 self
2100 }
2101
2102 pub fn set_tag(&mut self, v: i64) -> &mut Self {
2103 self.tag = v;
2104 self
2105 }
2106
2107 pub fn set_tag_string(&mut self, v: &str) -> &mut Self {
2108 self.rare_mut(|r| r.tag_string = v.into());
2109 self
2110 }
2111
2112 pub fn set_style(&mut self, v: impl Into<String>) -> &mut Self {
2113 self.style = v.into();
2114 self
2115 }
2116
2117 pub fn state_mut(&mut self) -> &mut ControlState {
2120 &mut self.state
2121 }
2122
2123 pub fn get_prop(&self, name: &str) -> Option<PropValue> {
2126 Some(match name {
2127 "left" => self.left.into(),
2128 "top" => self.top.into(),
2129 "width" => self.width.into(),
2130 "height" => self.height.into(),
2131 "align" => self.align.into(),
2132 "anchors" => self.anchors.into(),
2133 "margins" => self.margins.into(),
2134 "padding" => self.padding.into(),
2135 "visible" => self.visible.into(),
2136 "enabled" => self.enabled.into(),
2137 "hit_test" => self.hit_test.into(),
2138 "clip_children" => self.clip_children.into(),
2139 "inherit_state" => self.inherit_state.into(),
2140 "translate" => self.translatable.into(),
2141 "captures_wheel" => self.captures_wheel.into(),
2142 "captures_gesture" => self.captures_gesture.into(),
2143 "can_focus" => self.can_focus.into(),
2144 "draggable" => self.draggable.into(),
2145 "accepts_drops" => self.accepts_drops.into(),
2146 "drag_data" => self.drag_data().into(),
2147 "drag_label" => self.drag_label().into(),
2148 "drag_image" => PropValue::Component(self.drag_image()),
2149 "drop_types" => self.drop_types().into(),
2150 "tab_stop" => self.tab_stop.into(),
2151 "cursor" => PropValue::enum_value(self.cursor),
2152 "opacity" => self.opacity.into(),
2153 "blend_mode" => PropValue::enum_value(self.blend_mode),
2154 "cache_layer" => self.cache_layer.into(),
2155 "rotation" => self.rotation.into(),
2156 "scale" => self.scale.into(),
2157 "translate_x" => self.translate.x.into(),
2158 "translate_y" => self.translate.y.into(),
2159 "aspect_ratio" => self.aspect_ratio.into(),
2160 "max_width" => self.max_width.into(),
2161 "min_width" => self.min_width.into(),
2162 "min_height" => self.min_height.into(),
2163 "max_height" => self.max_height.into(),
2164 "self_align" => PropValue::enum_value(self.self_align),
2165 "auto_size" => self.auto_size.into(),
2166 "column_span" => (self.column_span() as i64).into(),
2167 "grid_row" => i64::from(self.grid_row).into(),
2168 "grid_column" => i64::from(self.grid_column).into(),
2169 "row_span" => (self.row_span() as i64).into(),
2170 "grow" => f64::from(self.grow).into(),
2171 "shadow" => crate::prop::PropType::to_value(&self.shadow),
2172 "style" => self.style.clone().into(),
2173 "fill" => crate::prop::PropType::to_value(&self.colors.fill),
2174 "border_color" => crate::prop::PropType::to_value(&self.colors.border),
2175 "text_color" => crate::prop::PropType::to_value(&self.colors.text),
2176 "accent_color" => crate::prop::PropType::to_value(&self.colors.accent),
2177 "success_color" => crate::prop::PropType::to_value(&self.colors.success),
2178 "warning_color" => crate::prop::PropType::to_value(&self.colors.warning),
2179 "danger_color" => crate::prop::PropType::to_value(&self.colors.danger),
2180 "font_family" => self.font.family.clone().into(),
2181 "font_size" => crate::prop::PropType::to_value(&self.font.size),
2182 "font_weight" => PropValue::Enum(FONT_WEIGHTS[self.font.weight.map_or(0, |w| w as usize + 1)].into()),
2183 "font_italic" => self.font.italic.into(),
2184 "font_underline" => self.font.underline.into(),
2185 "font_strikeout" => self.font.strikeout.into(),
2186 "theme" => self.theme.clone().into(),
2187 "hint" => self.hint.clone().into(),
2188 "tag" => self.tag.into(),
2189 "tag_string" => self.tag_string().to_string().into(),
2190 "accessible_name" => self.accessible_name().to_string().into(),
2191 "popup_menu" => PropValue::Component(self.popup_menu),
2192 _ => return None,
2193 })
2194 }
2195
2196 pub fn set_prop(&mut self, name: &str, value: PropValue) -> Result<()> {
2197 match name {
2198 "left" => self.set_left(value.to_f32()?),
2199 "top" => self.set_top(value.to_f32()?),
2200 "width" => self.set_width(value.to_f32()?),
2201 "height" => self.set_height(value.to_f32()?),
2202 "align" => self.set_align(value.to_enum()?),
2203 "anchors" => self.set_anchors(value.to_anchors()?),
2204 "margins" => self.set_margins(value.to_bounds()?),
2205 "padding" => self.set_padding(value.to_bounds()?),
2206 "visible" => self.set_visible(value.to_bool()?),
2207 "enabled" => self.set_enabled(value.to_bool()?),
2208 "hit_test" => self.set_hit_test(value.to_bool()?),
2209 "clip_children" => self.set_clip_children(value.to_bool()?),
2210 "inherit_state" => self.set_inherit_state(value.to_bool()?),
2211 "translate" => self.set_translatable(value.to_bool()?),
2212 "captures_wheel" => self.set_captures_wheel(value.to_bool()?),
2213 "captures_gesture" => self.set_captures_gesture(value.to_bool()?),
2214 "can_focus" => self.set_can_focus(value.to_bool()?),
2215 "draggable" => self.set_draggable(value.to_bool()?),
2216 "accepts_drops" => self.set_accepts_drops(value.to_bool()?),
2217 "drag_data" => {
2218 self.drag_decl().data = value.to_str()?.to_string();
2219 self
2220 }
2221 "drag_label" => {
2222 self.drag_decl().label = value.to_str()?.to_string();
2223 self
2224 }
2225 "drag_image" => {
2226 self.drag_decl().image = value.to_component()?;
2227 self
2228 }
2229 "drop_types" => {
2230 self.drag_decl().drop_types = value.to_str()?.to_string();
2231 self
2232 }
2233 "tab_stop" => self.set_tab_stop(value.to_bool()?),
2234 "cursor" => self.set_cursor(value.to_enum()?),
2235 "opacity" => self.set_opacity(value.to_f32()?),
2236 "blend_mode" => self.set_blend_mode(value.to_enum()?),
2237 "cache_layer" => self.set_cache_layer(value.to_bool()?),
2238 "rotation" => self.set_rotation(value.to_f32()?),
2239 "scale" => self.set_scale(value.to_f32()?),
2240 "translate_x" => self.set_translate(PointF::new(value.to_f32()?, self.translate.y)),
2241 "translate_y" => self.set_translate(PointF::new(self.translate.x, value.to_f32()?)),
2242 "aspect_ratio" => self.set_aspect_ratio(value.to_f32()?),
2243 "max_width" => self.set_max_width(value.to_f32()?),
2244 "min_width" => self.set_min_width(value.to_f32()?),
2245 "min_height" => self.set_min_height(value.to_f32()?),
2246 "max_height" => self.set_max_height(value.to_f32()?),
2247 "self_align" => self.set_self_align(value.to_enum()?),
2248 "auto_size" => self.set_auto_size(value.to_bool()?),
2249 "column_span" => self.set_column_span(value.to_f64()?.clamp(1.0, 64.0) as u32),
2250 "grid_row" => {
2251 self.grid_row = value.to_f64()?.clamp(-1.0, 4096.0) as i16;
2252 self
2253 }
2254 "grid_column" => {
2255 self.grid_column = value.to_f64()?.clamp(-1.0, 4096.0) as i16;
2256 self
2257 }
2258 "row_span" => self.set_row_span(value.to_f64()?.clamp(1.0, 64.0) as u32),
2259 "grow" => self.set_grow(value.to_f32()?),
2260 "shadow" => self.set_shadow(crate::prop::PropType::from_value(value)?),
2261 "style" => self.set_style(value.to_str()?),
2262 "fill" => {
2263 self.colors.fill = crate::prop::PropType::from_value(value)?;
2264 self
2265 }
2266 "border_color" => {
2267 self.colors.border = crate::prop::PropType::from_value(value)?;
2268 self
2269 }
2270 "text_color" => {
2271 self.colors.text = crate::prop::PropType::from_value(value)?;
2272 self
2273 }
2274 "accent_color" => {
2275 self.colors.accent = crate::prop::PropType::from_value(value)?;
2276 self
2277 }
2278 "success_color" => {
2279 self.colors.success = crate::prop::PropType::from_value(value)?;
2280 self
2281 }
2282 "warning_color" => {
2283 self.colors.warning = crate::prop::PropType::from_value(value)?;
2284 self
2285 }
2286 "danger_color" => {
2287 self.colors.danger = crate::prop::PropType::from_value(value)?;
2288 self
2289 }
2290 "font_family" => {
2291 self.font.family = value.to_str()?.to_string();
2292 self
2293 }
2294 "font_size" => {
2295 self.font.size = crate::prop::PropType::from_value(value)?;
2296 self
2297 }
2298 "font_weight" => {
2299 self.font.weight = font_weight_named(value.to_str()?)?;
2300 self
2301 }
2302 "font_italic" => {
2303 self.font.italic = value.to_bool()?;
2304 self
2305 }
2306 "font_underline" => {
2307 self.font.underline = value.to_bool()?;
2308 self
2309 }
2310 "font_strikeout" => {
2311 self.font.strikeout = value.to_bool()?;
2312 self
2313 }
2314 "theme" => self.set_theme_name(value.to_str()?),
2315 "hint" => self.set_hint(value.to_str()?),
2316 "tag" => self.set_tag(value.to_i64()?),
2317 "tag_string" => self.set_tag_string(value.to_str()?),
2318 "accessible_name" => self.set_accessible_name(value.to_str()?),
2319 "popup_menu" => {
2320 self.popup_menu = value.to_component()?;
2321 self
2322 }
2323 _ => return Err(Error::UnknownProperty(name.to_string())),
2324 };
2325 Ok(())
2326 }
2327}
2328
2329pub const FONT_WEIGHTS: [&str; 8] = ["default", "thin", "light", "normal", "medium", "semibold", "bold", "black"];
2331
2332fn font_weight_named(name: &str) -> Result<Option<crate::canvas::FontWeight>> {
2333 use crate::canvas::FontWeight::*;
2334 let all = [Thin, Light, Normal, Medium, SemiBold, Bold, Black];
2335 match FONT_WEIGHTS.iter().position(|n| n.eq_ignore_ascii_case(name)) {
2336 Some(0) => Ok(None),
2337 Some(i) => Ok(Some(all[i - 1])),
2338 None => Err(Error::invalid(format!("valor '{name}' inválido; use um de: {}", FONT_WEIGHTS.join(", ")))),
2339 }
2340}
2341
2342#[derive(Clone, Debug, Default, PartialEq)]
2346pub struct FontOverride {
2347 pub family: String,
2349 pub size: Option<f32>,
2351 pub weight: Option<crate::canvas::FontWeight>,
2353 pub italic: bool,
2355 pub underline: bool,
2357 pub strikeout: bool,
2359}
2360
2361impl FontOverride {
2362 pub fn is_empty(&self) -> bool {
2363 *self == Self::default()
2364 }
2365
2366 pub fn over(&self, parent: &FontOverride) -> FontOverride {
2368 FontOverride {
2369 family: if self.family.is_empty() { parent.family.clone() } else { self.family.clone() },
2370 size: self.size.or(parent.size),
2371 weight: self.weight.or(parent.weight),
2372 italic: self.italic || parent.italic,
2373 underline: self.underline || parent.underline,
2374 strikeout: self.strikeout || parent.strikeout,
2375 }
2376 }
2377
2378 pub fn apply(&self, font: &mut crate::canvas::FontSpec) {
2380 if !self.family.is_empty() {
2381 font.family = self.family.clone();
2382 }
2383 if let Some(size) = self.size.filter(|s| *s > 0.0) {
2384 font.size = size;
2385 }
2386 if let Some(weight) = self.weight {
2387 font.weight = weight;
2388 }
2389 font.italic |= self.italic;
2390 font.underline |= self.underline;
2391 font.strikeout |= self.strikeout;
2392 }
2393}
2394
2395impl ControlBase {
2396 pub fn font(&self) -> &FontOverride {
2398 &self.font
2399 }
2400
2401 pub fn set_font(&mut self, font: FontOverride) -> &mut Self {
2402 self.font = font;
2403 self
2404 }
2405}
2406
2407#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
2413pub struct ColorOverride {
2414 pub fill: Option<crate::Color>,
2416 pub border: Option<crate::Color>,
2418 pub text: Option<crate::Color>,
2420 pub accent: Option<crate::Color>,
2423 pub success: Option<crate::Color>,
2426 pub warning: Option<crate::Color>,
2428 pub danger: Option<crate::Color>,
2430}
2431
2432impl ColorOverride {
2433 pub fn is_empty(&self) -> bool {
2434 *self == Self::default()
2435 }
2436
2437 pub(crate) fn recolors_theme(&self) -> bool {
2439 !self.is_empty()
2440 }
2441
2442 pub(crate) fn apply_theme(&self, theme: &crate::Theme) -> crate::Theme {
2444 use crate::Color;
2445 let mut t = theme.clone();
2446 let mut set = |name: &str, c: Color| {
2447 t.colors.insert(name.to_string(), c);
2448 };
2449 if let Some(a) = self.accent {
2450 let dark = luminance(a) < 0.5;
2451 set("primary", a);
2452 set("primary_hover", a.lerp(if dark { Color::WHITE } else { Color::BLACK }, 0.12));
2453 set("primary_pressed", a.lerp(if dark { Color::BLACK } else { Color::BLACK }, 0.15));
2454 set("on_primary", if luminance(a) < 0.6 { Color::WHITE } else { Color::BLACK });
2455 set("focus_ring", a);
2456 set("selection", a.with_opacity(0.25));
2457 set("primary_soft", a.with_opacity(0.1));
2458 set("primary_container", a.lerp(Color::WHITE, 0.82));
2459 }
2460 if let Some(c) = self.fill {
2461 let toward = if luminance(c) < 0.5 { Color::WHITE } else { Color::BLACK };
2463 set("surface", c);
2464 set("background", c);
2465 set("surface_2", c.lerp(toward.with_opacity(c.a as f32 / 255.0), 0.06));
2466 }
2467 if let Some(c) = self.text {
2468 set("text", c);
2469 set("text_muted", c.with_opacity(0.65));
2470 for on in ["on_primary", "on_danger", "on_success", "on_primary_container"] {
2471 set(on, c);
2472 }
2473 }
2474 if let Some(c) = self.border {
2475 let lines = theme.colors.get("grid_line").copied().unwrap_or_else(|| theme.color("border"));
2480 set("grid_line", lines);
2481 set("border", c);
2482 set("track", c);
2483 }
2484 for (token, color) in [("success", self.success), ("warning", self.warning), ("danger", self.danger)] {
2485 if let Some(c) = color {
2486 set(token, c);
2487 set(&format!("{token}_soft"), c.with_opacity(0.1));
2488 set(&format!("{token}_hover"), c.lerp(Color::WHITE, 0.12));
2489 set(&format!("{token}_pressed"), c.lerp(Color::BLACK, 0.15));
2490 if token == "success" {
2491 set("meter_low", c);
2492 } else if token == "danger" {
2493 set("meter_high", c);
2494 } else {
2495 set("meter_mid", c);
2496 }
2497 }
2498 }
2499 t
2500 }
2501}
2502
2503pub(crate) fn luminance(c: crate::Color) -> f32 {
2505 (0.299 * c.r as f32 + 0.587 * c.g as f32 + 0.114 * c.b as f32) / 255.0
2506}
2507
2508#[derive(Clone, Copy, Debug, PartialEq)]
2510pub struct Connection {
2511 pub from: ComponentId,
2512 pub from_at: (f32, f32),
2514 pub to: ComponentId,
2515 pub to_at: (f32, f32),
2516}
2517
2518impl Connection {
2519 pub const STUB: f32 = 16.0;
2521
2522 fn normal(at: (f32, f32)) -> PointF {
2524 let (x, y) = at;
2525 let d = [(x, PointF::new(-1.0, 0.0)), (1.0 - x, PointF::new(1.0, 0.0)), (y, PointF::new(0.0, -1.0)), (1.0 - y, PointF::new(0.0, 1.0))];
2526 d.iter().min_by(|a, b| a.0.total_cmp(&b.0)).map_or(PointF::new(1.0, 0.0), |d| d.1)
2527 }
2528
2529 pub fn route(&self, from: RectF, to: RectF) -> Vec<PointF> {
2532 let p0 = PointF::new(from.x + from.width * self.from_at.0, from.y + from.height * self.from_at.1);
2533 let p1 = PointF::new(to.x + to.width * self.to_at.0, to.y + to.height * self.to_at.1);
2534 let (n0, n1) = (Self::normal(self.from_at), Self::normal(self.to_at));
2535 let s0 = PointF::new(p0.x + n0.x * Self::STUB, p0.y + n0.y * Self::STUB);
2536 let s1 = PointF::new(p1.x + n1.x * Self::STUB, p1.y + n1.y * Self::STUB);
2537 let mut points = vec![p0, s0];
2538 if n0.x != 0.0 {
2539 let mx = (s0.x + s1.x) / 2.0;
2541 points.push(PointF::new(mx, s0.y));
2542 points.push(PointF::new(mx, s1.y));
2543 } else {
2544 let my = (s0.y + s1.y) / 2.0;
2545 points.push(PointF::new(s0.x, my));
2546 points.push(PointF::new(s1.x, my));
2547 }
2548 points.push(s1);
2549 points.push(p1);
2550 points.dedup_by(|a, b| (a.x - b.x).abs() < 0.01 && (a.y - b.y).abs() < 0.01);
2551 points
2552 }
2553}
2554
2555#[derive(Clone, Debug, Default, PartialEq)]
2557pub struct DragDecl {
2558 pub data: String,
2561 pub label: String,
2563 pub drop_types: String,
2566 pub image: Option<ComponentId>,
2568}
2569
2570#[derive(Clone, Debug, Default)]
2572struct RareTexts {
2573 tag_string: Box<str>,
2575 accessible_name: Box<str>,
2578}