Skip to main content

i_slint_compiler/passes/
check_drag_area.rs

1// Copyright © SixtyFPS GmbH <info@slint.dev>
2// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
3
4//! This pass warns about a `DragArea` that permits no drag action, i.e. none of
5//! `allow-copy`, `allow-move`, or `allow-link` is set. Such a `DragArea` never starts a drag.
6
7use 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}