MCPcopy Create free account
hub / github.com/KebsCS/KBotExt / ColorEditRestoreHS

Function ColorEditRestoreHS

KBotExt/imgui/imgui_widgets.cpp:5080–5095  ·  view source on GitHub ↗

ColorEdit supports RGB and HSV inputs. In case of RGB input resulting color may have undefined hue and/or saturation. Since widget displays both RGB and HSV values we must preserve hue and saturation to prevent these values resetting.

Source from the content-addressed store, hash-verified

5078// ColorEdit supports RGB and HSV inputs. In case of RGB input resulting color may have undefined hue and/or saturation.
5079// Since widget displays both RGB and HSV values we must preserve hue and saturation to prevent these values resetting.
5080static void ColorEditRestoreHS(const float* col, float* H, float* S, float* V)
5081{
5082 ImGuiContext& g = *GImGui;
5083 IM_ASSERT(g.ColorEditCurrentID != 0);
5084 if (g.ColorEditSavedID != g.ColorEditCurrentID || g.ColorEditSavedColor != ImGui::ColorConvertFloat4ToU32(ImVec4(col[0], col[1], col[2], 0)))
5085 return;
5086
5087 // When S == 0, H is undefined.
5088 // When H == 1 it wraps around to 0.
5089 if (*S == 0.0f || (*H == 0.0f && g.ColorEditSavedHue == 1))
5090 *H = g.ColorEditSavedHue;
5091
5092 // When V == 0, S is undefined.
5093 if (*V == 0.0f)
5094 *S = g.ColorEditSavedSat;
5095}
5096
5097// Edit colors components (each component in 0.0f..1.0f range).
5098// See enum ImGuiColorEditFlags_ for available options. e.g. Only access 3 floats if ImGuiColorEditFlags_NoAlpha flag is set.

Callers 2

ColorEdit4Method · 0.85
ColorPicker4Method · 0.85

Calls 1

ImVec4Class · 0.85

Tested by

no test coverage detected