mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-22 20:07:01 +00:00
imgui-test: Added extra item info callbacks. Using nav_bb for interactions when possible. Comments, Demo tweaks.
This commit is contained in:
parent
aacf993ee1
commit
0a233a505d
10
imgui.cpp
10
imgui.cpp
@ -1278,6 +1278,7 @@ ImVec2 ImTriangleClosestPoint(const ImVec2& a, const ImVec2& b, const ImVec2& c,
|
||||
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 @@ int ImStrnicmp(const char* str1, const char* str2, size_t count)
|
||||
|
||||
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 @@ bool ImGui::ItemAdd(const ImRect& bb, ImGuiID id, const ImRect* nav_bb_arg)
|
||||
|
||||
#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
|
||||
|
@ -1034,16 +1034,18 @@ static void ShowDemoWindowWidgets()
|
||||
|
||||
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 @@ static void ShowDemoWindowWidgets()
|
||||
}
|
||||
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 @@ static void ShowDemoWindowWidgets()
|
||||
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))
|
||||
|
@ -1475,7 +1475,7 @@ IMGUI_API void ImFontAtlasBuildMultiplyRectAlpha8(const unsigned ch
|
||||
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)
|
||||
|
@ -577,6 +577,7 @@ bool ImGui::ButtonEx(const char* label, const ImVec2& size_arg, ImGuiButtonFlags
|
||||
//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 @@ bool ImGui::DragScalar(const char* label, ImGuiDataType data_type, void* v, floa
|
||||
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 @@ bool ImGui::SliderScalar(const char* label, ImGuiDataType data_type, void* v, co
|
||||
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 @@ bool ImGui::InputTextEx(const char* label, char* buf, int buf_size, const ImVec2
|
||||
if (value_changed)
|
||||
MarkItemEdited(id);
|
||||
|
||||
IMGUI_TEST_ENGINE_ITEM_INFO(id, label, window->DC.ItemFlags);
|
||||
if ((flags & ImGuiInputTextFlags_EnterReturnsTrue) != 0)
|
||||
return enter_pressed;
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user