From 6eeca57a06838491395e732d9b9521e3fbbe98eb Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Mon, 25 Jan 2021 01:05:21 +1000 Subject: [PATCH] CommonHostInterface: Wrap OSD messages --- src/frontend-common/common_host_interface.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/frontend-common/common_host_interface.cpp b/src/frontend-common/common_host_interface.cpp index d0ba80a95..f9df41675 100644 --- a/src/frontend-common/common_host_interface.cpp +++ b/src/frontend-common/common_host_interface.cpp @@ -932,6 +932,7 @@ void CommonHostInterface::DrawOSDMessages() return; const float scale = ImGui::GetIO().DisplayFramebufferScale.x; + const float max_width = ImGui::GetIO().DisplaySize.x - (20.0f * scale); auto iter = m_osd_messages.begin(); float position_x = 10.0f * scale; @@ -955,8 +956,11 @@ void CommonHostInterface::DrawOSDMessages() } const float opacity = std::min(time_remaining, 1.0f); + const ImVec2 text_size(ImGui::CalcTextSize(msg.text.c_str(), nullptr)); + const bool wrapped = (text_size.x > max_width); + ImGui::SetNextWindowPos(ImVec2(position_x, position_y)); - ImGui::SetNextWindowSize(ImVec2(0.0f, 0.0f)); + ImGui::SetNextWindowSize(ImVec2(wrapped ? max_width : 0.0f, 0.0f)); ImGui::PushStyleVar(ImGuiStyleVar_Alpha, opacity); char buf[64]; @@ -964,7 +968,11 @@ void CommonHostInterface::DrawOSDMessages() if (ImGui::Begin(buf, nullptr, window_flags)) { - ImGui::TextUnformatted(msg.text.c_str()); + if (wrapped) + ImGui::TextWrapped("%s", msg.text.c_str()); + else + ImGui::TextUnformatted(msg.text.c_str()); + position_y += ImGui::GetWindowSize().y + (4.0f * scale); }