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"),
1315 PropInfo::new("on_key_press", PropKind::Event, "Events"),
1316 PropInfo::new("on_key_up", PropKind::Event, "Events").event_arg(crate::EventArg::Key),
1317 PropInfo::new("on_enter", PropKind::Event, "Events").event_arg(crate::EventArg::None),
1318 PropInfo::new("on_exit", PropKind::Event, "Events").event_arg(crate::EventArg::None),
1319 PropInfo::new("on_resize", PropKind::Event, "Events").event_arg(crate::EventArg::None),
1320 PropInfo::new("on_drag_start", PropKind::Event, "Events"),
1321 PropInfo::new("on_drag_over", PropKind::Event, "Events"),
1322 PropInfo::new("on_drag_move", PropKind::Event, "Events").event_arg(crate::EventArg::Pointer),
1323 PropInfo::new("on_drag_leave", PropKind::Event, "Events").event_arg(crate::EventArg::Value(PropKind::String)),
1324 PropInfo::new("on_drag_drop", PropKind::Event, "Events").event_arg(crate::EventArg::Value(PropKind::String)),
1325 PropInfo::new("on_drag_end", PropKind::Event, "Events").event_arg(crate::EventArg::Value(PropKind::Bool)),
1326 ];
1327
1328 pub fn new(width: f32, height: f32) -> Self {
1329 Self {
1330 left: 0.0,
1331 top: 0.0,
1332 width,
1333 height,
1334 margins: Bounds::ZERO,
1335 padding: Bounds::ZERO,
1336 align: Align::None,
1337 anchors: Anchors::default(),
1338 visible: true,
1339 enabled: true,
1340 hit_test: true,
1341 clip_children: false,
1342 inherit_state: false,
1343 translatable: true,
1344 captures_wheel: false,
1345 captures_gesture: false,
1346 can_focus: false,
1347 draggable: false,
1348 accepts_drops: false,
1349 drag: None,
1350 tab_stop: true,
1351 pan_on_touch: true,
1352 hover_within: false,
1353 popup_menu: None,
1354 cursor: CursorShape::Default,
1355 opacity: 1.0,
1356 blend_mode: crate::BlendMode::Normal,
1357 rotation: 0.0,
1358 scale: 1.0,
1359 translate: PointF::ZERO,
1360 cache_layer: false,
1361 aspect_ratio: 0.0,
1362 max_width: 0.0,
1363 min_width: 0.0,
1364 min_height: 0.0,
1365 max_height: 0.0,
1366 self_align: SelfAlign::Stretch,
1367 auto_size: false,
1368 column_span: 1,
1369 grid_row: -1,
1370 grid_column: -1,
1371 row_span: 1,
1372 grow: 0.0,
1373 text_scale: 1.0,
1374 spacing_scale: 1.0,
1375 shadow: None,
1376 tag: 0,
1377 rare: None,
1378 style: String::new(),
1379 theme: String::new(),
1380 hint: String::new(),
1381 state: ControlState::default(),
1382 bounds: RectF::new(0.0, 0.0, width, height),
1383 anchor_ref: None,
1384 follow: None,
1385 design_hidden: false,
1386 design_only: false,
1387 keep_left_to_right: false,
1388 colors: ColorOverride::default(),
1389 font: FontOverride::default(),
1390 scroll_offset: PointF::ZERO,
1391 laid_out_scroll: PointF::ZERO,
1392 content_size: SizeF::ZERO,
1393 safe_area: Bounds::default(),
1394 }
1395 }
1396
1397 pub fn left(&self) -> f32 {
1400 self.left
1401 }
1402
1403 pub fn top(&self) -> f32 {
1404 self.top
1405 }
1406
1407 pub fn width(&self) -> f32 {
1408 self.width
1409 }
1410
1411 pub fn height(&self) -> f32 {
1412 self.height
1413 }
1414
1415 pub fn position(&self) -> PointF {
1416 PointF::new(self.left, self.top)
1417 }
1418
1419 pub fn size(&self) -> SizeF {
1420 SizeF::new(self.width, self.height)
1421 }
1422
1423 pub fn margins(&self) -> Bounds {
1426 if self.spacing_scale == 1.0 { self.margins } else { self.margins.scaled(self.spacing_scale) }
1427 }
1428
1429 pub fn padding(&self) -> Bounds {
1431 if self.spacing_scale == 1.0 { self.padding } else { self.padding.scaled(self.spacing_scale) }
1432 }
1433
1434 pub fn align(&self) -> Align {
1435 self.align
1436 }
1437
1438 pub fn anchors(&self) -> Anchors {
1439 self.anchors
1440 }
1441
1442 pub fn visible(&self) -> bool {
1443 self.visible
1444 }
1445
1446 pub fn design_only(&self) -> bool {
1448 self.design_only
1449 }
1450
1451 pub fn colors(&self) -> ColorOverride {
1453 self.colors
1454 }
1455
1456 pub fn set_colors(&mut self, colors: ColorOverride) -> &mut Self {
1457 self.colors = colors;
1458 self
1459 }
1460
1461 pub fn set_design_only(&mut self, on: bool) -> &mut Self {
1462 self.design_only = on;
1463 self
1464 }
1465
1466 pub fn keep_left_to_right(&self) -> bool {
1468 self.keep_left_to_right
1469 }
1470
1471 pub fn set_keep_left_to_right(&mut self, on: bool) -> &mut Self {
1472 self.keep_left_to_right = on;
1473 self
1474 }
1475
1476 pub fn enabled(&self) -> bool {
1477 self.enabled
1478 }
1479
1480 pub fn hit_test(&self) -> bool {
1481 self.hit_test
1482 }
1483
1484 pub fn translatable(&self) -> bool {
1485 self.translatable
1486 }
1487
1488 pub fn set_translatable(&mut self, v: bool) -> &mut Self {
1489 self.translatable = v;
1490 self
1491 }
1492
1493 pub fn inherit_state(&self) -> bool {
1494 self.inherit_state
1495 }
1496
1497 pub fn set_inherit_state(&mut self, v: bool) -> &mut Self {
1498 self.inherit_state = v;
1499 self
1500 }
1501
1502 pub fn clip_children(&self) -> bool {
1503 self.clip_children
1504 }
1505
1506 pub fn captures_wheel(&self) -> bool {
1507 self.captures_wheel
1508 }
1509
1510 pub fn captures_gesture(&self) -> bool {
1511 self.captures_gesture
1512 }
1513
1514 pub fn draggable(&self) -> bool {
1519 self.draggable
1520 }
1521
1522 pub fn set_draggable(&mut self, v: bool) -> &mut Self {
1523 self.draggable = v;
1524 self
1525 }
1526
1527 pub fn accepts_drops(&self) -> bool {
1530 self.accepts_drops
1531 }
1532
1533 pub fn set_accepts_drops(&mut self, v: bool) -> &mut Self {
1534 self.accepts_drops = v;
1535 self
1536 }
1537
1538 pub fn drag_data(&self) -> &str {
1540 self.drag.as_ref().map_or("", |d| d.data.as_str())
1541 }
1542
1543 pub fn drag_label(&self) -> &str {
1544 self.drag.as_ref().map_or("", |d| d.label.as_str())
1545 }
1546
1547 pub fn drag_image(&self) -> Option<ComponentId> {
1549 self.drag.as_ref().and_then(|d| d.image)
1550 }
1551
1552 pub(crate) fn forget_drag_image(&mut self, doomed: &[ComponentId]) {
1554 if let Some(d) = self.drag.as_mut().filter(|d| d.image.is_some_and(|i| doomed.contains(&i))) {
1555 d.image = None;
1556 }
1557 }
1558
1559 pub fn drop_types(&self) -> &str {
1561 self.drag.as_ref().map_or("", |d| d.drop_types.as_str())
1562 }
1563
1564 fn drag_decl(&mut self) -> &mut DragDecl {
1565 self.drag.get_or_insert_with(Default::default)
1566 }
1567
1568 pub fn can_focus(&self) -> bool {
1569 self.can_focus
1570 }
1571
1572 pub fn tab_stop(&self) -> bool {
1574 self.tab_stop
1575 }
1576
1577 pub fn popup_menu(&self) -> Option<ComponentId> {
1579 self.popup_menu
1580 }
1581
1582 pub fn set_popup_menu(&mut self, menu: Option<ComponentId>) -> &mut Self {
1583 self.popup_menu = menu;
1584 self
1585 }
1586
1587 pub fn pan_on_touch(&self) -> bool {
1589 self.pan_on_touch
1590 }
1591
1592 pub fn hover_within(&self) -> bool {
1594 self.hover_within
1595 }
1596
1597 pub fn set_hover_within(&mut self, v: bool) -> &mut Self {
1601 self.hover_within = v;
1602 self
1603 }
1604
1605 pub fn cursor(&self) -> CursorShape {
1607 self.cursor
1608 }
1609
1610 pub fn opacity(&self) -> f32 {
1611 self.opacity
1612 }
1613
1614 pub fn blend_mode(&self) -> crate::BlendMode {
1616 self.blend_mode
1617 }
1618
1619 pub fn set_blend_mode(&mut self, mode: crate::BlendMode) -> &mut Self {
1620 self.blend_mode = mode;
1621 self
1622 }
1623
1624 pub fn cache_layer(&self) -> bool {
1626 self.cache_layer
1627 }
1628
1629 pub fn set_cache_layer(&mut self, on: bool) -> &mut Self {
1630 self.cache_layer = on;
1631 self
1632 }
1633
1634 pub fn rotation(&self) -> f32 {
1637 self.rotation
1638 }
1639
1640 pub fn scale(&self) -> f32 {
1642 self.scale
1643 }
1644
1645 pub fn inner_size(&self) -> SizeF {
1648 let s = self.scale;
1649 if s == 1.0 { self.bounds.size() } else { SizeF::new(self.bounds.width / s, self.bounds.height / s) }
1650 }
1651
1652 pub fn shadow(&self) -> Option<crate::canvas::Shadow> {
1653 self.shadow
1654 }
1655
1656 pub fn aspect_ratio(&self) -> f32 {
1660 self.aspect_ratio
1661 }
1662
1663 pub fn set_aspect_ratio(&mut self, ratio: f32) -> &mut Self {
1664 self.aspect_ratio = if ratio.is_finite() { ratio.max(0.0) } else { 0.0 };
1665 self
1666 }
1667
1668 pub fn max_width(&self) -> f32 {
1672 self.max_width
1673 }
1674
1675 pub fn set_max_width(&mut self, width: f32) -> &mut Self {
1676 self.max_width = if width.is_finite() { width.max(0.0) } else { 0.0 };
1677 self
1678 }
1679
1680 pub fn min_width(&self) -> f32 {
1685 self.min_width
1686 }
1687
1688 pub fn set_min_width(&mut self, width: f32) -> &mut Self {
1689 self.min_width = if width.is_finite() { width.max(0.0) } else { 0.0 };
1690 self
1691 }
1692
1693 pub fn min_height(&self) -> f32 {
1695 self.min_height
1696 }
1697
1698 pub fn set_min_height(&mut self, height: f32) -> &mut Self {
1699 self.min_height = if height.is_finite() { height.max(0.0) } else { 0.0 };
1700 self
1701 }
1702
1703 pub fn max_height(&self) -> f32 {
1705 self.max_height
1706 }
1707
1708 pub fn set_max_height(&mut self, height: f32) -> &mut Self {
1709 self.max_height = if height.is_finite() { height.max(0.0) } else { 0.0 };
1710 self
1711 }
1712
1713 pub fn clamp_width(&self, available: f32) -> f32 {
1716 let w = if self.max_width > 0.0 { available.min(self.max_width) } else { available };
1717 w.max(self.min_width)
1718 }
1719
1720 pub fn clamp_height(&self, height: f32) -> f32 {
1722 let h = if self.max_height > 0.0 { height.min(self.max_height) } else { height };
1723 h.max(self.min_height)
1724 }
1725
1726 pub fn self_align(&self) -> SelfAlign {
1729 self.self_align
1730 }
1731
1732 pub fn set_self_align(&mut self, align: SelfAlign) -> &mut Self {
1733 self.self_align = align;
1734 self
1735 }
1736
1737 pub fn band_width(&self, available: f32) -> f32 {
1741 match self.self_align {
1742 SelfAlign::Stretch => self.clamp_width(available),
1743 _ if self.max_width > 0.0 => self.clamp_width(available),
1744 _ => self.clamp_width(self.width),
1745 }
1746 }
1747
1748 pub fn band_height(&self, available: f32) -> f32 {
1751 match self.self_align {
1752 SelfAlign::Stretch => self.clamp_height(available),
1753 _ if self.max_height > 0.0 => self.clamp_height(available),
1754 _ => self.clamp_height(self.height),
1755 }
1756 }
1757
1758 pub fn band_offset(&self, available: f32, size: f32) -> f32 {
1761 let spare = (available - size).max(0.0);
1762 match self.self_align {
1763 SelfAlign::Start => 0.0,
1764 SelfAlign::End => spare,
1765 SelfAlign::Stretch | SelfAlign::Center => spare / 2.0,
1766 }
1767 }
1768
1769 pub fn auto_size(&self) -> bool {
1774 self.auto_size
1775 }
1776
1777 pub fn set_auto_size(&mut self, on: bool) -> &mut Self {
1778 self.auto_size = on;
1779 self
1780 }
1781
1782 pub fn column_span(&self) -> u32 {
1785 self.column_span.max(1)
1786 }
1787
1788 pub fn grid_cell(&self) -> Option<(u32, u32)> {
1790 (self.grid_row >= 0 && self.grid_column >= 0).then(|| (self.grid_row as u32, self.grid_column as u32))
1791 }
1792
1793 pub fn set_grid_cell(&mut self, cell: Option<(u32, u32)>) -> &mut Self {
1794 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));
1795 self.grid_row = r;
1796 self.grid_column = c;
1797 self
1798 }
1799
1800 pub fn row_span(&self) -> u32 {
1802 u32::from(self.row_span.max(1))
1803 }
1804
1805 pub fn set_row_span(&mut self, span: u32) -> &mut Self {
1806 self.row_span = span.clamp(1, 64) as u16;
1807 self
1808 }
1809
1810 pub fn grow(&self) -> f32 {
1811 self.grow
1812 }
1813
1814 pub fn set_grow(&mut self, grow: f32) -> &mut Self {
1815 self.grow = grow.max(0.0);
1816 self
1817 }
1818
1819 pub fn set_column_span(&mut self, span: u32) -> &mut Self {
1820 self.column_span = span.max(1);
1821 self
1822 }
1823
1824 pub fn text_scale(&self) -> f32 {
1826 self.text_scale
1827 }
1828
1829 pub fn spacing_scale(&self) -> f32 {
1831 self.spacing_scale
1832 }
1833
1834 pub fn tag(&self) -> i64 {
1835 self.tag
1836 }
1837
1838 pub fn accessible_name(&self) -> &str {
1841 self.rare.as_ref().map_or("", |r| &r.accessible_name)
1842 }
1843
1844 pub fn set_accessible_name(&mut self, v: &str) -> &mut Self {
1845 self.rare_mut(|r| r.accessible_name = v.into());
1846 self
1847 }
1848
1849 fn rare_mut(&mut self, change: impl FnOnce(&mut RareTexts)) {
1850 let rare = self.rare.get_or_insert_with(Default::default);
1851 change(rare);
1852 if rare.tag_string.is_empty() && rare.accessible_name.is_empty() {
1853 self.rare = None;
1854 }
1855 }
1856
1857 pub fn tag_string(&self) -> &str {
1858 self.rare.as_ref().map_or("", |r| &r.tag_string)
1859 }
1860
1861 pub fn style(&self) -> &str {
1863 &self.style
1864 }
1865
1866 pub fn theme_name(&self) -> &str {
1868 &self.theme
1869 }
1870
1871 pub fn set_theme_name(&mut self, v: impl Into<String>) -> &mut Self {
1872 self.theme = v.into();
1873 self
1874 }
1875
1876 pub fn hint(&self) -> &str {
1878 &self.hint
1879 }
1880
1881 pub fn set_hint(&mut self, v: impl Into<String>) -> &mut Self {
1882 self.hint = v.into();
1883 self
1884 }
1885
1886 pub fn state(&self) -> ControlState {
1887 self.state
1888 }
1889
1890 pub fn bounds(&self) -> RectF {
1892 self.bounds
1893 }
1894
1895 pub fn scroll_offset(&self) -> PointF {
1897 self.scroll_offset
1898 }
1899
1900 pub fn laid_out_scroll(&self) -> PointF {
1903 self.laid_out_scroll
1904 }
1905
1906 pub fn set_scroll_offset(&mut self, offset: PointF) -> &mut Self {
1909 self.scroll_offset = offset;
1910 self
1911 }
1912
1913 pub fn content_size(&self) -> SizeF {
1916 self.content_size
1917 }
1918
1919 pub fn set_left(&mut self, v: f32) -> &mut Self {
1926 if self.left != v {
1927 self.left = v;
1928 self.anchor_ref = None;
1929 }
1930 self
1931 }
1932
1933 pub fn set_top(&mut self, v: f32) -> &mut Self {
1934 if self.top != v {
1935 self.top = v;
1936 self.anchor_ref = None;
1937 }
1938 self
1939 }
1940
1941 pub fn set_position(&mut self, left: f32, top: f32) -> &mut Self {
1942 self.set_left(left).set_top(top)
1943 }
1944
1945 pub fn set_width(&mut self, v: f32) -> &mut Self {
1946 if self.width != v.max(0.0) {
1947 self.width = v.max(0.0);
1948 self.anchor_ref = None;
1949 }
1950 self
1951 }
1952
1953 pub fn set_height(&mut self, v: f32) -> &mut Self {
1954 if self.height != v.max(0.0) {
1955 self.height = v.max(0.0);
1956 self.anchor_ref = None;
1957 }
1958 self
1959 }
1960
1961 pub(crate) fn set_measured_width(&mut self, v: f32) {
1963 self.width = v.max(0.0);
1964 if let Some(r) = self.anchor_ref.as_mut() {
1965 r.rect.width = self.width;
1966 }
1967 }
1968
1969 pub(crate) fn set_measured_height(&mut self, v: f32) {
1972 self.height = v.max(0.0);
1973 if let Some(r) = self.anchor_ref.as_mut() {
1974 r.rect.height = self.height;
1975 }
1976 }
1977
1978 pub fn set_size(&mut self, width: f32, height: f32) -> &mut Self {
1979 self.set_width(width).set_height(height)
1980 }
1981
1982 pub fn set_rect(&mut self, left: f32, top: f32, width: f32, height: f32) -> &mut Self {
1984 self.set_position(left, top).set_size(width, height)
1985 }
1986
1987 pub fn set_margins(&mut self, v: impl Into<Bounds>) -> &mut Self {
1988 self.margins = v.into();
1989 self
1990 }
1991
1992 pub fn set_padding(&mut self, v: impl Into<Bounds>) -> &mut Self {
1993 self.padding = v.into();
1994 self
1995 }
1996
1997 pub fn set_align(&mut self, v: Align) -> &mut Self {
1998 self.align = v;
1999 self.anchor_ref = None;
2000 self
2001 }
2002
2003 pub fn set_anchors(&mut self, v: Anchors) -> &mut Self {
2004 self.anchors = v;
2005 self.anchor_ref = None;
2006 self
2007 }
2008
2009 pub fn set_visible(&mut self, v: bool) -> &mut Self {
2010 self.visible = v;
2011 self
2012 }
2013
2014 pub fn set_enabled(&mut self, v: bool) -> &mut Self {
2015 self.enabled = v;
2016 self
2017 }
2018
2019 pub fn set_hit_test(&mut self, v: bool) -> &mut Self {
2020 self.hit_test = v;
2021 self
2022 }
2023
2024 pub fn set_clip_children(&mut self, v: bool) -> &mut Self {
2025 self.clip_children = v;
2026 self
2027 }
2028
2029 pub fn set_captures_wheel(&mut self, v: bool) -> &mut Self {
2030 self.captures_wheel = v;
2031 self
2032 }
2033
2034 pub fn set_captures_gesture(&mut self, v: bool) -> &mut Self {
2035 self.captures_gesture = v;
2036 self
2037 }
2038
2039 pub fn set_can_focus(&mut self, v: bool) -> &mut Self {
2040 self.can_focus = v;
2041 self
2042 }
2043
2044 pub fn set_pan_on_touch(&mut self, v: bool) -> &mut Self {
2048 self.pan_on_touch = v;
2049 self
2050 }
2051
2052 pub fn set_tab_stop(&mut self, v: bool) -> &mut Self {
2053 self.tab_stop = v;
2054 self
2055 }
2056
2057 pub fn set_cursor(&mut self, v: CursorShape) -> &mut Self {
2058 self.cursor = v;
2059 self
2060 }
2061
2062 pub fn set_opacity(&mut self, v: f32) -> &mut Self {
2063 self.opacity = v.clamp(0.0, 1.0);
2064 self
2065 }
2066
2067 pub fn translate(&self) -> PointF {
2069 self.translate
2070 }
2071
2072 pub fn set_translate(&mut self, offset: PointF) -> &mut Self {
2073 self.translate = if offset.x.is_finite() && offset.y.is_finite() { offset } else { PointF::ZERO };
2074 self
2075 }
2076
2077 pub fn set_scale(&mut self, scale: f32) -> &mut Self {
2079 self.scale = if scale.is_finite() && scale > 0.0 { scale.clamp(0.05, 20.0) } else { 1.0 };
2080 self
2081 }
2082
2083 pub fn set_rotation(&mut self, degrees: f32) -> &mut Self {
2084 self.rotation = if degrees.is_finite() { degrees % 360.0 } else { 0.0 };
2085 self
2086 }
2087
2088 pub fn set_shadow(&mut self, shadow: Option<crate::canvas::Shadow>) -> &mut Self {
2089 self.shadow = shadow;
2090 self
2091 }
2092
2093 pub fn set_tag(&mut self, v: i64) -> &mut Self {
2094 self.tag = v;
2095 self
2096 }
2097
2098 pub fn set_tag_string(&mut self, v: &str) -> &mut Self {
2099 self.rare_mut(|r| r.tag_string = v.into());
2100 self
2101 }
2102
2103 pub fn set_style(&mut self, v: impl Into<String>) -> &mut Self {
2104 self.style = v.into();
2105 self
2106 }
2107
2108 pub fn state_mut(&mut self) -> &mut ControlState {
2111 &mut self.state
2112 }
2113
2114 pub fn get_prop(&self, name: &str) -> Option<PropValue> {
2117 Some(match name {
2118 "left" => self.left.into(),
2119 "top" => self.top.into(),
2120 "width" => self.width.into(),
2121 "height" => self.height.into(),
2122 "align" => self.align.into(),
2123 "anchors" => self.anchors.into(),
2124 "margins" => self.margins.into(),
2125 "padding" => self.padding.into(),
2126 "visible" => self.visible.into(),
2127 "enabled" => self.enabled.into(),
2128 "hit_test" => self.hit_test.into(),
2129 "clip_children" => self.clip_children.into(),
2130 "inherit_state" => self.inherit_state.into(),
2131 "translate" => self.translatable.into(),
2132 "captures_wheel" => self.captures_wheel.into(),
2133 "captures_gesture" => self.captures_gesture.into(),
2134 "can_focus" => self.can_focus.into(),
2135 "draggable" => self.draggable.into(),
2136 "accepts_drops" => self.accepts_drops.into(),
2137 "drag_data" => self.drag_data().into(),
2138 "drag_label" => self.drag_label().into(),
2139 "drag_image" => PropValue::Component(self.drag_image()),
2140 "drop_types" => self.drop_types().into(),
2141 "tab_stop" => self.tab_stop.into(),
2142 "cursor" => PropValue::enum_value(self.cursor),
2143 "opacity" => self.opacity.into(),
2144 "blend_mode" => PropValue::enum_value(self.blend_mode),
2145 "cache_layer" => self.cache_layer.into(),
2146 "rotation" => self.rotation.into(),
2147 "scale" => self.scale.into(),
2148 "translate_x" => self.translate.x.into(),
2149 "translate_y" => self.translate.y.into(),
2150 "aspect_ratio" => self.aspect_ratio.into(),
2151 "max_width" => self.max_width.into(),
2152 "min_width" => self.min_width.into(),
2153 "min_height" => self.min_height.into(),
2154 "max_height" => self.max_height.into(),
2155 "self_align" => PropValue::enum_value(self.self_align),
2156 "auto_size" => self.auto_size.into(),
2157 "column_span" => (self.column_span() as i64).into(),
2158 "grid_row" => i64::from(self.grid_row).into(),
2159 "grid_column" => i64::from(self.grid_column).into(),
2160 "row_span" => (self.row_span() as i64).into(),
2161 "grow" => f64::from(self.grow).into(),
2162 "shadow" => crate::prop::PropType::to_value(&self.shadow),
2163 "style" => self.style.clone().into(),
2164 "fill" => crate::prop::PropType::to_value(&self.colors.fill),
2165 "border_color" => crate::prop::PropType::to_value(&self.colors.border),
2166 "text_color" => crate::prop::PropType::to_value(&self.colors.text),
2167 "accent_color" => crate::prop::PropType::to_value(&self.colors.accent),
2168 "success_color" => crate::prop::PropType::to_value(&self.colors.success),
2169 "warning_color" => crate::prop::PropType::to_value(&self.colors.warning),
2170 "danger_color" => crate::prop::PropType::to_value(&self.colors.danger),
2171 "font_family" => self.font.family.clone().into(),
2172 "font_size" => crate::prop::PropType::to_value(&self.font.size),
2173 "font_weight" => PropValue::Enum(FONT_WEIGHTS[self.font.weight.map_or(0, |w| w as usize + 1)].into()),
2174 "font_italic" => self.font.italic.into(),
2175 "font_underline" => self.font.underline.into(),
2176 "font_strikeout" => self.font.strikeout.into(),
2177 "theme" => self.theme.clone().into(),
2178 "hint" => self.hint.clone().into(),
2179 "tag" => self.tag.into(),
2180 "tag_string" => self.tag_string().to_string().into(),
2181 "accessible_name" => self.accessible_name().to_string().into(),
2182 "popup_menu" => PropValue::Component(self.popup_menu),
2183 _ => return None,
2184 })
2185 }
2186
2187 pub fn set_prop(&mut self, name: &str, value: PropValue) -> Result<()> {
2188 match name {
2189 "left" => self.set_left(value.to_f32()?),
2190 "top" => self.set_top(value.to_f32()?),
2191 "width" => self.set_width(value.to_f32()?),
2192 "height" => self.set_height(value.to_f32()?),
2193 "align" => self.set_align(value.to_enum()?),
2194 "anchors" => self.set_anchors(value.to_anchors()?),
2195 "margins" => self.set_margins(value.to_bounds()?),
2196 "padding" => self.set_padding(value.to_bounds()?),
2197 "visible" => self.set_visible(value.to_bool()?),
2198 "enabled" => self.set_enabled(value.to_bool()?),
2199 "hit_test" => self.set_hit_test(value.to_bool()?),
2200 "clip_children" => self.set_clip_children(value.to_bool()?),
2201 "inherit_state" => self.set_inherit_state(value.to_bool()?),
2202 "translate" => self.set_translatable(value.to_bool()?),
2203 "captures_wheel" => self.set_captures_wheel(value.to_bool()?),
2204 "captures_gesture" => self.set_captures_gesture(value.to_bool()?),
2205 "can_focus" => self.set_can_focus(value.to_bool()?),
2206 "draggable" => self.set_draggable(value.to_bool()?),
2207 "accepts_drops" => self.set_accepts_drops(value.to_bool()?),
2208 "drag_data" => {
2209 self.drag_decl().data = value.to_str()?.to_string();
2210 self
2211 }
2212 "drag_label" => {
2213 self.drag_decl().label = value.to_str()?.to_string();
2214 self
2215 }
2216 "drag_image" => {
2217 self.drag_decl().image = value.to_component()?;
2218 self
2219 }
2220 "drop_types" => {
2221 self.drag_decl().drop_types = value.to_str()?.to_string();
2222 self
2223 }
2224 "tab_stop" => self.set_tab_stop(value.to_bool()?),
2225 "cursor" => self.set_cursor(value.to_enum()?),
2226 "opacity" => self.set_opacity(value.to_f32()?),
2227 "blend_mode" => self.set_blend_mode(value.to_enum()?),
2228 "cache_layer" => self.set_cache_layer(value.to_bool()?),
2229 "rotation" => self.set_rotation(value.to_f32()?),
2230 "scale" => self.set_scale(value.to_f32()?),
2231 "translate_x" => self.set_translate(PointF::new(value.to_f32()?, self.translate.y)),
2232 "translate_y" => self.set_translate(PointF::new(self.translate.x, value.to_f32()?)),
2233 "aspect_ratio" => self.set_aspect_ratio(value.to_f32()?),
2234 "max_width" => self.set_max_width(value.to_f32()?),
2235 "min_width" => self.set_min_width(value.to_f32()?),
2236 "min_height" => self.set_min_height(value.to_f32()?),
2237 "max_height" => self.set_max_height(value.to_f32()?),
2238 "self_align" => self.set_self_align(value.to_enum()?),
2239 "auto_size" => self.set_auto_size(value.to_bool()?),
2240 "column_span" => self.set_column_span(value.to_f64()?.clamp(1.0, 64.0) as u32),
2241 "grid_row" => {
2242 self.grid_row = value.to_f64()?.clamp(-1.0, 4096.0) as i16;
2243 self
2244 }
2245 "grid_column" => {
2246 self.grid_column = value.to_f64()?.clamp(-1.0, 4096.0) as i16;
2247 self
2248 }
2249 "row_span" => self.set_row_span(value.to_f64()?.clamp(1.0, 64.0) as u32),
2250 "grow" => self.set_grow(value.to_f32()?),
2251 "shadow" => self.set_shadow(crate::prop::PropType::from_value(value)?),
2252 "style" => self.set_style(value.to_str()?),
2253 "fill" => {
2254 self.colors.fill = crate::prop::PropType::from_value(value)?;
2255 self
2256 }
2257 "border_color" => {
2258 self.colors.border = crate::prop::PropType::from_value(value)?;
2259 self
2260 }
2261 "text_color" => {
2262 self.colors.text = crate::prop::PropType::from_value(value)?;
2263 self
2264 }
2265 "accent_color" => {
2266 self.colors.accent = crate::prop::PropType::from_value(value)?;
2267 self
2268 }
2269 "success_color" => {
2270 self.colors.success = crate::prop::PropType::from_value(value)?;
2271 self
2272 }
2273 "warning_color" => {
2274 self.colors.warning = crate::prop::PropType::from_value(value)?;
2275 self
2276 }
2277 "danger_color" => {
2278 self.colors.danger = crate::prop::PropType::from_value(value)?;
2279 self
2280 }
2281 "font_family" => {
2282 self.font.family = value.to_str()?.to_string();
2283 self
2284 }
2285 "font_size" => {
2286 self.font.size = crate::prop::PropType::from_value(value)?;
2287 self
2288 }
2289 "font_weight" => {
2290 self.font.weight = font_weight_named(value.to_str()?)?;
2291 self
2292 }
2293 "font_italic" => {
2294 self.font.italic = value.to_bool()?;
2295 self
2296 }
2297 "font_underline" => {
2298 self.font.underline = value.to_bool()?;
2299 self
2300 }
2301 "font_strikeout" => {
2302 self.font.strikeout = value.to_bool()?;
2303 self
2304 }
2305 "theme" => self.set_theme_name(value.to_str()?),
2306 "hint" => self.set_hint(value.to_str()?),
2307 "tag" => self.set_tag(value.to_i64()?),
2308 "tag_string" => self.set_tag_string(value.to_str()?),
2309 "accessible_name" => self.set_accessible_name(value.to_str()?),
2310 "popup_menu" => {
2311 self.popup_menu = value.to_component()?;
2312 self
2313 }
2314 _ => return Err(Error::UnknownProperty(name.to_string())),
2315 };
2316 Ok(())
2317 }
2318}
2319
2320pub const FONT_WEIGHTS: [&str; 8] = ["default", "thin", "light", "normal", "medium", "semibold", "bold", "black"];
2322
2323fn font_weight_named(name: &str) -> Result<Option<crate::canvas::FontWeight>> {
2324 use crate::canvas::FontWeight::*;
2325 let all = [Thin, Light, Normal, Medium, SemiBold, Bold, Black];
2326 match FONT_WEIGHTS.iter().position(|n| n.eq_ignore_ascii_case(name)) {
2327 Some(0) => Ok(None),
2328 Some(i) => Ok(Some(all[i - 1])),
2329 None => Err(Error::invalid(format!("valor '{name}' inválido; use um de: {}", FONT_WEIGHTS.join(", ")))),
2330 }
2331}
2332
2333#[derive(Clone, Debug, Default, PartialEq)]
2337pub struct FontOverride {
2338 pub family: String,
2340 pub size: Option<f32>,
2342 pub weight: Option<crate::canvas::FontWeight>,
2344 pub italic: bool,
2346 pub underline: bool,
2348 pub strikeout: bool,
2350}
2351
2352impl FontOverride {
2353 pub fn is_empty(&self) -> bool {
2354 *self == Self::default()
2355 }
2356
2357 pub fn over(&self, parent: &FontOverride) -> FontOverride {
2359 FontOverride {
2360 family: if self.family.is_empty() { parent.family.clone() } else { self.family.clone() },
2361 size: self.size.or(parent.size),
2362 weight: self.weight.or(parent.weight),
2363 italic: self.italic || parent.italic,
2364 underline: self.underline || parent.underline,
2365 strikeout: self.strikeout || parent.strikeout,
2366 }
2367 }
2368
2369 pub fn apply(&self, font: &mut crate::canvas::FontSpec) {
2371 if !self.family.is_empty() {
2372 font.family = self.family.clone();
2373 }
2374 if let Some(size) = self.size.filter(|s| *s > 0.0) {
2375 font.size = size;
2376 }
2377 if let Some(weight) = self.weight {
2378 font.weight = weight;
2379 }
2380 font.italic |= self.italic;
2381 font.underline |= self.underline;
2382 font.strikeout |= self.strikeout;
2383 }
2384}
2385
2386impl ControlBase {
2387 pub fn font(&self) -> &FontOverride {
2389 &self.font
2390 }
2391
2392 pub fn set_font(&mut self, font: FontOverride) -> &mut Self {
2393 self.font = font;
2394 self
2395 }
2396}
2397
2398#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
2404pub struct ColorOverride {
2405 pub fill: Option<crate::Color>,
2407 pub border: Option<crate::Color>,
2409 pub text: Option<crate::Color>,
2411 pub accent: Option<crate::Color>,
2414 pub success: Option<crate::Color>,
2417 pub warning: Option<crate::Color>,
2419 pub danger: Option<crate::Color>,
2421}
2422
2423impl ColorOverride {
2424 pub fn is_empty(&self) -> bool {
2425 *self == Self::default()
2426 }
2427
2428 pub(crate) fn recolors_theme(&self) -> bool {
2430 !self.is_empty()
2431 }
2432
2433 pub(crate) fn apply_theme(&self, theme: &crate::Theme) -> crate::Theme {
2435 use crate::Color;
2436 let mut t = theme.clone();
2437 let mut set = |name: &str, c: Color| {
2438 t.colors.insert(name.to_string(), c);
2439 };
2440 if let Some(a) = self.accent {
2441 let dark = luminance(a) < 0.5;
2442 set("primary", a);
2443 set("primary_hover", a.lerp(if dark { Color::WHITE } else { Color::BLACK }, 0.12));
2444 set("primary_pressed", a.lerp(if dark { Color::BLACK } else { Color::BLACK }, 0.15));
2445 set("on_primary", if luminance(a) < 0.6 { Color::WHITE } else { Color::BLACK });
2446 set("focus_ring", a);
2447 set("selection", a.with_opacity(0.25));
2448 set("primary_soft", a.with_opacity(0.1));
2449 set("primary_container", a.lerp(Color::WHITE, 0.82));
2450 }
2451 if let Some(c) = self.fill {
2452 let toward = if luminance(c) < 0.5 { Color::WHITE } else { Color::BLACK };
2454 set("surface", c);
2455 set("background", c);
2456 set("surface_2", c.lerp(toward.with_opacity(c.a as f32 / 255.0), 0.06));
2457 }
2458 if let Some(c) = self.text {
2459 set("text", c);
2460 set("text_muted", c.with_opacity(0.65));
2461 for on in ["on_primary", "on_danger", "on_success", "on_primary_container"] {
2462 set(on, c);
2463 }
2464 }
2465 if let Some(c) = self.border {
2466 let lines = theme.colors.get("grid_line").copied().unwrap_or_else(|| theme.color("border"));
2471 set("grid_line", lines);
2472 set("border", c);
2473 set("track", c);
2474 }
2475 for (token, color) in [("success", self.success), ("warning", self.warning), ("danger", self.danger)] {
2476 if let Some(c) = color {
2477 set(token, c);
2478 set(&format!("{token}_soft"), c.with_opacity(0.1));
2479 set(&format!("{token}_hover"), c.lerp(Color::WHITE, 0.12));
2480 set(&format!("{token}_pressed"), c.lerp(Color::BLACK, 0.15));
2481 if token == "success" {
2482 set("meter_low", c);
2483 } else if token == "danger" {
2484 set("meter_high", c);
2485 } else {
2486 set("meter_mid", c);
2487 }
2488 }
2489 }
2490 t
2491 }
2492}
2493
2494pub(crate) fn luminance(c: crate::Color) -> f32 {
2496 (0.299 * c.r as f32 + 0.587 * c.g as f32 + 0.114 * c.b as f32) / 255.0
2497}
2498
2499#[derive(Clone, Copy, Debug, PartialEq)]
2501pub struct Connection {
2502 pub from: ComponentId,
2503 pub from_at: (f32, f32),
2505 pub to: ComponentId,
2506 pub to_at: (f32, f32),
2507}
2508
2509impl Connection {
2510 pub const STUB: f32 = 16.0;
2512
2513 fn normal(at: (f32, f32)) -> PointF {
2515 let (x, y) = at;
2516 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))];
2517 d.iter().min_by(|a, b| a.0.total_cmp(&b.0)).map_or(PointF::new(1.0, 0.0), |d| d.1)
2518 }
2519
2520 pub fn route(&self, from: RectF, to: RectF) -> Vec<PointF> {
2523 let p0 = PointF::new(from.x + from.width * self.from_at.0, from.y + from.height * self.from_at.1);
2524 let p1 = PointF::new(to.x + to.width * self.to_at.0, to.y + to.height * self.to_at.1);
2525 let (n0, n1) = (Self::normal(self.from_at), Self::normal(self.to_at));
2526 let s0 = PointF::new(p0.x + n0.x * Self::STUB, p0.y + n0.y * Self::STUB);
2527 let s1 = PointF::new(p1.x + n1.x * Self::STUB, p1.y + n1.y * Self::STUB);
2528 let mut points = vec![p0, s0];
2529 if n0.x != 0.0 {
2530 let mx = (s0.x + s1.x) / 2.0;
2532 points.push(PointF::new(mx, s0.y));
2533 points.push(PointF::new(mx, s1.y));
2534 } else {
2535 let my = (s0.y + s1.y) / 2.0;
2536 points.push(PointF::new(s0.x, my));
2537 points.push(PointF::new(s1.x, my));
2538 }
2539 points.push(s1);
2540 points.push(p1);
2541 points.dedup_by(|a, b| (a.x - b.x).abs() < 0.01 && (a.y - b.y).abs() < 0.01);
2542 points
2543 }
2544}
2545
2546#[derive(Clone, Debug, Default, PartialEq)]
2548pub struct DragDecl {
2549 pub data: String,
2552 pub label: String,
2554 pub drop_types: String,
2557 pub image: Option<ComponentId>,
2559}
2560
2561#[derive(Clone, Debug, Default)]
2563struct RareTexts {
2564 tag_string: Box<str>,
2566 accessible_name: Box<str>,
2569}