Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elements with no zOrder specified recieve Mouse Events back-to-front #652

Closed
PolyVector opened this issue May 11, 2022 · 5 comments
Closed
Labels
Bug Reproduced bug. Documentation This issue is about documentation.

Comments

@PolyVector
Copy link

PolyVector commented May 11, 2022

Hello,
I've noticed that if I don't call setZOrder() on UIElements, they will receive events like onMouseOver and onMouseClick in the wrong order (back-to-front). This is causing an issue for me where a "popup" dialog for credits allows clicking through to the knobs below.

This is easily resolved by setting the zOrder to anything above 0.

It appears this is caused by the list being built back-to-front, and the sorting algorithm leaving this untouched if zOrder values match. I believe building the list front-to-back would solve the issue.

From element.d

    final void recomputeZOrderedChildren()
    {
        // Get a z-ordered list of childrens
        _zOrderedChildren.clearContents();
        foreach(child; _children[]) // ### The culprit? Children should probably be added in reverse order
            _zOrderedChildren.pushBack(child);

        // This is a stable sort, so the order of children with same z-order still counts.
        grailSort!UIElement(_zOrderedChildren[],

Here's a quick demonstration of the problem: zOrderBug.zip

@p0nce
Copy link
Collaborator

p0nce commented May 11, 2022

Thanks for an excellent bug report! I'm pleased that you use so much Wren already :)
Did you know we have a new Discord? https://discord.com/invite/7PdUvUbyJs

And indeed, I think you are right with the bug and the solution too.
TODO

  • compare with HTML
  • Make an Option to use that, implement the Option

Because this could break existing plugins, the new behaviour will be guarded behind a "futureXXX" Dplug Option before becoming default.

(unrelated: zOrder is broken with PBR and Raw layers, as Raw widgets are always displayed above PBR ones, so even if their zOrder disagree they could be in another display order. Never occured yet as bug)

@p0nce
Copy link
Collaborator

p0nce commented May 11, 2022

<!doctype html>
<html>
<body>
  <div style="color: red; position: absolute; top: 10px; left: 10px; width: 50px; height: 50px; background: yellow">First</div>
  <div style="color: green; position: absolute; top: 20px; left: 20px; width: 50px; height: 50px; background: pink">Second</div>
  <div style="color: blue; position: absolute; top: 30px; left: 30px; width: 50px; height: 50px; background: black">Third</div>
</div>
</body>
</html>

leads to

image

so indeed what the rule should be: "next in the array of children => first to draw."

@PolyVector
Copy link
Author

LOL, you just made me realize I left the entire Wren script from my WiP plugin in there even though the test doesn't use it. Oops!

Yeah, Dplug+Wren has been amazing for quickly iterating, it sure beats my old Krita exporter that spit out layout information.

I'm glad if the report was helpful, and a futureXXX option sounds like a safe bet. :)

@p0nce
Copy link
Collaborator

p0nce commented May 11, 2022

Tip: RGBA now have .blacken(t) and .whiten(t) methods that make the color darker or whiter. It is like your darkenColor and lightenColor. Deleting the Wren file!

@p0nce p0nce added Bug Reproduced bug. Documentation This issue is about documentation. labels May 11, 2022
p0nce pushed a commit that referenced this issue May 11, 2022
@p0nce
Copy link
Collaborator

p0nce commented May 11, 2022

Solution: use Dplug v12.6.0+ and add

"versions": ["futureZOrder"],

to your dub.json.

@p0nce p0nce closed this as completed May 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Reproduced bug. Documentation This issue is about documentation.
Projects
None yet
Development

No branches or pull requests

2 participants