Wraithaven-Games / bevy_wh_elements

An object-based UI wrapper for Bevy.
MIT License
0 stars 0 forks source link

Cleaner Node Building Blocks #1

Open TheDudeFromCI opened 10 months ago

TheDudeFromCI commented 10 months ago

Currently, most elements simply contain a reference to WhNode, a struct that basically contains a 1:1 set of Style properties, with a few extra fields for BackgroundColor, Image, and BorderColor. While this is functional, it does produce a lot of messy code within the actual element definition files and makes creation of new elements a lot more awkward. In addition, as many fields are redundant in different circumstances, or completely ignored in some situations.

It would be a much better option to define a new set of node types that can be used as building blocks to define an element. These nodes should use a different structure than FlexBox, as it should conform to Rust's standardization of the rule that no invalid state should be representable.

These building blocks would also make creation of multi-layered elements, such as the scroll pane, much easier, as different nodes would describe different layout aspects of the element. In this case, separating the external layout properties from the internal layout properties. The external layout may be applied directly to the container of the element, while the internal layout node can be applied to the panel itself.

Additionally, I propose making use of derive macro on elements to make construction of elements far cleaner and easier, further requiring less boilerplate code to create new UI elements.

TheDudeFromCI commented 10 months ago

Implementation Proposal: Perhaps using Bevy Lunex would be a good approach for designing blocks as a replacement to the fluid and unstructured nature of FlexBox and similar CSS-like styles?

The goal of BevyLunex is for simply laying out the elements, rather than handling implementation for rendering or behaviors. If the underlying codebase was moved to be built on top of Lunex, a more user-friendly element builder API can be achieved, in theory.

In the very least, it's worth experimenting on.