i_slint_compiler/passes/
check_drag_area.rs1use crate::diagnostics::BuildDiagnostics;
8use crate::object_tree::{Component, ElementRc};
9
10const ALLOW_PROPERTIES: [&str; 3] = ["allow-copy", "allow-move", "allow-link"];
11
12pub fn check_drag_area(component: &Component, diag: &mut BuildDiagnostics) {
13 crate::object_tree::recurse_elem_including_sub_components_no_borrow(
14 component,
15 &(),
16 &mut |elem, _| {
17 if !is_drag_area(elem) {
18 return;
19 }
20 if ALLOW_PROPERTIES.iter().any(|prop| elem.borrow().is_property_set(prop)) {
21 return;
22 }
23 diag.push_warning(
24 "This 'DragArea' permits no drag action and will never start a drag; \
25 set 'allow-copy', 'allow-move', or 'allow-link' to true"
26 .into(),
27 &*elem.borrow(),
28 );
29 },
30 );
31}
32
33fn is_drag_area(e: &ElementRc) -> bool {
34 e.borrow().builtin_type().is_some_and(|bt| bt.name.as_str() == "DragArea")
35}