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
629pub trait Popup {
634 fn closes_on_outside_press(&self) -> bool {
641 false
642 }
643
644 fn dismissed(&mut self, _ctx: &mut EventCtx<'_>) -> bool {
650 false
651 }
652
653 fn dies_with(&self) -> Option<ComponentId> {
657 None
658 }
659}
660
661pub trait LayoutHooks {
665 fn arrange(&self, _area: RectF, _children: &[ArrangeItem]) -> Option<Vec<RectF>> {
670 None
671 }
672
673 fn baseline(&self, _ui: &crate::Ui, _id: ComponentId, _height: f32) -> Option<f32> {
677 None
678 }
679
680 fn dock_gap(&self) -> f32 {
683 0.0
684 }
685
686 fn auto_height(&self, _ui: &crate::Ui, _id: ComponentId, _width: f32) -> Option<f32> {
690 None
691 }
692
693 fn auto_width(&self, _ui: &crate::Ui, _id: ComponentId) -> Option<f32> {
697 None
698 }
699}
700
701pub trait Timed {
706 fn timer_interval(&self) -> Option<f64> {
709 None
710 }
711
712 fn timer_precision(&self) -> crate::TimerPrecision {
714 crate::TimerPrecision::default()
715 }
716
717 fn timer_background(&self) -> bool {
720 false
721 }
722
723 fn timer_late(&mut self, _late: f64) {}
725
726 fn frame(&mut self, _ctx: &mut EventCtx<'_>) -> bool {
730 false
731 }
732
733 fn timer(&mut self, ctx: &mut EventCtx<'_>) {
736 ctx.fire("on_timer", EventArgs::None);
737 }
738}
739
740pub trait ChildPointer {
751 fn child_pressed(&mut self, ctx: &mut EventCtx<'_>, child: ComponentId, event: &PointerEvent);
754 fn child_clicked(&mut self, ctx: &mut EventCtx<'_>, child: ComponentId);
756}
757
758pub trait DragDrop {
759 fn drag_item(&self, _ui: &crate::Ui) -> Option<(String, String)> {
764 None
765 }
766
767 fn drag_visual(&self, _ui: &crate::Ui, _source: ComponentId) -> Option<crate::DragVisual> {
770 None
771 }
772
773 fn drop_accepts(&self, _ui: &crate::Ui, _id: ComponentId, _data: &str) -> bool {
778 false
779 }
780
781 fn drop_hover(&mut self, _ctx: &mut EventCtx<'_>, _data: &str, _position: PointF) {}
784
785 fn drop_leave(&mut self, _ctx: &mut EventCtx<'_>) {}
787
788 fn drop_receive(&mut self, _ctx: &mut EventCtx<'_>, _data: &str, _position: PointF) {}
790
791 fn drag_ended(&mut self, _ctx: &mut EventCtx<'_>, _data: &str, _end: crate::DragEnd) {}
793}
794
795pub trait PlatformHooks {
799 fn taskbar(&self) -> Option<crate::taskbar::TaskbarSpec> {
801 None
802 }
803
804 fn tray(&self) -> Option<crate::tray::TraySpec> {
806 None
807 }
808
809 fn native_view(&self) -> Option<NativeView> {
813 None
814 }
815
816 fn take_native_commands(&self) -> Vec<NativeCommand> {
818 Vec::new()
819 }
820
821 fn connection(&self) -> Option<Connection> {
825 None
826 }
827
828 fn files_dropped(&mut self, _ctx: &mut EventCtx<'_>, _paths: &[String]) -> bool {
831 false
832 }
833
834 fn files_hovering(&mut self, _ctx: &mut EventCtx<'_>, _paths: Option<&[String]>) -> bool {
837 false
838 }
839}
840
841pub trait DesignHooks {
845 fn design_grip(&self, _local: PointF) -> Option<usize> {
848 None
849 }
850
851 fn design_drag(&mut self, _grip: usize, _delta: PointF, _begin: bool) -> Option<(Option<ComponentId>, &'static str, PropValue)> {
855 None
856 }
857}
858
859#[derive(Clone, Copy, Debug, PartialEq)]
861pub struct ArrangeItem {
862 pub id: ComponentId,
863 pub size: SizeF,
864 pub margins: Bounds,
866 pub span: u32,
868 pub row_span: u32,
870 pub cell: Option<(u32, u32)>,
872 pub grow: f32,
874 pub baseline: Option<f32>,
876 pub spacing: f32,
879}
880
881impl ArrangeItem {
882 pub fn of(id: ComponentId, cb: &ControlBase) -> Self {
884 ArrangeItem {
885 id,
886 size: SizeF::new(cb.width(), cb.height()),
887 margins: cb.margins(),
888 span: cb.column_span(),
889 row_span: cb.row_span(),
890 cell: cb.grid_cell(),
891 grow: cb.grow(),
892 baseline: None,
893 spacing: cb.spacing_scale(),
894 }
895 }
896}
897
898#[derive(Clone, Debug, PartialEq)]
900pub enum NativeView {
901 Web { url: String, html: String, generation: u64, navigation: Vec<String>, sandbox: String, background: Option<crate::Color>, data_dir: String, browser_args: String },
910}
911
912#[derive(Clone, Debug, PartialEq)]
916pub struct WebMessage {
917 pub text: String,
918 pub url: String,
919}
920
921pub fn navigation_allowed(allowed: &[String], url: &str) -> bool {
925 allowed.is_empty()
926 || url.starts_with("about:")
927 || url.starts_with("data:")
928 || allowed.iter().any(|a| {
929 let a = a.trim_end_matches('/');
930 url == a || url.starts_with(&format!("{a}/")) || url.starts_with(&format!("{a}?")) || (a.matches('/').count() <= 2 && url_origin(url) == url_origin(a))
931 })
932}
933
934pub fn url_origin(url: &str) -> String {
936 let Some((scheme, rest)) = url.split_once("://") else { return url.to_string() };
937 let host = rest.split(['/', '?', '#']).next().unwrap_or_default();
938 format!("{}://{}", scheme.to_ascii_lowercase(), host.to_ascii_lowercase())
939}
940
941#[derive(Clone, Copy, Debug, PartialEq)]
944pub struct MethodInfo {
945 pub name: &'static str,
946 pub args: &'static [PropKind],
947 pub returns: Option<PropKind>,
948 pub params: &'static [&'static str],
951 pub arg_types: &'static [&'static str],
954 pub returns_type: &'static str,
955}
956
957impl MethodInfo {
958 pub const fn new(name: &'static str, args: &'static [PropKind], returns: Option<PropKind>) -> Self {
959 Self { name, args, returns, params: &[], arg_types: &[], returns_type: "" }
960 }
961
962 pub const fn types(self, args: &'static [&'static str], returns: &'static str) -> Self {
964 Self { arg_types: args, returns_type: returns, ..self }
965 }
966
967 pub const fn params(self, names: &'static [&'static str]) -> Self {
970 Self { params: names, ..self }
971 }
972}
973
974#[derive(Clone, Debug, PartialEq)]
976pub enum NativeCommand {
977 Eval(String),
979 Back,
980 Forward,
981 Reload,
982}
983
984#[derive(Clone, Debug, PartialEq)]
986pub struct NativeViewSlot {
987 pub id: ComponentId,
988 pub rect: crate::RectF,
989 pub clip: Option<crate::RectF>,
992 pub visible: bool,
993 pub view: NativeView,
994 pub commands: Vec<NativeCommand>,
995}
996
997pub fn prop_infos_of(component: &dyn Component) -> Vec<PropInfo> {
1003 let mut out: Vec<PropInfo> = Vec::new();
1004 let mut seen = std::collections::HashSet::new();
1007 let mut push = |info: &PropInfo| {
1008 if seen.insert(info.name) {
1009 out.push(*info);
1010 }
1011 };
1012 let mut layer = Some(component);
1013 while let Some(l) = layer {
1014 l.props().iter().for_each(&mut push);
1015 layer = l.inner();
1016 }
1017 if component.control().is_some() {
1018 ControlBase::PROPS.iter().for_each(&mut push);
1019 }
1020 out
1021}
1022
1023pub fn prop_info_of(component: &dyn Component, name: &str) -> Option<PropInfo> {
1026 let mut layer = Some(component);
1027 while let Some(l) = layer {
1028 if let Some(info) = l.props().iter().find(|p| p.name == name) {
1029 return Some(*info);
1030 }
1031 layer = l.inner();
1032 }
1033 if component.control().is_some() {
1034 return ControlBase::PROPS.iter().find(|p| p.name == name).copied();
1035 }
1036 None
1037}
1038
1039pub const VALUE_PROPERTIES: [&str; 19] = [
1044 "text", "checked", "value", "item_index", "selected", "date", "end_date", "time", "color", "files", "html", "index", "page", "hotkey",
1045 "angle", "pressed", "position", "low", "high",
1046];
1047
1048pub fn is_value_property(info: &PropInfo) -> bool {
1052 match info.name {
1053 "tab_index" | "expanded" => true,
1054 name => matches!(info.category, "Data" | "Runtime") && VALUE_PROPERTIES.contains(&name),
1055 }
1056}
1057
1058pub fn read_prop(component: &dyn Component, name: &str) -> Option<PropValue> {
1059 let mut layer = Some(component);
1060 while let Some(l) = layer {
1061 if let Some(v) = l.get_prop(name) {
1062 return Some(v);
1063 }
1064 layer = l.inner();
1065 }
1066 component.control().and_then(|cb| cb.get_prop(name))
1067}
1068
1069#[derive(Clone, Copy, Debug, PartialEq)]
1072pub(crate) struct AnchorRef {
1073 pub(crate) parent: SizeF,
1074 pub(crate) rect: RectF,
1075}
1076
1077#[derive(Clone, Debug)]
1082pub struct ControlBase {
1083 left: f32,
1085 top: f32,
1087 width: f32,
1089 height: f32,
1091 margins: Bounds,
1093 padding: Bounds,
1095 align: Align,
1097 anchors: Anchors,
1099 visible: bool,
1101 enabled: bool,
1103 hit_test: bool,
1105 clip_children: bool,
1107 inherit_state: bool,
1110 translatable: bool,
1114 captures_wheel: bool,
1117 captures_gesture: bool,
1120 can_focus: bool,
1122 draggable: bool,
1124 accepts_drops: bool,
1126 drag: Option<Box<DragDecl>>,
1129 tab_stop: bool,
1131 pan_on_touch: bool,
1133 hover_within: bool,
1136 pub(crate) popup_menu: Option<ComponentId>,
1138 cursor: CursorShape,
1140 opacity: f32,
1142 blend_mode: crate::BlendMode,
1145 rotation: f32,
1147 scale: f32,
1152 translate: PointF,
1154 cache_layer: bool,
1157 aspect_ratio: f32,
1159 max_width: f32,
1161 min_width: f32,
1163 min_height: f32,
1165 max_height: f32,
1167 self_align: SelfAlign,
1169 auto_size: bool,
1171 column_span: u32,
1173 grid_row: i16,
1176 grid_column: i16,
1178 row_span: u16,
1180 grow: f32,
1183 pub(crate) text_scale: f32,
1186 pub(crate) spacing_scale: f32,
1187 shadow: Option<crate::canvas::Shadow>,
1189 tag: i64,
1191 rare: Option<Box<RareTexts>>,
1194 style: String,
1196 theme: String,
1198 hint: String,
1200 state: ControlState,
1201 pub(crate) bounds: RectF,
1202 pub(crate) anchor_ref: Option<AnchorRef>,
1203 pub(crate) follow: Option<(ComponentId, Option<PointF>)>,
1206 pub(crate) design_hidden: bool,
1209 pub(crate) design_only: bool,
1211 pub(crate) keep_left_to_right: bool,
1214 pub(crate) colors: ColorOverride,
1216 pub(crate) font: FontOverride,
1218 scroll_offset: PointF,
1220 pub(crate) laid_out_scroll: PointF,
1223 pub(crate) safe_area: Bounds,
1225 pub(crate) content_size: SizeF,
1227}
1228
1229impl Default for ControlBase {
1230 fn default() -> Self {
1231 Self::new(100.0, 100.0)
1232 }
1233}
1234
1235impl ControlBase {
1236 pub const PROPS: &'static [PropInfo] = &[
1238 PropInfo::new("left", PropKind::Float, "Layout"),
1239 PropInfo::new("top", PropKind::Float, "Layout"),
1240 PropInfo::new("width", PropKind::Float, "Layout"),
1241 PropInfo::new("height", PropKind::Float, "Layout"),
1242 PropInfo::new("align", PropKind::Enum(<Align as crate::prop::PropEnum>::NAMES), "Layout").rust_type("Align"),
1243 PropInfo::new("anchors", PropKind::Set(&Anchors::NAMES), "Layout").rust_type("Anchors"),
1244 PropInfo::new("margins", PropKind::Bounds, "Layout"),
1245 PropInfo::new("padding", PropKind::Bounds, "Layout"),
1246 PropInfo::new("visible", PropKind::Bool, "Behavior"),
1247 PropInfo::new("enabled", PropKind::Bool, "Behavior"),
1248 PropInfo::new("hit_test", PropKind::Bool, "Behavior"),
1249 PropInfo::new("clip_children", PropKind::Bool, "Behavior"),
1250 PropInfo::new("inherit_state", PropKind::Bool, "Appearance"),
1251 PropInfo::new("translate", PropKind::Bool, "Behavior"),
1252 PropInfo::new("captures_wheel", PropKind::Bool, "Behavior"),
1253 PropInfo::new("captures_gesture", PropKind::Bool, "Behavior"),
1254 PropInfo::new("can_focus", PropKind::Bool, "Behavior"),
1255 PropInfo::new("draggable", PropKind::Bool, "Behavior"),
1256 PropInfo::new("accepts_drops", PropKind::Bool, "Behavior"),
1257 PropInfo::new("drag_data", PropKind::String, "Behavior"),
1258 PropInfo::new("drag_label", PropKind::String, "Behavior"),
1259 PropInfo::new("drag_image", PropKind::Component, "Behavior"),
1260 PropInfo::new("drop_types", PropKind::String, "Behavior"),
1261 PropInfo::new("tab_stop", PropKind::Bool, "Behavior"),
1262 PropInfo::new("cursor", PropKind::Enum(<CursorShape as crate::prop::PropEnum>::NAMES), "Behavior").rust_type("CursorShape"),
1263 PropInfo::new("opacity", PropKind::Float, "Appearance"),
1264 PropInfo::new("blend_mode", PropKind::Enum(<crate::BlendMode as crate::prop::PropEnum>::NAMES), "Appearance").rust_type("BlendMode"),
1265 PropInfo::new("cache_layer", PropKind::Bool, "Appearance"),
1266 PropInfo::new("rotation", PropKind::Angle, "Layout"),
1267 PropInfo::new("scale", PropKind::Float, "Layout"),
1268 PropInfo::new("translate_x", PropKind::Float, "Appearance"),
1269 PropInfo::new("translate_y", PropKind::Float, "Appearance"),
1270 PropInfo::new("aspect_ratio", PropKind::Float, "Layout"),
1271 PropInfo::new("max_width", PropKind::Float, "Layout"),
1272 PropInfo::new("min_width", PropKind::Float, "Layout"),
1273 PropInfo::new("min_height", PropKind::Float, "Layout"),
1274 PropInfo::new("max_height", PropKind::Float, "Layout"),
1275 PropInfo::new("self_align", PropKind::Enum(<SelfAlign as crate::prop::PropEnum>::NAMES), "Layout").rust_type("SelfAlign"),
1276 PropInfo::new("auto_size", PropKind::Bool, "Layout"),
1277 PropInfo::new("column_span", PropKind::Int, "Layout"),
1278 PropInfo::new("grid_row", PropKind::Int, "Layout"),
1279 PropInfo::new("grid_column", PropKind::Int, "Layout"),
1280 PropInfo::new("row_span", PropKind::Int, "Layout"),
1281 PropInfo::new("grow", PropKind::Float, "Layout"),
1282 PropInfo::new("shadow", PropKind::Shadow, "Appearance"),
1283 PropInfo::new("style", PropKind::StyleName, "Appearance"),
1284 PropInfo::new("theme", PropKind::ThemeName, "Appearance"),
1285 PropInfo::new("fill", PropKind::Color, "Appearance"),
1286 PropInfo::new("border_color", PropKind::Color, "Appearance"),
1287 PropInfo::new("text_color", PropKind::Color, "Appearance"),
1288 PropInfo::new("accent_color", PropKind::Color, "Appearance"),
1289 PropInfo::new("success_color", PropKind::Color, "Appearance"),
1290 PropInfo::new("warning_color", PropKind::Color, "Appearance"),
1291 PropInfo::new("danger_color", PropKind::Color, "Appearance"),
1292 PropInfo::new("font_family", PropKind::String, "Font"),
1293 PropInfo::new("font_size", PropKind::Float, "Font"),
1294 PropInfo::new("font_weight", PropKind::Enum(&FONT_WEIGHTS), "Font"),
1295 PropInfo::new("font_italic", PropKind::Bool, "Font"),
1296 PropInfo::new("font_underline", PropKind::Bool, "Font"),
1297 PropInfo::new("font_strikeout", PropKind::Bool, "Font"),
1298 PropInfo::new("hint", PropKind::String, "Behavior"),
1299 PropInfo::new("tag", PropKind::Int, "Misc"),
1300 PropInfo::new("tag_string", PropKind::String, "Misc"),
1301 PropInfo::new("accessible_name", PropKind::String, "Behavior"),
1302 PropInfo::new("popup_menu", PropKind::Component, "Behavior"),
1303 PropInfo::new("on_click", PropKind::Event, "Events").event_arg(crate::EventArg::None),
1304 PropInfo::new("on_dbl_click", PropKind::Event, "Events").event_arg(crate::EventArg::Pointer),
1305 PropInfo::new("on_long_press", PropKind::Event, "Events").event_arg(crate::EventArg::Pointer),
1306 PropInfo::new("on_pointer_down", PropKind::Event, "Events").event_arg(crate::EventArg::Pointer),
1307 PropInfo::new("on_pointer_up", PropKind::Event, "Events").event_arg(crate::EventArg::Pointer),
1308 PropInfo::new("on_pointer_move", PropKind::Event, "Events").event_arg(crate::EventArg::Pointer),
1309 PropInfo::new("on_pointer_enter", PropKind::Event, "Events").event_arg(crate::EventArg::None),
1310 PropInfo::new("on_pointer_leave", PropKind::Event, "Events").event_arg(crate::EventArg::None),
1311 PropInfo::new("on_wheel", PropKind::Event, "Events").event_arg(crate::EventArg::Wheel),
1312 PropInfo::new("on_gesture", PropKind::Event, "Events").event_arg(crate::EventArg::Gesture),
1313 PropInfo::new("on_swipe", PropKind::Event, "Events").event_arg(crate::EventArg::Swipe),
1314 PropInfo::new("on_key_down", PropKind::Event, "Events").event_arg(crate::EventArg::Key),
1317 PropInfo::new("on_key_press", PropKind::Event, "Events"),
1318 PropInfo::new("on_key_up", PropKind::Event, "Events").event_arg(crate::EventArg::Key),
1319 PropInfo::new("on_enter", PropKind::Event, "Events").event_arg(crate::EventArg::None),
1320 PropInfo::new("on_exit", PropKind::Event, "Events").event_arg(crate::EventArg::None),
1321 PropInfo::new("on_resize", PropKind::Event, "Events").event_arg(crate::EventArg::None),
1322 PropInfo::new("on_drag_start", PropKind::Event, "Events"),
1323 PropInfo::new("on_drag_over", PropKind::Event, "Events"),
1324 PropInfo::new("on_drag_move", PropKind::Event, "Events").event_arg(crate::EventArg::Pointer),
1325 PropInfo::new("on_drag_leave", PropKind::Event, "Events").event_arg(crate::EventArg::Value(PropKind::String)),
1326 PropInfo::new("on_drag_drop", PropKind::Event, "Events").event_arg(crate::EventArg::Value(PropKind::String)),
1327 PropInfo::new("on_drag_end", PropKind::Event, "Events").event_arg(crate::EventArg::Value(PropKind::Bool)),
1328 ];
1329
1330 pub fn new(width: f32, height: f32) -> Self {
1331 Self {
1332 left: 0.0,
1333 top: 0.0,
1334 width,
1335 height,
1336 margins: Bounds::ZERO,
1337 padding: Bounds::ZERO,
1338 align: Align::None,
1339 anchors: Anchors::default(),
1340 visible: true,
1341 enabled: true,
1342 hit_test: true,
1343 clip_children: false,
1344 inherit_state: false,
1345 translatable: true,
1346 captures_wheel: false,
1347 captures_gesture: false,
1348 can_focus: false,
1349 draggable: false,
1350 accepts_drops: false,
1351 drag: None,
1352 tab_stop: true,
1353 pan_on_touch: true,
1354 hover_within: false,
1355 popup_menu: None,
1356 cursor: CursorShape::Default,
1357 opacity: 1.0,
1358 blend_mode: crate::BlendMode::Normal,
1359 rotation: 0.0,
1360 scale: 1.0,
1361 translate: PointF::ZERO,
1362 cache_layer: false,
1363 aspect_ratio: 0.0,
1364 max_width: 0.0,
1365 min_width: 0.0,
1366 min_height: 0.0,
1367 max_height: 0.0,
1368 self_align: SelfAlign::Stretch,
1369 auto_size: false,
1370 column_span: 1,
1371 grid_row: -1,
1372 grid_column: -1,
1373 row_span: 1,
1374 grow: 0.0,
1375 text_scale: 1.0,
1376 spacing_scale: 1.0,
1377 shadow: None,
1378 tag: 0,
1379 rare: None,
1380 style: String::new(),
1381 theme: String::new(),
1382 hint: String::new(),
1383 state: ControlState::default(),
1384 bounds: RectF::new(0.0, 0.0, width, height),
1385 anchor_ref: None,
1386 follow: None,
1387 design_hidden: false,
1388 design_only: false,
1389 keep_left_to_right: false,
1390 colors: ColorOverride::default(),
1391 font: FontOverride::default(),
1392 scroll_offset: PointF::ZERO,
1393 laid_out_scroll: PointF::ZERO,
1394 content_size: SizeF::ZERO,
1395 safe_area: Bounds::default(),
1396 }
1397 }
1398
1399 pub fn left(&self) -> f32 {
1402 self.left
1403 }
1404
1405 pub fn top(&self) -> f32 {
1406 self.top
1407 }
1408
1409 pub fn width(&self) -> f32 {
1410 self.width
1411 }
1412
1413 pub fn height(&self) -> f32 {
1414 self.height
1415 }
1416
1417 pub fn position(&self) -> PointF {
1418 PointF::new(self.left, self.top)
1419 }
1420
1421 pub fn size(&self) -> SizeF {
1422 SizeF::new(self.width, self.height)
1423 }
1424
1425 pub fn margins(&self) -> Bounds {
1428 if self.spacing_scale == 1.0 { self.margins } else { self.margins.scaled(self.spacing_scale) }
1429 }
1430
1431 pub fn padding(&self) -> Bounds {
1433 if self.spacing_scale == 1.0 { self.padding } else { self.padding.scaled(self.spacing_scale) }
1434 }
1435
1436 pub fn align(&self) -> Align {
1437 self.align
1438 }
1439
1440 pub fn anchors(&self) -> Anchors {
1441 self.anchors
1442 }
1443
1444 pub fn visible(&self) -> bool {
1445 self.visible
1446 }
1447
1448 pub fn design_only(&self) -> bool {
1450 self.design_only
1451 }
1452
1453 pub fn colors(&self) -> ColorOverride {
1455 self.colors
1456 }
1457
1458 pub fn set_colors(&mut self, colors: ColorOverride) -> &mut Self {
1459 self.colors = colors;
1460 self
1461 }
1462
1463 pub fn set_design_only(&mut self, on: bool) -> &mut Self {
1464 self.design_only = on;
1465 self
1466 }
1467
1468 pub fn keep_left_to_right(&self) -> bool {
1470 self.keep_left_to_right
1471 }
1472
1473 pub fn set_keep_left_to_right(&mut self, on: bool) -> &mut Self {
1474 self.keep_left_to_right = on;
1475 self
1476 }
1477
1478 pub fn enabled(&self) -> bool {
1479 self.enabled
1480 }
1481
1482 pub fn hit_test(&self) -> bool {
1483 self.hit_test
1484 }
1485
1486 pub fn translatable(&self) -> bool {
1487 self.translatable
1488 }
1489
1490 pub fn set_translatable(&mut self, v: bool) -> &mut Self {
1491 self.translatable = v;
1492 self
1493 }
1494
1495 pub fn inherit_state(&self) -> bool {
1496 self.inherit_state
1497 }
1498
1499 pub fn set_inherit_state(&mut self, v: bool) -> &mut Self {
1500 self.inherit_state = v;
1501 self
1502 }
1503
1504 pub fn clip_children(&self) -> bool {
1505 self.clip_children
1506 }
1507
1508 pub fn captures_wheel(&self) -> bool {
1509 self.captures_wheel
1510 }
1511
1512 pub fn captures_gesture(&self) -> bool {
1513 self.captures_gesture
1514 }
1515
1516 pub fn draggable(&self) -> bool {
1521 self.draggable
1522 }
1523
1524 pub fn set_draggable(&mut self, v: bool) -> &mut Self {
1525 self.draggable = v;
1526 self
1527 }
1528
1529 pub fn accepts_drops(&self) -> bool {
1532 self.accepts_drops
1533 }
1534
1535 pub fn set_accepts_drops(&mut self, v: bool) -> &mut Self {
1536 self.accepts_drops = v;
1537 self
1538 }
1539
1540 pub fn drag_data(&self) -> &str {
1542 self.drag.as_ref().map_or("", |d| d.data.as_str())
1543 }
1544
1545 pub fn drag_label(&self) -> &str {
1546 self.drag.as_ref().map_or("", |d| d.label.as_str())
1547 }
1548
1549 pub fn drag_image(&self) -> Option<ComponentId> {
1551 self.drag.as_ref().and_then(|d| d.image)
1552 }
1553
1554 pub(crate) fn forget_drag_image(&mut self, doomed: &[ComponentId]) {
1556 if let Some(d) = self.drag.as_mut().filter(|d| d.image.is_some_and(|i| doomed.contains(&i))) {
1557 d.image = None;
1558 }
1559 }
1560
1561 pub fn drop_types(&self) -> &str {
1563 self.drag.as_ref().map_or("", |d| d.drop_types.as_str())
1564 }
1565
1566 fn drag_decl(&mut self) -> &mut DragDecl {
1567 self.drag.get_or_insert_with(Default::default)
1568 }
1569
1570 pub fn can_focus(&self) -> bool {
1571 self.can_focus
1572 }
1573
1574 pub fn tab_stop(&self) -> bool {
1576 self.tab_stop
1577 }
1578
1579 pub fn popup_menu(&self) -> Option<ComponentId> {
1581 self.popup_menu
1582 }
1583
1584 pub fn set_popup_menu(&mut self, menu: Option<ComponentId>) -> &mut Self {
1585 self.popup_menu = menu;
1586 self
1587 }
1588
1589 pub fn pan_on_touch(&self) -> bool {
1591 self.pan_on_touch
1592 }
1593
1594 pub fn hover_within(&self) -> bool {
1596 self.hover_within
1597 }
1598
1599 pub fn set_hover_within(&mut self, v: bool) -> &mut Self {
1603 self.hover_within = v;
1604 self
1605 }
1606
1607 pub fn cursor(&self) -> CursorShape {
1609 self.cursor
1610 }
1611
1612 pub fn opacity(&self) -> f32 {
1613 self.opacity
1614 }
1615
1616 pub fn blend_mode(&self) -> crate::BlendMode {
1618 self.blend_mode
1619 }
1620
1621 pub fn set_blend_mode(&mut self, mode: crate::BlendMode) -> &mut Self {
1622 self.blend_mode = mode;
1623 self
1624 }
1625
1626 pub fn cache_layer(&self) -> bool {
1628 self.cache_layer
1629 }
1630
1631 pub fn set_cache_layer(&mut self, on: bool) -> &mut Self {
1632 self.cache_layer = on;
1633 self
1634 }
1635
1636 pub fn rotation(&self) -> f32 {
1639 self.rotation
1640 }
1641
1642 pub fn scale(&self) -> f32 {
1644 self.scale
1645 }
1646
1647 pub fn inner_size(&self) -> SizeF {
1650 let s = self.scale;
1651 if s == 1.0 { self.bounds.size() } else { SizeF::new(self.bounds.width / s, self.bounds.height / s) }
1652 }
1653
1654 pub fn shadow(&self) -> Option<crate::canvas::Shadow> {
1655 self.shadow
1656 }
1657
1658 pub fn aspect_ratio(&self) -> f32 {
1662 self.aspect_ratio
1663 }
1664
1665 pub fn set_aspect_ratio(&mut self, ratio: f32) -> &mut Self {
1666 self.aspect_ratio = if ratio.is_finite() { ratio.max(0.0) } else { 0.0 };
1667 self
1668 }
1669
1670 pub fn max_width(&self) -> f32 {
1674 self.max_width
1675 }
1676
1677 pub fn set_max_width(&mut self, width: f32) -> &mut Self {
1678 self.max_width = if width.is_finite() { width.max(0.0) } else { 0.0 };
1679 self
1680 }
1681
1682 pub fn min_width(&self) -> f32 {
1687 self.min_width
1688 }
1689
1690 pub fn set_min_width(&mut self, width: f32) -> &mut Self {
1691 self.min_width = if width.is_finite() { width.max(0.0) } else { 0.0 };
1692 self
1693 }
1694
1695 pub fn min_height(&self) -> f32 {
1697 self.min_height
1698 }
1699
1700 pub fn set_min_height(&mut self, height: f32) -> &mut Self {
1701 self.min_height = if height.is_finite() { height.max(0.0) } else { 0.0 };
1702 self
1703 }
1704
1705 pub fn max_height(&self) -> f32 {
1707 self.max_height
1708 }
1709
1710 pub fn set_max_height(&mut self, height: f32) -> &mut Self {
1711 self.max_height = if height.is_finite() { height.max(0.0) } else { 0.0 };
1712 self
1713 }
1714
1715 pub fn clamp_width(&self, available: f32) -> f32 {
1718 let w = if self.max_width > 0.0 { available.min(self.max_width) } else { available };
1719 w.max(self.min_width)
1720 }
1721
1722 pub fn clamp_height(&self, height: f32) -> f32 {
1724 let h = if self.max_height > 0.0 { height.min(self.max_height) } else { height };
1725 h.max(self.min_height)
1726 }
1727
1728 pub fn self_align(&self) -> SelfAlign {
1731 self.self_align
1732 }
1733
1734 pub fn set_self_align(&mut self, align: SelfAlign) -> &mut Self {
1735 self.self_align = align;
1736 self
1737 }
1738
1739 pub fn band_width(&self, available: f32) -> f32 {
1743 match self.self_align {
1744 SelfAlign::Stretch => self.clamp_width(available),
1745 _ if self.max_width > 0.0 => self.clamp_width(available),
1746 _ => self.clamp_width(self.width),
1747 }
1748 }
1749
1750 pub fn band_height(&self, available: f32) -> f32 {
1753 match self.self_align {
1754 SelfAlign::Stretch => self.clamp_height(available),
1755 _ if self.max_height > 0.0 => self.clamp_height(available),
1756 _ => self.clamp_height(self.height),
1757 }
1758 }
1759
1760 pub fn band_offset(&self, available: f32, size: f32) -> f32 {
1763 let spare = (available - size).max(0.0);
1764 match self.self_align {
1765 SelfAlign::Start => 0.0,
1766 SelfAlign::End => spare,
1767 SelfAlign::Stretch | SelfAlign::Center => spare / 2.0,
1768 }
1769 }
1770
1771 pub fn auto_size(&self) -> bool {
1776 self.auto_size
1777 }
1778
1779 pub fn set_auto_size(&mut self, on: bool) -> &mut Self {
1780 self.auto_size = on;
1781 self
1782 }
1783
1784 pub fn column_span(&self) -> u32 {
1787 self.column_span.max(1)
1788 }
1789
1790 pub fn grid_cell(&self) -> Option<(u32, u32)> {
1792 (self.grid_row >= 0 && self.grid_column >= 0).then(|| (self.grid_row as u32, self.grid_column as u32))
1793 }
1794
1795 pub fn set_grid_cell(&mut self, cell: Option<(u32, u32)>) -> &mut Self {
1796 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));
1797 self.grid_row = r;
1798 self.grid_column = c;
1799 self
1800 }
1801
1802 pub fn row_span(&self) -> u32 {
1804 u32::from(self.row_span.max(1))
1805 }
1806
1807 pub fn set_row_span(&mut self, span: u32) -> &mut Self {
1808 self.row_span = span.clamp(1, 64) as u16;
1809 self
1810 }
1811
1812 pub fn grow(&self) -> f32 {
1813 self.grow
1814 }
1815
1816 pub fn set_grow(&mut self, grow: f32) -> &mut Self {
1817 self.grow = grow.max(0.0);
1818 self
1819 }
1820
1821 pub fn set_column_span(&mut self, span: u32) -> &mut Self {
1822 self.column_span = span.max(1);
1823 self
1824 }
1825
1826 pub fn text_scale(&self) -> f32 {
1828 self.text_scale
1829 }
1830
1831 pub fn spacing_scale(&self) -> f32 {
1833 self.spacing_scale
1834 }
1835
1836 pub fn tag(&self) -> i64 {
1837 self.tag
1838 }
1839
1840 pub fn accessible_name(&self) -> &str {
1843 self.rare.as_ref().map_or("", |r| &r.accessible_name)
1844 }
1845
1846 pub fn set_accessible_name(&mut self, v: &str) -> &mut Self {
1847 self.rare_mut(|r| r.accessible_name = v.into());
1848 self
1849 }
1850
1851 fn rare_mut(&mut self, change: impl FnOnce(&mut RareTexts)) {
1852 let rare = self.rare.get_or_insert_with(Default::default);
1853 change(rare);
1854 if rare.tag_string.is_empty() && rare.accessible_name.is_empty() {
1855 self.rare = None;
1856 }
1857 }
1858
1859 pub fn tag_string(&self) -> &str {
1860 self.rare.as_ref().map_or("", |r| &r.tag_string)
1861 }
1862
1863 pub fn style(&self) -> &str {
1865 &self.style
1866 }
1867
1868 pub fn theme_name(&self) -> &str {
1870 &self.theme
1871 }
1872
1873 pub fn set_theme_name(&mut self, v: impl Into<String>) -> &mut Self {
1874 self.theme = v.into();
1875 self
1876 }
1877
1878 pub fn hint(&self) -> &str {
1880 &self.hint
1881 }
1882
1883 pub fn set_hint(&mut self, v: impl Into<String>) -> &mut Self {
1884 self.hint = v.into();
1885 self
1886 }
1887
1888 pub fn state(&self) -> ControlState {
1889 self.state
1890 }
1891
1892 pub fn bounds(&self) -> RectF {
1894 self.bounds
1895 }
1896
1897 pub fn scroll_offset(&self) -> PointF {
1899 self.scroll_offset
1900 }
1901
1902 pub fn laid_out_scroll(&self) -> PointF {
1905 self.laid_out_scroll
1906 }
1907
1908 pub fn set_scroll_offset(&mut self, offset: PointF) -> &mut Self {
1911 self.scroll_offset = offset;
1912 self
1913 }
1914
1915 pub fn content_size(&self) -> SizeF {
1918 self.content_size
1919 }
1920
1921 pub fn set_left(&mut self, v: f32) -> &mut Self {
1928 if self.left != v {
1929 self.left = v;
1930 self.anchor_ref = None;
1931 }
1932 self
1933 }
1934
1935 pub fn set_top(&mut self, v: f32) -> &mut Self {
1936 if self.top != v {
1937 self.top = v;
1938 self.anchor_ref = None;
1939 }
1940 self
1941 }
1942
1943 pub fn set_position(&mut self, left: f32, top: f32) -> &mut Self {
1944 self.set_left(left).set_top(top)
1945 }
1946
1947 pub fn set_width(&mut self, v: f32) -> &mut Self {
1948 if self.width != v.max(0.0) {
1949 self.width = v.max(0.0);
1950 self.anchor_ref = None;
1951 }
1952 self
1953 }
1954
1955 pub fn set_height(&mut self, v: f32) -> &mut Self {
1956 if self.height != v.max(0.0) {
1957 self.height = v.max(0.0);
1958 self.anchor_ref = None;
1959 }
1960 self
1961 }
1962
1963 pub(crate) fn set_measured_width(&mut self, v: f32) {
1965 self.width = v.max(0.0);
1966 if let Some(r) = self.anchor_ref.as_mut() {
1967 r.rect.width = self.width;
1968 }
1969 }
1970
1971 pub(crate) fn set_measured_height(&mut self, v: f32) {
1974 self.height = v.max(0.0);
1975 if let Some(r) = self.anchor_ref.as_mut() {
1976 r.rect.height = self.height;
1977 }
1978 }
1979
1980 pub fn set_size(&mut self, width: f32, height: f32) -> &mut Self {
1981 self.set_width(width).set_height(height)
1982 }
1983
1984 pub fn set_rect(&mut self, left: f32, top: f32, width: f32, height: f32) -> &mut Self {
1986 self.set_position(left, top).set_size(width, height)
1987 }
1988
1989 pub fn set_margins(&mut self, v: impl Into<Bounds>) -> &mut Self {
1990 self.margins = v.into();
1991 self
1992 }
1993
1994 pub fn set_padding(&mut self, v: impl Into<Bounds>) -> &mut Self {
1995 self.padding = v.into();
1996 self
1997 }
1998
1999 pub fn set_align(&mut self, v: Align) -> &mut Self {
2000 self.align = v;
2001 self.anchor_ref = None;
2002 self
2003 }
2004
2005 pub fn set_anchors(&mut self, v: Anchors) -> &mut Self {
2006 self.anchors = v;
2007 self.anchor_ref = None;
2008 self
2009 }
2010
2011 pub fn set_visible(&mut self, v: bool) -> &mut Self {
2012 self.visible = v;
2013 self
2014 }
2015
2016 pub fn set_enabled(&mut self, v: bool) -> &mut Self {
2017 self.enabled = v;
2018 self
2019 }
2020
2021 pub fn set_hit_test(&mut self, v: bool) -> &mut Self {
2022 self.hit_test = v;
2023 self
2024 }
2025
2026 pub fn set_clip_children(&mut self, v: bool) -> &mut Self {
2027 self.clip_children = v;
2028 self
2029 }
2030
2031 pub fn set_captures_wheel(&mut self, v: bool) -> &mut Self {
2032 self.captures_wheel = v;
2033 self
2034 }
2035
2036 pub fn set_captures_gesture(&mut self, v: bool) -> &mut Self {
2037 self.captures_gesture = v;
2038 self
2039 }
2040
2041 pub fn set_can_focus(&mut self, v: bool) -> &mut Self {
2042 self.can_focus = v;
2043 self
2044 }
2045
2046 pub fn set_pan_on_touch(&mut self, v: bool) -> &mut Self {
2050 self.pan_on_touch = v;
2051 self
2052 }
2053
2054 pub fn set_tab_stop(&mut self, v: bool) -> &mut Self {
2055 self.tab_stop = v;
2056 self
2057 }
2058
2059 pub fn set_cursor(&mut self, v: CursorShape) -> &mut Self {
2060 self.cursor = v;
2061 self
2062 }
2063
2064 pub fn set_opacity(&mut self, v: f32) -> &mut Self {
2065 self.opacity = v.clamp(0.0, 1.0);
2066 self
2067 }
2068
2069 pub fn translate(&self) -> PointF {
2071 self.translate
2072 }
2073
2074 pub fn set_translate(&mut self, offset: PointF) -> &mut Self {
2075 self.translate = if offset.x.is_finite() && offset.y.is_finite() { offset } else { PointF::ZERO };
2076 self
2077 }
2078
2079 pub fn set_scale(&mut self, scale: f32) -> &mut Self {
2081 self.scale = if scale.is_finite() && scale > 0.0 { scale.clamp(0.05, 20.0) } else { 1.0 };
2082 self
2083 }
2084
2085 pub fn set_rotation(&mut self, degrees: f32) -> &mut Self {
2086 self.rotation = if degrees.is_finite() { degrees % 360.0 } else { 0.0 };
2087 self
2088 }
2089
2090 pub fn set_shadow(&mut self, shadow: Option<crate::canvas::Shadow>) -> &mut Self {
2091 self.shadow = shadow;
2092 self
2093 }
2094
2095 pub fn set_tag(&mut self, v: i64) -> &mut Self {
2096 self.tag = v;
2097 self
2098 }
2099
2100 pub fn set_tag_string(&mut self, v: &str) -> &mut Self {
2101 self.rare_mut(|r| r.tag_string = v.into());
2102 self
2103 }
2104
2105 pub fn set_style(&mut self, v: impl Into<String>) -> &mut Self {
2106 self.style = v.into();
2107 self
2108 }
2109
2110 pub fn state_mut(&mut self) -> &mut ControlState {
2113 &mut self.state
2114 }
2115
2116 pub fn get_prop(&self, name: &str) -> Option<PropValue> {
2119 Some(match name {
2120 "left" => self.left.into(),
2121 "top" => self.top.into(),
2122 "width" => self.width.into(),
2123 "height" => self.height.into(),
2124 "align" => self.align.into(),
2125 "anchors" => self.anchors.into(),
2126 "margins" => self.margins.into(),
2127 "padding" => self.padding.into(),
2128 "visible" => self.visible.into(),
2129 "enabled" => self.enabled.into(),
2130 "hit_test" => self.hit_test.into(),
2131 "clip_children" => self.clip_children.into(),
2132 "inherit_state" => self.inherit_state.into(),
2133 "translate" => self.translatable.into(),
2134 "captures_wheel" => self.captures_wheel.into(),
2135 "captures_gesture" => self.captures_gesture.into(),
2136 "can_focus" => self.can_focus.into(),
2137 "draggable" => self.draggable.into(),
2138 "accepts_drops" => self.accepts_drops.into(),
2139 "drag_data" => self.drag_data().into(),
2140 "drag_label" => self.drag_label().into(),
2141 "drag_image" => PropValue::Component(self.drag_image()),
2142 "drop_types" => self.drop_types().into(),
2143 "tab_stop" => self.tab_stop.into(),
2144 "cursor" => PropValue::enum_value(self.cursor),
2145 "opacity" => self.opacity.into(),
2146 "blend_mode" => PropValue::enum_value(self.blend_mode),
2147 "cache_layer" => self.cache_layer.into(),
2148 "rotation" => self.rotation.into(),
2149 "scale" => self.scale.into(),
2150 "translate_x" => self.translate.x.into(),
2151 "translate_y" => self.translate.y.into(),
2152 "aspect_ratio" => self.aspect_ratio.into(),
2153 "max_width" => self.max_width.into(),
2154 "min_width" => self.min_width.into(),
2155 "min_height" => self.min_height.into(),
2156 "max_height" => self.max_height.into(),
2157 "self_align" => PropValue::enum_value(self.self_align),
2158 "auto_size" => self.auto_size.into(),
2159 "column_span" => (self.column_span() as i64).into(),
2160 "grid_row" => i64::from(self.grid_row).into(),
2161 "grid_column" => i64::from(self.grid_column).into(),
2162 "row_span" => (self.row_span() as i64).into(),
2163 "grow" => f64::from(self.grow).into(),
2164 "shadow" => crate::prop::PropType::to_value(&self.shadow),
2165 "style" => self.style.clone().into(),
2166 "fill" => crate::prop::PropType::to_value(&self.colors.fill),
2167 "border_color" => crate::prop::PropType::to_value(&self.colors.border),
2168 "text_color" => crate::prop::PropType::to_value(&self.colors.text),
2169 "accent_color" => crate::prop::PropType::to_value(&self.colors.accent),
2170 "success_color" => crate::prop::PropType::to_value(&self.colors.success),
2171 "warning_color" => crate::prop::PropType::to_value(&self.colors.warning),
2172 "danger_color" => crate::prop::PropType::to_value(&self.colors.danger),
2173 "font_family" => self.font.family.clone().into(),
2174 "font_size" => crate::prop::PropType::to_value(&self.font.size),
2175 "font_weight" => PropValue::Enum(FONT_WEIGHTS[self.font.weight.map_or(0, |w| w as usize + 1)].into()),
2176 "font_italic" => self.font.italic.into(),
2177 "font_underline" => self.font.underline.into(),
2178 "font_strikeout" => self.font.strikeout.into(),
2179 "theme" => self.theme.clone().into(),
2180 "hint" => self.hint.clone().into(),
2181 "tag" => self.tag.into(),
2182 "tag_string" => self.tag_string().to_string().into(),
2183 "accessible_name" => self.accessible_name().to_string().into(),
2184 "popup_menu" => PropValue::Component(self.popup_menu),
2185 _ => return None,
2186 })
2187 }
2188
2189 pub fn set_prop(&mut self, name: &str, value: PropValue) -> Result<()> {
2190 match name {
2191 "left" => self.set_left(value.to_f32()?),
2192 "top" => self.set_top(value.to_f32()?),
2193 "width" => self.set_width(value.to_f32()?),
2194 "height" => self.set_height(value.to_f32()?),
2195 "align" => self.set_align(value.to_enum()?),
2196 "anchors" => self.set_anchors(value.to_anchors()?),
2197 "margins" => self.set_margins(value.to_bounds()?),
2198 "padding" => self.set_padding(value.to_bounds()?),
2199 "visible" => self.set_visible(value.to_bool()?),
2200 "enabled" => self.set_enabled(value.to_bool()?),
2201 "hit_test" => self.set_hit_test(value.to_bool()?),
2202 "clip_children" => self.set_clip_children(value.to_bool()?),
2203 "inherit_state" => self.set_inherit_state(value.to_bool()?),
2204 "translate" => self.set_translatable(value.to_bool()?),
2205 "captures_wheel" => self.set_captures_wheel(value.to_bool()?),
2206 "captures_gesture" => self.set_captures_gesture(value.to_bool()?),
2207 "can_focus" => self.set_can_focus(value.to_bool()?),
2208 "draggable" => self.set_draggable(value.to_bool()?),
2209 "accepts_drops" => self.set_accepts_drops(value.to_bool()?),
2210 "drag_data" => {
2211 self.drag_decl().data = value.to_str()?.to_string();
2212 self
2213 }
2214 "drag_label" => {
2215 self.drag_decl().label = value.to_str()?.to_string();
2216 self
2217 }
2218 "drag_image" => {
2219 self.drag_decl().image = value.to_component()?;
2220 self
2221 }
2222 "drop_types" => {
2223 self.drag_decl().drop_types = value.to_str()?.to_string();
2224 self
2225 }
2226 "tab_stop" => self.set_tab_stop(value.to_bool()?),
2227 "cursor" => self.set_cursor(value.to_enum()?),
2228 "opacity" => self.set_opacity(value.to_f32()?),
2229 "blend_mode" => self.set_blend_mode(value.to_enum()?),
2230 "cache_layer" => self.set_cache_layer(value.to_bool()?),
2231 "rotation" => self.set_rotation(value.to_f32()?),
2232 "scale" => self.set_scale(value.to_f32()?),
2233 "translate_x" => self.set_translate(PointF::new(value.to_f32()?, self.translate.y)),
2234 "translate_y" => self.set_translate(PointF::new(self.translate.x, value.to_f32()?)),
2235 "aspect_ratio" => self.set_aspect_ratio(value.to_f32()?),
2236 "max_width" => self.set_max_width(value.to_f32()?),
2237 "min_width" => self.set_min_width(value.to_f32()?),
2238 "min_height" => self.set_min_height(value.to_f32()?),
2239 "max_height" => self.set_max_height(value.to_f32()?),
2240 "self_align" => self.set_self_align(value.to_enum()?),
2241 "auto_size" => self.set_auto_size(value.to_bool()?),
2242 "column_span" => self.set_column_span(value.to_f64()?.clamp(1.0, 64.0) as u32),
2243 "grid_row" => {
2244 self.grid_row = value.to_f64()?.clamp(-1.0, 4096.0) as i16;
2245 self
2246 }
2247 "grid_column" => {
2248 self.grid_column = value.to_f64()?.clamp(-1.0, 4096.0) as i16;
2249 self
2250 }
2251 "row_span" => self.set_row_span(value.to_f64()?.clamp(1.0, 64.0) as u32),
2252 "grow" => self.set_grow(value.to_f32()?),
2253 "shadow" => self.set_shadow(crate::prop::PropType::from_value(value)?),
2254 "style" => self.set_style(value.to_str()?),
2255 "fill" => {
2256 self.colors.fill = crate::prop::PropType::from_value(value)?;
2257 self
2258 }
2259 "border_color" => {
2260 self.colors.border = crate::prop::PropType::from_value(value)?;
2261 self
2262 }
2263 "text_color" => {
2264 self.colors.text = crate::prop::PropType::from_value(value)?;
2265 self
2266 }
2267 "accent_color" => {
2268 self.colors.accent = crate::prop::PropType::from_value(value)?;
2269 self
2270 }
2271 "success_color" => {
2272 self.colors.success = crate::prop::PropType::from_value(value)?;
2273 self
2274 }
2275 "warning_color" => {
2276 self.colors.warning = crate::prop::PropType::from_value(value)?;
2277 self
2278 }
2279 "danger_color" => {
2280 self.colors.danger = crate::prop::PropType::from_value(value)?;
2281 self
2282 }
2283 "font_family" => {
2284 self.font.family = value.to_str()?.to_string();
2285 self
2286 }
2287 "font_size" => {
2288 self.font.size = crate::prop::PropType::from_value(value)?;
2289 self
2290 }
2291 "font_weight" => {
2292 self.font.weight = font_weight_named(value.to_str()?)?;
2293 self
2294 }
2295 "font_italic" => {
2296 self.font.italic = value.to_bool()?;
2297 self
2298 }
2299 "font_underline" => {
2300 self.font.underline = value.to_bool()?;
2301 self
2302 }
2303 "font_strikeout" => {
2304 self.font.strikeout = value.to_bool()?;
2305 self
2306 }
2307 "theme" => self.set_theme_name(value.to_str()?),
2308 "hint" => self.set_hint(value.to_str()?),
2309 "tag" => self.set_tag(value.to_i64()?),
2310 "tag_string" => self.set_tag_string(value.to_str()?),
2311 "accessible_name" => self.set_accessible_name(value.to_str()?),
2312 "popup_menu" => {
2313 self.popup_menu = value.to_component()?;
2314 self
2315 }
2316 _ => return Err(Error::UnknownProperty(name.to_string())),
2317 };
2318 Ok(())
2319 }
2320}
2321
2322pub const FONT_WEIGHTS: [&str; 8] = ["default", "thin", "light", "normal", "medium", "semibold", "bold", "black"];
2324
2325fn font_weight_named(name: &str) -> Result<Option<crate::canvas::FontWeight>> {
2326 use crate::canvas::FontWeight::*;
2327 let all = [Thin, Light, Normal, Medium, SemiBold, Bold, Black];
2328 match FONT_WEIGHTS.iter().position(|n| n.eq_ignore_ascii_case(name)) {
2329 Some(0) => Ok(None),
2330 Some(i) => Ok(Some(all[i - 1])),
2331 None => Err(Error::invalid(format!("valor '{name}' inválido; use um de: {}", FONT_WEIGHTS.join(", ")))),
2332 }
2333}
2334
2335#[derive(Clone, Debug, Default, PartialEq)]
2339pub struct FontOverride {
2340 pub family: String,
2342 pub size: Option<f32>,
2344 pub weight: Option<crate::canvas::FontWeight>,
2346 pub italic: bool,
2348 pub underline: bool,
2350 pub strikeout: bool,
2352}
2353
2354impl FontOverride {
2355 pub fn is_empty(&self) -> bool {
2356 *self == Self::default()
2357 }
2358
2359 pub fn over(&self, parent: &FontOverride) -> FontOverride {
2361 FontOverride {
2362 family: if self.family.is_empty() { parent.family.clone() } else { self.family.clone() },
2363 size: self.size.or(parent.size),
2364 weight: self.weight.or(parent.weight),
2365 italic: self.italic || parent.italic,
2366 underline: self.underline || parent.underline,
2367 strikeout: self.strikeout || parent.strikeout,
2368 }
2369 }
2370
2371 pub fn apply(&self, font: &mut crate::canvas::FontSpec) {
2373 if !self.family.is_empty() {
2374 font.family = self.family.clone();
2375 }
2376 if let Some(size) = self.size.filter(|s| *s > 0.0) {
2377 font.size = size;
2378 }
2379 if let Some(weight) = self.weight {
2380 font.weight = weight;
2381 }
2382 font.italic |= self.italic;
2383 font.underline |= self.underline;
2384 font.strikeout |= self.strikeout;
2385 }
2386}
2387
2388impl ControlBase {
2389 pub fn font(&self) -> &FontOverride {
2391 &self.font
2392 }
2393
2394 pub fn set_font(&mut self, font: FontOverride) -> &mut Self {
2395 self.font = font;
2396 self
2397 }
2398}
2399
2400#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
2406pub struct ColorOverride {
2407 pub fill: Option<crate::Color>,
2409 pub border: Option<crate::Color>,
2411 pub text: Option<crate::Color>,
2413 pub accent: Option<crate::Color>,
2416 pub success: Option<crate::Color>,
2419 pub warning: Option<crate::Color>,
2421 pub danger: Option<crate::Color>,
2423}
2424
2425impl ColorOverride {
2426 pub fn is_empty(&self) -> bool {
2427 *self == Self::default()
2428 }
2429
2430 pub(crate) fn recolors_theme(&self) -> bool {
2432 !self.is_empty()
2433 }
2434
2435 pub(crate) fn apply_theme(&self, theme: &crate::Theme) -> crate::Theme {
2437 use crate::Color;
2438 let mut t = theme.clone();
2439 let mut set = |name: &str, c: Color| {
2440 t.colors.insert(name.to_string(), c);
2441 };
2442 if let Some(a) = self.accent {
2443 let dark = luminance(a) < 0.5;
2444 set("primary", a);
2445 set("primary_hover", a.lerp(if dark { Color::WHITE } else { Color::BLACK }, 0.12));
2446 set("primary_pressed", a.lerp(if dark { Color::BLACK } else { Color::BLACK }, 0.15));
2447 set("on_primary", if luminance(a) < 0.6 { Color::WHITE } else { Color::BLACK });
2448 set("focus_ring", a);
2449 set("selection", a.with_opacity(0.25));
2450 set("primary_soft", a.with_opacity(0.1));
2451 set("primary_container", a.lerp(Color::WHITE, 0.82));
2452 }
2453 if let Some(c) = self.fill {
2454 let toward = if luminance(c) < 0.5 { Color::WHITE } else { Color::BLACK };
2456 set("surface", c);
2457 set("background", c);
2458 set("surface_2", c.lerp(toward.with_opacity(c.a as f32 / 255.0), 0.06));
2459 }
2460 if let Some(c) = self.text {
2461 set("text", c);
2462 set("text_muted", c.with_opacity(0.65));
2463 for on in ["on_primary", "on_danger", "on_success", "on_primary_container"] {
2464 set(on, c);
2465 }
2466 }
2467 if let Some(c) = self.border {
2468 let lines = theme.colors.get("grid_line").copied().unwrap_or_else(|| theme.color("border"));
2473 set("grid_line", lines);
2474 set("border", c);
2475 set("track", c);
2476 }
2477 for (token, color) in [("success", self.success), ("warning", self.warning), ("danger", self.danger)] {
2478 if let Some(c) = color {
2479 set(token, c);
2480 set(&format!("{token}_soft"), c.with_opacity(0.1));
2481 set(&format!("{token}_hover"), c.lerp(Color::WHITE, 0.12));
2482 set(&format!("{token}_pressed"), c.lerp(Color::BLACK, 0.15));
2483 if token == "success" {
2484 set("meter_low", c);
2485 } else if token == "danger" {
2486 set("meter_high", c);
2487 } else {
2488 set("meter_mid", c);
2489 }
2490 }
2491 }
2492 t
2493 }
2494}
2495
2496pub(crate) fn luminance(c: crate::Color) -> f32 {
2498 (0.299 * c.r as f32 + 0.587 * c.g as f32 + 0.114 * c.b as f32) / 255.0
2499}
2500
2501#[derive(Clone, Copy, Debug, PartialEq)]
2503pub struct Connection {
2504 pub from: ComponentId,
2505 pub from_at: (f32, f32),
2507 pub to: ComponentId,
2508 pub to_at: (f32, f32),
2509}
2510
2511impl Connection {
2512 pub const STUB: f32 = 16.0;
2514
2515 fn normal(at: (f32, f32)) -> PointF {
2517 let (x, y) = at;
2518 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))];
2519 d.iter().min_by(|a, b| a.0.total_cmp(&b.0)).map_or(PointF::new(1.0, 0.0), |d| d.1)
2520 }
2521
2522 pub fn route(&self, from: RectF, to: RectF) -> Vec<PointF> {
2525 let p0 = PointF::new(from.x + from.width * self.from_at.0, from.y + from.height * self.from_at.1);
2526 let p1 = PointF::new(to.x + to.width * self.to_at.0, to.y + to.height * self.to_at.1);
2527 let (n0, n1) = (Self::normal(self.from_at), Self::normal(self.to_at));
2528 let s0 = PointF::new(p0.x + n0.x * Self::STUB, p0.y + n0.y * Self::STUB);
2529 let s1 = PointF::new(p1.x + n1.x * Self::STUB, p1.y + n1.y * Self::STUB);
2530 let mut points = vec![p0, s0];
2531 if n0.x != 0.0 {
2532 let mx = (s0.x + s1.x) / 2.0;
2534 points.push(PointF::new(mx, s0.y));
2535 points.push(PointF::new(mx, s1.y));
2536 } else {
2537 let my = (s0.y + s1.y) / 2.0;
2538 points.push(PointF::new(s0.x, my));
2539 points.push(PointF::new(s1.x, my));
2540 }
2541 points.push(s1);
2542 points.push(p1);
2543 points.dedup_by(|a, b| (a.x - b.x).abs() < 0.01 && (a.y - b.y).abs() < 0.01);
2544 points
2545 }
2546}
2547
2548#[derive(Clone, Debug, Default, PartialEq)]
2550pub struct DragDecl {
2551 pub data: String,
2554 pub label: String,
2556 pub drop_types: String,
2559 pub image: Option<ComponentId>,
2561}
2562
2563#[derive(Clone, Debug, Default)]
2565struct RareTexts {
2566 tag_string: Box<str>,
2568 accessible_name: Box<str>,
2571}