Skip to content

Commit

Permalink
ImGuiManager: Split OSD and debug window fonts
Browse files Browse the repository at this point in the history
Fixes the latter not fitting on screen anymore.
  • Loading branch information
stenzek committed Sep 1, 2024
1 parent a180a2d commit 895c489
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 16 deletions.
8 changes: 5 additions & 3 deletions src/core/imgui_overlays.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ void ImGuiManager::DrawPerformanceOverlay(float& position_y, float scale, float

const float shadow_offset = std::ceil(1.0f * scale);
ImFont* fixed_font = ImGuiManager::GetFixedFont();
ImFont* standard_font = ImGuiManager::GetStandardFont();
ImFont* standard_font = ImGuiManager::GetOSDFont();
ImDrawList* dl = ImGui::GetBackgroundDrawList();
SmallString text;
ImVec2 text_size;
Expand Down Expand Up @@ -506,7 +506,7 @@ void ImGuiManager::DrawMediaCaptureOverlay(float& position_y, float scale, float
return;

const float shadow_offset = std::ceil(scale);
ImFont* const standard_font = ImGuiManager::GetStandardFont();
ImFont* const standard_font = ImGuiManager::GetOSDFont();
ImDrawList* dl = ImGui::GetBackgroundDrawList();

static constexpr const char* ICON = ICON_PF_CIRCLE;
Expand Down Expand Up @@ -614,7 +614,7 @@ void ImGuiManager::DrawInputsOverlay()
const float shadow_offset = 1.0f * scale;
const float margin = 10.0f * scale;
const float spacing = 5.0f * scale;
ImFont* font = ImGuiManager::GetStandardFont();
ImFont* font = ImGuiManager::GetOSDFont();

static constexpr u32 text_color = IM_COL32(0xff, 0xff, 0xff, 255);
static constexpr u32 shadow_color = IM_COL32(0x00, 0x00, 0x00, 100);
Expand Down Expand Up @@ -984,6 +984,7 @@ void SaveStateSelectorUI::Draw()
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, padding_and_rounding);
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(padding_and_rounding, padding_and_rounding));
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0.11f, 0.15f, 0.17f, 0.8f));
ImGui::PushFont(ImGuiManager::GetOSDFont());
ImGui::SetNextWindowSize(ImVec2(width, height), ImGuiCond_Always);
ImGui::SetNextWindowPos(ImVec2(io.DisplaySize.x * 0.5f, io.DisplaySize.y * 0.5f), ImGuiCond_Always,
ImVec2(0.5f, 0.5f));
Expand Down Expand Up @@ -1103,6 +1104,7 @@ void SaveStateSelectorUI::Draw()
}
ImGui::End();

ImGui::PopFont();
ImGui::PopStyleVar(2);
ImGui::PopStyleColor();

Expand Down
3 changes: 1 addition & 2 deletions src/util/imgui_fullscreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,8 @@ static std::vector<BackgroundProgressDialogData> s_background_progress_dialogs;
static std::mutex s_background_progress_lock;
} // namespace ImGuiFullscreen

void ImGuiFullscreen::SetFonts(ImFont* standard_font, ImFont* medium_font, ImFont* large_font)
void ImGuiFullscreen::SetFonts(ImFont* medium_font, ImFont* large_font)
{
g_standard_font = standard_font;
g_medium_font = medium_font;
g_large_font = large_font;
}
Expand Down
3 changes: 1 addition & 2 deletions src/util/imgui_fullscreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ static constexpr float LAYOUT_HORIZONTAL_MENU_HEIGHT = 320.0f;
static constexpr float LAYOUT_HORIZONTAL_MENU_PADDING = 30.0f;
static constexpr float LAYOUT_HORIZONTAL_MENU_ITEM_WIDTH = 250.0f;

extern ImFont* g_standard_font;
extern ImFont* g_medium_font;
extern ImFont* g_large_font;

Expand Down Expand Up @@ -121,7 +120,7 @@ ImRect CenterImage(const ImRect& fit_rect, const ImVec2& image_size);
bool Initialize(const char* placeholder_image_path);

