@@ -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 ();
8283private:
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+
104113inline 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