bevy icon indicating copy to clipboard operation
bevy copied to clipboard

UI Nodes with a `CalculatedSize` shouldn't have child nodes or both `Image` and `Text` components

Open ickshonpe opened this issue 2 years ago • 2 comments

Objective

If a parent UI node with a MeasureFunc has a child node, the parent's size won't be determined by the MeasureFunc.

Ui Nodes with CalculatedSize. Image, and Text components won't be sized correctly.

It's hard to understand/explain, sometimes causes no problems, and sometimes causes unpredictable and confusing bugs.

#7894 is an example of where this has caused a problem.

Solution

Add some doc comments telling users not to do any of these things. Panic if any of them is done.

Changelog

  • Added a system detect_calculated_size_conflicts that panics if a Ui Node with a CalculatedSize component has a child UI node or both Image and Text components

ickshonpe avatar Mar 06 '23 01:03 ickshonpe

I feel like UI nodes ought to have some kind of "node type" tag. And only read components that are relevant to the specified node type. For example images would ignore text, text would ignore images, flexbox nodes would ignore both text and images, etc.

nicoburns avatar Mar 06 '23 20:03 nicoburns

Yes, ideally that would be implemented with entity relations I think, where Text and UiImage would be mutually exclusive components and it would be impossible to construct an entity containing both of them.

ickshonpe avatar Mar 06 '23 22:03 ickshonpe

Closed as not that important and there will be better ways to implement it soon.

ickshonpe avatar Apr 13 '23 07:04 ickshonpe