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.
| 5666 | // ColorEdit supports RGB and HSV inputs. In case of RGB input resulting color may have undefined hue and/or saturation. |
| 5667 | // Since widget displays both RGB and HSV values we must preserve hue and saturation to prevent these values resetting. |
| 5668 | static void ColorEditRestoreHS(const float* col, float* H, float* S, float* V) |
| 5669 | { |
| 5670 | ImGuiContext& g = *GImGui; |
| 5671 | IM_ASSERT(g.ColorEditCurrentID != 0); |
| 5672 | if (g.ColorEditSavedID != g.ColorEditCurrentID || g.ColorEditSavedColor != ImGui::ColorConvertFloat4ToU32(ImVec4(col[0], col[1], col[2], 0))) |
| 5673 | return; |
| 5674 | |
| 5675 | // When S == 0, H is undefined. |
| 5676 | // When H == 1 it wraps around to 0. |
| 5677 | if (*S == 0.0f || (*H == 0.0f && g.ColorEditSavedHue == 1)) |
| 5678 | *H = g.ColorEditSavedHue; |
| 5679 | |
| 5680 | // When V == 0, S is undefined. |
| 5681 | if (*V == 0.0f) |
| 5682 | *S = g.ColorEditSavedSat; |
| 5683 | } |
| 5684 | |
| 5685 | // Edit colors components (each component in 0.0f..1.0f range). |
| 5686 | // See enum ImGuiColorEditFlags_ for available options. e.g. Only access 3 floats if ImGuiColorEditFlags_NoAlpha flag is set. |
no test coverage detected