1#[doc(hidden)]
5pub const CODEGEN_ABI_VERSION: u32 = 12;
6
7mod animation;
8mod arithmetic;
9mod button_group;
10mod calendar;
11mod callback;
12mod child_window;
13mod color_picker;
14mod combo;
15mod controls;
16mod delegate;
17mod double_spin;
18mod drag;
19mod event_loop;
20#[doc(hidden)]
21pub use event_loop::EventLoopRegistration;
22pub use event_loop::{EventLoopError, WeakComponent, invoke_from_event_loop};
23mod focus;
24mod font_picker;
25mod geometry;
26mod ui_log;
27pub use ui_log::LogLevel;
28#[doc(hidden)]
29pub use ui_log::log_ui;
30mod hover;
31mod image_animation;
32mod image_asset;
33mod inspection;
34#[doc(hidden)]
35pub use inspection::{InspectionInput, RecordedAction, WindowInspector};
36mod media;
37#[doc(hidden)]
38pub mod update_profile;
39pub use media::{
40 MediaCommand, MediaFrame, MediaOptions, MediaQueue, MediaRegistration, MediaSession, MediaSlot,
41 MediaState, MediaStatus, open_media_session, register_media_backend, register_sound_backend,
42};
43mod keyboard;
44mod list;
45mod list_keys;
46mod localization;
47mod localized_number;
48mod model;
49mod native_dialog;
50mod picker;
51mod pointer;
52mod property;
53mod range;
54mod record;
55pub use record::{RecordList, RecordRowValidator, RecordValue};
56mod list_sections;
57mod repeat;
58mod row_heights;
59mod scale_rotate;
60mod scene_plan;
61mod split;
62mod stack;
63mod styled_text;
64mod swipe_gesture;
65mod table_clipboard;
66mod table_history;
67mod table_rows;
68mod table_selection;
69mod text_input;
70mod time_picker;
71mod timer;
72mod tree;
73mod tumbler;
74mod viewport;
75mod window_status;
76pub use animation::{Animation, Easing, SceneTransition, StateTiming};
77#[doc(hidden)]
78pub use arithmetic::{
79 ceil_to_int, character_count, clamp_float, clamp_int, floor_to_int, format_fixed_float,
80 format_fixed_int, max_float, min_float, modulo_int, number_sign, parse_float, parse_int,
81 same_float_bits,
82};
83#[doc(hidden)]
84pub use arithmetic::{int_divide, int_remainder, round_to_int, try_int_divide, try_int_remainder};
85#[doc(hidden)]
86pub use button_group::{
87 ButtonGroup, ButtonGroupMembership, ButtonGroupOptions, ButtonGroupSelection, RadioMembership,
88 bind_button_group, bind_button_group_options, bind_check_group, bind_dynamic_button_group,
89 is_exclusive_push_option, prepare_button_group_option, prepare_radio_selection, radio_value,
90 summarize_checks, try_prepare_button_group_option, try_prepare_radio_selection,
91 try_summarize_checks,
92};
93pub use calendar::{CalendarAction, CalendarState, Date, is_calendar_control};
94#[doc(hidden)]
95pub use calendar::{
96 CalendarCell, CalendarCells, CalendarUpdate, DateBounds, DatePopupState, apply_calendar_action,
97 calendar_input_is_current, try_apply_calendar_action, try_calendar_input_is_current,
98};
99#[doc(hidden)]
100pub use callback::{CallbackAlreadyRunning, CallbackSlot, EffectfulCallback};
101#[doc(hidden)]
102pub use child_window::{SecondaryWindowCommand, SecondaryWindowRegistration, SecondaryWindowSlot};
103#[doc(hidden)]
104pub use color_picker::ColorPopupState;
105pub use combo::{
106 ChoiceIdentity, choice_enabled, choice_identity, combo_count, combo_find_enabled_label,
107 combo_find_label, combo_index, combo_label, combo_labels, combo_row_index, combo_row_key,
108 combo_text,
109};
110#[doc(hidden)]
111pub use combo::{
112 ComboEditor, ComboInput, ComboItems, ComboModel, ComboSelection, ComboSubmission, ComboUpdate,
113 combo_model_is_current, combo_submission, combo_value, prepare_combo_input,
114 prepare_combo_input_with_draft, prepare_combo_input_with_live_draft, try_prepare_combo_input,
115 try_prepare_combo_input_with_draft, try_prepare_combo_input_with_live_draft,
116};
117pub use controls::{
118 ActionKey, ControlAction, DialogCommand, DialogRole, PopupPlacement, SpinAction, SpinRange,
119 StandardButtonKind, SwipeSide, TableColumnOrder, TableHeader, TableSort, button_text,
120 combo_editable, delay_millis, dialog_button_action, group_index, group_item, is_button,
121 is_modal_overlay, is_pane, is_spin_box, is_window_overlay, page_indicator_count,
122 page_indicator_index, resizable_table_column, resolve_swipe_index, search_suggestion,
123 search_suggestions, spin_editable, spin_text, spin_value_after, text_input_value,
124};
125#[doc(hidden)]
126pub use controls::{
127 DialogEvent, TableHeaderAction, prepare_swipe_side, set_overlay_open, try_prepare_swipe_side,
128 try_resolve_swipe_index, try_set_overlay_open,
129};
130#[doc(hidden)]
131pub use controls::{
132 SPIN_VIEW_PROPERTIES, prepare_spin_view, spin_view_is_current, try_prepare_spin_view,
133 try_spin_view_is_current,
134};
135#[doc(hidden)]
136pub use controls::{
137 delay_button_transition_is_current, group_selection_item, prepare_action_activation,
138 prepare_action_view, prepare_group_box_toggle, prepare_group_selection,
139 prepare_group_selection_with_model, prepare_index_selection, prepare_row_toggle,
140 prepare_row_toggle_matching, prepare_source_selection, resize_table_column,
141 table_drag_available, try_delay_button_transition_is_current, try_prepare_action_activation,
142 try_prepare_action_view, try_prepare_group_box_toggle, try_prepare_group_selection,
143 try_prepare_group_selection_with_model, try_prepare_index_selection, try_prepare_row_toggle,
144 try_prepare_row_toggle_matching, try_prepare_source_selection, try_table_drag_available,
145};
146#[doc(hidden)]
147pub use delegate::{ComponentRepeater, RowContext};
148pub use double_spin::{
149 DecimalSpinRange, SpinDecimal, decimal_separator, decimal_spin_value_after, spin_text_is_valid,
150};
151#[doc(hidden)]
152pub use drag::DragArguments;
153pub use drag::{DragAction, DragEvent, is_drag_area};
154#[doc(hidden)]
155pub use focus::{ButtonPressHandle, FocusCommandMethod, FocusHandler, is_focus_handler};
156pub use focus::{
157 FocusAction, FocusContext, FocusEvent, FocusHandle, FocusReason, FocusRequest, FocusRequests,
158 TextCommand, TextCommandAvailability,
159};
160pub use font_picker::Font;
161#[doc(hidden)]
162pub use font_picker::{FontPopupState, is_font_family_choice, set_font_family_choices};
163#[doc(hidden)]
164pub use geometry::{GeometryHandle, GeometryMetric};
165pub use hover::{CursorShape, HoverHandle};
166pub use image_animation::{ImageAnimation, ImageAnimationFrame};
167#[doc(hidden)]
168pub use image_animation::{ImagePlaybackQueue, ImagePlaybackRegistration, ImagePlaybackSlot};
169pub use image_asset::{ImageAsset, ImageIdentity, ImagePixels, LoadedAnimation, LoadedImage};
170pub use keyboard::{EventResult, KeyEvent, KeyModifiers, KeyPhase, WheelEvent};
171#[doc(hidden)]
172pub use list::ViewIndex;
173pub use list::{ListMetrics, RowKey};
174#[doc(hidden)]
175pub use list::{
176 ListModel, ListRowLocator, ListRowRenderer, ListTextSearch, RowLifetime, TableCellEditor,
177 TableColumnWindow, TableField, project_standard_table_rows, render_standard_table_rows,
178 standard_list_rows, standard_list_rows_in_view, standard_table_rows,
179 standard_table_rows_in_order, standard_table_rows_with_editors_in_order,
180 standard_table_rows_with_header, try_project_standard_table_rows, try_render_rows_from_source,
181 try_render_standard_table_rows,
182};
183#[doc(hidden)]
184pub use list_keys::ListSelectionKeys;
185pub use list_sections::{
186 ListSection, ListSectionInput, ListSectionParameter, ListSectionProjection, ListSectionRenderer,
187};
188pub use localization::LocaleContext;
189#[doc(hidden)]
190pub use localization::{LocaleBinding, LocaleId, TranslationCatalog, TranslationValue};
191pub use model::VecModel;
192pub use native_dialog::{
193 FileDialogMode, FileDialogOptions, FileDialogSelection, MessageButtons, MessageDialogOptions,
194 MessageLevel,
195};
196#[doc(hidden)]
197pub use native_dialog::{
198 NativeDialogEvent, NativeDialogOptions, NativeDialogPresentation, NativeDialogQueue,
199 NativeDialogRegistration, NativeDialogResult, NativeDialogSlot,
200};
201pub use pointer::{
202 PointerButton, PointerButtons, PointerEvent, PointerEventKind, PointerHandle, TouchPoint,
203 TouchPoints,
204};
205#[doc(hidden)]
206pub use property::ComponentLifetime;
207pub use property::{ChangeSignal, InputProperty, Property};
208pub use range::{
209 DialInputMode, IndicatorState, RangeAction, ScrollBarRange, ScrollSnapMode, SliderInterval,
210 SliderRange, indicator_state, progress_value,
211};
212#[doc(hidden)]
213pub use range::{
214 RANGE_VIEW_PROPERTIES, prepare_range_view, range_view_properties, try_prepare_range_view,
215};
216#[doc(hidden)]
217pub use repeat::{Repeater, repeat_scene, static_repeat_scene};
218#[doc(hidden)]
219pub use row_heights::{RowHeightOverrides, RowHeightProjection, RowHeights};
220pub use scale_rotate::{ScaleRotateHandle, ScaleRotateSample};
221#[doc(hidden)]
222pub use scene_plan::{
223 GridCellPosition, GridCellSlot, GridPlanner, GridTrackInput, LoadedVectorPath, ScenePlanSlice,
224 StaticVectorPath, VectorSegment,
225};
226#[doc(hidden)]
227pub use split::{
228 SplitHandleInput, SplitResizeHandle, SplitState, decode_split_sizes, decode_split_state,
229 encode_split_sizes, encode_split_state,
230};
231#[doc(hidden)]
232pub use stack::{StackChange, StackEvent, StackNavigationArgument, StackNavigationMethod};
233pub use stack::{StackNavigation, StackSnapshot, StackState};
234use std::{collections::BTreeMap, rc::Rc, sync::Arc};
235pub use styled_text::{StyledLink, StyledRun, StyledText, StyledTextError, TextStyle};
236pub use swipe_gesture::{SwipeHandle, SwipeSample};
237#[doc(hidden)]
238pub use table_clipboard::{
239 TablePaste, TablePasteInput, paste_table_text, prepare_table_paste, table_paste_bool,
240 table_paste_check_state, table_paste_number, try_table_paste_number,
241 try_with_table_paste_target, with_table_paste_target,
242};
243#[doc(hidden)]
244pub use table_history::{TableEditHistory, TableHistoryPayload, TablePasteHistory, TableRowPatch};
245pub use table_rows::{
246 TableCellEditTarget, TableEditPosition, TableRowOrder, TableRowPositions, TableRows,
247 next_table_edit_cell, next_table_edit_cell_in_view, next_table_edit_cell_in_view_if,
248 next_table_edit_cell_while_current, table_cell_edit_target, table_cell_edit_target_if,
249 table_cell_edit_target_matching, try_history_replay_source, try_next_table_edit_cell,
250 try_next_table_edit_cell_in_view, try_next_table_edit_cell_while_current,
251 try_prepare_history_replay, try_table_cell_edit_target, try_table_cell_edit_target_matching,
252};
253#[doc(hidden)]
254pub use table_selection::{
255 ListSelectionCommand, TableSelectionChange, TableSelectionCommand, TableSelectionEvent,
256 TableSelectionMethod, TableSelectionOptions,
257};
258pub use table_selection::{
259 RowSelection, SelectionTarget, TableSelection, TableSelectionAction, TableSelectionSnapshot,
260};
261pub use table_selection::{
262 copy_table_text, copy_table_text_in_order, copy_table_text_in_view, copy_table_text_in_view_if,
263 copy_table_text_while_current, try_copy_table_text_in_order, try_copy_table_text_in_view,
264 try_copy_table_text_while_current,
265};
266pub use text_input::InputType;
267#[doc(hidden)]
268pub use text_input::{
269 NumericTextLimits, SearchInput, SearchUpdate, text_submission_is_valid, text_submission_with,
270 try_text_submission_is_valid, try_text_submission_with,
271};
272pub use time_picker::Time;
273#[doc(hidden)]
274pub use time_picker::{TimePickerOptions, TimePopupState};
275#[doc(hidden)]
276pub use timer::{
277 TimerCommand, TimerConfig, TimerDelivery, TimerQueue, TimerRegistration, TimerSlot, TimerTick,
278};
279pub use tree::{TreeAction, TreeCommand, TreeItem, TreeSelectionAction, TreeSnapshot, TreeState};
280#[doc(hidden)]
281pub use tree::{
282 TreeCommandMethod, TreeControlChange, TreeControlEvent, TreeExpansionChange,
283 TreeSelectionChange, TreeSelectionCommand, TreeSelectionLookup,
284};
285pub use tumbler::{Tumbler, TumblerItems};
286pub use viewport::{
287 ScrollAction, ScrollAlignment, ScrollContext, ScrollRequest, ScrollRequests, ViewportHandle,
288 ViewportMotion,
289};
290#[doc(hidden)]
291pub use viewport::{ScrollCommand, ScrollCommandMethod, SourceScroll};
292pub use window_status::{WindowCommand, WindowStatus};
293#[doc(hidden)]
294pub use window_status::{WindowCommandMethod, WindowLifecycle, WindowMetric, WindowStatusBinding};
295
296pub trait Component {
298 fn render(&self) -> Node;
299
300 #[doc(hidden)]
301 fn window_inspector(&self, _scene: &Rc<Node>) -> Option<WindowInspector> {
302 None
303 }
304
305 #[doc(hidden)]
307 fn set_locale_context(&self, _context: LocaleContext) {}
308
309 fn render_shared(&self) -> Rc<Node> {
311 Rc::new(self.render())
312 }
313
314 fn scene_dirty(&self) -> bool {
316 false
317 }
318
319 fn close_requested(&mut self) -> bool {
321 true
322 }
323
324 fn take_window_close_request(&mut self) -> bool {
326 false
327 }
328
329 fn take_window_commands(&mut self) -> Vec<WindowCommand> {
331 Vec::new()
332 }
333
334 #[doc(hidden)]
335 fn has_window_commands(&self) -> bool {
336 false
337 }
338
339 fn publish_window_status(&self, _status: WindowStatus) {}
341
342 #[doc(hidden)]
344 fn secondary_windows(&self) -> Option<Rc<[SecondaryWindowRegistration]>> {
345 None
346 }
347
348 fn list_rows(&self, _path: &[usize], _rows: std::ops::Range<usize>) -> Vec<Node> {
350 Vec::new()
351 }
352
353 #[doc(hidden)]
354 fn next_table_edit_cell(
355 &self,
356 _scene: &Node,
357 _path: &[usize],
358 _origin: TableEditPosition,
359 _columns: &[usize],
360 _backward: bool,
361 ) -> Option<TableEditPosition> {
362 None
363 }
364
365 #[doc(hidden)]
366 fn copy_table_at(&self, _scene: &Node, _path: &[usize], _columns: &[usize]) -> Option<String> {
367 None
368 }
369
370 #[doc(hidden)]
371 fn route_table_query(
372 &self,
373 scene: &Node,
374 path: &[usize],
375 input: InputRoute<'_>,
376 ) -> Option<TableQueryResult> {
377 let RoutedEvent::QueryTable(query) = *input.event() else {
378 return None;
379 };
380 match query {
381 TableQuery::Copy(columns) => self
382 .copy_table_at(scene, path, columns)
383 .map(TableQueryResult::Text),
384 TableQuery::NextEdit(query) => self
385 .next_table_edit_cell(scene, path, query.origin, query.columns, query.backward)
386 .map(TableQueryResult::Position),
387 }
388 }
389
390 #[doc(hidden)]
391 fn prepare_table_paste(
392 &self,
393 _scene: &Node,
394 _path: &[usize],
395 _row: usize,
396 _columns: Vec<usize>,
397 ) -> Option<TablePaste> {
398 None
399 }
400
401 #[doc(hidden)]
402 fn table_paste_stamp(&self, _scene: &Node, _path: &[usize]) -> Option<(u64, u64)> {
403 None
404 }
405
406 #[doc(hidden)]
407 fn replay_table_paste_at(&self, _scene: &Node, _path: &[usize], _redo: bool) -> bool {
408 false
409 }
410
411 #[doc(hidden)]
412 fn replay_table_edit_at(&self, scene: &Node, path: &[usize], redo: bool) -> bool {
413 self.replay_table_paste_at(scene, path, redo)
414 }
415
416 fn dispatch(&mut self, element_id: &str, event: &str) -> bool;
417
418 fn edit_at(&mut self, _scene: &Node, _path: &[usize], _text: String) -> bool {
420 false
421 }
422
423 fn commit_table_cell(
425 &mut self,
426 _scene: &Node,
427 _path: &[usize],
428 _original: &str,
429 _text: String,
430 ) -> bool {
431 false
432 }
433
434 fn adjust_range_at(&mut self, _scene: &Node, _path: &[usize], _action: RangeAction) -> bool {
436 false
437 }
438
439 fn control_at(&mut self, _scene: &Node, _path: &[usize], _action: ControlAction) -> bool {
440 false
441 }
442
443 #[doc(hidden)]
444 fn drag_event_at(&mut self, _scene: &Node, _path: &[usize], _event: &DragEvent) -> bool {
445 false
446 }
447
448 #[doc(hidden)]
449 fn key_event_at(
450 &mut self,
451 _scene: &Node,
452 _path: &[usize],
453 _phase: KeyPhase,
454 _event: &KeyEvent,
455 ) -> EventResult {
456 EventResult::Reject
457 }
458
459 #[doc(hidden)]
460 fn focus_event_at(&mut self, _scene: &Node, _path: &[usize], _event: FocusEvent) -> bool {
461 false
462 }
463
464 #[doc(hidden)]
465 fn wheel_event_at(
466 &mut self,
467 _scene: &Node,
468 _path: &[usize],
469 _event: &WheelEvent,
470 ) -> EventResult {
471 EventResult::Reject
472 }
473
474 #[doc(hidden)]
475 fn pointer_event_at(&mut self, _scene: &Node, _path: &[usize], _event: &PointerEvent) -> bool {
476 false
477 }
478
479 #[doc(hidden)]
480 fn route_input(&mut self, scene: &Node, path: &[usize], input: InputRoute<'_>) -> bool {
481 input.event().apply(self, scene, path)
482 }
483
484 fn resize_split_at(
485 &mut self,
486 _scene: &Node,
487 _path: &[usize],
488 _weights: &[(usize, f32)],
489 ) -> bool {
490 false
491 }
492
493 fn resize_split_sizes_at(
494 &mut self,
495 _scene: &Node,
496 _path: &[usize],
497 _sizes: &[(usize, f32)],
498 ) -> bool {
499 false
500 }
501
502 fn dispatch_at(&mut self, scene: &Node, path: &[usize], event: &str) -> bool {
504 scene
505 .at_path(path)
506 .and_then(Node::element_id)
507 .is_some_and(|id| self.dispatch(id, event))
508 }
509}
510
511impl<T: Component + ?Sized> Component for Box<T> {
512 fn route_input(&mut self, scene: &Node, path: &[usize], input: InputRoute<'_>) -> bool {
513 (**self).route_input(scene, path, input)
514 }
515
516 fn render(&self) -> Node {
517 (**self).render()
518 }
519 fn window_inspector(&self, scene: &Rc<Node>) -> Option<WindowInspector> {
520 (**self).window_inspector(scene)
521 }
522 fn set_locale_context(&self, context: LocaleContext) {
523 (**self).set_locale_context(context);
524 }
525 fn focus_event_at(&mut self, scene: &Node, path: &[usize], event: FocusEvent) -> bool {
526 (**self).focus_event_at(scene, path, event)
527 }
528 fn drag_event_at(&mut self, scene: &Node, path: &[usize], event: &DragEvent) -> bool {
529 (**self).drag_event_at(scene, path, event)
530 }
531 fn key_event_at(
532 &mut self,
533 scene: &Node,
534 path: &[usize],
535 phase: KeyPhase,
536 event: &KeyEvent,
537 ) -> EventResult {
538 (**self).key_event_at(scene, path, phase, event)
539 }
540 fn render_shared(&self) -> Rc<Node> {
541 (**self).render_shared()
542 }
543 fn scene_dirty(&self) -> bool {
544 (**self).scene_dirty()
545 }
546 fn close_requested(&mut self) -> bool {
547 (**self).close_requested()
548 }
549 fn take_window_close_request(&mut self) -> bool {
550 (**self).take_window_close_request()
551 }
552 fn take_window_commands(&mut self) -> Vec<WindowCommand> {
553 (**self).take_window_commands()
554 }
555 fn has_window_commands(&self) -> bool {
556 (**self).has_window_commands()
557 }
558 fn publish_window_status(&self, status: WindowStatus) {
559 (**self).publish_window_status(status);
560 }
561 fn secondary_windows(&self) -> Option<Rc<[SecondaryWindowRegistration]>> {
562 (**self).secondary_windows()
563 }
564
565 fn list_rows(&self, path: &[usize], rows: std::ops::Range<usize>) -> Vec<Node> {
566 (**self).list_rows(path, rows)
567 }
568
569 fn next_table_edit_cell(
570 &self,
571 scene: &Node,
572 path: &[usize],
573 origin: TableEditPosition,
574 columns: &[usize],
575 backward: bool,
576 ) -> Option<TableEditPosition> {
577 (**self).next_table_edit_cell(scene, path, origin, columns, backward)
578 }
579
580 fn copy_table_at(&self, scene: &Node, path: &[usize], columns: &[usize]) -> Option<String> {
581 (**self).copy_table_at(scene, path, columns)
582 }
583
584 fn route_table_query(
585 &self,
586 scene: &Node,
587 path: &[usize],
588 input: InputRoute<'_>,
589 ) -> Option<TableQueryResult> {
590 (**self).route_table_query(scene, path, input)
591 }
592
593 fn prepare_table_paste(
594 &self,
595 scene: &Node,
596 path: &[usize],
597 row: usize,
598 columns: Vec<usize>,
599 ) -> Option<TablePaste> {
600 (**self).prepare_table_paste(scene, path, row, columns)
601 }
602
603 fn table_paste_stamp(&self, scene: &Node, path: &[usize]) -> Option<(u64, u64)> {
604 (**self).table_paste_stamp(scene, path)
605 }
606
607 fn replay_table_paste_at(&self, scene: &Node, path: &[usize], redo: bool) -> bool {
608 (**self).replay_table_paste_at(scene, path, redo)
609 }
610
611 fn replay_table_edit_at(&self, scene: &Node, path: &[usize], redo: bool) -> bool {
612 (**self).replay_table_edit_at(scene, path, redo)
613 }
614
615 fn dispatch(&mut self, element_id: &str, event: &str) -> bool {
616 (**self).dispatch(element_id, event)
617 }
618
619 fn edit_at(&mut self, scene: &Node, path: &[usize], text: String) -> bool {
620 (**self).edit_at(scene, path, text)
621 }
622
623 fn commit_table_cell(
624 &mut self,
625 scene: &Node,
626 path: &[usize],
627 original: &str,
628 text: String,
629 ) -> bool {
630 (**self).commit_table_cell(scene, path, original, text)
631 }
632
633 fn adjust_range_at(&mut self, scene: &Node, path: &[usize], action: RangeAction) -> bool {
634 (**self).adjust_range_at(scene, path, action)
635 }
636
637 fn control_at(&mut self, scene: &Node, path: &[usize], action: ControlAction) -> bool {
638 (**self).control_at(scene, path, action)
639 }
640
641 fn resize_split_at(&mut self, scene: &Node, path: &[usize], weights: &[(usize, f32)]) -> bool {
642 (**self).resize_split_at(scene, path, weights)
643 }
644 fn resize_split_sizes_at(
645 &mut self,
646 scene: &Node,
647 path: &[usize],
648 sizes: &[(usize, f32)],
649 ) -> bool {
650 (**self).resize_split_sizes_at(scene, path, sizes)
651 }
652
653 fn dispatch_at(&mut self, scene: &Node, path: &[usize], event: &str) -> bool {
654 (**self).dispatch_at(scene, path, event)
655 }
656
657 fn wheel_event_at(&mut self, scene: &Node, path: &[usize], event: &WheelEvent) -> EventResult {
658 (**self).wheel_event_at(scene, path, event)
659 }
660
661 fn pointer_event_at(&mut self, scene: &Node, path: &[usize], event: &PointerEvent) -> bool {
662 (**self).pointer_event_at(scene, path, event)
663 }
664}
665
666#[doc(hidden)]
667#[derive(Clone, Copy)]
668pub struct TableEditNavigation<'a> {
669 pub origin: TableEditPosition,
670 pub columns: &'a [usize],
671 pub backward: bool,
672}
673
674#[doc(hidden)]
675#[derive(Clone, Copy)]
676pub enum TableQuery<'a> {
677 Copy(&'a [usize]),
678 NextEdit(TableEditNavigation<'a>),
679}
680
681impl TableQuery<'_> {
682 pub fn run(
683 self,
684 ui: &(impl Component + ?Sized),
685 scene: &Node,
686 path: &[usize],
687 ) -> Option<TableQueryResult> {
688 RoutedEvent::QueryTable(self)
689 .with_input(scene, path, |input| {
690 ui.route_table_query(scene, path, input)
691 })
692 .flatten()
693 }
694}
695
696#[doc(hidden)]
697pub enum TableQueryResult {
698 Text(String),
699 Position(TableEditPosition),
700}
701
702impl TableQueryResult {
703 pub fn text(self) -> Option<String> {
704 match self {
705 Self::Text(text) => Some(text),
706 Self::Position(_) => None,
707 }
708 }
709
710 pub fn position(self) -> Option<TableEditPosition> {
711 match self {
712 Self::Position(position) => Some(position),
713 Self::Text(_) => None,
714 }
715 }
716}
717
718#[doc(hidden)]
719pub enum RoutedEvent<'a> {
720 Dispatch(&'a str),
721 Edit(&'a str),
722 CommitCell { original: &'a str, text: &'a str },
723 PasteTable(TablePasteInput<'a>),
724 ReplayTable { redo: bool },
725 QueryTable(TableQuery<'a>),
726 Range(RangeAction),
727 Control(ControlAction),
728 Drag(&'a DragEvent),
729 Key(KeyPhase, &'a KeyEvent),
730 Wheel(&'a WheelEvent),
731 Pointer(&'a PointerEvent),
732 Focus(FocusEvent),
733 ResizeSplit(&'a [(usize, f32)]),
734 ResizeSplitSizes(&'a [(usize, f32)]),
735}
736
737#[doc(hidden)]
739#[derive(Clone, Copy)]
740pub struct InputRoute<'a> {
741 event: &'a RoutedEvent<'a>,
742 reads: Option<&'a property::ReadWatch>,
743 root_visibility_overridden: bool,
744}
745
746impl<'a> InputRoute<'a> {
747 pub fn event(self) -> &'a RoutedEvent<'a> {
748 self.event
749 }
750
751 pub fn checks_availability(self) -> bool {
752 self.reads.is_some()
753 }
754
755 pub fn root_visibility_overridden(self) -> bool {
756 self.root_visibility_overridden
757 }
758
759 pub fn with_root_visibility_override(mut self, overridden: bool) -> Self {
760 self.root_visibility_overridden = overridden;
761 self
762 }
763
764 pub fn record_root_visibility_override(self, lifetime: &ComponentLifetime) {
765 if self.root_visibility_overridden && self.checks_availability() {
766 lifetime.record_input_root_override();
767 }
768 }
769
770 pub fn try_visible<E>(self, visible: impl FnOnce() -> Result<bool, E>) -> Result<bool, E> {
771 if self.root_visibility_overridden {
772 Ok(true)
773 } else {
774 visible()
775 }
776 }
777
778 pub fn visible(self, visible: impl FnOnce() -> bool) -> bool {
779 self.root_visibility_overridden || visible()
780 }
781
782 pub fn is_current(self) -> bool {
783 self.reads.is_none_or(|reads| !reads.changed())
784 }
785
786 pub fn can_open_drawer(self, node: &Node, is_target: bool) -> bool {
787 is_target
788 && node.kind == "Drawer"
789 && matches!(
790 self.event,
791 RoutedEvent::Control(ControlAction::Drawer(true))
792 )
793 }
794
795 pub fn try_available<E>(self, available: impl FnOnce() -> Result<bool, E>) -> Result<bool, E> {
796 match self.reads {
797 Some(reads) => Ok(!reads.changed()
798 && property::track_input_availability(available)?
799 && !reads.changed()),
800 None => Ok(true),
801 }
802 }
803
804 pub fn available(self, available: impl FnOnce() -> bool) -> bool {
805 self.try_available(|| Ok::<_, std::convert::Infallible>(available()))
806 .unwrap_or_else(|error| match error {})
807 }
808
809 pub fn try_prepare<T, E>(
811 self,
812 available: impl FnOnce() -> Result<bool, E>,
813 prepare: impl FnOnce() -> Result<Option<T>, E>,
814 ) -> Result<Option<T>, E> {
815 if !self.try_available(available)? {
816 return Ok(None);
817 }
818 Ok(prepare()?.filter(|_| self.is_current()))
819 }
820
821 pub fn prepare<T>(
822 self,
823 available: impl FnOnce() -> bool,
824 prepare: impl FnOnce() -> Option<T>,
825 ) -> Option<T> {
826 self.try_prepare(
827 || Ok::<_, std::convert::Infallible>(available()),
828 || Ok(prepare()),
829 )
830 .unwrap_or_else(|error| match error {})
831 }
832}
833
834impl RoutedEvent<'_> {
835 #[doc(hidden)]
836 pub fn activates_item_delegate(&self, has_action: bool) -> bool {
837 matches!(
838 self,
839 Self::Dispatch("clicked" | "toggled") | Self::Control(ControlAction::SetSwitch(_))
840 ) || has_action && matches!(self, Self::Control(ControlAction::ActivateAction))
841 }
842
843 #[doc(hidden)]
844 pub fn checked_after(&self, current: bool) -> Option<bool> {
845 match *self {
846 Self::Dispatch("clicked") => Some(!current),
847 Self::Control(ControlAction::SetSwitch(checked)) if checked != current => Some(checked),
848 _ => None,
849 }
850 }
851
852 fn is_input_cleanup(&self) -> bool {
853 match self {
854 Self::Focus(event) => event.is_loss(),
855 Self::Pointer(event) => event.kind == PointerEventKind::Cancel,
856 Self::Drag(event) => event.is_terminal(),
857 _ => false,
858 }
859 }
860
861 pub fn follows_row(&self, scene: &Node, path: &[usize]) -> bool {
863 match self {
864 Self::Dispatch(event) => scene
865 .at_path(path)
866 .is_some_and(|node| node.terminal_dispatch(event)),
867 _ => self.is_input_cleanup(),
868 }
869 }
870
871 pub fn input_target<'a>(&self, scene: &'a Node, path: &[usize]) -> Option<&'a Node> {
873 let target = || {
874 if self.is_input_cleanup() {
875 scene.at_path(path)
876 } else {
877 scene.interactive_at_path(path)
878 }
879 };
880 match self {
881 Self::Dispatch(event) => scene.dispatch_target(path, event),
882 Self::Control(action) => scene.control_target(path, *action),
883 Self::Range(_) => scene.range_target(path),
884 Self::CommitCell { original, .. } => scene.table_cell_commit_target(path, original),
885 Self::PasteTable(_) => scene
886 .interactive_at_path(path)
887 .filter(|node| node.kind == "TableView" && node.boolean("pasteable", false)),
888 Self::ReplayTable { .. } => {
889 scene.table_edit_history_model(path)?;
890 scene.at_path(path)
891 }
892 Self::QueryTable(query) => scene.interactive_at_path(path).filter(|node| {
893 node.kind == "TableView"
894 && node.boolean(
895 match query {
896 TableQuery::Copy(_) => "copyable",
897 TableQuery::NextEdit(_) => "edit-on-tab",
898 },
899 false,
900 )
901 }),
902 Self::ResizeSplit(_) | Self::ResizeSplitSizes(_) => scene
903 .interactive_at_path(path)
904 .filter(|node| node.kind == "SplitView"),
905 Self::Edit(text) => scene
906 .interactive_at_path(path)
907 .filter(|node| node.accepts_editor_update(text)),
908 Self::Focus(event) => scene.focus_event_target(path, *event),
909 Self::Key(phase, _) => scene.key_event_target(path, *phase),
910 Self::Wheel(_) => scene
911 .interactive_at_path(path)
912 .filter(|node| node.handles_wheel()),
913 Self::Pointer(_) => target().filter(|node| node.pointer_handle.is_some()),
914 Self::Drag(event) => target().filter(|node| node.kind == event.target_kind()),
915 }
916 }
917
918 pub fn with_input<T>(
919 &self,
920 scene: &Node,
921 path: &[usize],
922 route: impl FnOnce(InputRoute<'_>) -> T,
923 ) -> Option<T> {
924 self.input_target(scene, path)?;
925 let input = InputRoute {
926 event: self,
927 reads: None,
928 root_visibility_overridden: false,
929 };
930 Some(property::with_input_path(|| {
931 if self.follows_row(scene, path) {
932 route(input)
933 } else {
934 property::watch_reads(|reads| {
935 route(InputRoute {
936 reads: Some(reads),
937 ..input
938 })
939 })
940 }
941 }))
942 }
943
944 pub fn deliver_input(
945 &self,
946 ui: &mut (impl Component + ?Sized),
947 scene: &Node,
948 path: &[usize],
949 ) -> bool {
950 self.with_input(scene, path, |input| ui.route_input(scene, path, input))
951 .unwrap_or(false)
952 }
953
954 pub fn apply(&self, ui: &mut (impl Component + ?Sized), scene: &Node, path: &[usize]) -> bool {
955 match self {
956 Self::Dispatch(event) => ui.dispatch_at(scene, path, event),
957 Self::Edit(text) => ui.edit_at(scene, path, (*text).into()),
958 Self::CommitCell { original, text } => {
959 ui.commit_table_cell(scene, path, original, (*text).into())
960 }
961 Self::PasteTable(_) => false,
962 Self::ReplayTable { redo } => ui.replay_table_edit_at(scene, path, *redo),
963 Self::QueryTable(_) => false,
964 Self::Range(action) => ui.adjust_range_at(scene, path, *action),
965 Self::Control(action) => ui.control_at(scene, path, *action),
966 Self::Drag(event) => ui.drag_event_at(scene, path, event),
967 Self::Key(phase, event) => {
968 ui.key_event_at(scene, path, *phase, event) == EventResult::Accept
969 }
970 Self::Wheel(event) => ui.wheel_event_at(scene, path, event) == EventResult::Accept,
971 Self::Pointer(event) => ui.pointer_event_at(scene, path, event),
972 Self::Focus(event) => ui.focus_event_at(scene, path, *event),
973 Self::ResizeSplit(weights) => ui.resize_split_at(scene, path, weights),
974 Self::ResizeSplitSizes(sizes) => ui.resize_split_sizes_at(scene, path, sizes),
975 }
976 }
977}
978
979#[derive(Clone, Copy, Debug, Default, PartialEq)]
980pub struct Length(pub f64);
981
982#[derive(Clone, Copy, Debug, PartialEq)]
983pub struct Percent(pub f64);
984
985#[derive(Clone, Copy, Debug, Default, Hash, PartialEq, Eq)]
986pub struct Color(pub u32);
987
988impl Color {
989 #[doc(hidden)]
990 pub fn from_rgba(red: i64, green: i64, blue: i64, alpha: f64) -> Self {
991 let channel = |value: i64| value.clamp(0, 255) as u32;
992 let rgb = (channel(red) << 24) | (channel(green) << 16) | (channel(blue) << 8);
993 Self(rgb).with_alpha(alpha)
994 }
995
996 #[doc(hidden)]
997 pub fn with_alpha(self, alpha: f64) -> Self {
998 let alpha = (alpha.clamp(0.0, 1.0) * 255.0).round() as u32;
999 Self((self.0 & 0xffff_ff00) | alpha)
1000 }
1001
1002 #[doc(hidden)]
1003 pub fn mix(self, other: Self, amount: f64) -> Self {
1004 let amount = if amount.is_nan() {
1005 0.0
1006 } else {
1007 amount.clamp(0.0, 1.0)
1008 };
1009 crate::animation::mix_color(self, other, amount)
1010 }
1011
1012 #[doc(hidden)]
1014 pub fn parse_hex_literal(spelling: &str) -> Option<Self> {
1015 let digits = spelling.strip_prefix('#')?;
1016 if !matches!(digits.len(), 3 | 4 | 6 | 8)
1017 || !digits.bytes().all(|digit| digit.is_ascii_hexdigit())
1018 {
1019 return None;
1020 }
1021 let value = u32::from_str_radix(digits, 16).ok()?;
1022 let rgba = match digits.len() {
1023 3 | 4 => {
1024 let expanded = (0..digits.len()).rev().fold(0, |rgba, index| {
1025 let digit = (value >> (index * 4)) & 0xf;
1026 (rgba << 8) | (digit * 17)
1027 });
1028 if digits.len() == 3 {
1029 (expanded << 8) | 0xff
1030 } else {
1031 expanded
1032 }
1033 }
1034 6 => (value << 8) | 0xff,
1035 _ => value,
1036 };
1037 Some(Self(rgba))
1038 }
1039}
1040
1041#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
1042pub enum ColorScheme {
1043 #[default]
1044 System,
1045 Light,
1046 Dark,
1047}
1048
1049#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
1050pub enum ImageFormat {
1051 Png,
1052 Svg,
1053}
1054
1055#[derive(Clone, Debug, Default)]
1056pub enum Image {
1057 #[default]
1058 Empty,
1059 Embedded {
1060 format: ImageFormat,
1061 bytes: &'static [u8],
1062 size: [u32; 2],
1063 },
1064 Animated(&'static ImageAnimation),
1065 Loaded(LoadedImage),
1066 NineSliced {
1067 format: ImageFormat,
1068 bytes: &'static [u8],
1069 size: [u32; 2],
1070 edges: NineSlice,
1071 },
1072}
1073
1074#[derive(Clone, Copy, Debug, PartialEq, Eq)]
1076pub struct NineSlice {
1077 pub top: u32,
1078 pub right: u32,
1079 pub bottom: u32,
1080 pub left: u32,
1081}
1082
1083impl NineSlice {
1084 pub fn fits(self, [width, height]: [u32; 2]) -> bool {
1085 self.left.saturating_add(self.right) < width
1086 && self.top.saturating_add(self.bottom) < height
1087 }
1088}
1089
1090#[derive(Clone, Copy, Debug, PartialEq, Eq, thiserror::Error)]
1091#[error("nine-slice edges must leave a nonempty center in the source image")]
1092pub struct InvalidNineSlice;
1093
1094impl PartialEq for Image {
1095 fn eq(&self, other: &Self) -> bool {
1096 match (self, other) {
1097 (Self::Empty, Self::Empty) => true,
1098 (
1099 Self::Embedded {
1100 format: a,
1101 bytes: b,
1102 size: c,
1103 },
1104 Self::Embedded {
1105 format: x,
1106 bytes: y,
1107 size: z,
1108 },
1109 ) => (a, b, c) == (x, y, z),
1110 (
1111 Self::NineSliced {
1112 format: a,
1113 bytes: b,
1114 size: c,
1115 edges: d,
1116 },
1117 Self::NineSliced {
1118 format: w,
1119 bytes: x,
1120 size: y,
1121 edges: z,
1122 },
1123 ) => (a, b, c, d) == (w, x, y, z),
1124 (Self::Animated(left), Self::Animated(right)) => left == right,
1125 (Self::Loaded(left), Self::Loaded(right)) => left == right,
1126 (Self::Loaded(_), _) | (_, Self::Loaded(_)) => {
1127 ImageAsset::from(self.clone()) == ImageAsset::from(other.clone())
1128 }
1129 _ => false,
1130 }
1131 }
1132}
1133
1134impl Eq for Image {}
1135
1136impl Image {
1137 pub fn size(&self) -> [u32; 2] {
1138 match self {
1139 Self::Loaded(image) => image.size(),
1140 Self::Empty => [0, 0],
1141 Self::Animated(animation) => animation.size(),
1142 Self::Embedded { size, .. } | Self::NineSliced { size, .. } => *size,
1143 }
1144 }
1145
1146 pub fn frame_count(&self) -> usize {
1147 match self {
1148 Self::Empty => 0,
1149 Self::Animated(animation) => animation.frame_count(),
1150 _ => 1,
1151 }
1152 }
1153
1154 pub fn frame(self, index: usize) -> Self {
1155 match self {
1156 Self::Animated(animation) => animation.frame(index),
1157 _ => self,
1158 }
1159 }
1160
1161 pub fn with_nine_slice(self, edges: NineSlice) -> Result<Self, InvalidNineSlice> {
1162 match self {
1163 Self::Embedded {
1164 format,
1165 bytes,
1166 size,
1167 }
1168 | Self::NineSliced {
1169 format,
1170 bytes,
1171 size,
1172 ..
1173 } if edges.fits(size) => Ok(Self::NineSliced {
1174 format,
1175 bytes,
1176 size,
1177 edges,
1178 }),
1179 Self::Loaded(image) => image.with_nine_slice(edges).map(Self::Loaded),
1180 _ => Err(InvalidNineSlice),
1181 }
1182 }
1183}
1184
1185pub struct EmbeddedFonts(&'static [&'static [u8]]);
1187
1188impl EmbeddedFonts {
1189 pub const fn new(fonts: &'static [&'static [u8]]) -> Self {
1190 Self(fonts)
1191 }
1192
1193 pub fn sources(&self) -> &'static [&'static [u8]] {
1194 self.0
1195 }
1196}
1197
1198impl PartialEq for EmbeddedFonts {
1199 fn eq(&self, other: &Self) -> bool {
1200 std::ptr::eq(self, other)
1201 }
1202}
1203
1204impl std::fmt::Debug for EmbeddedFonts {
1205 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1206 f.debug_struct("EmbeddedFonts")
1207 .field("count", &self.0.len())
1208 .finish()
1209 }
1210}
1211
1212#[derive(Clone)]
1214pub struct LoadedFonts(Arc<Vec<Arc<Vec<u8>>>>);
1215
1216impl LoadedFonts {
1217 pub fn new(fonts: Vec<Vec<u8>>) -> Self {
1218 Self(Arc::new(fonts.into_iter().map(Arc::new).collect()))
1219 }
1220
1221 pub fn sources(&self) -> &[Arc<Vec<u8>>] {
1222 &self.0
1223 }
1224}
1225
1226impl std::fmt::Debug for LoadedFonts {
1227 fn fmt(&self, output: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1228 output
1229 .debug_struct("LoadedFonts")
1230 .field("count", &self.0.len())
1231 .finish()
1232 }
1233}
1234
1235impl PartialEq for LoadedFonts {
1236 fn eq(&self, other: &Self) -> bool {
1237 Arc::ptr_eq(&self.0, &other.0)
1238 }
1239}
1240
1241#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
1242pub enum ImageFit {
1243 Fill,
1244 #[default]
1245 Contain,
1246 Cover,
1247 Preserve,
1248}
1249
1250#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
1251pub enum ImageTileMode {
1252 #[default]
1253 Stretch,
1254 Repeat,
1255 Round,
1256}
1257
1258#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
1259pub enum ImageHorizontalAlignment {
1260 Left,
1261 #[default]
1262 Center,
1263 Right,
1264}
1265
1266#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
1267pub enum ImageVerticalAlignment {
1268 Top,
1269 #[default]
1270 Center,
1271 Bottom,
1272}
1273
1274#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
1275pub enum ImageRendering {
1276 #[default]
1277 Smooth,
1278 Pixelated,
1279}
1280
1281#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
1282pub enum LayoutAlignment {
1283 #[default]
1284 Stretch,
1285 Center,
1286 Start,
1287 End,
1288 SpaceBetween,
1289 SpaceAround,
1290 SpaceEvenly,
1291}
1292
1293#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
1294pub enum CrossAxisAlignment {
1295 #[default]
1296 Auto,
1297 Stretch,
1298 Start,
1299 End,
1300 Center,
1301}
1302
1303#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
1304pub enum Orientation {
1305 #[default]
1306 Horizontal,
1307 Vertical,
1308}
1309
1310#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
1311pub enum FlickDirection {
1312 #[default]
1313 Both,
1314 Horizontal,
1315 Vertical,
1316}
1317
1318#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
1319pub enum FlickBoundsBehavior {
1320 #[default]
1321 StopAtBounds,
1322 DragOverBounds,
1323 OvershootBounds,
1324 DragAndOvershootBounds,
1325}
1326
1327impl FlickBoundsBehavior {
1328 pub fn allows_overshoot(self, flick: bool) -> bool {
1329 matches!(
1330 (self, flick),
1331 (Self::DragAndOvershootBounds, _)
1332 | (Self::DragOverBounds, false)
1333 | (Self::OvershootBounds, true)
1334 )
1335 }
1336}
1337
1338#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
1339pub enum FlickBoundsMovement {
1340 #[default]
1341 FollowBoundsBehavior,
1342 StopAtBounds,
1343}
1344
1345impl FlickDirection {
1346 pub fn allows(self, axis: Orientation) -> bool {
1347 matches!(
1348 (self, axis),
1349 (Self::Both, _)
1350 | (Self::Horizontal, Orientation::Horizontal)
1351 | (Self::Vertical, Orientation::Vertical)
1352 )
1353 }
1354}
1355
1356#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
1357pub enum LayoutDirection {
1358 #[default]
1359 LeftToRight,
1360 RightToLeft,
1361}
1362
1363#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
1364pub enum FlexboxLayoutDirection {
1365 #[default]
1366 Row,
1367 RowReverse,
1368 Column,
1369 ColumnReverse,
1370}
1371
1372#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
1373pub enum FlexboxLayoutWrap {
1374 #[default]
1375 Wrap,
1376 NoWrap,
1377 WrapReverse,
1378}
1379
1380#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
1381pub enum DrawerEdge {
1382 #[default]
1383 Left,
1384 Right,
1385 Top,
1386 Bottom,
1387}
1388
1389#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
1390pub enum ScrollBarPolicy {
1391 #[default]
1392 AsNeeded,
1393 AlwaysOn,
1394 AlwaysOff,
1395}
1396
1397#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
1398pub enum TextWrap {
1399 #[default]
1400 WordWrap,
1401 NoWrap,
1402 CharWrap,
1403}
1404
1405#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
1406pub enum TextHorizontalAlignment {
1407 #[default]
1408 Start,
1409 End,
1410 Left,
1411 Center,
1412 Right,
1413}
1414
1415#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
1416pub enum TextVerticalAlignment {
1417 #[default]
1418 Top,
1419 Center,
1420 Bottom,
1421}
1422
1423#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
1424pub enum TextOverflow {
1425 #[default]
1426 Clip,
1427 Elide,
1428}
1429
1430#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
1431pub enum CheckState {
1432 #[default]
1433 Unchecked,
1434 PartiallyChecked,
1435 Checked,
1436}
1437
1438impl From<bool> for CheckState {
1439 fn from(checked: bool) -> Self {
1440 if checked {
1441 Self::Checked
1442 } else {
1443 Self::Unchecked
1444 }
1445 }
1446}
1447
1448impl CheckState {
1449 pub fn next(self, tristate: bool) -> Self {
1450 match self {
1451 Self::Checked => Self::Unchecked,
1452 Self::Unchecked if tristate => Self::PartiallyChecked,
1453 _ => Self::Checked,
1454 }
1455 }
1456}
1457
1458#[derive(Clone, Copy, Debug, PartialEq)]
1459pub struct GradientStop {
1460 pub color: Color,
1461 pub offset: f64,
1463}
1464
1465#[derive(Clone, Debug, PartialEq)]
1466pub enum Brush {
1467 Solid(Color),
1468 Linear {
1469 angle_degrees: f64,
1470 stops: Arc<[GradientStop]>,
1471 },
1472 Radial {
1473 stops: Arc<[GradientStop]>,
1474 },
1475}
1476
1477impl Default for Brush {
1478 fn default() -> Self {
1479 Self::Solid(Color::default())
1480 }
1481}
1482
1483#[derive(Clone, Debug, PartialEq)]
1484pub enum Value {
1485 EventResult(EventResult),
1486 FocusReason(FocusReason),
1487 KeyEvent(KeyEvent),
1488 WheelEvent(WheelEvent),
1489 PointerEvent(PointerEvent),
1490 TouchPoint(TouchPoint),
1491 TouchPoints(TouchPoints),
1492 KeyModifiers(KeyModifiers),
1493 Int(i64),
1494 Float(f64),
1495 Bool(bool),
1496 String(String),
1497 StyledText(StyledText),
1498 IntList(Vec<i64>),
1499 IntModel(VecModel<i64>),
1501 StringList(Vec<String>),
1502 StringModel(VecModel<String>),
1504 Record(RecordValue),
1505 RecordList(RecordList),
1506 ComboModel(ComboModel),
1507 Length(Length),
1508 Percent(Percent),
1509 Color(Color),
1510 Brush(Brush),
1511 Image(Image),
1512 ImageAsset(ImageAsset),
1513 LogLevel(LogLevel),
1514 ImageFit(ImageFit),
1515 ImageTileMode(ImageTileMode),
1516 ImageHorizontalAlignment(ImageHorizontalAlignment),
1517 ImageVerticalAlignment(ImageVerticalAlignment),
1518 ImageRendering(ImageRendering),
1519 LayoutAlignment(LayoutAlignment),
1520 CrossAxisAlignment(CrossAxisAlignment),
1521 Orientation(Orientation),
1522 FlickDirection(FlickDirection),
1523 FlickBoundsBehavior(FlickBoundsBehavior),
1524 FlickBoundsMovement(FlickBoundsMovement),
1525 LayoutDirection(LayoutDirection),
1526 FlexboxLayoutDirection(FlexboxLayoutDirection),
1527 FlexboxLayoutWrap(FlexboxLayoutWrap),
1528 DialInputMode(DialInputMode),
1529 ScrollBarPolicy(ScrollBarPolicy),
1530 ScrollSnapMode(ScrollSnapMode),
1531 ScrollAlignment(ScrollAlignment),
1532 TextWrap(TextWrap),
1533 TextHorizontalAlignment(TextHorizontalAlignment),
1534 TextVerticalAlignment(TextVerticalAlignment),
1535 TextOverflow(TextOverflow),
1536 InputType(InputType),
1537 CursorShape(CursorShape),
1538 PointerEventKind(PointerEventKind),
1539 PointerButton(PointerButton),
1540 PointerButtons(PointerButtons),
1541 ColorScheme(ColorScheme),
1542 FileDialogMode(FileDialogMode),
1543 MessageLevel(MessageLevel),
1544 MessageButtons(MessageButtons),
1545 CheckState(CheckState),
1546 DialogRole(DialogRole),
1547 StandardButtonKind(StandardButtonKind),
1548 SwipeSide(SwipeSide),
1549 DragAction(DragAction),
1550 DrawerEdge(DrawerEdge),
1551 PopupPlacement(PopupPlacement),
1552 SelectionTarget(SelectionTarget),
1553 Date(Date),
1554 Time(Time),
1555 Font(Font),
1556}
1557
1558impl Value {
1559 #[doc(hidden)]
1561 pub fn same_property_value(&self, other: &Self) -> bool {
1562 match (self, other) {
1563 (Self::Float(left), Self::Float(right)) => same_float_bits(left, right),
1564 (Self::Length(left), Self::Length(right)) => same_float_bits(&left.0, &right.0),
1565 (Self::Percent(left), Self::Percent(right)) => same_float_bits(&left.0, &right.0),
1566 _ => self.eq_with_image_assets(other),
1567 }
1568 }
1569
1570 #[doc(hidden)]
1572 pub fn eq_with_image_assets(&self, other: &Self) -> bool {
1573 match (self, other) {
1574 (Self::Image(embedded), Self::ImageAsset(asset))
1575 | (Self::ImageAsset(asset), Self::Image(embedded)) => {
1576 ImageAsset::from(embedded.clone()) == *asset
1577 }
1578 _ => self == other,
1579 }
1580 }
1581}
1582
1583macro_rules! value_from {
1584 ($ty:ty, $variant:ident) => {
1585 impl From<$ty> for Value {
1586 fn from(value: $ty) -> Self {
1587 Self::$variant(value)
1588 }
1589 }
1590 };
1591}
1592value_from!(i64, Int);
1593value_from!(f64, Float);
1594value_from!(bool, Bool);
1595value_from!(String, String);
1596value_from!(StyledText, StyledText);
1597value_from!(Vec<String>, StringList);
1598
1599impl From<VecModel<String>> for Value {
1600 fn from(model: VecModel<String>) -> Self {
1601 Self::StringList(model.into_snapshot())
1602 }
1603}
1604value_from!(Length, Length);
1605value_from!(Percent, Percent);
1606value_from!(Color, Color);
1607value_from!(Image, Image);
1608value_from!(LogLevel, LogLevel);
1609value_from!(ImageFit, ImageFit);
1610value_from!(ImageTileMode, ImageTileMode);
1611value_from!(ImageHorizontalAlignment, ImageHorizontalAlignment);
1612value_from!(ImageVerticalAlignment, ImageVerticalAlignment);
1613value_from!(ImageRendering, ImageRendering);
1614value_from!(LayoutAlignment, LayoutAlignment);
1615value_from!(CrossAxisAlignment, CrossAxisAlignment);
1616value_from!(Orientation, Orientation);
1617value_from!(FlickDirection, FlickDirection);
1618value_from!(FlickBoundsBehavior, FlickBoundsBehavior);
1619value_from!(FlickBoundsMovement, FlickBoundsMovement);
1620value_from!(LayoutDirection, LayoutDirection);
1621value_from!(FlexboxLayoutDirection, FlexboxLayoutDirection);
1622value_from!(FlexboxLayoutWrap, FlexboxLayoutWrap);
1623value_from!(DialInputMode, DialInputMode);
1624value_from!(ScrollBarPolicy, ScrollBarPolicy);
1625value_from!(ScrollSnapMode, ScrollSnapMode);
1626value_from!(ScrollAlignment, ScrollAlignment);
1627value_from!(TextWrap, TextWrap);
1628value_from!(TextHorizontalAlignment, TextHorizontalAlignment);
1629value_from!(TextVerticalAlignment, TextVerticalAlignment);
1630value_from!(TextOverflow, TextOverflow);
1631value_from!(InputType, InputType);
1632value_from!(CursorShape, CursorShape);
1633value_from!(PointerEventKind, PointerEventKind);
1634value_from!(PointerButton, PointerButton);
1635value_from!(PointerButtons, PointerButtons);
1636value_from!(ColorScheme, ColorScheme);
1637value_from!(FileDialogMode, FileDialogMode);
1638value_from!(MessageLevel, MessageLevel);
1639value_from!(MessageButtons, MessageButtons);
1640value_from!(CheckState, CheckState);
1641value_from!(DialogRole, DialogRole);
1642value_from!(StandardButtonKind, StandardButtonKind);
1643value_from!(SwipeSide, SwipeSide);
1644value_from!(DragAction, DragAction);
1645value_from!(DrawerEdge, DrawerEdge);
1646value_from!(PopupPlacement, PopupPlacement);
1647value_from!(SelectionTarget, SelectionTarget);
1648value_from!(Date, Date);
1649value_from!(Time, Time);
1650value_from!(Font, Font);
1651
1652impl From<Brush> for Value {
1653 fn from(value: Brush) -> Self {
1654 match value {
1655 Brush::Solid(color) => Self::Color(color),
1656 gradient => Self::Brush(gradient),
1657 }
1658 }
1659}
1660
1661#[derive(Clone, Debug)]
1662pub struct Node(NodeStorage);
1663
1664#[derive(Clone, Debug)]
1665#[allow(clippy::large_enum_variant)] enum NodeStorage {
1667 Inline(NodeData),
1668 Shared(Arc<NodeData>),
1669}
1670
1671#[doc(hidden)]
1673#[derive(Clone, Debug, PartialEq)]
1674pub struct NodeData {
1675 pub kind: &'static str,
1676 #[doc(hidden)]
1677 pub application_window: bool,
1678 pub id: Option<&'static str>,
1679 owned_id: Option<Arc<str>>,
1680 pub properties: BTreeMap<&'static str, Value>,
1681 #[doc(hidden)]
1682 pub fonts: Option<&'static EmbeddedFonts>,
1683 #[doc(hidden)]
1684 pub loaded_fonts: Option<LoadedFonts>,
1685 pub tumbler_items: Option<TumblerItems>,
1686 pub children: Vec<Node>,
1687 #[doc(hidden)]
1688 pub table_column_window: TableColumnWindow,
1689 #[doc(hidden)]
1690 pub timers: Vec<TimerRegistration>,
1691 #[doc(hidden)]
1692 pub image_playback: Option<Rc<ImagePlaybackRegistration>>,
1693 #[doc(hidden)]
1694 pub media: Option<MediaRegistration>,
1695 #[doc(hidden)]
1696 pub sound_effects: Vec<MediaRegistration>,
1697 #[doc(hidden)]
1698 pub media_frame: Option<MediaFrame>,
1699 #[doc(hidden)]
1700 pub native_dialogs: Vec<NativeDialogRegistration>,
1701 pub animations: BTreeMap<&'static str, Animation>,
1702 #[doc(hidden)]
1703 pub state_timings: Option<Box<BTreeMap<&'static str, StateTiming>>>,
1704 #[doc(hidden)]
1705 pub focus_handle: Option<FocusHandle>,
1706 #[doc(hidden)]
1707 pub button_press_handle: Option<ButtonPressHandle>,
1708 #[doc(hidden)]
1709 pub scale_rotate_handle: Option<ScaleRotateHandle>,
1710 #[doc(hidden)]
1711 pub swipe_handle: Option<SwipeHandle>,
1712 #[doc(hidden)]
1713 pub hover_handle: Option<HoverHandle>,
1714 #[doc(hidden)]
1715 pub pointer_handle: Option<PointerHandle>,
1716 #[doc(hidden)]
1717 pub scroll_event_handler: bool,
1718 #[doc(hidden)]
1719 pub press_and_hold_handler: bool,
1720 #[doc(hidden)]
1721 pub viewport_handle: Option<ViewportHandle>,
1722 #[doc(hidden)]
1723 pub scroll_target: Option<ViewportHandle>,
1724 #[doc(hidden)]
1725 pub geometry_handle: Option<GeometryHandle>,
1726 #[doc(hidden)]
1727 pub instance_geometry_handle: Option<GeometryHandle>,
1728 #[doc(hidden)]
1729 pub initial_focus: Option<FocusHandle>,
1730 #[doc(hidden)]
1731 pub key_handlers: u8,
1732 pub list: Option<ListMetrics>,
1733 #[doc(hidden)]
1734 pub row_locator: Option<ListRowLocator>,
1735 #[doc(hidden)]
1736 pub list_row_renderer: Option<ListRowRenderer>,
1737 #[doc(hidden)]
1738 pub row_heights: Option<Arc<RowHeights>>,
1739 #[doc(hidden)]
1740 pub list_sections: Option<Arc<[ListSection]>>,
1741 #[doc(hidden)]
1742 pub list_section_renderer: Option<ListSectionRenderer>,
1743 #[doc(hidden)]
1744 pub list_text_search: Option<ListTextSearch>,
1745 #[doc(hidden)]
1747 pub standard_list_stamp: Option<(u64, u64)>,
1748 pub table_header: Option<Box<TableHeader>>,
1749 #[doc(hidden)]
1750 pub table_column_order: TableColumnOrder,
1751 pub table_selection: Option<Box<TableSelectionSnapshot>>,
1752 #[doc(hidden)]
1753 pub table_cell_editor: Option<TableCellEditor>,
1754 pub tree: Option<Arc<TreeSnapshot>>,
1755 pub stack: Option<Arc<StackSnapshot>>,
1756 pub action: Option<ActionKey>,
1757 #[doc(hidden)]
1758 pub button_group: Option<ButtonGroupMembership>,
1759 pub(crate) radio_option_blocks: Option<Rc<Vec<controls::RadioOptionBlock>>>,
1760 pub tree_selection: Option<Arc<BTreeMap<i64, RowKey>>>,
1762 pub split_weights: Option<Arc<[Option<f32>]>>,
1763 #[doc(hidden)]
1764 pub split_fill_pane: Option<&'static str>,
1765 #[doc(hidden)]
1766 pub split_fill_index: Option<usize>,
1767 #[doc(hidden)]
1768 pub split_sizes: Option<Arc<[Option<f32>]>>,
1769 #[doc(hidden)]
1770 pub split_resize_handle: Option<SplitResizeHandle>,
1771 pub row_key: Option<RowKey>,
1772 #[doc(hidden)]
1773 pub row_scope: u64,
1774 paint_only: u8,
1775 static_paint_order: Option<ScenePlanSlice<usize>>,
1776 precompiled_path: Option<&'static StaticVectorPath>,
1777 loaded_path: Option<LoadedVectorPath>,
1778 static_grid: Option<ScenePlanSlice<GridCellSlot>>,
1779}
1780
1781impl std::ops::Deref for Node {
1782 type Target = NodeData;
1783
1784 fn deref(&self) -> &Self::Target {
1785 match &self.0 {
1786 NodeStorage::Inline(data) => data,
1787 NodeStorage::Shared(data) => data,
1788 }
1789 }
1790}
1791
1792impl std::ops::DerefMut for Node {
1793 fn deref_mut(&mut self) -> &mut Self::Target {
1794 let data = self.data_mut();
1795 data.static_grid = None;
1797 data.static_paint_order = None;
1798 data
1799 }
1800}
1801
1802impl PartialEq for Node {
1803 fn eq(&self, other: &Self) -> bool {
1804 **self == **other
1805 }
1806}
1807
1808impl NodeData {
1809 fn same_structure_and_state(&self, other: &Self) -> bool {
1810 macro_rules! compare {
1811 ($($field:ident),+ $(,)?) => {{
1812 let Self { properties: _, children: _, paint_only: _, media_frame: _, $($field: _,)+ } = self;
1814 $(self.$field == other.$field)&&+
1815 }};
1816 }
1817 compare!(
1818 kind,
1819 table_column_window,
1820 application_window,
1821 id,
1822 owned_id,
1823 fonts,
1824 loaded_fonts,
1825 tumbler_items,
1826 timers,
1827 image_playback,
1828 media,
1829 sound_effects,
1830 native_dialogs,
1831 animations,
1832 state_timings,
1833 focus_handle,
1834 button_press_handle,
1835 scale_rotate_handle,
1836 swipe_handle,
1837 hover_handle,
1838 pointer_handle,
1839 scroll_event_handler,
1840 press_and_hold_handler,
1841 viewport_handle,
1842 scroll_target,
1843 geometry_handle,
1844 instance_geometry_handle,
1845 initial_focus,
1846 key_handlers,
1847 list,
1848 row_locator,
1849 list_row_renderer,
1850 row_heights,
1851 list_sections,
1852 list_section_renderer,
1853 list_text_search,
1854 standard_list_stamp,
1855 table_header,
1856 table_column_order,
1857 table_selection,
1858 table_cell_editor,
1859 tree,
1860 stack,
1861 action,
1862 button_group,
1863 radio_option_blocks,
1864 tree_selection,
1865 split_weights,
1866 split_fill_pane,
1867 split_fill_index,
1868 split_sizes,
1869 split_resize_handle,
1870 row_key,
1871 row_scope,
1872 precompiled_path,
1873 loaded_path,
1874 static_grid,
1875 static_paint_order,
1876 )
1877 }
1878}
1879
1880pub fn is_text_input(kind: &str) -> bool {
1881 matches!(kind, "TextInput" | "LineEdit" | "SearchField") || is_multiline_text_input(kind)
1882}
1883
1884pub fn editable_table_cell(node: &Node) -> bool {
1885 matches!(node.kind, "TableCell" | "TreeCell")
1886 && node.boolean("editable", false)
1887 && !node.boolean("read-only", false)
1888}
1889
1890pub fn is_multiline_text_input(kind: &str) -> bool {
1891 matches!(kind, "TextEdit" | "TextArea")
1892}
1893
1894pub fn is_toggle(kind: &str) -> bool {
1895 matches!(kind, "CheckBox" | "Switch")
1896}
1897
1898#[doc(hidden)]
1900pub fn supports_untyped_dispatch(kind: &str, event: &str) -> bool {
1901 if matches!(event, "scrolled" | "flicked") || (kind == "SwipeDelegate" && event == "clicked") {
1902 return true;
1903 }
1904 !matches!(
1905 event,
1906 "check-state-changed" | "close-requested" | "pointer-event" | "scroll-event"
1907 ) && !is_multiline_text_input(kind)
1908 && !matches!(
1909 kind,
1910 "Slider"
1911 | "WheelHandler"
1912 | "Dial"
1913 | "ScrollBar"
1914 | "RangeSlider"
1915 | "SpinBox"
1916 | "DoubleSpinBox"
1917 | "SearchField"
1918 | "ComboBox"
1919 | "RadioGroup"
1920 | "ButtonGroup"
1921 | "TabWidget"
1922 | "TabBar"
1923 | "SwipeView"
1924 | "SwipeDelegate"
1925 | "StackView"
1926 | "StackPage"
1927 | "PageIndicator"
1928 | "Tumbler"
1929 | "Calendar"
1930 | "MonthGrid"
1931 | "TimePicker"
1932 | "TimePickerPopup"
1933 | "DatePickerPopup"
1934 | "ColorPickerPopup"
1935 | "FontPickerPopup"
1936 | "ListView"
1937 | "GridView"
1938 | "StandardListView"
1939 | "TableView"
1940 | "StandardTableView"
1941 | "SplitView"
1942 | "TreeView"
1943 | "Dialog"
1944 | "Drawer"
1945 | "PopupWindow"
1946 | "MenuItem"
1947 | "Shortcut"
1948 | "DelayButton"
1949 | "FocusScope"
1950 | "StyledText"
1951 | "AnimatedImage"
1952 | "DragArea"
1953 | "DropArea"
1954 | "GroupBox"
1955 )
1956}
1957
1958impl Node {
1959 #[doc(hidden)]
1960 pub fn table_edit_history_enabled(&self) -> bool {
1961 self.boolean("undoable", false) || self.boolean("pasteable", false)
1962 }
1963
1964 #[doc(hidden)]
1965 pub fn table_edit_history_model(&self, path: &[usize]) -> Option<u64> {
1966 let table = self.interactive_at_path(path)?;
1967 if !table.table_edit_history_enabled() {
1968 return None;
1969 }
1970 table.standard_list_stamp.map(|(model, _)| model)
1971 }
1972
1973 pub fn calendar_cells(&self) -> Option<&[Node]> {
1974 self.children
1975 .last()
1976 .filter(|child| child.kind == "CalendarCells")
1977 .map(|child| child.children.as_slice())
1978 }
1979
1980 pub fn is_item_delegate(&self) -> bool {
1981 self.boolean("__item-delegate", false)
1982 }
1983
1984 #[doc(hidden)]
1985 pub fn enables_children(&self) -> bool {
1986 !self.input_requires_enabled(false) || self.boolean("enabled", true)
1987 }
1988
1989 #[doc(hidden)]
1990 pub fn input_requires_enabled(&self, is_target: bool) -> bool {
1991 is_target
1992 || !(is_drag_area(self.kind)
1993 || matches!(
1994 self.kind,
1995 "WindowMoveArea"
1996 | "ScaleRotateGestureHandler"
1997 | "SwipeGestureHandler"
1998 | "WheelHandler"
1999 | "HoverHandler"
2000 | "TouchArea"
2001 ))
2002 }
2003 pub fn check_state(&self) -> CheckState {
2004 match self.properties.get("check-state") {
2005 Some(Value::CheckState(state)) if self.kind == "CheckBox" => *state,
2006 _ => self.boolean("checked", false).into(),
2007 }
2008 }
2009
2010 pub fn date(&self, name: &str) -> Option<Date> {
2011 match self.properties.get(name) {
2012 Some(Value::Date(date)) => Some(*date),
2013 _ => None,
2014 }
2015 }
2016
2017 pub fn time(&self, name: &str) -> Option<Time> {
2018 match self.properties.get(name) {
2019 Some(Value::Time(time)) => Some(*time),
2020 _ => None,
2021 }
2022 }
2023
2024 pub fn new(kind: &'static str, id: Option<&'static str>) -> Self {
2025 Self(NodeStorage::Inline(NodeData {
2026 kind,
2027 application_window: false,
2028 id,
2029 owned_id: None,
2030 properties: BTreeMap::new(),
2031 fonts: None,
2032 loaded_fonts: None,
2033 tumbler_items: None,
2034 children: Vec::new(),
2035 table_column_window: TableColumnWindow::default(),
2036 timers: Vec::new(),
2037 image_playback: None,
2038 media: None,
2039 sound_effects: Vec::new(),
2040 media_frame: None,
2041 native_dialogs: Vec::new(),
2042 animations: BTreeMap::new(),
2043 state_timings: None,
2044 focus_handle: None,
2045 button_press_handle: None,
2046 scale_rotate_handle: None,
2047 swipe_handle: None,
2048 hover_handle: None,
2049 pointer_handle: None,
2050 scroll_event_handler: false,
2051 press_and_hold_handler: false,
2052 viewport_handle: None,
2053 scroll_target: None,
2054 geometry_handle: None,
2055 instance_geometry_handle: None,
2056 initial_focus: None,
2057 key_handlers: 0,
2058 list: None,
2059 row_locator: None,
2060 list_row_renderer: None,
2061 row_heights: None,
2062 list_sections: None,
2063 list_section_renderer: None,
2064 list_text_search: None,
2065 standard_list_stamp: None,
2066 table_header: None,
2067 table_column_order: TableColumnOrder::default(),
2068 table_selection: None,
2069 table_cell_editor: None,
2070 tree: None,
2071 stack: None,
2072 action: None,
2073 button_group: None,
2074 radio_option_blocks: None,
2075 tree_selection: None,
2076 split_weights: None,
2077 split_fill_pane: None,
2078 split_fill_index: None,
2079 split_sizes: None,
2080 split_resize_handle: None,
2081 row_key: None,
2082 row_scope: 0,
2083 paint_only: 0,
2084 static_paint_order: None,
2085 precompiled_path: None,
2086 loaded_path: None,
2087 static_grid: None,
2088 }))
2089 }
2090
2091 #[doc(hidden)]
2093 pub fn into_shared(self) -> Self {
2094 match self.0 {
2095 NodeStorage::Inline(mut data) => {
2096 data.children = data.children.into_iter().map(Self::into_shared).collect();
2097 Self(NodeStorage::Shared(Arc::new(data)))
2098 }
2099 NodeStorage::Shared(data) => Self(NodeStorage::Shared(data)),
2100 }
2101 }
2102
2103 pub fn shares_storage_with(&self, other: &Self) -> bool {
2104 std::ptr::eq(self, other)
2105 || matches!((&self.0, &other.0), (NodeStorage::Shared(a), NodeStorage::Shared(b)) if Arc::ptr_eq(a, b))
2106 }
2107
2108 #[doc(hidden)]
2109 pub fn set_precompiled_path(&mut self, path: &'static StaticVectorPath) {
2110 self.precompiled_path = Some(path);
2111 }
2112
2113 #[doc(hidden)]
2114 pub fn precompiled_path(&self, commands: &str) -> Option<&'static StaticVectorPath> {
2115 self.precompiled_path
2116 .filter(|path| path.commands == commands)
2117 }
2118 #[doc(hidden)]
2119 pub fn set_loaded_vector_path(&mut self, path: LoadedVectorPath) {
2120 self.loaded_path = Some(path);
2121 }
2122
2123 #[doc(hidden)]
2124 pub fn vector_path_geometry(&self, commands: &str) -> Option<([f32; 4], &[VectorSegment])> {
2125 self.precompiled_path(commands)
2126 .map(|path| (path.bounds, path.segments))
2127 .or_else(|| self.loaded_path.as_ref()?.geometry(commands))
2128 }
2129
2130 fn data_mut(&mut self) -> &mut NodeData {
2133 match &mut self.0 {
2134 NodeStorage::Inline(data) => data,
2135 NodeStorage::Shared(data) => Arc::make_mut(data),
2136 }
2137 }
2138
2139 #[doc(hidden)]
2140 pub fn set_static_grid(&mut self, cells: &'static [GridCellSlot]) {
2141 self.data_mut().static_grid = Some(ScenePlanSlice::Static(cells));
2142 }
2143
2144 #[doc(hidden)]
2145 pub fn set_shared_grid(&mut self, cells: Arc<[GridCellSlot]>) {
2146 self.data_mut().static_grid = Some(ScenePlanSlice::Shared(cells));
2147 }
2148
2149 #[doc(hidden)]
2150 pub fn static_grid(&self) -> Option<&[GridCellSlot]> {
2151 self.static_grid.as_deref()
2152 }
2153
2154 #[doc(hidden)]
2155 pub fn set_static_paint_order(&mut self, order: &'static [usize]) {
2156 self.data_mut().static_paint_order =
2157 (!order.is_empty()).then_some(ScenePlanSlice::Static(order));
2158 }
2159
2160 #[doc(hidden)]
2161 pub fn set_shared_paint_order(&mut self, order: Arc<[usize]>) {
2162 self.data_mut().static_paint_order = Some(ScenePlanSlice::Shared(order));
2163 }
2164
2165 #[doc(hidden)]
2166 pub fn set_natural_paint_order(&mut self) {
2167 self.data_mut().static_paint_order = Some(ScenePlanSlice::Static(&[]));
2168 }
2169
2170 #[doc(hidden)]
2171 pub fn has_natural_paint_order(&self) -> bool {
2172 self.static_paint_order
2173 .as_deref()
2174 .is_some_and(<[usize]>::is_empty)
2175 }
2176
2177 #[doc(hidden)]
2178 pub fn static_paint_order(&self) -> Option<&[usize]> {
2179 self.paint_order_plan().map(std::ops::Deref::deref)
2180 }
2181
2182 #[doc(hidden)]
2183 pub fn paint_order_plan(&self) -> Option<&ScenePlanSlice<usize>> {
2184 self.static_paint_order
2185 .as_ref()
2186 .filter(|order| !order.is_empty())
2187 }
2188
2189 #[doc(hidden)]
2190 pub fn set_loaded_fonts(&mut self, fonts: Option<LoadedFonts>) {
2191 self.data_mut().loaded_fonts = fonts;
2192 }
2193
2194 #[doc(hidden)]
2195 pub fn set_embedded_fonts(&mut self, fonts: &'static EmbeddedFonts) {
2196 self.data_mut().fonts = Some(fonts);
2197 }
2198
2199 #[doc(hidden)]
2200 pub fn set_row_key(&mut self, key: Option<RowKey>) {
2201 if self.row_key != key {
2202 self.data_mut().row_key = key;
2203 }
2204 }
2205
2206 fn paint_only_bit(&self, property: &str) -> u8 {
2207 match (self.kind, property) {
2208 ("Rectangle", "background") => 1,
2209 ("Text", "color") => 2,
2210 ("Text" | "Label", "text") => 4,
2211 ("Image", "source") => 8,
2212 _ => 0,
2213 }
2214 }
2215
2216 #[doc(hidden)]
2217 pub fn mark_paint_only(&mut self, property: &str) {
2218 let bit = self.paint_only_bit(property);
2219 self.data_mut().paint_only |= bit;
2220 }
2221
2222 #[doc(hidden)]
2223 pub fn mark_paint_only_background(&mut self) {
2224 self.mark_paint_only("background");
2225 }
2226
2227 #[doc(hidden)]
2229 pub fn same_frame_inputs(&self, other: &Self) -> bool {
2230 if self.shares_storage_with(other) {
2231 return true;
2232 }
2233 let paint_only = self.paint_only & other.paint_only;
2234 let ignore_frame = self.kind == "AnimatedImage" && other.kind == "AnimatedImage";
2235 let ignore_colorize =
2236 matches!(self.kind, "Image" | "AnimatedImage") && self.kind == other.kind;
2237 let fixed_visual_box =
2238 |node: &Self| node.length("width").is_some() && node.length("height").is_some();
2239 let relevant = |(name, _): &(&&str, &Value)| match **name {
2240 "text" | "source" if paint_only & self.paint_only_bit(name) != 0 => {
2241 !fixed_visual_box(self) || !fixed_visual_box(other)
2242 }
2243 name if paint_only & self.paint_only_bit(name) != 0 => false,
2244 "opacity" => false,
2245 "drop-shadow-blur"
2246 | "drop-shadow-color"
2247 | "drop-shadow-offset-x"
2248 | "drop-shadow-offset-y"
2249 | "drop-shadow-spread"
2250 | "inner-shadow-blur"
2251 | "inner-shadow-color"
2252 | "inner-shadow-offset-x"
2253 | "inner-shadow-offset-y"
2254 | "inner-shadow-spread" => self.kind != "Rectangle",
2255 "current-frame" => !ignore_frame,
2256 "colorize" => !ignore_colorize,
2257 _ => true,
2258 };
2259 self.same_structure_and_state(other)
2260 && self
2261 .properties
2262 .iter()
2263 .filter(relevant)
2264 .eq(other.properties.iter().filter(relevant))
2265 && self.children.len() == other.children.len()
2266 && self
2267 .children
2268 .iter()
2269 .zip(&other.children)
2270 .all(|(child, other)| child.same_frame_inputs(other))
2271 }
2272
2273 #[doc(hidden)]
2275 pub fn same_paint_except_opacity(&self, other: &Self) -> bool {
2276 let without_opacity = |(name, _): &(&&str, &Value)| **name != "opacity";
2277 self.shares_storage_with(other)
2278 || self.same_structure_and_state(other)
2279 && self.media_frame == other.media_frame
2280 && self
2281 .properties
2282 .iter()
2283 .filter(without_opacity)
2284 .eq(other.properties.iter().filter(without_opacity))
2285 && self.children == other.children
2286 }
2287 pub fn hidden() -> Self {
2289 let mut node = Self::new("Empty", None);
2290 node.properties.insert("visible", Value::Bool(false));
2291 node
2292 }
2293 pub fn element_id(&self) -> Option<&str> {
2295 self.id.or(self.owned_id.as_deref())
2296 }
2297
2298 #[doc(hidden)]
2299 pub fn shared_element_id(&self) -> Option<Arc<str>> {
2300 self.owned_id.clone()
2301 }
2302
2303 #[doc(hidden)]
2304 pub fn element_id_owned(&self) -> Option<std::borrow::Cow<'static, str>> {
2305 use std::borrow::Cow;
2306 self.id
2307 .map(Cow::Borrowed)
2308 .or_else(|| self.owned_id.as_ref().map(|id| Cow::Owned(id.to_string())))
2309 }
2310
2311 #[doc(hidden)]
2312 pub fn set_owned_id(&mut self, id: Option<Arc<str>>) {
2313 let data = self.data_mut();
2314 data.id = None;
2315 data.owned_id = id;
2316 }
2317
2318 #[doc(hidden)]
2319 pub fn set_static_id(&mut self, id: Option<&'static str>) {
2320 let data = self.data_mut();
2321 data.id = id;
2322 data.owned_id = None;
2323 }
2324
2325 #[doc(hidden)]
2326 pub fn set_instance_geometry_handle(&mut self, handle: GeometryHandle) {
2327 self.data_mut().instance_geometry_handle = Some(handle);
2328 }
2329
2330 #[doc(hidden)]
2333 pub fn set_instance_layout_property(&mut self, name: &'static str, value: Value) {
2334 self.data_mut().properties.insert(name, value);
2335 }
2336
2337 pub fn find(&self, id: &str) -> Option<&Node> {
2338 if self.element_id() == Some(id) {
2339 Some(self)
2340 } else {
2341 self.children.iter().find_map(|n| n.find(id))
2342 }
2343 }
2344
2345 pub fn length(&self, name: &str) -> Option<f32> {
2346 match self.properties.get(name) {
2347 Some(Value::Length(Length(value))) if value.is_finite() => {
2348 Some(value.clamp(-1_000_000.0, 1_000_000.0) as f32)
2349 }
2350 _ => None,
2351 }
2352 }
2353
2354 pub fn relative_length(&self, name: &str, reference: f32) -> Option<f32> {
2355 match self.properties.get(name) {
2356 Some(Value::Percent(Percent(factor))) if factor.is_finite() => {
2357 Some((factor * f64::from(reference)).clamp(-1_000_000.0, 1_000_000.0) as f32)
2358 }
2359 _ => self.length(name),
2360 }
2361 }
2362
2363 pub fn boolean(&self, name: &str, default: bool) -> bool {
2364 match self.properties.get(name) {
2365 Some(Value::Bool(value)) => *value,
2366 _ => default,
2367 }
2368 }
2369
2370 pub fn text(&self, name: &str) -> Option<&str> {
2371 match self.properties.get(name) {
2372 Some(Value::String(value)) => Some(value),
2373 Some(Value::StyledText(value)) => Some(value.text()),
2374 _ => None,
2375 }
2376 }
2377
2378 pub fn font(&self, name: &str) -> Option<&Font> {
2379 match self.properties.get(name) {
2380 Some(Value::Font(font)) => Some(font),
2381 _ => None,
2382 }
2383 }
2384
2385 pub fn font_size(&self) -> Option<f32> {
2386 self.length("font-size")
2387 .or_else(|| self.font("font").and_then(Font::finite_size))
2388 }
2389
2390 pub fn styled_text(&self, name: &str) -> Option<&StyledText> {
2391 match self.properties.get(name) {
2392 Some(Value::StyledText(value)) => Some(value),
2393 _ => None,
2394 }
2395 }
2396
2397 #[doc(hidden)]
2399 pub fn try_prepare_text_link<E>(
2400 &self,
2401 index: usize,
2402 input: InputRoute<'_>,
2403 live: impl FnOnce() -> Result<StyledText, E>,
2404 ) -> Result<Option<&str>, E> {
2405 let Some(document) = self.styled_text("text") else {
2406 return Ok(None);
2407 };
2408 let Some(link) = document.links().get(index) else {
2409 return Ok(None);
2410 };
2411 input.try_prepare(
2412 || Ok(true),
2413 || Ok((live()? == *document).then_some(link.href.as_ref())),
2414 )
2415 }
2416
2417 #[doc(hidden)]
2418 pub fn prepare_text_link(
2419 &self,
2420 index: usize,
2421 input: InputRoute<'_>,
2422 live: impl FnOnce() -> StyledText,
2423 ) -> Option<&str> {
2424 self.try_prepare_text_link(index, input, || Ok::<_, std::convert::Infallible>(live()))
2425 .unwrap_or_else(|error| match error {})
2426 }
2427
2428 pub fn strings(&self, name: &str) -> &[String] {
2429 match self.properties.get(name) {
2430 Some(Value::StringList(values)) => values,
2431 _ => &[],
2432 }
2433 }
2434
2435 pub fn float(&self, name: &str) -> Option<f32> {
2436 self.number(name)
2437 .map(|value| value.clamp(-1_000_000.0, 1_000_000.0) as f32)
2438 }
2439
2440 pub fn number(&self, name: &str) -> Option<f64> {
2441 match self.properties.get(name) {
2442 Some(Value::Float(value)) if value.is_finite() => Some(*value),
2443 _ => None,
2444 }
2445 }
2446
2447 pub fn opacity(&self) -> f32 {
2449 self.number("opacity").unwrap_or(1.0).clamp(0.0, 1.0) as f32
2450 }
2451
2452 pub fn z(&self) -> f64 {
2454 self.number("z").filter(|&z| z != 0.0).unwrap_or_default()
2455 }
2456
2457 pub fn layout_direction(&self) -> Option<LayoutDirection> {
2458 match self.properties.get("layout-direction") {
2459 Some(Value::LayoutDirection(direction)) => Some(*direction),
2460 _ => None,
2461 }
2462 }
2463
2464 pub fn orientation(&self) -> Orientation {
2465 match self.properties.get("orientation") {
2466 Some(Value::Orientation(value)) => *value,
2467 _ if matches!(self.kind, "ScrollBar" | "ScrollIndicator" | "ToolSeparator") => {
2468 Orientation::Vertical
2469 }
2470 _ => Orientation::Horizontal,
2471 }
2472 }
2473
2474 pub fn dial_input_mode(&self) -> DialInputMode {
2475 match self.properties.get("input-mode") {
2476 Some(Value::DialInputMode(value)) => *value,
2477 _ => DialInputMode::Circular,
2478 }
2479 }
2480
2481 pub fn scroll_bar_policy(&self, orientation: Orientation) -> ScrollBarPolicy {
2482 let property = match orientation {
2483 Orientation::Horizontal => "horizontal-scroll-bar-policy",
2484 Orientation::Vertical => "vertical-scroll-bar-policy",
2485 };
2486 match self.properties.get(property) {
2487 Some(Value::ScrollBarPolicy(policy)) => *policy,
2488 _ => ScrollBarPolicy::AsNeeded,
2489 }
2490 }
2491
2492 pub fn text_wrap(&self) -> TextWrap {
2493 match self.properties.get("wrap") {
2494 Some(Value::TextWrap(wrap)) => *wrap,
2495 _ => TextWrap::default(),
2496 }
2497 }
2498
2499 pub fn is_password(&self) -> bool {
2500 self.input_type() == InputType::Password
2501 }
2502
2503 pub fn password_masked(&self) -> bool {
2504 self.is_password() && !self.boolean("password-visible", false)
2505 }
2506
2507 pub fn dialog_role(&self) -> DialogRole {
2508 match self.properties.get("role") {
2509 Some(Value::DialogRole(role)) => *role,
2510 _ => DialogRole::default(),
2511 }
2512 }
2513
2514 pub fn standard_button_kind(&self) -> Option<StandardButtonKind> {
2515 match (self.kind, self.properties.get("kind")) {
2516 ("Button", Some(Value::StandardButtonKind(kind))) => Some(*kind),
2517 _ => None,
2518 }
2519 }
2520
2521 pub fn swipe_side(&self) -> SwipeSide {
2522 match self.properties.get("open-side") {
2523 Some(Value::SwipeSide(side)) => *side,
2524 _ => SwipeSide::Closed,
2525 }
2526 }
2527
2528 #[doc(hidden)]
2529 pub fn accepts_swipe_side(&self, current: SwipeSide, side: SwipeSide) -> bool {
2530 self.swipe_side() == current
2531 && current != side
2532 && (side == SwipeSide::Closed || self.swipe_panel(side).is_some())
2533 }
2534
2535 pub fn swipe_panel(&self, side: SwipeSide) -> Option<&Node> {
2536 let kind = side.panel()?;
2537 self.children
2538 .iter()
2539 .find(|child| child.kind == kind && child.is_visible())
2540 }
2541
2542 pub fn drawer_edge(&self) -> DrawerEdge {
2543 match self.properties.get("edge") {
2544 Some(Value::DrawerEdge(edge)) => *edge,
2545 _ => DrawerEdge::Left,
2546 }
2547 }
2548
2549 pub fn selection_target(&self) -> SelectionTarget {
2550 match self.properties.get("selection-target") {
2551 Some(Value::SelectionTarget(target)) => *target,
2552 _ => SelectionTarget::Rows,
2553 }
2554 }
2555
2556 pub fn is_visible(&self) -> bool {
2557 self.boolean("visible", true)
2558 && (!is_window_overlay(self.kind) || self.boolean("open", false))
2559 }
2560
2561 #[doc(hidden)]
2562 pub fn handles_wheel(&self) -> bool {
2563 self.kind == "WheelHandler" || self.kind == "TouchArea" && self.scroll_event_handler
2564 }
2565
2566 #[doc(hidden)]
2567 pub fn accepts_pointer_button(&self, button: PointerButton) -> bool {
2568 match self.properties.get("accepted-buttons") {
2569 Some(Value::PointerButtons(buttons)) => buttons.contains(button),
2570 _ => true,
2571 }
2572 }
2573
2574 pub fn cursor_shape(&self) -> CursorShape {
2575 match self.properties.get("cursor-shape") {
2576 Some(Value::CursorShape(shape)) => *shape,
2577 _ => CursorShape::Auto,
2578 }
2579 }
2580
2581 pub fn is_modal(&self) -> bool {
2582 is_modal_overlay(self.kind) || self.kind == "PopupWindow" && self.boolean("modal", false)
2583 }
2584
2585 pub fn stack_page_index(&self) -> Option<usize> {
2586 self.stack_route_index(self.stack.as_ref()?.current()?)
2587 }
2588
2589 #[doc(hidden)]
2590 pub fn stack_route_index(&self, page: &str) -> Option<usize> {
2591 self.children
2592 .iter()
2593 .position(|node| node.text("__stack-route").or_else(|| node.element_id()) == Some(page))
2594 }
2595
2596 pub fn int(&self, name: &str) -> Option<i64> {
2597 match self.properties.get(name) {
2598 Some(Value::Int(value)) => Some(*value),
2599 _ => None,
2600 }
2601 }
2602
2603 pub fn image(&self, name: &str) -> Option<Image> {
2604 match self.properties.get(name) {
2605 Some(Value::Image(value)) => Some(value.clone()),
2606 _ => None,
2607 }
2608 }
2609
2610 pub fn image_asset(&self, name: &str) -> Option<ImageAsset> {
2611 match self.properties.get(name) {
2612 Some(Value::Image(value)) => Some(value.clone().into()),
2613 Some(Value::ImageAsset(value)) => Some(value.clone()),
2614 _ => None,
2615 }
2616 }
2617
2618 pub fn image_fit(&self, name: &str) -> Option<ImageFit> {
2619 match self.properties.get(name) {
2620 Some(Value::ImageFit(value)) => Some(*value),
2621 _ => None,
2622 }
2623 }
2624
2625 pub fn image_tile_mode(&self, name: &str) -> ImageTileMode {
2626 match self.properties.get(name) {
2627 Some(Value::ImageTileMode(value)) => *value,
2628 _ => ImageTileMode::default(),
2629 }
2630 }
2631
2632 pub fn color(&self, name: &str) -> Option<Color> {
2633 match self.properties.get(name) {
2634 Some(Value::Color(value) | Value::Brush(Brush::Solid(value))) => Some(*value),
2635 _ => None,
2636 }
2637 }
2638
2639 pub fn color_scheme(&self) -> Option<ColorScheme> {
2640 match self.properties.get("color-scheme") {
2641 Some(Value::ColorScheme(scheme)) => Some(*scheme),
2642 _ => None,
2643 }
2644 }
2645
2646 pub fn child_at(&self, index: usize) -> Option<&Self> {
2648 self.children
2649 .get(self.table_column_window.dense_index(index)?)
2650 }
2651
2652 #[doc(hidden)]
2653 pub fn child_at_mut(&mut self, index: usize) -> Option<&mut Self> {
2654 let index = self.table_column_window.dense_index(index)?;
2655 self.children.get_mut(index)
2656 }
2657
2658 pub fn materialized_children(
2660 &self,
2661 ) -> impl DoubleEndedIterator<Item = (usize, &Self)> + ExactSizeIterator {
2662 self.children
2663 .iter()
2664 .enumerate()
2665 .map(|(index, child)| (self.table_column_window.logical_index(index), child))
2666 }
2667
2668 #[doc(hidden)]
2669 pub fn control_part(&self, kind: &str) -> Option<&Self> {
2670 self.children.iter().find(|child| child.kind == kind)
2671 }
2672
2673 #[doc(hidden)]
2674 pub fn is_control_part(&self) -> bool {
2675 matches!(
2676 self.kind,
2677 "ButtonContent"
2678 | "SliderHandle"
2679 | "RangeLowerHandle"
2680 | "RangeUpperHandle"
2681 | "ToggleIndicator"
2682 | "SwitchThumb"
2683 | "SpinUpIndicator"
2684 | "SpinDownIndicator"
2685 | "TreeDisclosure"
2686 )
2687 }
2688
2689 pub fn at_path(&self, path: &[usize]) -> Option<&Self> {
2690 let mut node = self;
2691 for &index in path {
2692 node = node.child_at(index)?;
2693 }
2694 Some(node)
2695 }
2696
2697 #[doc(hidden)]
2699 pub fn try_input_scope_available<E>(
2700 &self,
2701 child: Option<&Self>,
2702 open: impl FnOnce() -> Result<bool, E>,
2703 checkable: impl FnOnce() -> Result<bool, E>,
2704 checked: impl FnOnce() -> Result<bool, E>,
2705 swipe_side: impl FnOnce() -> Result<SwipeSide, E>,
2706 ) -> Result<bool, E> {
2707 if is_window_overlay(self.kind) && !open()? {
2708 return Ok(false);
2709 }
2710 let Some(child) = child else {
2711 return Ok(true);
2712 };
2713 if self.kind == "GroupBox" && checkable()? && !checked()? {
2714 return Ok(false);
2715 }
2716 if self.kind == "SwipeDelegate" && matches!(child.kind, "SwipeLeft" | "SwipeRight") {
2717 return Ok(swipe_side()?.panel() == Some(child.kind));
2718 }
2719 Ok(true)
2720 }
2721
2722 #[doc(hidden)]
2723 pub fn input_scope_available(
2724 &self,
2725 child: Option<&Self>,
2726 open: impl FnOnce() -> bool,
2727 checkable: impl FnOnce() -> bool,
2728 checked: impl FnOnce() -> bool,
2729 swipe_side: impl FnOnce() -> SwipeSide,
2730 ) -> bool {
2731 self.try_input_scope_available(
2732 child,
2733 || Ok::<_, std::convert::Infallible>(open()),
2734 || Ok(checkable()),
2735 || Ok(checked()),
2736 || Ok(swipe_side()),
2737 )
2738 .unwrap_or_else(|error| match error {})
2739 }
2740
2741 fn scene_input_scope_available(&self, child: Option<&Self>) -> bool {
2742 self.input_scope_available(
2743 child,
2744 || self.boolean("open", false),
2745 || self.group_checkable(),
2746 || self.boolean("checked", true),
2747 || self.swipe_side(),
2748 )
2749 }
2750
2751 pub fn interactive_at_path(&self, path: &[usize]) -> Option<&Self> {
2752 let mut node = self;
2753 for (depth, index) in path.iter().enumerate() {
2754 if !node.boolean("visible", true) || !node.enables_children() {
2755 return None;
2756 }
2757 let child = node.child_at(*index)?;
2758 if !node.scene_input_scope_available(Some(child)) {
2759 return None;
2760 }
2761 let has_page_content = depth + 1 < path.len() || node.kind != "TabWidget";
2762 if has_page_content {
2763 let active = match node.kind {
2764 "TabWidget" | "SwipeView" => group_index(node),
2765 "StackView" => node.stack_page_index(),
2766 _ => Some(*index),
2767 };
2768 if active != Some(*index) {
2769 return None;
2770 }
2771 }
2772 node = child;
2773 }
2774 (node.boolean("visible", true)
2775 && node.boolean("enabled", true)
2776 && node.scene_input_scope_available(None))
2777 .then_some(node)
2778 }
2779
2780 #[doc(hidden)]
2782 pub fn table_cell_commit_target(&self, path: &[usize], original: &str) -> Option<&Self> {
2783 self.interactive_at_path(path).filter(|node| {
2784 editable_table_cell(node) && node.text("text").unwrap_or_default() == original
2785 })
2786 }
2787
2788 #[doc(hidden)]
2790 pub fn dispatch_target(&self, path: &[usize], event: &str) -> Option<&Self> {
2791 let node = self.at_path(path)?;
2792 let target = if node.terminal_dispatch(event) {
2793 node
2794 } else {
2795 self.interactive_at_path(path)?
2796 };
2797 (event != "accepted" || !is_text_input(target.kind) || target.accepts_text_submission())
2798 .then_some(target)
2799 }
2800
2801 fn terminal_dispatch(&self, event: &str) -> bool {
2802 matches!(
2803 (self.kind, event),
2804 ("ScaleRotateGestureHandler", "ended" | "cancelled")
2805 | ("SwipeGestureHandler", "swiped" | "cancelled")
2806 | ("HoverHandler", "exited")
2807 | ("Button" | "ToolButton" | "RoundButton", "canceled")
2808 )
2809 }
2810
2811 #[doc(hidden)]
2812 pub fn focus_event_target(&self, path: &[usize], event: FocusEvent) -> Option<&Self> {
2813 let node = if event.is_loss() {
2814 self.at_path(path)
2815 } else {
2816 self.interactive_at_path(path)
2817 };
2818 node.filter(|node| node.kind == "FocusScope")
2819 }
2820
2821 #[doc(hidden)]
2822 pub fn key_event_target(&self, path: &[usize], phase: KeyPhase) -> Option<&Self> {
2823 self.interactive_at_path(path)
2824 .filter(|node| node.kind == "FocusScope" && node.key_handlers & phase.mask() != 0)
2825 }
2826
2827 pub fn group_checkable(&self) -> bool {
2828 self.kind == "GroupBox" && self.boolean("checkable", false)
2829 }
2830
2831 pub fn group_content_enabled(&self) -> bool {
2832 !self.group_checkable() || self.boolean("checked", true)
2833 }
2834
2835 #[doc(hidden)]
2836 pub fn control_target(&self, path: &[usize], action: ControlAction) -> Option<&Self> {
2837 if action != ControlAction::Drawer(true) {
2838 return self.interactive_at_path(path).filter(|node| {
2839 !matches!(action, ControlAction::SetSwitch(_)) || node.kind == "Switch"
2840 });
2841 }
2842 let node = match path.split_last() {
2843 Some((&index, parent)) => {
2844 let parent = self.interactive_at_path(parent)?;
2845 if !parent.group_content_enabled() {
2846 return None;
2847 }
2848 parent.child_at(index)?
2849 }
2850 None => self,
2851 };
2852 (node.kind == "Drawer" && node.boolean("visible", true) && node.boolean("enabled", true))
2853 .then_some(node)
2854 }
2855
2856 pub fn routing_row_key(&self) -> Option<RowKey> {
2858 self.row_key.map(|key| key.in_view(self.row_scope))
2859 }
2860
2861 pub fn row_key_at(&self, path: &[usize]) -> Option<RowKey> {
2863 let mut node = self;
2864 let mut key = None;
2865 for &index in path {
2866 node = node.child_at(index)?;
2867 if node.kind == "ListRow" {
2868 key = node.routing_row_key();
2869 }
2870 }
2871 key
2872 }
2873
2874 pub fn displayed_row_for_key(&self, key: RowKey, source_index: usize) -> Option<usize> {
2876 if let Some(tree) = &self.tree {
2877 tree.position_of_source_key(key, source_index)
2878 } else {
2879 self.row_locator
2880 .as_ref()?
2881 .position_of_source_key(key, source_index)
2882 }
2883 }
2884}