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