summaryrefslogtreecommitdiffhomepage
path: root/editor/imgui-raii.hpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-11-22 13:44:40 +0100
committerStanislaw Halik <sthalik@misaki.pl>2022-11-22 13:46:14 +0100
commitd33fb4adbfc5b43d90a3d0a541579d7724dce027 (patch)
treef294b0e548b2bebaad68277deba59c937cb5a5e8 /editor/imgui-raii.hpp
parent0fa4a8542bf9eda8bd9c28da199b3e90e04279b9 (diff)
hidpi work
Diffstat (limited to 'editor/imgui-raii.hpp')
-rw-r--r--editor/imgui-raii.hpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/editor/imgui-raii.hpp b/editor/imgui-raii.hpp
index 5920e7d9..a3059d1b 100644
--- a/editor/imgui-raii.hpp
+++ b/editor/imgui-raii.hpp
@@ -93,4 +93,36 @@ template<std::size_t N>
ImGui::TextEx(buf, buf + N - 1, flags);
}
+struct style_saver final
+{
+ style_saver() : style{ImGui::GetStyle()} {}
+ ~style_saver() { ImGui::GetStyle() = style; }
+private:
+ ImGuiStyle style;
+};
+
+struct font_saver final
+{
+ font_saver(float size) : font_saver{*ImGui::GetCurrentContext(), size} {}
+ ~font_saver();
+private:
+ font_saver(ImGuiContext& ctx, float size);
+
+ float font_size, font_base_size;
+};
+
+font_saver::~font_saver()
+{
+ auto& ctx = *ImGui::GetCurrentContext();
+ ctx.FontSize = font_size;
+ ctx.FontBaseSize = font_base_size;
+}
+
+font_saver::font_saver(ImGuiContext& ctx, float size) :
+ font_size{ctx.FontSize}, font_base_size{ctx.FontBaseSize}
+{
+ ctx.FontSize = size;
+ ctx.FontBaseSize = size;
+}
+
} // namespace floormat::imgui