imgui-test: Added extra item info callbacks. Using nav_bb for interactions when possible. Comments, Demo tweaks.
diff --git a/imgui.cpp b/imgui.cpp
index 4fd20a9..320b664 100644
--- a/imgui.cpp
+++ b/imgui.cpp
@@ -1278,6 +1278,7 @@
return proj_ca;
}
+// Consider using _stricmp/_strnicmp under Windows or strcasecmp/strncasecmp. We don't actually use either ImStricmp/ImStrnicmp in the codebase any more.
int ImStricmp(const char* str1, const char* str2)
{
int d;
@@ -1294,10 +1295,11 @@
void ImStrncpy(char* dst, const char* src, size_t count)
{
- if (count < 1) return;
+ if (count < 1)
+ return;
if (count > 1)
- strncpy(dst, src, count-1);
- dst[count-1] = 0;
+ strncpy(dst, src, count - 1);
+ dst[count - 1] = 0;
}
char* ImStrdup(const char* str)
@@ -2796,7 +2798,7 @@
#ifdef IMGUI_ENABLE_TEST_ENGINE
if (id != 0)
- ImGuiTestEngineHook_ItemAdd(&g, bb, id);
+ ImGuiTestEngineHook_ItemAdd(&g, nav_bb_arg ? *nav_bb_arg : bb, id);
#endif
// Clipping test
diff --git a/imgui_demo.cpp b/imgui_demo.cpp
index 68dc8b1..ffdc106 100644
--- a/imgui_demo.cpp
+++ b/imgui_demo.cpp
@@ -1034,16 +1034,18 @@
ImGui::Text("Color button with Custom Picker Popup:");
- // Generate a dummy palette
- static bool saved_palette_inited = false;
- static ImVec4 saved_palette[32];
- if (!saved_palette_inited)
+ // Generate a dummy default palette. The palette will persist and can be edited.
+ static bool saved_palette_init = true;
+ static ImVec4 saved_palette[32] = { };
+ if (saved_palette_init)
+ {
for (int n = 0; n < IM_ARRAYSIZE(saved_palette); n++)
{
ImGui::ColorConvertHSVtoRGB(n / 31.0f, 0.8f, 0.8f, saved_palette[n].x, saved_palette[n].y, saved_palette[n].z);
saved_palette[n].w = 1.0f; // Alpha
}
- saved_palette_inited = true;
+ saved_palette_init = false;
+ }
static ImVec4 backup_color;
bool open_popup = ImGui::ColorButton("MyColor##3b", color, misc_flags);
@@ -1056,12 +1058,12 @@
}
if (ImGui::BeginPopup("mypicker"))
{
- // FIXME: Adding a drag and drop example here would be perfect!
ImGui::Text("MY CUSTOM COLOR PICKER WITH AN AMAZING PALETTE!");
ImGui::Separator();
ImGui::ColorPicker4("##picker", (float*)&color, misc_flags | ImGuiColorEditFlags_NoSidePreview | ImGuiColorEditFlags_NoSmallPreview);
ImGui::SameLine();
- ImGui::BeginGroup();
+
+ ImGui::BeginGroup(); // Lock X position
ImGui::Text("Current");
ImGui::ColorButton("##current", color, ImGuiColorEditFlags_NoPicker | ImGuiColorEditFlags_AlphaPreviewHalf, ImVec2(60,40));
ImGui::Text("Previous");
@@ -1077,6 +1079,8 @@
if (ImGui::ColorButton("##palette", saved_palette[n], ImGuiColorEditFlags_NoAlpha | ImGuiColorEditFlags_NoPicker | ImGuiColorEditFlags_NoTooltip, ImVec2(20,20)))
color = ImVec4(saved_palette[n].x, saved_palette[n].y, saved_palette[n].z, color.w); // Preserve alpha!
+ // Allow user to drop colors into each palette entry
+ // (Note that ColorButton is already a drag source by default, unless using ImGuiColorEditFlags_NoDragDrop)
if (ImGui::BeginDragDropTarget())
{
if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload(IMGUI_PAYLOAD_TYPE_COLOR_3F))
diff --git a/imgui_internal.h b/imgui_internal.h
index 92b3b96..5195338 100644
--- a/imgui_internal.h
+++ b/imgui_internal.h
@@ -1475,7 +1475,7 @@
extern void ImGuiTestEngineHook_PreNewFrame(ImGuiContext* ctx);
extern void ImGuiTestEngineHook_PostNewFrame(ImGuiContext* ctx);
extern void ImGuiTestEngineHook_ItemAdd(ImGuiContext* ctx, const ImRect& bb, ImGuiID id);
-extern void ImGuiTestEngineHook_ItemInfo(ImGuiContext* ctx, ImGuiID id, const char* label, int flags);
+extern void ImGuiTestEngineHook_ItemInfo(ImGuiContext* ctx, ImGuiID id, const char* label, ImGuiItemStatusFlags flags);
#define IMGUI_TEST_ENGINE_ITEM_INFO(_ID, _LABEL, _FLAGS) ImGuiTestEngineHook_ItemInfo(&g, _ID, _LABEL, _FLAGS) // Register status flags
#else
#define IMGUI_TEST_ENGINE_ITEM_INFO(_ID, _LABEL, _FLAGS) do { } while (0)
diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp
index 60aebb2..886c29b 100644
--- a/imgui_widgets.cpp
+++ b/imgui_widgets.cpp
@@ -577,6 +577,7 @@
//if (pressed && !(flags & ImGuiButtonFlags_DontClosePopups) && (window->Flags & ImGuiWindowFlags_Popup))
// CloseCurrentPopup();
+ IMGUI_TEST_ENGINE_ITEM_INFO(id, label, window->DC.LastItemStatusFlags);
return pressed;
}
@@ -1929,6 +1930,7 @@
if (label_size.x > 0.0f)
RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, inner_bb.Min.y), label);
+ IMGUI_TEST_ENGINE_ITEM_INFO(id, label, window->DC.ItemFlags);
return value_changed;
}
@@ -2368,6 +2370,7 @@
if (label_size.x > 0.0f)
RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label);
+ IMGUI_TEST_ENGINE_ITEM_INFO(id, label, window->DC.ItemFlags);
return value_changed;
}
@@ -3791,6 +3794,7 @@
if (value_changed)
MarkItemEdited(id);
+ IMGUI_TEST_ENGINE_ITEM_INFO(id, label, window->DC.ItemFlags);
if ((flags & ImGuiInputTextFlags_EnterReturnsTrue) != 0)
return enter_pressed;
else