FyroxEngine / Fyrox

3D and 2D game engine written in Rust
https://fyrox.rs
MIT License
7.69k stars 348 forks source link

Feature: UI palette #554

Closed jacobtread closed 11 months ago

jacobtread commented 11 months ago

Description

This feature adds a widget palette system onto widgets themselves which defines the brushes to use for the normal and hover states (On all widgets).

This enable things like the border color changing when a button is hovered as opposed to this only being supported by the background color for Decorator.

This should be backward compatible with the existing with_background/with_hover_brush/with_normal_brush system thats already in place as I modified those functions to update the palette instead.

Usage

The WidgetBuilder structure now has a palette field and a with_palette function which takes in a WidgetPaletteBuilder which you can use to define the colors for the different background and foreground states:

image

There are also with_background and with_foreground functions on the palette builder to set both the hovered and normal colors (If a hovered color is not picked but a normal color is then when the palette is built it will use the normal color for the hovered color)

image

In-game usage

Below is usage of this feature to make the border color of buttons transparent until they are hovered:

https://github.com/FyroxEngine/Fyrox/assets/33708767/a8d6a5d8-9774-4724-8e57-4532630ad1fd

Related Issue

mrDIMAS commented 11 months ago

Have you checked the editor with your changes? It is works as before?

jacobtread commented 11 months ago

I have not checked the editor i will have to get a game setup with one and will check that shortly

jacobtread commented 11 months ago

Ah the performance in the editor for the editor tabs is heavily degraded from the nested widgets and having to do has_descendant to check descendants for hovering, looks like the custom widget approach you mentioned in #550 is definitely the better way to go.

Looks like i'll close this pull request as it doesn't seem like the viable approach unless you've got any ideas for making it work well?

jacobtread commented 11 months ago

After switching over to custom widgets they are definitely the way to go, closing this pr