Skip to content

Conversation

@TristanCacqueray
Copy link
Contributor

This change enables changing the font size dynamically, after the initialization. The font texture needs to be updated, otherwise the text is rendered as white squares.

@falkTX
Copy link
Contributor

falkTX commented Jun 2, 2025

I have not needed this in my own plugins, but if it works for you I guess it does not hurt.

The code changes does not match style though, there is a decrement in indication for each #ifdef block.
Since you added a new #ifdef the one around it needs to go 1 step back.

I can handle this later if it sounds confusing to you

@TristanCacqueray
Copy link
Contributor Author

Here is what I observe on Fedora 42 (Gnome/Wayland) using this code (even with dear-imgui v1.91):

--- a/tests/imgui.cpp
+++ b/tests/imgui.cpp
@@ -33,7 +33,13 @@ protected:
     {
         ImGui::SetNextWindowPos(ImVec2(0, 0));
         ImGui::SetNextWindowSize(ImVec2(getWidth(), getHeight()));
-        ImGui::ShowDemoWindow();
+        int fontSize = 0;
+        if (ImGui::Begin("Test", nullptr, 0))
+          if (ImGui::Button("change font size"))
+            fontSize = 23;
+        ImGui::End();
+        if (fontSize)
+          setFontSize(fontSize);
     }
 };

… clicking the button results in:

image

Initially I was using SetWindowFontScale, but the result was a bit blurry, and the instructions to do that correctly are not very clear. I'm also not sure how to call ImGui_ImplOpenGL3 functions from the plugin code because they produced duplicate symbols on link. So I believe this change is correct, and setFontSize seems to still work when called by the UI constructor (in that case, I believe the texture were created by ImGui_ImplOpenGL3_Init).

Thank you for the feedback, let me fix the code style.

This change enables changing the font size dynamically, after the
initialization. The font texture needs to be updated, otherwise
the text is rendered as white squares.
@falkTX
Copy link
Contributor

falkTX commented Jun 2, 2025

Here is what I observe on Fedora 42 (Gnome/Wayland) using this code (even with dear-imgui v1.91):

I think that is quite expected, you are recreating a texture during the opengl drawing operations.
By the time the function ends, the previously active imgui font texture has been destroyed, but it is after the function ends that imgui sets up the real opengl painting details.

Your idea is not bad, it solves the case of recreating font in the middle of drawing. but if you call setFontSize in some other methods (like the constructor) then the issue should not be visible.

@TristanCacqueray
Copy link
Contributor Author

I thought that would be the issue, but couldn't figure out where to set the font size. For example, this doesn't work either:

  void onDisplay() override {
    ImGuiStandaloneWindow::onDisplay();
    setFontSize(42);
  }

If I understand the following comment correctly, calling Font->Build() doesn't seem to be enough: https://github.com/ocornut/imgui/blob/69e1fb50cacbde1c2c585ae59898e68c1818d9b7/imgui.h#L3378

@TristanCacqueray
Copy link
Contributor Author

I mean, I'd be happy to fully understand what's the issue here, and avoid un-necessary texture re-creation if that can be avoided. The original goal was to enable UI scaling, as described in: https://codeberg.org/TristanCacqueray/pluguzu/issues/2 , e.g. to adjust the font size dynamically, after the constructor got called.

@falkTX
Copy link
Contributor

falkTX commented Jun 2, 2025

I mean, I'd be happy to fully understand what's the issue here, and avoid un-necessary texture re-creation if that can be avoided. The original goal was to enable UI scaling, as described in: https://codeberg.org/TristanCacqueray/pluguzu/issues/2 , e.g. to adjust the font size dynamically, after the constructor got called.

my point was to try to do it on any function that is not related to drawing.

constructor is one place, another would be event handling. but since the event handling is protected overridden and handled internally, best to not use that one.

the way I recommend to do it is via "idle callback". on plugin UI instances you can use void uiIdle() override {}
just set some internal class vars to indicate from drawing functions the need to reload font size, then on the next uiIdle() check if font size needs changing.
I believe this should work

@TristanCacqueray
Copy link
Contributor Author

I tried doing that in the idle callback, here is another attempt in: https://codeberg.org/TristanCacqueray/pluguzu/commit/f166b745dd3e6d60084a0291be897483d8c7efe6 , but I got the same result (without this PR):

image

Interestingly, I get a different behavior with that PR (when changing the font from the idle callback):

image

What I observed is that changing the font size between the ImGui::Begin and ImGui::End could cause a segfault in carla (but not in clap-host or Ardour), but I don't have any issue right after ImGui::End so far.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants