mirror of
https://github.com/ocornut/imgui.git
synced 2026-11-14 19:04:44 +00:00
ColorPicker: unable to update uint32_t color when saturation is zero #4014
Labels
No labels
accidentally closed
android
backends
bug
building
clipper
coloredit
color spaces
cplusplus
data types
demo
disabled
doc
docking
dpi
drag drop
drawing/drawlist
dropped
dx12
enhancement
focus
font/text
gallery
help wanted
idle/power saving
ime
in progress
inputs
inputtext
internals
label/id and id stack
language bindings
layout
linux/bsd
menus
multi-contexts
multi-threading
multi-viewports
nav
news/info
opengl
optimization
osx/ios
overlap
plot/graph
popups
question
scrolling
selection
settings
sliders/drags
style
tables/columns
tabs
test wanted
tools
tooltips
tree
tricks & tips
useful widgets
vulkan
web
window pos/depth
window sizing
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
ocornut/imgui#4014
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Version/Branch of Dear ImGui:
My Issue/Question:
When change a color with saturation==0 (which is converted from uint32_t), in color picker in RGB mode, clicking on the hue bar will temporarily change the color but the color is immediately reverted to the original.
The return value of
ImGui::ColorEdit4is true, however, the color value is almost identical to the original. See code below.If the saturation is non-zero, the color can be changed successfully.
But the expected behaviour should be correctly changing the color no matter what the original color value is.
Screenshots/Video
Standalone, minimal, complete and verifiable example:
Further investigation shows the problem may be due to this line:
ocornut/imgui@58075c4414/imgui_widgets.cpp (L5087)Clicking the hue bar will give an
H. However, no matter what valueHis, this function always set RGB value (very close) to (v,v,v).My current solution is to set fallback saturation value to
50 * 1e-4(rather than10 * 1e-6) when it is zero. This gives an updated color value with S=1(/255). However, the indicator in the vertical hur bar will just jump round, which is the case for any color with S=1.I think changing the underlying color storage from uint32_t to float4 is a better solution for me. This can avoid the precision lost when converting colors.
But when uint32_t color is a must, can the color picker GUI be designed to avoid various jumping back/around?
We already have mitigation code in the picker to temporarily preserve varying Hue while Saturation is 0.0f, but somehow this code doesn't work on a round-trip through int32 packing. So I would say on our end it is a bug that this mitigation code doesn't work and we could try to keep it working in that case.
The reason why round-trip through int32 packing is not working is because the precision of int32 is not enough for editing Hue with zero Saturation when int32 is seen as RGB and converting to/from HSV must be performed. The edition (to RGB space) in HSV space is not uniformly equal under different saturation.
Say we are editing color 0xD8D8D8, which is RGB(216, 216, 216)/HSV(0,0,216). If we change H to 100, HSV(100,0,216) stills corresponds to RGB(216,216,216) and thus color is not changed. However, if color is stored in float4, HSV(100,0,216) will change float4 value, even RGB (converted from float4) still looks the same.
So just not use color picker to edit in32 color and the trouble is gone...
Should now be fixed by
30546bc0e7