raysan5 / raygui

A simple and easy-to-use immediate-mode gui library
zlib License
3.26k stars 280 forks source link

`GuiColorBarHue` bug when selecting a color #369

Closed jk- closed 5 months ago

jk- commented 6 months ago

I'm not sure this is the expected behavior?

The hue bar on the right is moving as you select a color and if you end up on white or black it completely resets

https://github.com/raysan5/raygui/assets/577382/7ed73f84-580f-4eea-9672-aee1919c757e

raysan5 commented 5 months ago

@jk- I'm afraid this is related to multi-float-operations rounding issues due to the immediate-mode nature of the control. I think https://github.com/raysan5/raygui/pull/370 should minimize this issue...

LievenPetersen commented 5 months ago

This happens, because as the RGB Color approaches black or white there is not enough 'color' information to infer a hue. This issue can be avoided by using the HSV equivalent (GuiColorPickerHSV), to avoid conversion from RGBA to HSV.

This can be a bit tricky to deal with and basically requires the 'global' color to be stored as HSV and converted to Color when needed.


further description of the issue:

The specific sequence of events in GuiColorPicker (the Color/RGBA variant) is:

LievenPetersen commented 5 months ago

@jk- I'm afraid this is related to multi-float-operations rounding issues due to the immediate-mode nature of the control. I think #370 should minimize this issue...

I don't think it will change this. I am not sure that this situation can be improved, because it would require buffering of the hue value, which is goes against the immediate-mode, as you already said.

jk- commented 5 months ago

i think docs are fine here. should we update the examples?

LievenPetersen commented 5 months ago

should we update the examples?

I just had a look and it seemed so simple that I just did it :P The controls_test_suite is the only example that needs updating I think