diff --git a/src/olympic/studio/applib/src/studioui.cpp b/src/olympic/studio/applib/src/studioui.cpp index f644d166..7daffd52 100644 --- a/src/olympic/studio/applib/src/studioui.cpp +++ b/src/olympic/studio/applib/src/studioui.cpp @@ -43,7 +43,7 @@ ox::Vector const &modules() noexcept { return g_modules; } -void registerModule(Module const*mod) noexcept { +void registerModule(Module const *mod) noexcept { if (mod) { g_modules.emplace_back(mod); } @@ -121,25 +121,7 @@ using StudioConfig = StudioConfigV2; StudioUI::StudioUI(turbine::Context &tctx, ox::StringParam projectDataDir) noexcept: m_sctx{*this, tctx}, m_projectDataDir{std::move(projectDataDir)} { - { - auto const scale = turbine::isWayland() || ox::defines::OS == ox::OS::Darwin ? - 1.f : turbine::scale(m_tctx); - ImFontConfig fontCfg; - fontCfg.FontDataOwnedByAtlas = false; - auto const &io = ImGui::GetIO(); - auto const font = files::RobotoMedium_ttf(); - // const_cast is needed because this data is definitely const, - // but AddFontFromMemoryTTF requires a mutable buffer. - // However, setting fontCfg.FontDataOwnedByAtlas ensures - // that it will still be treated as const. - // ImGui documentation recognizes that this is a bad design, - // and hopefully it will change at some point. - io.Fonts->AddFontFromMemoryTTF( - const_cast(font.data()), - static_cast(font.size()), - 13 * scale, - &fontCfg); - } + loadFont(); auto &kctx = keelCtx(m_tctx); kctx.converters.emplace_back(keel::Converter::make()); oxLogError(headerizeConfigFile(kctx)); @@ -206,6 +188,7 @@ void StudioUI::draw() noexcept { if (turbine::isWayland() || ox::defines::OS == ox::OS::Darwin) { ig::setDpiScale(1.f); } else { + loadFont(); ig::setDpiScale(ImGui::GetWindowDpiScale()); } glutils::clearScreen(); @@ -240,6 +223,29 @@ void StudioUI::draw() noexcept { procFileMoves(); } +void StudioUI::loadFont() noexcept { + auto const scale = turbine::isWayland() || ox::defines::OS == ox::OS::Darwin ? + 1.f : turbine::scale(m_tctx); + if (m_fontScale != scale) { + m_fontScale = scale; + ImFontConfig fontCfg; + fontCfg.FontDataOwnedByAtlas = false; + auto const &io = ImGui::GetIO(); + auto const font = files::RobotoMedium_ttf(); + // const_cast is needed because this data is definitely const, + // but AddFontFromMemoryTTF requires a mutable buffer. + // However, setting fontCfg.FontDataOwnedByAtlas ensures + // that it will still be treated as const. + // ImGui documentation recognizes that this is a bad design, + // and hopefully it will change at some point. + io.Fonts->AddFontFromMemoryTTF( + const_cast(font.data()), + static_cast(font.size()), + 13 * scale, + &fontCfg); + } +} + bool StudioUI::handleShutdown() noexcept { auto const out = ox::all_of(m_editors.begin(), m_editors.end(), [](ox::UPtr const &e) { return !e->unsavedChanges(); diff --git a/src/olympic/studio/applib/src/studioui.hpp b/src/olympic/studio/applib/src/studioui.hpp index 618350be..de35897e 100644 --- a/src/olympic/studio/applib/src/studioui.hpp +++ b/src/olympic/studio/applib/src/studioui.hpp @@ -84,6 +84,7 @@ class StudioUI final: public ox::SignalHandler { ox::String args; }; ox::Optional m_navAction; + float m_fontScale{}; public: explicit StudioUI(turbine::Context &tctx, ox::StringParam projectDataDir) noexcept; @@ -105,6 +106,8 @@ class StudioUI final: public ox::SignalHandler { void draw() noexcept; private: + void loadFont() noexcept; + void drawMenu() noexcept; void drawTabBar() noexcept;