Skip to content

Commit

Permalink
incorporate r-lyeh's table variant from ocornut/imgui#513
Browse files Browse the repository at this point in the history
  • Loading branch information
ekmett committed Aug 26, 2016
1 parent 33b9159 commit a43212b
Show file tree
Hide file tree
Showing 7 changed files with 193 additions and 30 deletions.
15 changes: 5 additions & 10 deletions proc/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "framework/signal.h"
#include "imgui.h"
#include "imgui_impl.h"
#include "imgui_table.h"
#include <glm/gtc/matrix_transform.hpp>

using namespace framework;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}
Expand Down
62 changes: 61 additions & 1 deletion proc/imgui.ini
Original file line number Diff line number Diff line change
@@ -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

14 changes: 8 additions & 6 deletions proc/imgui_impl.h
Original file line number Diff line number Diff line change
@@ -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();
92 changes: 92 additions & 0 deletions proc/imgui_table.h
Original file line number Diff line number Diff line change
@@ -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();
}

}
1 change: 1 addition & 0 deletions proc/proc.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ XCOPY "$(OpenALSoftDir)bin\$(WinXX)\soft_oal.dll" "$(TargetDir)" /D /K /Y</Comma
<ClInclude Include="..\third-party\imgui\stb_textedit.h" />
<ClInclude Include="..\third-party\imgui\stb_truetype.h" />
<ClInclude Include="imgui_impl.h" />
<ClInclude Include="imgui_table.h" />
<ClInclude Include="stdafx.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
Expand Down
33 changes: 23 additions & 10 deletions proc/proc.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,44 @@
<ClCompile Include="stdafx.cpp">
<Filter>boilerplate</Filter>
</ClCompile>
<ClCompile Include="imgui_impl.cpp">
<Filter>imgui\extensions</Filter>
</ClCompile>
<ClCompile Include="..\third-party\imgui\imgui.cpp">
<Filter>imgui</Filter>
<Filter>imgui\standard</Filter>
</ClCompile>
<ClCompile Include="..\third-party\imgui\imgui_demo.cpp">
<Filter>imgui</Filter>
<Filter>imgui\standard</Filter>
</ClCompile>
<ClCompile Include="..\third-party\imgui\imgui_draw.cpp">
<Filter>imgui</Filter>
<Filter>imgui\standard</Filter>
</ClCompile>
<ClCompile Include="imgui_impl.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="stdafx.h">
<Filter>boilerplate</Filter>
</ClInclude>
<ClInclude Include="imgui_impl.h">
<Filter>imgui\extensions</Filter>
</ClInclude>
<ClInclude Include="imgui_table.h">
<Filter>imgui\extensions</Filter>
</ClInclude>
<ClInclude Include="..\third-party\imgui\imgui.h">
<Filter>imgui</Filter>
<Filter>imgui\standard</Filter>
</ClInclude>
<ClInclude Include="..\third-party\imgui\imgui_internal.h">
<Filter>imgui</Filter>
<Filter>imgui\standard</Filter>
</ClInclude>
<ClInclude Include="..\third-party\imgui\stb_rect_pack.h">
<Filter>imgui</Filter>
<Filter>imgui\standard</Filter>
</ClInclude>
<ClInclude Include="..\third-party\imgui\stb_textedit.h">
<Filter>imgui</Filter>
<Filter>imgui\standard</Filter>
</ClInclude>
<ClInclude Include="..\third-party\imgui\stb_truetype.h">
<Filter>imgui</Filter>
<Filter>imgui\standard</Filter>
</ClInclude>
<ClInclude Include="imgui_impl.h" />
</ItemGroup>
<ItemGroup>
<Filter Include="boilerplate">
Expand All @@ -44,5 +51,11 @@
<Filter Include="imgui">
<UniqueIdentifier>{c2cd084c-ca84-4939-a864-514315ef7518}</UniqueIdentifier>
</Filter>
<Filter Include="imgui\extensions">
<UniqueIdentifier>{e6d75649-5292-417b-a6b2-68d2af6905b2}</UniqueIdentifier>
</Filter>
<Filter Include="imgui\standard">
<UniqueIdentifier>{3c2d62ab-5edf-4517-9e33-a4567a69a7ef}</UniqueIdentifier>
</Filter>
</ItemGroup>
</Project>
6 changes: 3 additions & 3 deletions src/framework/sdl_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit a43212b

Please sign in to comment.