Skip to content

Commit 9eb4094

Browse files
authored
Merge pull request #52 from ocornut/fixes_192
Fixes for dear imgui 1.92
2 parents f146624 + ea7d581 commit 9eb4094

3 files changed

Lines changed: 28 additions & 4 deletions

File tree

example/example.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ int main(int, char**)
8787
ImGui_ImplOpenGL3_Init(glsl_version);
8888
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
8989

90+
// Create a node editor with width and height
91+
NodeEditor* neditor = new(NodeEditor)(500, 500);
92+
9093
// Main loop
9194
bool done = false;
9295
#ifdef __EMSCRIPTEN__
@@ -121,8 +124,8 @@ int main(int, char**)
121124
ImGui::SetNextWindowSize(window_size);
122125
ImGui::SetNextWindowPos(window_pos);
123126
ImGui::Begin("Node Editor", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse);
124-
neditor.set_size(node_editor_size);
125-
neditor.draw();
127+
neditor->set_size(node_editor_size);
128+
neditor->draw();
126129
ImGui::End();
127130

128131
// Rendering
@@ -137,6 +140,9 @@ int main(int, char**)
137140
EMSCRIPTEN_MAINLOOP_END;
138141
#endif
139142

143+
delete neditor;
144+
neditor = nullptr;
145+
140146
// Cleanup
141147
ImGui_ImplOpenGL3_Shutdown();
142148
ImGui_ImplSDL2_Shutdown();

example/example.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,3 @@ struct NodeEditor : ImFlow::BaseNode {
6363
}
6464
};
6565

66-
/* Create a node editor with width and height */
67-
NodeEditor neditor(500, 1500);

src/context_wrapper.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class ContainedContext
7979
[[nodiscard]] bool hovered() const { return m_hovered; }
8080
[[nodiscard]] const ImVec2& scroll() const { return m_scroll; }
8181
ImGuiContext* getRawContext() { return m_ctx; }
82+
void setFontDensity();
8283
private:
8384
ContainedContextConfig m_config;
8485

@@ -101,11 +102,20 @@ inline ContainedContext::~ContainedContext()
101102
if (m_ctx) ImGui::DestroyContext(m_ctx);
102103
}
103104

105+
// Call after Begin()
106+
inline void ContainedContext::setFontDensity()
107+
{
108+
#if IMGUI_VERSION_NUM >= 19198
109+
ImGui::SetFontRasterizerDensity(roundf(m_scale * 100.0f) / 100.0f); // Round density to two digits.
110+
#endif
111+
}
112+
104113
inline void ContainedContext::begin()
105114
{
106115
ImGui::PushID(this);
107116
ImGui::PushStyleColor(ImGuiCol_ChildBg, m_config.color);
108117
ImGui::BeginChild("view_port", m_config.size, 0, ImGuiWindowFlags_NoMove);
118+
setFontDensity();
109119
ImGui::PopStyleColor();
110120
m_pos = ImGui::GetWindowPos();
111121

@@ -122,6 +132,15 @@ inline void ContainedContext::begin()
122132

123133
ImGui::GetIO().DisplaySize = m_size / m_scale;
124134
ImGui::GetIO().ConfigInputTrickleEventQueue = false;
135+
136+
// Copy the ImGuiBackendFlags_RendererHasTextures flag as they need to be matching.
137+
// This will also copy the ImGuiBackendFlags_RendererHasVtxOffset flag which will be more optimal in case large draw calls are being made.
138+
ImGui::GetIO().ConfigFlags = m_original_ctx->IO.ConfigFlags;
139+
ImGui::GetIO().BackendFlags = m_original_ctx->IO.BackendFlags;
140+
#ifdef IMGUI_HAS_VIEWPORT
141+
ImGui::GetIO().ConfigFlags &= ~(ImGuiConfigFlags_ViewportsEnable | ImGuiConfigFlags_DockingEnable);
142+
#endif
143+
125144
ImGui::NewFrame();
126145

127146
if (!m_config.extra_window_wrapper)
@@ -131,6 +150,7 @@ inline void ContainedContext::begin()
131150
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));
132151
ImGui::Begin("viewport_container", nullptr, ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoMove
133152
| ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse);
153+
setFontDensity();
134154
ImGui::PopStyleVar();
135155
}
136156

0 commit comments

Comments
 (0)