UmbraLuminosa / sickle_ui

A widget library built on top of bevy_ui.
Apache License 2.0
205 stars 24 forks source link

Add trait for UiBuilder #14

Closed UkoeHB closed 3 months ago

UkoeHB commented 3 months ago

I recommend moving the spawn method fromUiBuilder to a trait implemented by both UiRoot and Entity variants. Then you only need a single impl for extension traits, using the T: UiSpawner trait bound.

eidloi commented 3 months ago

This makes sense

UkoeHB commented 3 months ago

On second thought this makes less sense to me. spawn for the UiRoot version means 'create self', while spawn forEntity` version means 'create child'.

eidloi commented 3 months ago

On second thought this makes less sense to me. spawn for the UiRoot version means 'create self', while spawn forEntity` version means 'create child'.

The reason I had the double implementation is because there aren't many elements that support being a Root element. Basically rows and columns. The current version would let us create a widget with a different setup if they are root elements. Not sure how useful it is, but let's keep it as it is now and revisit later when there are more use-cases

UkoeHB commented 3 months ago

I added a style-loading-from-file extension to UiBuilder that returns the current node. The value returned is a bit different if you have a root vs normal entity in the builder.

I could just not return anything from these methods, but it's an example where the behavior could be dependent on the builder type.

eidloi commented 3 months ago

Another, albeit crude example would be that a root-spawn could insert the default theme automatically. Or we could have an extension only on the UiRoot that does that (i.e. ui_builder.themed_root(...)

eidloi commented 3 months ago

Let's keep it as-is. If we run into an issue where it becomes too much to maintain the two, we can revisit then. Cheers.