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

Setting the visibility of UI nodes is confusing and redundant #5368

Open
alice-i-cecile opened this issue Jul 18, 2022 · 13 comments
Open

Setting the visibility of UI nodes is confusing and redundant #5368

alice-i-cecile opened this issue Jul 18, 2022 · 13 comments
Labels
A-UI Graphical user interfaces, styles, layouts, and widgets C-Docs An addition or correction to our documentation

Comments

@alice-i-cecile
Copy link
Member

alice-i-cecile commented Jul 18, 2022

What problem does this solve or what need does it fill?

The visibility of UI entities can be controlled in two distinct ways: via the Style component's field, and by setting Visibility (you could also muck with ComputedVisibility but please don't).

This is both confusing, and results in inconsistent behavior (see #5360 and the resulting #5361).

What solution would you like?

Remove the Display field of Style, and let users set this via the Visiblity component instead. In the interface with taffy, construct the taffy::Style struct information based on the combination of these components.

This is simple, allows for direct querying and is much more consistent with the rest of the engine.

What alternative(s) have you considered?

  1. Use Display as the canonical representation. This is confusing, and ties us tightly to CSS's model rather than being modular. It's also very inconsistent with the way visibility is handled elsewhere.
  2. Automatically sync these. This has non-zero computational costs and serious complexity (and bug-risk) costs, for no apparent benefit.

Additional context

Prompted by @mockersf complaining about this in #5361 (comment) <3

@alice-i-cecile alice-i-cecile added C-Bug An unexpected or incorrect behavior A-UI Graphical user interfaces, styles, layouts, and widgets C-Code-Quality A section of code that is hard to understand or change labels Jul 18, 2022
@hymm
Copy link
Contributor

hymm commented Jul 18, 2022

Just for some context. In CSS changing the display property removes the node from layouting, while visibility just makes it not visible, but doesn't affect the layout.

Not sure if this is similar in bevy.

@mockersf
Copy link
Member

Not sure if this is similar in bevy.

Oh... then that's how Bevy currently work... do you know if events are still triggered by a not visible element?

@hymm
Copy link
Contributor

hymm commented Jul 18, 2022

do you know if events are still triggered by a not visible element?

they don't get interaction events.

https://codepen.io/hymm/pen/MWVpKXR?editors=1111

@alice-i-cecile
Copy link
Member Author

@mockersf what do you think the right path forward is then?

  1. Merge [Merged by Bors] - Disable UI node Interaction when ComputedVisibility is false #5361 as is for reduced footgunnery and consistency with the web. Then clean up this duplication in a separate more controversial PR.
  2. Just jump straight to deduplication.

@sixfold-origami
Copy link
Contributor

sixfold-origami commented Jul 18, 2022

Not sure if this is similar in bevy.

Oh... then that's how Bevy currently work... do you know if events are still triggered by a not visible element?

In general, you can't trigger interaction on them because you can't see them, but you can still trigger them mechanically (through javascript). Also, because of the inspector, you can just... unhide them. This was actually the source of a few bugs that I've encountered in the wild.

@alice-i-cecile
Copy link
Member Author

WRT triggering them mechanically, users will be able to achieve the same effect by manually setting the Interaction component values.

That inspector stuff seems like a nasty security issue...

@mockersf
Copy link
Member

@mockersf what do you think the right path forward is then?

  1. Merge Disable UI node Interaction when ComputedVisibility is false #5361 as is for reduced footgunnery and consistency with the web. Then clean up this duplication in a separate more controversial PR.
  2. Just jump straight to deduplication.

If we merge #5361 we would work completely like CSS... I think that would be what I prefer, but it would need documentation to explain. But it should be feasible. Mentioning on the visibility component that it hides and stop events, but don't remove from layout, and mention the display field.

Keeping the two separated (visibility / computed in layout) can be useful to allow for invisible nodes in layout, so that everything stays in the same place when something else becomes visible / invisible.

@Nilirad
Copy link
Contributor

Nilirad commented Jul 22, 2022

#5361 has been merged. What's the status of this?

@alice-i-cecile
Copy link
Member Author

alice-i-cecile commented Jul 22, 2022

To close this, we either need

a) consensus that we want both + #5380 fixed
b) removal of either Display::None or UiNode visibility
c) autosynchronization (plz no)

@Nilirad
Copy link
Contributor

Nilirad commented Jul 22, 2022

I would like the (a) scenario, just like in CSS. Also, the visibility vs display has been well documented. Implementing #5380 will also consolidate the pattern.

@inodentry
Copy link
Contributor

I would also like the (a) scenario. In fact, I have deliberately made use of that distinction in my own UIs before. The ability to choose between "don't render, but keep it in the layout" and "remove it from the layout", is a useful feature to have.

@doup
Copy link
Contributor

doup commented Mar 7, 2023

I also like (a), given how Bevy already follows CSS it feels natural (although it's surprising for those not familiar with it). It has its use as pointed by inodentry.

Should #7629 mention that it closes this issue?

@alice-i-cecile
Copy link
Member Author

Agreed, I think that #7629 will resolve this.

@alice-i-cecile alice-i-cecile added C-Docs An addition or correction to our documentation and removed C-Bug An unexpected or incorrect behavior C-Code-Quality A section of code that is hard to understand or change labels Mar 7, 2023
alice-i-cecile pushed a commit that referenced this issue Jun 19, 2023
# Objective

An example demonstrating how Display and Visibility work in Bevy UI.

fixes #5380
related #5368

![Bevy App 15_02_2023
20_40_46](https://user-images.githubusercontent.com/27962798/219150865-419ade53-250b-4030-8197-907cac7aa5da.png)

## Changelog

* Added the example `flex_display.rs`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-UI Graphical user interfaces, styles, layouts, and widgets C-Docs An addition or correction to our documentation
Projects
None yet
Development

No branches or pull requests

7 participants