From f480a0c1eab99c1060d8af0b9542171557712099 Mon Sep 17 00:00:00 2001 From: Lendemor Date: Tue, 10 Apr 2018 00:22:02 +0200 Subject: [PATCH] re-added custom modification to imgui --- src/imconfig.h | 20 ++++++++++++-------- src/imgui.cpp | 23 +++++++++++++++++++++++ src/imgui.h | 4 ++++ 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/src/imconfig.h b/src/imconfig.h index 47f4f54..ef8abe7 100644 --- a/src/imconfig.h +++ b/src/imconfig.h @@ -11,6 +11,9 @@ #pragma once +#include +#include + //---- Define assertion handler. Defaults to calling assert(). //#define IM_ASSERT(_EXPR) MyAssert(_EXPR) @@ -19,7 +22,7 @@ //#define IMGUI_API __declspec( dllimport ) //---- Don't define obsolete functions/enums names. Consider enabling from time to time after updating to avoid using soon-to-be obsolete function/names -//#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS +#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS //---- Don't implement default handlers for Windows (so as not to link with certain functions) //#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS // Don't use and link with OpenClipboard/GetClipboardData/CloseClipboard etc. @@ -27,7 +30,7 @@ //---- Don't implement demo windows functionality (ShowDemoWindow()/ShowStyleEditor()/ShowUserGuide() methods will be empty) //---- It is very strongly recommended to NOT disable the demo windows during development. Please read the comments in imgui_demo.cpp. -//#define IMGUI_DISABLE_DEMO_WINDOWS +#define IMGUI_DISABLE_DEMO_WINDOWS //---- Don't implement ImFormatString(), ImFormatStringV() so you can reimplement them yourself. //#define IMGUI_DISABLE_FORMAT_STRING_FUNCTIONS @@ -47,15 +50,16 @@ //---- Define constructor and implicit cast operators to convert back<>forth from your math types and ImVec2/ImVec4. // This will be inlined as part of ImVec2 and ImVec4 class declarations. -/* + #define IM_VEC2_CLASS_EXTRA \ - ImVec2(const MyVec2& f) { x = f.x; y = f.y; } \ - operator MyVec2() const { return MyVec2(x,y); } + ImVec2(const glm::vec2& f) { x = f.x; y = f.y; } \ + operator glm::vec2() const { return glm::vec2(x,y); } #define IM_VEC4_CLASS_EXTRA \ - ImVec4(const MyVec4& f) { x = f.x; y = f.y; z = f.z; w = f.w; } \ - operator MyVec4() const { return MyVec4(x,y,z,w); } -*/ + ImVec4(const glm::vec4& f) { x = f.x; y = f.y; z = f.z; w = f.w; } \ + operator glm::vec4() const { return glm::vec4(x,y,z,w); } + + //---- Use 32-bit vertex indices (default is 16-bit) to allow meshes with more than 64K vertices. Render function needs to support it. //#define ImDrawIdx unsigned int diff --git a/src/imgui.cpp b/src/imgui.cpp index 33b3519..e8916e3 100644 --- a/src/imgui.cpp +++ b/src/imgui.cpp @@ -2020,6 +2020,16 @@ ImGuiID ImGuiWindow::GetIDFromRectangle(const ImRect& r_abs) // Internal API exposed in imgui_internal.h //----------------------------------------------------------------------------- +//used by listbox/combo wrapper for compatibility with std::vector +static auto vector_getter = [](void* vec, int idx, const char** out_text) +{ + auto& vector = *static_cast*>(vec); + if (idx < 0 || idx >= static_cast(vector.size())) { return false; } + *out_text = vector.at(idx).c_str(); + return true; +}; + + static void SetCurrentWindow(ImGuiWindow* window) { ImGuiContext& g = *GImGui; @@ -10876,6 +10886,13 @@ bool ImGui::Combo(const char* label, int* current_item, const char* items_separa return value_changed; } +// Combo box helper allowing to pass a vector of std::string. +bool ImGui::Combo(const char* label, int* current_item, std::vector& items) +{ + if (items.empty()) { return false; } + return Combo(label, current_item, vector_getter, static_cast(&items), items.size()); +} + // Tip: pass an empty label (e.g. "##dummy") then you can use the space to draw other text or image. // But you need to make sure the ID is unique, e.g. enclose calls in PushID/PopID. bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags flags, const ImVec2& size_arg) @@ -11070,6 +11087,12 @@ bool ImGui::ListBox(const char* label, int* current_item, bool (*items_getter)(v return value_changed; } +bool ImGui::ListBox(const char* label, int* current_item, std::vector& items) +{ + if (items.empty()) { return false; } + return ListBox(label, current_item, vector_getter, static_cast(&items), items.size()); +} + bool ImGui::MenuItem(const char* label, const char* shortcut, bool selected, bool enabled) { ImGuiWindow* window = GetCurrentWindow(); diff --git a/src/imgui.h b/src/imgui.h index d1174bd..c25ad06 100644 --- a/src/imgui.h +++ b/src/imgui.h @@ -20,6 +20,8 @@ #include // va_list #include // ptrdiff_t, NULL #include // memset, memmove, memcpy, strlen, strchr, strcpy, strcmp +#include +#include #define IMGUI_VERSION "1.60" @@ -331,6 +333,7 @@ namespace ImGui IMGUI_API bool Combo(const char* label, int* current_item, const char* const items[], int items_count, int popup_max_height_in_items = -1); IMGUI_API bool Combo(const char* label, int* current_item, const char* items_separated_by_zeros, int popup_max_height_in_items = -1); // Separate items with \0 within a string, end item-list with \0\0. e.g. "One\0Two\0Three\0" IMGUI_API bool Combo(const char* label, int* current_item, bool(*items_getter)(void* data, int idx, const char** out_text), void* data, int items_count, int popup_max_height_in_items = -1); + IMGUI_API bool Combo(const char* label, int* current_item, std::vector& items); // Widgets: Drags (tip: ctrl+click on a drag box to input with keyboard. manually input values aren't clamped, can go off-bounds) // For all the Float2/Float3/Float4/Int2/Int3/Int4 versions of every functions, note that a 'float v[X]' function argument is the same as 'float* v', the array syntax is just a way to document the number of elements that are expected to be accessible. You can pass address of your first element out of a contiguous set, e.g. &myvector.x @@ -406,6 +409,7 @@ namespace ImGui IMGUI_API bool Selectable(const char* label, bool* p_selected, ImGuiSelectableFlags flags = 0, const ImVec2& size = ImVec2(0,0)); // "bool* p_selected" point to the selection state (read-write), as a convenient helper. IMGUI_API bool ListBox(const char* label, int* current_item, const char* const items[], int items_count, int height_in_items = -1); IMGUI_API bool ListBox(const char* label, int* current_item, bool (*items_getter)(void* data, int idx, const char** out_text), void* data, int items_count, int height_in_items = -1); + IMGUI_API bool ListBox(const char* label, int* current_item, std::vector& items); IMGUI_API bool ListBoxHeader(const char* label, const ImVec2& size = ImVec2(0,0)); // use if you want to reimplement ListBox() will custom data or interactions. make sure to call ListBoxFooter() afterwards. IMGUI_API bool ListBoxHeader(const char* label, int items_count, int height_in_items = -1); // " IMGUI_API void ListBoxFooter(); // terminate the scrolling region