Skip to content
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

Fix overlapped button, ImGui::Indent should also consider DPI scale #118

Merged
merged 3 commits into from
Apr 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion engine/source/editor/source/editor_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,8 @@ namespace Pilot
ImGui::SameLine();

float indent_val = 0.0f;
indent_val = m_engine_window_size.x - 100.0f;
indent_val = m_engine_window_size.x - 100.0f * getIndentScale();

ImGui::Indent(indent_val);
if (m_is_editor_mode)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ namespace Pilot
void draw_frame();
int clear();
void setDefaultStyle();
protected:
float getContentScale() const;
float getIndentScale() const;
};

class Surface
Expand Down
38 changes: 28 additions & 10 deletions engine/source/runtime/function/render/source/surface_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,33 @@

using namespace Pilot;

void window_content_scale_callback(GLFWwindow* window, float x_scale, float y_scale)
{
inline void windowContentScaleUpdate(float scale) {
#if defined(__MACH__)
float font_scale = fmax(1.0f, fmax(x_scale, y_scale));
float font_scale = fmaxf(1.0f, scale);
ImGui::GetIO().FontGlobalScale = 1.0f / font_scale;
#endif
// TOOD: Reload fonts if DPI scale is larger than previous font loading DPI scale
}

inline void windowContentScaleCallback(GLFWwindow* window, float x_scale, float y_scale)
{
windowContentScaleUpdate(fmaxf(x_scale, y_scale));
}

float SurfaceUI::getContentScale() const
{
float x_scale, y_scale;
glfwGetWindowContentScale(m_io->m_window, &x_scale, &y_scale);
return fmaxf(1.0f, fmaxf(x_scale, y_scale));
}

float SurfaceUI::getIndentScale() const
{
#if defined(__MACH__)
return 1.0f;
#else // Not tested on Linux
return getContentScale();
#endif
}

int SurfaceUI::initialize(SurfaceRHI* rhi, PilotRenderer* prenderer, std::shared_ptr<SurfaceIO> pio)
Expand All @@ -31,12 +52,12 @@ int SurfaceUI::initialize(SurfaceRHI* rhi, PilotRenderer* prenderer, std::shared
io.ConfigDockingAlwaysTabBar = true;
io.ConfigWindowsMoveFromTitleBarOnly = true;

float x_scale, y_scale;
glfwGetWindowContentScale(pio->m_window, &x_scale, &y_scale);
float font_scale = fmax(1.0f, fmax(x_scale, y_scale));
float content_scale = getContentScale();
windowContentScaleUpdate(content_scale);
glfwSetWindowContentScaleCallback(pio->m_window, windowContentScaleCallback);

io.Fonts->AddFontFromFileTTF(
ConfigManager::getInstance().getEditorFontPath().generic_string().data(), font_scale * 16, nullptr, nullptr);
ConfigManager::getInstance().getEditorFontPath().generic_string().data(), content_scale * 16, nullptr, nullptr);
io.Fonts->Build();
style.WindowPadding = ImVec2(1.0, 0);
style.FramePadding = ImVec2(14.0, 2.0f);
Expand All @@ -61,9 +82,6 @@ int SurfaceUI::initialize(SurfaceRHI* rhi, PilotRenderer* prenderer, std::shared
init_info.MinImageCount = rhi->m_vulkan_manager->m_max_frames_in_flight;
init_info.ImageCount = rhi->m_vulkan_manager->m_max_frames_in_flight;
ImGui_ImplVulkan_Init(&init_info, rhi->m_vulkan_manager->getLightingPass());

window_content_scale_callback(pio->m_window, x_scale, y_scale);
glfwSetWindowContentScaleCallback(pio->m_window, window_content_scale_callback);

// fonts upload
fontsUpload(rhi);
Expand Down