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.73k stars 614 forks source link

`z` property in base component doesn't work unless one sets the `visible` property #4466

Open asuper0 opened 10 months ago

asuper0 commented 10 months ago

Environment: Slint 1.3.2 Win 10

Please see the code. I implement a message box with slint. Currently the code is ok. If I comment out visable: false within the PopMessageBox and uncomment // visible: false; in main window, the message box can't mask the whole window. You can try to reproduce by invoke show_message_box in main.rs .

asuper0 commented 10 months ago

I just add two commit for testing. this commit support "save" button to show message box this one show the bug

overlap_ok overlap_bug

and the two pictures show difference between the two commits.

ogoffart commented 2 months ago

Thanks for filling a bug report. I can reproduce the problem: Here is a minimal testcase:

component PopMessageBox inherits Rectangle {
    background: red;
    z: 1;
    // Incomment for this to work
    // visible: true;
}

export component Main inherits Window {
    PopMessageBox{  }
    Rectangle { background: blue; }
}

You'd expect the red rectangle to be on top because of the z:1, but that doesn't work. It strangely does work when setting visible: true. This seems to point to a bug in the compiler.

ogoffart commented 2 months ago

When there is a visible property in the root, we always inline earlier in the process. Which is why it "works" when visible property is present.

That said, I'm actually wondering if the z on the root element should be allowed at all.

For example if you have:

component SomeComponent {
   Abc {}
   Def {}
}

Would you expect Def to be under Abc? (if Abc or Def have a z at their root changing the order) IMHO, the z ordering should be limited to the current "scope" of components, and one shouldn't be able to hack the order by having z set on the root. So I'd say Def should always be on top of Abc regardless what z property they set internally.

tronical commented 2 months ago

IMO it should always apply to siblings in the tree of elements. Abc and Def are siblings. Their z should apply regardless of set inside Abc or at the use-site.

asuper0 commented 2 months ago

So it's better to move message-box := PopMessageBox to bottom of the main window, without giving the z property, right?