void SetTheme(bool light);
void SetFonts(ImFont* standard_font, ImFont* medium_font, ImFont* large_font);
void SetFonts(ImFont* medium_font, ImFont* large_font);
bool UpdateLayoutScale();

/// Shuts down, clearing all state.
Expand Down
28 changes: 19 additions & 9 deletions src/util/imgui_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ static std::vector<WCharType> s_font_range;
static std::vector<WCharType> s_emoji_range;

static ImFont* s_standard_font;
static ImFont* s_osd_font;
static ImFont* s_fixed_font;
static ImFont* s_medium_font;
static ImFont* s_large_font;
Expand Down Expand Up @@ -274,7 +275,7 @@ void ImGuiManager::Shutdown()
s_fixed_font = nullptr;
s_medium_font = nullptr;
s_large_font = nullptr;
ImGuiFullscreen::SetFonts(nullptr, nullptr, nullptr);
ImGuiFullscreen::SetFonts(nullptr, nullptr);
}

float ImGuiManager::GetWindowWidth()
Expand Down Expand Up @@ -654,20 +655,24 @@ bool ImGuiManager::AddIconFonts(float size)

bool ImGuiManager::AddImGuiFonts(bool fullscreen_fonts)
{
const float standard_font_size = std::ceil(18.0f * s_global_scale);
const float fixed_font_size = std::ceil(15.0f * s_global_scale);
const float standard_font_size = std::ceil(15.0f * s_global_scale);
const float osd_font_size = std::ceil(17.0f * s_global_scale);

ImGuiIO& io = ImGui::GetIO();
io.Fonts->Clear();

s_standard_font = AddTextFont(standard_font_size);
if (!s_standard_font || !AddIconFonts(standard_font_size))
if (!s_standard_font)
return false;

s_fixed_font = AddFixedFont(fixed_font_size);
s_fixed_font = AddFixedFont(standard_font_size);
if (!s_fixed_font)
return false;

s_osd_font = AddTextFont(osd_font_size);
if (!s_osd_font || !AddIconFonts(osd_font_size))
return false;

if (fullscreen_fonts)
{
const float medium_font_size = ImGuiFullscreen::LayoutScale(ImGuiFullscreen::LAYOUT_MEDIUM_FONT_SIZE);
Expand All @@ -686,7 +691,7 @@ bool ImGuiManager::AddImGuiFonts(bool fullscreen_fonts)
s_large_font = nullptr;
}

ImGuiFullscreen::SetFonts(s_standard_font, s_medium_font, s_large_font);
ImGuiFullscreen::SetFonts(s_medium_font, s_large_font);

return io.Fonts->Build();
}
Expand Down Expand Up @@ -837,11 +842,11 @@ void ImGuiManager::DrawOSDMessages(Common::Timer::Value current_time)
{
static constexpr float MOVE_DURATION = 0.5f;

ImFont* const font = ImGui::GetFont();
ImFont* const font = s_osd_font;
const float scale = s_global_scale;
const float spacing = std::ceil(6.0f * scale);
const float margin = std::ceil(12.0f * scale);
const float padding = std::ceil(10.0f * scale);
const float margin = std::ceil(11.0f * scale);
const float padding = std::ceil(9.0f * scale);
const float rounding = std::ceil(6.0f * scale);
const float max_width = s_window_width - (margin + padding) * 2.0f;
float position_x = margin;
Expand Down Expand Up @@ -942,6 +947,11 @@ ImFont* ImGuiManager::GetStandardFont()
return s_standard_font;
}

ImFont* ImGuiManager::GetOSDFont()
{
return s_osd_font;
}

ImFont* ImGuiManager::GetFixedFont()
{
return s_fixed_font;
Expand Down
3 changes: 3 additions & 0 deletions src/util/imgui_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ bool AddFullscreenFontsIfMissing();
/// Returns the standard font for external drawing.
ImFont* GetStandardFont();

/// Returns the standard font for on-screen display drawing.
ImFont* GetOSDFont();

/// Returns the fixed-width font for external drawing.
ImFont* GetFixedFont();

Expand Down

0 comments on commit 895c489

Please sign in to comment.