From a43212bf9b2894e70dce5430fe37fb535cfd1818 Mon Sep 17 00:00:00 2001 From: Edward Kmett Date: Fri, 26 Aug 2016 04:41:46 -0400 Subject: [PATCH] incorporate r-lyeh's table variant from ocornut/imgui#513 --- proc/app.cpp | 15 +++---- proc/imgui.ini | 62 ++++++++++++++++++++++++- proc/imgui_impl.h | 14 +++--- proc/imgui_table.h | 92 ++++++++++++++++++++++++++++++++++++++ proc/proc.vcxproj | 1 + proc/proc.vcxproj.filters | 33 +++++++++----- src/framework/sdl_window.h | 6 +-- 7 files changed, 193 insertions(+), 30 deletions(-) create mode 100644 proc/imgui_table.h diff --git a/proc/app.cpp b/proc/app.cpp index c9d3d1c..35caf73 100644 --- a/proc/app.cpp +++ b/proc/app.cpp @@ -6,6 +6,7 @@ #include "framework/signal.h" #include "imgui.h" #include "imgui_impl.h" +#include "imgui_table.h" #include using namespace framework; @@ -50,7 +51,7 @@ static float reverseZ_contents[16] = { // transposed of course static mat4 reverseZ = glm::make_mat4(reverseZ_contents); #endif -app::app() : window("proc", { 4, 5, gl::profile::core }, false, 100, 100, 800, 600), vr(), compositor(*vr::VRCompositor()), nearClip(0.1f), farClip(10000.f) { +app::app() : window("proc", { 4, 5, gl::profile::core }, false), vr(), compositor(*vr::VRCompositor()), nearClip(0.1f), farClip(10000.f) { // load matrices. @@ -115,6 +116,7 @@ app::~app() { void app::run() { while (!vr.poll() && !window.poll()) { // clear the display window + ImGui_ImplSdlGL3_NewFrame(window.sdl_window); glClearColor(0.15f, 0.15f, 0.15f, 1.f); glClear(GL_COLOR_BUFFER_BIT); glEnable(GL_MULTISAMPLE); @@ -143,19 +145,12 @@ void app::run() { } compositor.PostPresentHandoff(); glBindFramebuffer(GL_FRAMEBUFFER, 0); + + //ImGui::ShowTestWindow(); - ImGui_ImplSdlGL3_NewFrame(window.sdl_window); - - if (ImGui::Button("Hello")) { - OutputDebugStringA("Hello\n"); - } ImGui::Render(); - - // set glViewport - // draw anything else we need on the main SDL window, imgui elements, etc. - SDL_GL_SwapWindow(window.sdl_window); } } diff --git a/proc/imgui.ini b/proc/imgui.ini index 2842ce3..ad967f3 100644 --- a/proc/imgui.ini +++ b/proc/imgui.ini @@ -1,5 +1,65 @@ [Debug] -Pos=131,11 +Pos=192,219 Size=582,388 Collapsed=0 +[ImGui Demo] +Pos=824,220 +Size=550,680 +Collapsed=0 + +[Example: Console] +Pos=73,62 +Size=520,600 +Collapsed=0 + +[Example: Log] +Pos=60,60 +Size=500,400 +Collapsed=0 + +[Example: Layout] +Pos=60,60 +Size=500,440 +Collapsed=0 + +[Example: Long text display] +Pos=60,60 +Size=520,600 +Collapsed=0 + +[Same title as another window##1] +Pos=100,100 +Size=441,61 +Collapsed=0 + +[Same title as another window##2] +Pos=100,200 +Size=441,61 +Collapsed=0 + +[###AnimatedTitle] +Pos=195,298 +Size=238,48 +Collapsed=0 + +[Example: Custom rendering] +Pos=60,60 +Size=350,560 +Collapsed=0 + +[ImGui Metrics] +Pos=60,60 +Size=380,194 +Collapsed=0 + +[About ImGui] +Pos=60,60 +Size=525,86 +Collapsed=0 + +[Example: Constrained Resize] +Pos=60,60 +Size=200,200 +Collapsed=0 + diff --git a/proc/imgui_impl.h b/proc/imgui_impl.h index d7e57a9..68574ca 100644 --- a/proc/imgui_impl.h +++ b/proc/imgui_impl.h @@ -1,13 +1,15 @@ #pragma once +#include "imgui.h" + struct SDL_Window; typedef union SDL_Event SDL_Event; -extern bool ImGui_ImplSdlGL3_Init(SDL_Window* window); -extern void ImGui_ImplSdlGL3_Shutdown(); -extern void ImGui_ImplSdlGL3_NewFrame(SDL_Window* window); -extern bool ImGui_ImplSdlGL3_ProcessEvent(SDL_Event* event); +IMGUI_API bool ImGui_ImplSdlGL3_Init(SDL_Window* window); +IMGUI_API void ImGui_ImplSdlGL3_Shutdown(); +IMGUI_API void ImGui_ImplSdlGL3_NewFrame(SDL_Window* window); +IMGUI_API bool ImGui_ImplSdlGL3_ProcessEvent(SDL_Event* event); // Use if you want to reset your rendering device without losing ImGui state. -extern void ImGui_ImplSdlGL3_InvalidateDeviceObjects(); -extern bool ImGui_ImplSdlGL3_CreateDeviceObjects(); +IMGUI_API void ImGui_ImplSdlGL3_InvalidateDeviceObjects(); +IMGUI_API bool ImGui_ImplSdlGL3_CreateDeviceObjects(); diff --git a/proc/imgui_table.h b/proc/imgui_table.h new file mode 100644 index 0000000..65f708d --- /dev/null +++ b/proc/imgui_table.h @@ -0,0 +1,92 @@ +#pragma once + +#include "imgui.h" + +/* // [src] https://github.com/ocornut/imgui/issues/513 + +// Usage: +static const char *headers[] = { +"Index", "Color", "Flip?", "Filename" +}; +static float widths[ IM_ARRAYSIZE(headers) ] = {}; +if( ImGui::BeginTable("WinTextureContent", headers, widths, IM_ARRAYSIZE(headers)) ) { +// Draw as many rows as needed +for( int i = 0; i < 10; ++i ) { +ImGui::Text("%d", i); ImGui::NextColumn(); +ImGui::ColorButton( ImVec4(0.5f,0.2f,i*0.3f,1.f)); ImGui::NextColumn(); +ImGui::Text("%s", i % 2 ? "yes" : "no"); ImGui::NextColumn(); +ImGui::Text(__FILE__); ImGui::NextColumn(); +} +ImGui::EndTable(); +} +*/ + +// .h +namespace ImGui { + IMGUI_API int BeginTable(const char* columnsId, const char** headers, float *widths, int count, bool border = true); + IMGUI_API void EndTable(); +} + +// .cpp +namespace ImGui { + static inline IMGUI_API + int BeginTable(const char* columnsId, const char** headers, float* widths, int count, bool draw_border) { + if (count <= 0) + return 0; + + // Draw column headers + ImGuiStyle & style = ImGui::GetStyle(); + const ImVec2 firstTextSize = ImGui::CalcTextSize(headers[0], NULL, true); + + ImGui::BeginChild(columnsId, ImVec2(0, firstTextSize.y + 2 * style.ItemSpacing.y), true); + + char str_id[256]; + sprintf(str_id, "tbl0_%s", columnsId); + ImGui::Columns(count, str_id, draw_border); + + float offset = 0.0f; + for (int i = 0; i < count; i++) { + ImGui::SetColumnOffset(i, offset); + + if (widths[i] <= 0) { + const ImVec2 textsize = ImGui::CalcTextSize(headers[i], NULL, true); + const float colSizeX = (textsize.x + 2 * style.ItemSpacing.x); + widths[i] = colSizeX + 1; + } + + if (i < (count - 1)) { + float curOffset = offset; + offset = ImGui::GetColumnOffset(i + 1); + widths[i] = offset - curOffset + 1; + } + + ImGui::Text(headers[i]); + ImGui::NextColumn(); + } + + ImGui::Columns(1); + ImGui::EndChild(); + + // Draw body + str_id[3] = '1'; + columnsId = str_id; + + ImGui::BeginChild(columnsId, ImVec2(0, 0), true); + ImGui::Columns(count, columnsId, draw_border); + + offset = 0.0f; + for (int i = 0; i < count; i++) { + ImGui::SetColumnOffset(i, offset); + offset += widths[i] - 1; + } + + return 1; + } + + static inline IMGUI_API + void EndTable() { + ImGui::Columns(1); + ImGui::EndChild(); + } + +} \ No newline at end of file diff --git a/proc/proc.vcxproj b/proc/proc.vcxproj index 77a37c5..b855f76 100644 --- a/proc/proc.vcxproj +++ b/proc/proc.vcxproj @@ -218,6 +218,7 @@ XCOPY "$(OpenALSoftDir)bin\$(WinXX)\soft_oal.dll" "$(TargetDir)" /D /K /Y + diff --git a/proc/proc.vcxproj.filters b/proc/proc.vcxproj.filters index 9fe8625..9667500 100644 --- a/proc/proc.vcxproj.filters +++ b/proc/proc.vcxproj.filters @@ -5,37 +5,44 @@ boilerplate + + imgui\extensions + - imgui + imgui\standard - imgui + imgui\standard - imgui + imgui\standard - boilerplate + + imgui\extensions + + + imgui\extensions + - imgui + imgui\standard - imgui + imgui\standard - imgui + imgui\standard - imgui + imgui\standard - imgui + imgui\standard - @@ -44,5 +51,11 @@ {c2cd084c-ca84-4939-a864-514315ef7518} + + {e6d75649-5292-417b-a6b2-68d2af6905b2} + + + {3c2d62ab-5edf-4517-9e33-a4567a69a7ef} + \ No newline at end of file diff --git a/src/framework/sdl_window.h b/src/framework/sdl_window.h index 6532f00..39d3d1c 100644 --- a/src/framework/sdl_window.h +++ b/src/framework/sdl_window.h @@ -22,10 +22,10 @@ namespace framework { string title, gl::version version = { 4, 5, gl::profile::core }, bool debug = false, - int x = 800, + int x = 300, int y = 50, - int width = 160, - int height = 100 + int width = 2160, + int height = 1200 ); virtual ~window();