@@ -4222,8 +4222,13 @@ bool ImGui::ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flag
4222
4222
{
4223
4223
// Hue is lost when converting from greyscale rgb (saturation=0). Restore it.
4224
4224
ColorConvertRGBtoHSV (f[0 ], f[1 ], f[2 ], f[0 ], f[1 ], f[2 ]);
4225
- if (f[1 ] == 0 && memcmp (g.ColorEditLastColor , col, sizeof (float ) * 3 ) == 0 )
4226
- f[0 ] = g.ColorEditLastHue ;
4225
+ if (memcmp (g.ColorEditLastColor , col, sizeof (float ) * 3 ) == 0 )
4226
+ {
4227
+ if (f[1 ] == 0 )
4228
+ f[0 ] = g.ColorEditLastHue ;
4229
+ if (f[2 ] == 0 )
4230
+ f[1 ] = g.ColorEditLastSaturation ;
4231
+ }
4227
4232
}
4228
4233
int i[4 ] = { IM_F32_TO_INT8_UNBOUND (f[0 ]), IM_F32_TO_INT8_UNBOUND (f[1 ]), IM_F32_TO_INT8_UNBOUND (f[2 ]), IM_F32_TO_INT8_UNBOUND (f[3 ]) };
4229
4234
@@ -4262,16 +4267,15 @@ bool ImGui::ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flag
4262
4267
SameLine (0 , style.ItemInnerSpacing .x );
4263
4268
SetNextItemWidth ((n + 1 < components) ? w_item_one : w_item_last);
4264
4269
4265
- // Disable Hue edit when Saturation is zero
4266
- const bool disable_hue_edit = (n == 0 && (flags & ImGuiColorEditFlags_DisplayHSV) && i[1 ] == 0 );
4270
+ // FIXME: When ImGuiColorEditFlags_HDR flag is passed HS values snap in weird ways when SV values go below 0.
4267
4271
if (flags & ImGuiColorEditFlags_Float)
4268
4272
{
4269
- value_changed |= DragFloat (ids[n], &f[n], 1 .0f /255 .0f , disable_hue_edit ? +FLT_MAX : 0 .0f , disable_hue_edit ? -FLT_MAX : hdr ? 0 .0f : 1 .0f , fmt_table_float[fmt_idx][n]);
4273
+ value_changed |= DragFloat (ids[n], &f[n], 1 .0f /255 .0f , 0 .0f , hdr ? 0 .0f : 1 .0f , fmt_table_float[fmt_idx][n]);
4270
4274
value_changed_as_float |= value_changed;
4271
4275
}
4272
4276
else
4273
4277
{
4274
- value_changed |= DragInt (ids[n], &i[n], 1 .0f , disable_hue_edit ? INT_MAX : 0 , disable_hue_edit ? INT_MIN : hdr ? 0 : 255 , fmt_table_int[fmt_idx][n]);
4278
+ value_changed |= DragInt (ids[n], &i[n], 1 .0f , 0 , hdr ? 0 : 255 , fmt_table_int[fmt_idx][n]);
4275
4279
}
4276
4280
if (!(flags & ImGuiColorEditFlags_NoOptions))
4277
4281
OpenPopupOnItemClick (" context" );
@@ -4354,6 +4358,7 @@ bool ImGui::ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flag
4354
4358
if ((flags & ImGuiColorEditFlags_DisplayHSV) && (flags & ImGuiColorEditFlags_InputRGB))
4355
4359
{
4356
4360
g.ColorEditLastHue = f[0 ];
4361
+ g.ColorEditLastSaturation = f[1 ];
4357
4362
ColorConvertHSVtoRGB (f[0 ], f[1 ], f[2 ], f[0 ], f[1 ], f[2 ]);
4358
4363
memcpy (g.ColorEditLastColor , f, sizeof (float ) * 3 );
4359
4364
}
@@ -4536,8 +4541,13 @@ bool ImGui::ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags fl
4536
4541
{
4537
4542
// Hue is lost when converting from greyscale rgb (saturation=0). Restore it.
4538
4543
ColorConvertRGBtoHSV (R, G, B, H, S, V);
4539
- if (S == 0 && memcmp (g.ColorEditLastColor , col, sizeof (float ) * 3 ) == 0 )
4540
- H = g.ColorEditLastHue ;
4544
+ if (memcmp (g.ColorEditLastColor , col, sizeof (float ) * 3 ) == 0 )
4545
+ {
4546
+ if (S == 0 )
4547
+ H = g.ColorEditLastHue ;
4548
+ if (V == 0 )
4549
+ S = g.ColorEditLastSaturation ;
4550
+ }
4541
4551
}
4542
4552
else if (flags & ImGuiColorEditFlags_InputHSV)
4543
4553
{
@@ -4665,6 +4675,7 @@ bool ImGui::ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags fl
4665
4675
{
4666
4676
ColorConvertHSVtoRGB (H >= 1 .0f ? H - 10 * 1e-6f : H, S > 0 .0f ? S : 10 *1e-6f , V > 0 .0f ? V : 1e-6f , col[0 ], col[1 ], col[2 ]);
4667
4677
g.ColorEditLastHue = H;
4678
+ g.ColorEditLastSaturation = S;
4668
4679
memcpy (g.ColorEditLastColor , col, sizeof (float ) * 3 );
4669
4680
}
4670
4681
else if (flags & ImGuiColorEditFlags_InputHSV)
@@ -4719,8 +4730,13 @@ bool ImGui::ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags fl
4719
4730
G = col[1 ];
4720
4731
B = col[2 ];
4721
4732
ColorConvertRGBtoHSV (R, G, B, H, S, V);
4722
- if (S == 0 && memcmp (g.ColorEditLastColor , col, sizeof (float ) * 3 ) == 0 ) // Fix local Hue as display below will use it immediately.
4723
- H = g.ColorEditLastHue ;
4733
+ if (memcmp (g.ColorEditLastColor , col, sizeof (float ) * 3 ) == 0 ) // Fix local Hue as display below will use it immediately.
4734
+ {
4735
+ if (S == 0 )
4736
+ H = g.ColorEditLastHue ;
4737
+ if (V == 0 )
4738
+ S = g.ColorEditLastSaturation ;
4739
+ }
4724
4740
}
4725
4741
else if (flags & ImGuiColorEditFlags_InputHSV)
4726
4742
{
0 commit comments