Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Allow to change imgui font size at runtime
Signed-off-by: falkTX <falktx@falktx.com>
  • Loading branch information
falkTX committed May 6, 2023
1 parent a0aa731 commit 5acb1b9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
21 changes: 21 additions & 0 deletions opengl/DearImGui.cpp
Expand Up @@ -179,6 +179,27 @@ struct ImGuiWidget<BaseWidget>::PrivateData {

// --------------------------------------------------------------------------------------------------------------------

template <class BaseWidget>
void ImGuiWidget<BaseWidget>::setFontSize(const float fontSize)
{
ImGui::SetCurrentContext(imData->context);
ImGuiIO& io(ImGui::GetIO());

const double scaleFactor = BaseWidget::getTopLevelWidget()->getScaleFactor();

#ifndef DGL_NO_SHARED_RESOURCES
using namespace dpf_resources;
ImFontConfig fc;
fc.FontDataOwnedByAtlas = false;
fc.OversampleH = 1;
fc.OversampleV = 1;
fc.PixelSnapH = true;
io.Fonts->Clear();
io.Fonts->AddFontFromMemoryTTF((void*)dejavusans_ttf, dejavusans_ttf_size, fontSize * scaleFactor, &fc);
io.Fonts->Build();
#endif
}

template <class BaseWidget>
void ImGuiWidget<BaseWidget>::idleCallback()
{
Expand Down
5 changes: 5 additions & 0 deletions opengl/DearImGui.hpp
Expand Up @@ -80,6 +80,11 @@ class ImGuiWidget : public BaseWidget,
*/
~ImGuiWidget() override;

/**
Change global font size.
*/
void setFontSize(float fontSize);

protected:
/**
New virtual onDisplay function.
Expand Down

0 comments on commit 5acb1b9

Please sign in to comment.