ColorEdit3: fixed id collision leading to an assertion. (#5707)

This commit is contained in:
ocornut 2022-09-26 16:32:09 +02:00
parent c261dac02f
commit 04316bd223
2 changed files with 14 additions and 10 deletions

View File

@ -110,6 +110,7 @@ Other Changes:
- InputText: added support for shift+click style selection. (#5619) [@procedural] - InputText: added support for shift+click style selection. (#5619) [@procedural]
- InputText: clarified that callbacks cannot modify buffer when using the ReadOnly flag. - InputText: clarified that callbacks cannot modify buffer when using the ReadOnly flag.
- InputText: fixed minor one-frame selection glitch when reverting with Escape. - InputText: fixed minor one-frame selection glitch when reverting with Escape.
- ColorEdit3: fixed id collision leading to an assertion. (#5707)
- IsItemHovered: Added ImGuiHoveredFlags_DelayNormal and ImGuiHoveredFlags_DelayShort flags, - IsItemHovered: Added ImGuiHoveredFlags_DelayNormal and ImGuiHoveredFlags_DelayShort flags,
allowing to introduce a shared delay for tooltip idioms. The delays are respectively allowing to introduce a shared delay for tooltip idioms. The delays are respectively
io.HoverDelayNormal (default to 0.30f) and io.HoverDelayFast (default to 0.10f). (#1485) io.HoverDelayNormal (default to 0.30f) and io.HoverDelayFast (default to 0.10f). (#1485)

View File

@ -5114,16 +5114,19 @@ bool ImGui::ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flag
if (BeginPopup("picker")) if (BeginPopup("picker"))
{ {
picker_active_window = g.CurrentWindow; if (g.CurrentWindow->BeginCount == 1)
if (label != label_display_end)
{ {
TextEx(label, label_display_end); picker_active_window = g.CurrentWindow;
Spacing(); if (label != label_display_end)
{
TextEx(label, label_display_end);
Spacing();
}
ImGuiColorEditFlags picker_flags_to_forward = ImGuiColorEditFlags_DataTypeMask_ | ImGuiColorEditFlags_PickerMask_ | ImGuiColorEditFlags_InputMask_ | ImGuiColorEditFlags_HDR | ImGuiColorEditFlags_NoAlpha | ImGuiColorEditFlags_AlphaBar;
ImGuiColorEditFlags picker_flags = (flags_untouched & picker_flags_to_forward) | ImGuiColorEditFlags_DisplayMask_ | ImGuiColorEditFlags_NoLabel | ImGuiColorEditFlags_AlphaPreviewHalf;
SetNextItemWidth(square_sz * 12.0f); // Use 256 + bar sizes?
value_changed |= ColorPicker4("##picker", col, picker_flags, &g.ColorPickerRef.x);
} }
ImGuiColorEditFlags picker_flags_to_forward = ImGuiColorEditFlags_DataTypeMask_ | ImGuiColorEditFlags_PickerMask_ | ImGuiColorEditFlags_InputMask_ | ImGuiColorEditFlags_HDR | ImGuiColorEditFlags_NoAlpha | ImGuiColorEditFlags_AlphaBar;
ImGuiColorEditFlags picker_flags = (flags_untouched & picker_flags_to_forward) | ImGuiColorEditFlags_DisplayMask_ | ImGuiColorEditFlags_NoLabel | ImGuiColorEditFlags_AlphaPreviewHalf;
SetNextItemWidth(square_sz * 12.0f); // Use 256 + bar sizes?
value_changed |= ColorPicker4("##picker", col, picker_flags, &g.ColorPickerRef.x);
EndPopup(); EndPopup();
} }
} }
@ -5186,7 +5189,7 @@ bool ImGui::ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flag
if (picker_active_window && g.ActiveId != 0 && g.ActiveIdWindow == picker_active_window) if (picker_active_window && g.ActiveId != 0 && g.ActiveIdWindow == picker_active_window)
g.LastItemData.ID = g.ActiveId; g.LastItemData.ID = g.ActiveId;
if (value_changed) if (value_changed && g.LastItemData.ID != 0) // In case of ID collision, the second EndGroup() won't catch g.ActiveId
MarkItemEdited(g.LastItemData.ID); MarkItemEdited(g.LastItemData.ID);
return value_changed; return value_changed;
@ -5574,7 +5577,7 @@ bool ImGui::ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags fl
if (value_changed && memcmp(backup_initial_col, col, components * sizeof(float)) == 0) if (value_changed && memcmp(backup_initial_col, col, components * sizeof(float)) == 0)
value_changed = false; value_changed = false;
if (value_changed) if (value_changed && g.LastItemData.ID != 0) // In case of ID collision, the second EndGroup() won't catch g.ActiveId
MarkItemEdited(g.LastItemData.ID); MarkItemEdited(g.LastItemData.ID);
PopID(); PopID();