diff --git a/ImGuiToolkit.cpp b/ImGuiToolkit.cpp index 4912bd7..7d4536a 100644 --- a/ImGuiToolkit.cpp +++ b/ImGuiToolkit.cpp @@ -111,11 +111,11 @@ void ImGuiToolkit::ButtonSwitch(const char* label, bool* toggle, const char* hel // draw the label right aligned const ImVec2 label_size = ImGui::CalcTextSize(label, NULL, true); - ImVec2 text_pos = draw_pos + ImVec2(frame_width -120.f -label_size.x, 0.f); + ImVec2 text_pos = draw_pos + ImVec2(frame_width -3.5f * ImGui::GetTextLineHeightWithSpacing() -label_size.x, 0.f); ImGui::RenderText(text_pos, label); // draw switch after the text - ImVec2 p = draw_pos + ImVec2(frame_width - 100.f, 0.f); + ImVec2 p = draw_pos + ImVec2(frame_width -3.1f * ImGui::GetTextLineHeightWithSpacing(), 0.f); draw_list->AddRectFilled(p, ImVec2(p.x + width, p.y + height), col_bg, height * 0.5f); draw_list->AddCircleFilled(ImVec2(p.x + radius + t * (width - radius * 2.0f), p.y + radius), radius - 1.5f, IM_COL32(255, 255, 255, 250)); @@ -777,6 +777,8 @@ void ImGuiToolkit::ShowStats(bool *p_open, int* p_corner) ImGui::Text("Mouse "); ImGui::Text("Window (%.1f,%.1f)", io.DisplaySize.x, io.DisplaySize.y); + ImGui::Text("HiDPI (retina) %s", io.DisplayFramebufferScale.x > 1.f ? "on" : "off"); +// ImGui::Text("DPI Scale (%.1f,%.1f)", io.DisplayFramebufferScale.x, io.DisplayFramebufferScale.y); ImGui::Text("Rendering %.1f FPS", io.Framerate); ImGui::PopFont(); diff --git a/UserInterfaceManager.cpp b/UserInterfaceManager.cpp index b6a99fe..7351de6 100644 --- a/UserInterfaceManager.cpp +++ b/UserInterfaceManager.cpp @@ -142,8 +142,9 @@ bool UserInterface::Init() IMGUI_CHECKVERSION(); ImGui::CreateContext(); ImGuiIO& io = ImGui::GetIO(); (void)io; - io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls + io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // TODO Enable Keyboard Controls? io.MouseDrawCursor = true; + io.FontGlobalScale = Settings::application.scale; // Setup Platform/Renderer bindings ImGui_ImplGlfw_InitForOpenGL(Rendering::manager().main_window_, true); @@ -152,16 +153,20 @@ bool UserInterface::Init() // Setup Dear ImGui style ImGuiToolkit::SetAccentColor(static_cast(Settings::application.accent_color)); - // Load Fonts (using resource manager, a temporary copy of the raw data is necessary) - ImGuiToolkit::SetFont(ImGuiToolkit::FONT_DEFAULT, "Roboto-Regular", 22); - ImGuiToolkit::SetFont(ImGuiToolkit::FONT_BOLD, "Roboto-Bold", 22); - ImGuiToolkit::SetFont(ImGuiToolkit::FONT_ITALIC, "Roboto-Italic", 22); - ImGuiToolkit::SetFont(ImGuiToolkit::FONT_MONO, "Hack-Regular", 20); - ImGuiToolkit::SetFont(ImGuiToolkit::FONT_LARGE, "Hack-Regular", 40); - io.FontGlobalScale = Settings::application.scale; + // Load Fonts (using resource manager, NB: a temporary copy of the raw data is necessary) + int base_font_size = int ( Rendering::manager().Height() / 110.f ); +// Log::Info("Base font size %d / %f", base_font_size, Rendering::manager().Height() ); + ImGuiToolkit::SetFont(ImGuiToolkit::FONT_DEFAULT, "Roboto-Regular", base_font_size); + ImGuiToolkit::SetFont(ImGuiToolkit::FONT_BOLD, "Roboto-Bold", base_font_size); + ImGuiToolkit::SetFont(ImGuiToolkit::FONT_ITALIC, "Roboto-Italic", base_font_size); + ImGuiToolkit::SetFont(ImGuiToolkit::FONT_MONO, "Hack-Regular", base_font_size - 2); + // font for Navigator = 1.5 x base size, and less than 38 (unknown imgui bug for fonts larger than 40) + ImGuiToolkit::SetFont(ImGuiToolkit::FONT_LARGE, "Hack-Regular", MIN(base_font_size+base_font_size/2, 38) ); // Style ImGuiStyle& style = ImGui::GetStyle(); + + Log::Info("DPI Scale (%.1f,%.1f)", ImGui::GetIO().DisplayFramebufferScale.x, ImGui::GetIO().DisplayFramebufferScale.y); style.WindowPadding.x = 12.f; style.WindowPadding.y = 6.f; style.FramePadding.x = 10.f; @@ -864,11 +869,12 @@ void Navigator::Render() ImGui::PushStyleVar(ImGuiStyleVar_SelectableTextAlign, ImVec2(0.50f, 0.50f)); // calculate size of items based on text size and display dimensions - width = 2.f * ImGui::GetTextLineHeightWithSpacing(); - padding_width = 2.f * style.WindowPadding.x; - height = io.DisplaySize.y; - sourcelist_height = height - 6 * ImGui::GetTextLineHeight(); - float icon_width = width - 2.f * style.WindowPadding.x; + width = 2.f * ImGui::GetTextLineHeightWithSpacing(); // dimension of left bar depends on FONT_LARGE + pannel_width = 5.f * width; // pannel is 5x the bar + padding_width = 2.f * style.WindowPadding.x; // panning for alighment + height = io.DisplaySize.y; // cover vertically + sourcelist_height = height - 6.f * ImGui::GetTextLineHeight(); // space for 3 icons of view + float icon_width = width - 2.f * style.WindowPadding.x; // icons keep padding ImVec2 iconsize(icon_width, icon_width); // Left bar top @@ -1142,7 +1148,7 @@ void Navigator::RenderMainPannel() ImGui::Text(" "); ImGui::Text("Appearance"); ImGui::SetNextItemWidth(IMGUI_RIGHT_ALIGN); - if ( ImGui::SliderFloat("Scale", &Settings::application.scale, 0.8f, 1.2f, "%.1f")) + if ( ImGui::DragFloat("Scale", &Settings::application.scale, 0.01, 0.8f, 1.2f, "%.1f")) ImGui::GetIO().FontGlobalScale = Settings::application.scale; ImGui::SetNextItemWidth(IMGUI_RIGHT_ALIGN); diff --git a/defines.h b/defines.h index a8e70d7..34136a7 100644 --- a/defines.h +++ b/defines.h @@ -32,7 +32,7 @@ #define IMGUI_TITLE_SHADEREDITOR ICON_FA_CODE " Shader Editor" #define IMGUI_TITLE_PREVIEW ICON_FA_LAPTOP " Preview" #define IMGUI_TITLE_DELETE ICON_FA_BROOM " Delete?" -#define IMGUI_RIGHT_ALIGN -100 +#define IMGUI_RIGHT_ALIGN -3.5f * ImGui::GetTextLineHeightWithSpacing() #define COLOR_BGROUND 0.2f, 0.2f, 0.2f #define COLOR_NAVIGATOR 0.1f, 0.1f, 0.1f