-
-
Notifications
You must be signed in to change notification settings - Fork 9
Create Fonts Texture when calling setFontSize #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
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. I can handle this later if it sounds confusing to you |
|
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: 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 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.
96d2f51 to
11555a0
Compare
I think that is quite expected, you are recreating a texture during the opengl drawing operations. 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. |
|
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 |
|
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 |
|
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): Interestingly, I get a different behavior with that PR (when changing the font from the idle callback): What I observed is that changing the font size between the |



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.