Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ColorEdit/Picker: bug on drag and drop and text input due to HSV-wrapping code #2050

Closed
BloodSharp opened this issue Aug 29, 2018 · 2 comments
Labels

Comments

@BloodSharp
Copy link

Version/Branch of Dear ImGui:

Tested on 1.53 WIP (branch 2017 drag&drop latest closed) and 1.62 (in release download section)

Back-ends: 1.53 WIP (my own custom winapi+opengl 3) / 1.62 (SDL2+GL3 standard no modifications)
OS: Linux Mint Tara x64 / Windows 7 Ultimate SP1
Compiler: GCC / MingW (from codeblocks installer)

My Issue/Question: There is a bug in drag and drop if someone uses only black and white color buttons, if the color button is black the RGB will be divided by 2 each time used, in white color cases I have no idea how the color is changing...
Any help to make a temporally fix will be also appreciated...

Standalone, minimal, complete and verifiable example:

static ImColor testingcolor=ImColor(255,128,0,255);
ImGui::SetNextWindowSize(ImVec2(250,250),ImGuiCond_Once);
ImGui::SetNextWindowPosCenter(ImGuiCond_Once);
if(ImGui::Begin("Testing Colors"))
{
   ImGui::BeginGroup();
   ImGui::ColorButton("Orange",ImColor(255,128,0,255),0,ImVec2(20,0));
   ImGui::ColorButton("Red",ImColor(255,0,0,255),0,ImVec2(20,0));
   ImGui::ColorButton("Green",ImColor(0,255,0,255),0,ImVec2(20,0));
   ImGui::ColorButton("Blue",ImColor(0,0,255,255),0,ImVec2(20,0));
   ImGui::ColorButton("Black",ImColor(0,0,0,255),0,ImVec2(20,0));
   ImGui::ColorButton("White",ImColor(255,255,255,255),0,ImVec2(20,0));
   ImGui::EndGroup();
   ImGui::SameLine();
   ImGui::PushItemWidth(200);
   ImGui::ColorPicker4("##COLOR_PICKER_TEST",(float*)&testingcolor,
            ImGuiColorEditFlags_RGB|ImGuiColorEditFlags_AlphaBar|ImGuiColorEditFlags_NoSidePreview);
   ImGui::PopItemWidth();
   ImGui::End();
}

Screenshots/Video

imguicolorbuttonandpicker

B#

@ocornut ocornut added bug drag drop drag and drop labels Aug 29, 2018
@ocornut
Copy link
Owner

ocornut commented Aug 29, 2018

Nice find! This has been in since the initial implementation in #346.
The problem lies in the code which does:

// Try to cancel hue wrap (after ColorEdit), if any

This code is useful in other situations. With:
huv_wrap_code_enabled

without:
huv_wrap_code_disabled

Another way to reproduce a similar bug is to have a RGB(0,0,255) value and just input 0 into the B box:

input_0_into_b

So my guess is that we could avoid running the hue wrap fix up when inputting/dropping an absolute value, but keep it when dragging. EDIT It's not a super trivial change because we are relying on the value_changed output from ColorEdit4() which doesn't allow us to distinguish between a dragging edit and a text input/drop.

I don't actually properly grok that HSV logic so I may be wrong.

@ocornut ocornut changed the title [Bug] Drag and drop issues ColorEdit/Picker: bug on drag and drop and text input due to HSV-wrapping code Aug 29, 2018
ocornut added a commit that referenced this issue Aug 29, 2018
…nsaturated HSL values would erroneously alter the resulting color. (#2050)
@ocornut
Copy link
Owner

ocornut commented Aug 29, 2018

I have now pushed a fix for this. I am not entirely satisfied but it'll probably be enough for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants