slint-ui / slint

Slint is a declarative GUI toolkit to build native user interfaces for Rust, C++, or JavaScript apps.
https://slint.dev
Other
17.64k stars 607 forks source link

Element click penetration #6812

Closed xjy12345654 closed 3 days ago

xjy12345654 commented 4 days ago

platform :windows11,slintPad expected behavior:When self.checked=true and re1 overrides re2, clicking re1 should not trigger the callback fn of chekbox; code: code_url

import { CheckBox } from "std-widgets.slint";
export component Recipe inherits Window {
    width: 200px;
    height: 100px;
     re1 := Rectangle {
        property <duration> ani_dutime:300ms;
        x: 0;
        y: 0;
        width: 50px;
        height: 50px;
        background: blueviolet;
        z: 2;
        animate x { duration: self.ani_dutime; }
        animate y {
            delay: self.ani_dutime;
            duration: self.ani_dutime;
        }
    }

    re2 := Rectangle {
        y: re1.height;
        background: #aaa;
        VerticalLayout {
            CheckBox {
                text: "check";
                toggled => {
                    if (self.checked) {
                       // re1.x = root.width - re1.width;
                        re1.y = re1.height;
                    } else {
                        re1.x = 0;
                        re1.y = 0;
                    }
                }
            }
        }
    }
}
hunger commented 3 days ago

Interesting problem this, I do not think this is a bug though.

Rectangle are "transparent" to events, so I kind of expect the behavior this code exhibits. You can put a TouchArea { } into re1 and then the rectangle is no longer transparent for events.

xjy12345654 commented 3 days ago

有趣的问题是,我不认为这是一个错误。

Rectangle 对事件是 “透明的”,所以我有点期待这段代码所展示的行为。您可以输入 into,然后矩形对于事件不再透明。TouchArea { }``re1

@hunger Thank you for your answer!I was deeply influenced by the HTML DOM system and my own philosophy....sorry. Adding touch areas has indeed achieved the expected behavior