diff --git a/src/core/fullscreen_ui.cpp b/src/core/fullscreen_ui.cpp index 71d8cb9bd..ccf27ff98 100644 --- a/src/core/fullscreen_ui.cpp +++ b/src/core/fullscreen_ui.cpp @@ -97,6 +97,7 @@ using ImGuiFullscreen::BeginFullscreenWindow; using ImGuiFullscreen::BeginHorizontalMenu; using ImGuiFullscreen::BeginMenuButtons; using ImGuiFullscreen::BeginNavBar; +using ImGuiFullscreen::BeginFixedPopupModal; using ImGuiFullscreen::CancelPendingMenuClose; using ImGuiFullscreen::CenterImage; using ImGuiFullscreen::DefaultActiveButton; @@ -107,6 +108,7 @@ using ImGuiFullscreen::EndFullscreenWindow; using ImGuiFullscreen::EndHorizontalMenu; using ImGuiFullscreen::EndMenuButtons; using ImGuiFullscreen::EndNavBar; +using ImGuiFullscreen::EndFixedPopupModal; using ImGuiFullscreen::EnumChoiceButton; using ImGuiFullscreen::FloatingButton; using ImGuiFullscreen::ForceKeyNavEnabled; @@ -2379,19 +2381,9 @@ void FullscreenUI::DrawInputBindingWindow() const char* title = FSUI_ICONSTR(ICON_FA_GAMEPAD, "Set Input Binding"); ImGui::SetNextWindowSize(LayoutScale(500.0f, 0.0f)); - ImGui::SetNextWindowPos(ImGui::GetIO().DisplaySize * 0.5f, ImGuiCond_Always, ImVec2(0.5f, 0.5f)); ImGui::OpenPopup(title); - ImGui::PushFont(UIStyle.LargeFont); - ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, LayoutScale(10.0f)); - ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, LayoutScale(ImGuiFullscreen::LAYOUT_MENU_BUTTON_X_PADDING, - ImGuiFullscreen::LAYOUT_MENU_BUTTON_Y_PADDING)); - ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0f); - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, LayoutScale(20.0f, 20.0f)); - - if (ImGui::BeginPopupModal(title, nullptr, - ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoScrollWithMouse | - ImGuiWindowFlags_NoCollapse)) + if (BeginFixedPopupModal(title)) { ImGui::TextWrapped("%s", SmallString::from_format(FSUI_FSTR("Setting {} binding {}."), s_state.input_binding_section, s_state.input_binding_display_name) @@ -2399,11 +2391,8 @@ void FullscreenUI::DrawInputBindingWindow() ImGui::TextUnformatted(FSUI_CSTR("Push a controller button or axis now.")); ImGui::NewLine(); ImGui::TextUnformatted(SmallString::from_format(FSUI_FSTR("Timing out in {:.0f} seconds..."), time_remaining)); - ImGui::EndPopup(); + EndFixedPopupModal(); } - - ImGui::PopStyleVar(4); - ImGui::PopFont(); } bool FullscreenUI::DrawToggleSetting(SettingsInterface* bsi, const char* title, const char* summary, @@ -2575,16 +2564,8 @@ void FullscreenUI::DrawIntRangeSetting(SettingsInterface* bsi, const char* title ImGui::SetNextWindowSize(LayoutScale(500.0f, 194.0f)); ImGui::SetNextWindowPos(ImGui::GetIO().DisplaySize * 0.5f, ImGuiCond_Always, ImVec2(0.5f, 0.5f)); - ImGui::PushFont(UIStyle.LargeFont); - ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, LayoutScale(10.0f)); - ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, LayoutScale(ImGuiFullscreen::LAYOUT_MENU_BUTTON_X_PADDING, - ImGuiFullscreen::LAYOUT_MENU_BUTTON_Y_PADDING)); - ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0f); - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, LayoutScale(20.0f, 20.0f)); - bool is_open = true; - if (ImGui::BeginPopupModal(title, &is_open, - ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove)) + if (BeginFixedPopupModal(title, &is_open)) { BeginMenuButtons(); @@ -2609,11 +2590,8 @@ void FullscreenUI::DrawIntRangeSetting(SettingsInterface* bsi, const char* title } EndMenuButtons(); - ImGui::EndPopup(); + EndFixedPopupModal(); } - - ImGui::PopStyleVar(4); - ImGui::PopFont(); } void FullscreenUI::DrawFloatRangeSetting(SettingsInterface* bsi, const char* title, const char* summary, @@ -2631,18 +2609,9 @@ void FullscreenUI::DrawFloatRangeSetting(SettingsInterface* bsi, const char* tit ImGui::OpenPopup(title); ImGui::SetNextWindowSize(LayoutScale(500.0f, 194.0f)); - ImGui::SetNextWindowPos(ImGui::GetIO().DisplaySize * 0.5f, ImGuiCond_Always, ImVec2(0.5f, 0.5f)); - - ImGui::PushFont(UIStyle.LargeFont); - ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, LayoutScale(10.0f)); - ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, LayoutScale(ImGuiFullscreen::LAYOUT_MENU_BUTTON_X_PADDING, - ImGuiFullscreen::LAYOUT_MENU_BUTTON_Y_PADDING)); - ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0f); - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, LayoutScale(20.0f, 20.0f)); bool is_open = true; - if (ImGui::BeginPopupModal(title, &is_open, - ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove)) + if (BeginFixedPopupModal(title, &is_open)) { BeginMenuButtons(); @@ -2670,11 +2639,8 @@ void FullscreenUI::DrawFloatRangeSetting(SettingsInterface* bsi, const char* tit } EndMenuButtons(); - ImGui::EndPopup(); + EndFixedPopupModal(); } - - ImGui::PopStyleVar(4); - ImGui::PopFont(); } void FullscreenUI::DrawFloatSpinBoxSetting(SettingsInterface* bsi, const char* title, const char* summary, @@ -2697,18 +2663,9 @@ void FullscreenUI::DrawFloatSpinBoxSetting(SettingsInterface* bsi, const char* t } ImGui::SetNextWindowSize(LayoutScale(500.0f, 194.0f)); - ImGui::SetNextWindowPos(ImGui::GetIO().DisplaySize * 0.5f, ImGuiCond_Always, ImVec2(0.5f, 0.5f)); - - ImGui::PushFont(UIStyle.LargeFont); - ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, LayoutScale(10.0f)); - ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, LayoutScale(ImGuiFullscreen::LAYOUT_MENU_BUTTON_X_PADDING, - ImGuiFullscreen::LAYOUT_MENU_BUTTON_Y_PADDING)); - ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0f); - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, LayoutScale(20.0f, 20.0f)); bool is_open = true; - if (ImGui::BeginPopupModal(title, &is_open, - ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove)) + if (BeginFixedPopupModal(title, &is_open)) { BeginMenuButtons(); @@ -2800,11 +2757,8 @@ void FullscreenUI::DrawFloatSpinBoxSetting(SettingsInterface* bsi, const char* t } EndMenuButtons(); - ImGui::EndPopup(); + EndFixedPopupModal(); } - - ImGui::PopStyleVar(4); - ImGui::PopFont(); } bool FullscreenUI::DrawIntRectSetting(SettingsInterface* bsi, const char* title, const char* summary, @@ -2834,19 +2788,10 @@ bool FullscreenUI::DrawIntRectSetting(SettingsInterface* bsi, const char* title, ImGui::OpenPopup(title); ImGui::SetNextWindowSize(LayoutScale(500.0f, 370.0f)); - ImGui::SetNextWindowPos(ImGui::GetIO().DisplaySize * 0.5f, ImGuiCond_Always, ImVec2(0.5f, 0.5f)); - - ImGui::PushFont(font); - ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, LayoutScale(10.0f)); - ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, LayoutScale(ImGuiFullscreen::LAYOUT_MENU_BUTTON_X_PADDING, - ImGuiFullscreen::LAYOUT_MENU_BUTTON_Y_PADDING)); - ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0f); - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, LayoutScale(20.0f, 20.0f)); bool is_open = true; bool changed = false; - if (ImGui::BeginPopupModal(title, &is_open, - ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove)) + if (BeginFixedPopupModal(title, &is_open)) { s32 dlg_left_value = static_cast(left_value.value_or(default_left)); s32 dlg_top_value = static_cast(top_value.value_or(default_top)); @@ -2921,12 +2866,9 @@ bool FullscreenUI::DrawIntRectSetting(SettingsInterface* bsi, const char* title, } EndMenuButtons(); - ImGui::EndPopup(); + EndFixedPopupModal(); } - ImGui::PopStyleVar(4); - ImGui::PopFont(); - return changed; } @@ -2953,18 +2895,9 @@ void FullscreenUI::DrawIntSpinBoxSetting(SettingsInterface* bsi, const char* tit } ImGui::SetNextWindowSize(LayoutScale(500.0f, 194.0f)); - ImGui::SetNextWindowPos(ImGui::GetIO().DisplaySize * 0.5f, ImGuiCond_Always, ImVec2(0.5f, 0.5f)); - - ImGui::PushFont(UIStyle.LargeFont); - ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, LayoutScale(10.0f)); - ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, LayoutScale(ImGuiFullscreen::LAYOUT_MENU_BUTTON_X_PADDING, - ImGuiFullscreen::LAYOUT_MENU_BUTTON_Y_PADDING)); - ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0f); - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, LayoutScale(20.0f, 20.0f)); bool is_open = true; - if (ImGui::BeginPopupModal(title, &is_open, - ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove)) + if (BeginFixedPopupModal(title, &is_open)) { BeginMenuButtons(); @@ -3050,11 +2983,8 @@ void FullscreenUI::DrawIntSpinBoxSetting(SettingsInterface* bsi, const char* tit } EndMenuButtons(); - ImGui::EndPopup(); + EndFixedPopupModal(); } - - ImGui::PopStyleVar(4); - ImGui::PopFont(); } [[maybe_unused]] void FullscreenUI::DrawStringListSetting(SettingsInterface* bsi, const char* title, @@ -4663,16 +4593,8 @@ void FullscreenUI::DrawControllerSettingsPage() 1.0f, 0.01f, 100.0f, "%.0f%%"); ImGui::SetNextWindowSize(LayoutScale(500.0f, 180.0f)); - ImGui::SetNextWindowPos(ImGui::GetIO().DisplaySize * 0.5f, ImGuiCond_Always, ImVec2(0.5f, 0.5f)); - ImGui::PushFont(UIStyle.LargeFont); - ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, LayoutScale(10.0f)); - ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, LayoutScale(ImGuiFullscreen::LAYOUT_MENU_BUTTON_X_PADDING, - ImGuiFullscreen::LAYOUT_MENU_BUTTON_Y_PADDING)); - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, LayoutScale(20.0f, 20.0f)); - - if (ImGui::BeginPopupModal(freq_label, nullptr, - ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove)) + if (BeginFixedPopupModal(freq_label, nullptr)) { ImGui::SetNextItemWidth(LayoutScale(450.0f)); if (ImGui::SliderInt("##value", &frequency, 0, 60, FSUI_CSTR("Toggle every %d frames"), @@ -4689,11 +4611,8 @@ void FullscreenUI::DrawControllerSettingsPage() ImGui::CloseCurrentPopup(); EndMenuButtons(); - ImGui::EndPopup(); + EndFixedPopupModal(); } - - ImGui::PopStyleVar(3); - ImGui::PopFont(); } if (!ci->settings.empty()) @@ -5511,18 +5430,9 @@ void FullscreenUI::DrawPostProcessingSettingsPage() ImGui::OpenPopup(tstr); ImGui::SetNextWindowSize(LayoutScale(500.0f, 194.0f)); - ImGui::SetNextWindowPos(ImGui::GetIO().DisplaySize * 0.5f, ImGuiCond_Always, ImVec2(0.5f, 0.5f)); - - ImGui::PushFont(UIStyle.LargeFont); - ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, LayoutScale(10.0f)); - ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, LayoutScale(ImGuiFullscreen::LAYOUT_MENU_BUTTON_X_PADDING, - ImGuiFullscreen::LAYOUT_MENU_BUTTON_Y_PADDING)); - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, LayoutScale(20.0f, 20.0f)); - ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0f); bool is_open = true; - if (ImGui::BeginPopupModal(tstr, &is_open, - ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove)) + if (BeginFixedPopupModal(tstr, &is_open)) { BeginMenuButtons(); @@ -5595,11 +5505,8 @@ void FullscreenUI::DrawPostProcessingSettingsPage() } EndMenuButtons(); - ImGui::EndPopup(); + EndFixedPopupModal(); } - - ImGui::PopStyleVar(4); - ImGui::PopFont(); } break; @@ -5612,18 +5519,9 @@ void FullscreenUI::DrawPostProcessingSettingsPage() ImGui::OpenPopup(tstr); ImGui::SetNextWindowSize(LayoutScale(500.0f, 194.0f)); - ImGui::SetNextWindowPos(ImGui::GetIO().DisplaySize * 0.5f, ImGuiCond_Always, ImVec2(0.5f, 0.5f)); - - ImGui::PushFont(UIStyle.LargeFont); - ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, LayoutScale(10.0f)); - ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, LayoutScale(ImGuiFullscreen::LAYOUT_MENU_BUTTON_X_PADDING, - ImGuiFullscreen::LAYOUT_MENU_BUTTON_Y_PADDING)); - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, LayoutScale(20.0f, 20.0f)); - ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0f); bool is_open = true; - if (ImGui::BeginPopupModal(tstr, &is_open, - ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove)) + if (BeginFixedPopupModal(tstr, &is_open)) { BeginMenuButtons(); @@ -5695,11 +5593,8 @@ void FullscreenUI::DrawPostProcessingSettingsPage() } EndMenuButtons(); - ImGui::EndPopup(); + EndFixedPopupModal(); } - - ImGui::PopStyleVar(4); - ImGui::PopFont(); } break; @@ -6041,22 +5936,11 @@ void FullscreenUI::DrawAchievementsLoginWindow() }; ImGui::SetNextWindowSize(LayoutScale(600.0f, 0.0f)); - ImGui::SetNextWindowPos(ImGui::GetIO().DisplaySize * 0.5f, ImGuiCond_Always, ImVec2(0.5f, 0.5f)); - - ImGui::PushFont(UIStyle.LargeFont); - ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, LayoutScale(10.0f)); - ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, - LayoutScale(LAYOUT_MENU_BUTTON_X_PADDING, LAYOUT_MENU_BUTTON_Y_PADDING)); - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, LayoutScale(20.0f, 20.0f)); - ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0f); - ImGui::PushStyleColor(ImGuiCol_Text, UIStyle.PrimaryTextColor); - ImGui::PushStyleColor(ImGuiCol_TitleBg, UIStyle.PrimaryDarkColor); - ImGui::PushStyleColor(ImGuiCol_TitleBgActive, UIStyle.PrimaryColor); const char* popup_title = FSUI_ICONSTR(ICON_FA_KEY, "RetroAchievements Login"); bool popup_closed = false; ImGui::OpenPopup(popup_title); - if (ImGui::BeginPopupModal(popup_title, nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize)) + if (BeginFixedPopupModal(popup_title, nullptr)) { BeginMenuButtons(); @@ -6131,13 +6015,9 @@ void FullscreenUI::DrawAchievementsLoginWindow() EndMenuButtons(); - ImGui::EndPopup(); + EndFixedPopupModal(); } - ImGui::PopStyleColor(3); - ImGui::PopStyleVar(4); - ImGui::PopFont(); - if (popup_closed) actually_close_popup(); } @@ -6298,18 +6178,9 @@ void FullscreenUI::DrawPatchesOrCheatsSettingsPage(bool cheats) ImGui::OpenPopup(title); ImGui::SetNextWindowSize(LayoutScale(500.0f, 194.0f)); - ImGui::SetNextWindowPos(ImGui::GetIO().DisplaySize * 0.5f, ImGuiCond_Always, ImVec2(0.5f, 0.5f)); - - ImGui::PushFont(UIStyle.LargeFont); - ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, LayoutScale(10.0f)); - ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, LayoutScale(ImGuiFullscreen::LAYOUT_MENU_BUTTON_X_PADDING, - ImGuiFullscreen::LAYOUT_MENU_BUTTON_Y_PADDING)); - ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0f); - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, LayoutScale(20.0f, 20.0f)); bool is_open = true; - if (ImGui::BeginPopupModal(title, &is_open, - ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove)) + if (BeginFixedPopupModal(title, &is_open)) { BeginMenuButtons(); @@ -6380,11 +6251,8 @@ void FullscreenUI::DrawPatchesOrCheatsSettingsPage(bool cheats) } EndMenuButtons(); - ImGui::EndPopup(); + EndFixedPopupModal(); } - - ImGui::PopStyleVar(4); - ImGui::PopFont(); } else { @@ -8406,7 +8274,7 @@ void FullscreenUI::CopyTextToClipboard(std::string title, std::string_view text) void FullscreenUI::DrawAboutWindow() { - ImGui::SetNextWindowSize(LayoutScale(1000.0f, 545.0f)); + ImGui::SetNextWindowSize(LayoutScale(1000.0f, 550.0f)); ImGui::SetNextWindowPos(ImGui::GetIO().DisplaySize * 0.5f, ImGuiCond_Always, ImVec2(0.5f, 0.5f)); ImGui::OpenPopup(FSUI_CSTR("About DuckStation")); diff --git a/src/util/imgui_fullscreen.cpp b/src/util/imgui_fullscreen.cpp index 78220fc8f..aa29ba1a4 100644 --- a/src/util/imgui_fullscreen.cpp +++ b/src/util/imgui_fullscreen.cpp @@ -46,6 +46,8 @@ static constexpr float SMOOTH_SCROLLING_SPEED = 3.5f; static std::optional LoadTextureImage(std::string_view path, u32 svg_width, u32 svg_height); static std::shared_ptr UploadTexture(std::string_view path, const Image& image); +static void PushPopupStyle(float window_padding = 20.0f); +static void PopPopupStyle(); static void DrawFileSelector(); static void DrawChoiceDialog(); static void DrawInputDialog(); @@ -619,6 +621,54 @@ void ImGuiFullscreen::EndLayout() s_state.had_hovered_menu_item = std::exchange(s_state.has_hovered_menu_item, false); } +void ImGuiFullscreen::PushPopupStyle(float window_padding) +{ + ImGui::PushFont(UIStyle.LargeFont); + ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, LayoutScale(20.0f)); + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, LayoutScale(window_padding, window_padding)); + ImGui::PushStyleVar(ImGuiStyleVar_ScrollbarRounding, LayoutScale(10.0f)); + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, + LayoutScale(LAYOUT_MENU_BUTTON_X_PADDING, LAYOUT_MENU_BUTTON_Y_PADDING)); + ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0f); + ImGui::PushStyleColor(ImGuiCol_PopupBg, UIStyle.PopupBackgroundColor); + ImGui::PushStyleColor(ImGuiCol_FrameBg, UIStyle.PopupFrameBackgroundColor); + ImGui::PushStyleColor(ImGuiCol_TitleBg, UIStyle.PrimaryDarkColor); + ImGui::PushStyleColor(ImGuiCol_TitleBgActive, UIStyle.PrimaryColor); + ImGui::PushStyleColor(ImGuiCol_Text, UIStyle.PrimaryTextColor); +} + +bool ImGuiFullscreen::BeginFixedPopupModal(const char* name, bool* p_open) +{ + PushPopupStyle(); + + ImGui::SetNextWindowPos((ImGui::GetIO().DisplaySize - LayoutScale(0.0f, LAYOUT_FOOTER_HEIGHT)) * 0.5f, + ImGuiCond_Always, ImVec2(0.5f, 0.5f)); + + if (!ImGui::BeginPopupModal(name, p_open, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove)) + { + PopPopupStyle(); + return false; + } + + // don't draw unreadable text + ImGui::PushStyleColor(ImGuiCol_Text, UIStyle.BackgroundTextColor); + return true; +} + +void ImGuiFullscreen::PopPopupStyle() +{ + ImGui::PopStyleColor(5); + ImGui::PopStyleVar(5); + ImGui::PopFont(); +} + +void ImGuiFullscreen::EndFixedPopupModal() +{ + ImGui::PopStyleColor(); + ImGui::EndPopup(); + PopPopupStyle(); +} + void ImGuiFullscreen::RenderOverlays() { if (!s_state.initialized) @@ -1755,18 +1805,8 @@ bool ImGuiFullscreen::RangeButton(const char* title, const char* summary, s32* v bool changed = false; ImGui::SetNextWindowSize(LayoutScale(500.0f, 192.0f)); - ImGui::SetNextWindowPos((ImGui::GetIO().DisplaySize - LayoutScale(0.0f, LAYOUT_FOOTER_HEIGHT)) * 0.5f, - ImGuiCond_Always, ImVec2(0.5f, 0.5f)); - ImGui::PushFont(UIStyle.LargeFont); - ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, LayoutScale(10.0f)); - ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, LayoutScale(ImGuiFullscreen::LAYOUT_MENU_BUTTON_X_PADDING, - ImGuiFullscreen::LAYOUT_MENU_BUTTON_Y_PADDING)); - ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0f); - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, LayoutScale(20.0f, 20.0f)); - - if (ImGui::BeginPopupModal(title, nullptr, - ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove)) + if (BeginFixedPopupModal(title, nullptr)) { BeginMenuButtons(); @@ -1781,12 +1821,9 @@ bool ImGuiFullscreen::RangeButton(const char* title, const char* summary, s32* v ImGui::CloseCurrentPopup(); EndMenuButtons(); - ImGui::EndPopup(); + EndFixedPopupModal(); } - ImGui::PopStyleVar(4); - ImGui::PopFont(); - return changed; } @@ -1834,18 +1871,8 @@ bool ImGuiFullscreen::RangeButton(const char* title, const char* summary, float* bool changed = false; ImGui::SetNextWindowSize(LayoutScale(500.0f, 192.0f)); - ImGui::SetNextWindowPos((ImGui::GetIO().DisplaySize - LayoutScale(0.0f, LAYOUT_FOOTER_HEIGHT)) * 0.5f, - ImGuiCond_Always, ImVec2(0.5f, 0.5f)); - ImGui::PushFont(UIStyle.LargeFont); - ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, LayoutScale(10.0f)); - ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, LayoutScale(ImGuiFullscreen::LAYOUT_MENU_BUTTON_X_PADDING, - ImGuiFullscreen::LAYOUT_MENU_BUTTON_Y_PADDING)); - ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0f); - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, LayoutScale(20.0f, 20.0f)); - - if (ImGui::BeginPopupModal(title, nullptr, - ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove)) + if (BeginFixedPopupModal(title, nullptr)) { BeginMenuButtons(); @@ -1859,12 +1886,9 @@ bool ImGuiFullscreen::RangeButton(const char* title, const char* summary, float* ImGui::CloseCurrentPopup(); EndMenuButtons(); - ImGui::EndPopup(); + EndFixedPopupModal(); } - ImGui::PopStyleVar(4); - ImGui::PopFont(); - return changed; } @@ -2383,20 +2407,11 @@ void ImGuiFullscreen::DrawFileSelector() return; ImGui::SetNextWindowSize(LayoutScale(1000.0f, 650.0f)); - ImGui::SetNextWindowPos((ImGui::GetIO().DisplaySize - LayoutScale(0.0f, LAYOUT_FOOTER_HEIGHT)) * 0.5f, - ImGuiCond_Always, ImVec2(0.5f, 0.5f)); ImGui::OpenPopup(s_state.file_selector_title.c_str()); FileSelectorItem* selected = nullptr; - ImGui::PushFont(UIStyle.LargeFont); - ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, LayoutScale(10.0f)); - ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, - LayoutScale(LAYOUT_MENU_BUTTON_X_PADDING, LAYOUT_MENU_BUTTON_Y_PADDING)); - ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0f); - ImGui::PushStyleColor(ImGuiCol_Text, UIStyle.PrimaryTextColor); - ImGui::PushStyleColor(ImGuiCol_TitleBg, UIStyle.PrimaryDarkColor); - ImGui::PushStyleColor(ImGuiCol_TitleBgActive, UIStyle.PrimaryColor); + PushPopupStyle(10.0f); bool is_open = !WantsToCloseMenu(); bool directory_selected = false; @@ -2443,9 +2458,7 @@ void ImGuiFullscreen::DrawFileSelector() is_open = false; } - ImGui::PopStyleColor(3); - ImGui::PopStyleVar(3); - ImGui::PopFont(); + PopPopupStyle(); if (is_open) GetFileSelectorHelpText(s_state.fullscreen_footer_text); @@ -2532,15 +2545,7 @@ void ImGuiFullscreen::DrawChoiceDialog() if (!s_state.choice_dialog_open) return; - ImGui::PushFont(UIStyle.LargeFont); - ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, LayoutScale(10.0f)); - ImGui::PushStyleVar(ImGuiStyleVar_ScrollbarRounding, LayoutScale(10.0f)); - ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, - LayoutScale(LAYOUT_MENU_BUTTON_X_PADDING, LAYOUT_MENU_BUTTON_Y_PADDING)); - ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0f); - ImGui::PushStyleColor(ImGuiCol_Text, UIStyle.PrimaryTextColor); - ImGui::PushStyleColor(ImGuiCol_TitleBg, UIStyle.PrimaryDarkColor); - ImGui::PushStyleColor(ImGuiCol_TitleBgActive, UIStyle.PrimaryColor); + PushPopupStyle(10.0f); const float width = LayoutScale(600.0f); const float title_height = @@ -2602,9 +2607,7 @@ void ImGuiFullscreen::DrawChoiceDialog() ImGui::EndPopup(); } - ImGui::PopStyleColor(3); - ImGui::PopStyleVar(4); - ImGui::PopFont(); + PopPopupStyle(); is_open &= !WantsToCloseMenu(); @@ -2664,21 +2667,15 @@ void ImGuiFullscreen::DrawInputDialog() ImGuiCond_Always, ImVec2(0.5f, 0.5f)); ImGui::OpenPopup(s_state.input_dialog_title.c_str()); - ImGui::PushFont(UIStyle.LargeFont); - ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, LayoutScale(10.0f)); - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, LayoutScale(20.0f, 20.0f)); - ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, - LayoutScale(LAYOUT_MENU_BUTTON_X_PADDING, LAYOUT_MENU_BUTTON_Y_PADDING)); - ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0f); - ImGui::PushStyleColor(ImGuiCol_Text, UIStyle.PrimaryTextColor); - ImGui::PushStyleColor(ImGuiCol_TitleBg, UIStyle.PrimaryDarkColor); - ImGui::PushStyleColor(ImGuiCol_TitleBgActive, UIStyle.PrimaryColor); + PushPopupStyle(); bool is_open = true; if (ImGui::BeginPopupModal(s_state.input_dialog_title.c_str(), &is_open, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove)) { + ImGui::PushStyleColor(ImGuiCol_Text, UIStyle.BackgroundTextColor); + ResetFocusHere(); ImGui::TextWrapped("%s", s_state.input_dialog_message.c_str()); @@ -2721,6 +2718,8 @@ void ImGuiFullscreen::DrawInputDialog() EndMenuButtons(); + ImGui::PopStyleColor(1); + ImGui::EndPopup(); } if (!is_open) @@ -2728,9 +2727,7 @@ void ImGuiFullscreen::DrawInputDialog() else GetInputDialogHelpText(s_state.fullscreen_footer_text); - ImGui::PopStyleColor(3); - ImGui::PopStyleVar(4); - ImGui::PopFont(); + PopPopupStyle(); } void ImGuiFullscreen::CloseInputDialog() @@ -2827,15 +2824,7 @@ void ImGuiFullscreen::DrawMessageDialog() ImGuiCond_Always, ImVec2(0.5f, 0.5f)); ImGui::OpenPopup(win_id); - ImGui::PushFont(UIStyle.LargeFont); - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, LayoutScale(20.0f, 20.0f)); - ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, LayoutScale(10.0f)); - ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, - LayoutScale(LAYOUT_MENU_BUTTON_X_PADDING, LAYOUT_MENU_BUTTON_Y_PADDING)); - ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0f); - ImGui::PushStyleColor(ImGuiCol_Text, UIStyle.PrimaryTextColor); - ImGui::PushStyleColor(ImGuiCol_TitleBg, UIStyle.PrimaryDarkColor); - ImGui::PushStyleColor(ImGuiCol_TitleBgActive, UIStyle.PrimaryColor); + PushPopupStyle(); bool is_open = true; const u32 flags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | @@ -2844,6 +2833,8 @@ void ImGuiFullscreen::DrawMessageDialog() if (ImGui::BeginPopupModal(win_id, &is_open, flags)) { + ImGui::PushStyleColor(ImGuiCol_Text, UIStyle.BackgroundTextColor); + ResetFocusHere(); BeginMenuButtons(); @@ -2862,12 +2853,11 @@ void ImGuiFullscreen::DrawMessageDialog() EndMenuButtons(); + ImGui::PopStyleColor(); ImGui::EndPopup(); } - ImGui::PopStyleColor(3); - ImGui::PopStyleVar(4); - ImGui::PopFont(); + PopPopupStyle(); if (!is_open || result.has_value()) { @@ -3469,6 +3459,7 @@ void ImGuiFullscreen::SetTheme(bool light) UIStyle.BackgroundLineColor = HEX_TO_IMVEC4(0xf0f0f0, 0xff); UIStyle.BackgroundHighlight = HEX_TO_IMVEC4(0x4b4b4b, 0xc0); UIStyle.PopupBackgroundColor = HEX_TO_IMVEC4(0x212121, 0xf2); + UIStyle.PopupFrameBackgroundColor = HEX_TO_IMVEC4(0x313131, 0xf2); UIStyle.PrimaryColor = HEX_TO_IMVEC4(0x2e2e2e, 0xff); UIStyle.PrimaryLightColor = HEX_TO_IMVEC4(0x484848, 0xff); UIStyle.PrimaryDarkColor = HEX_TO_IMVEC4(0x000000, 0xff); @@ -3489,6 +3480,7 @@ void ImGuiFullscreen::SetTheme(bool light) UIStyle.BackgroundLineColor = HEX_TO_IMVEC4(0xe1e2e1, 0xff); UIStyle.BackgroundHighlight = HEX_TO_IMVEC4(0xe1e2e1, 0xc0); UIStyle.PopupBackgroundColor = HEX_TO_IMVEC4(0xd8d8d8, 0xf2); + UIStyle.PopupFrameBackgroundColor = HEX_TO_IMVEC4(0xc8c8c8, 0xf2); UIStyle.PrimaryColor = HEX_TO_IMVEC4(0x2a3e78, 0xff); UIStyle.PrimaryLightColor = HEX_TO_IMVEC4(0x235cd9, 0xff); UIStyle.PrimaryDarkColor = HEX_TO_IMVEC4(0x1d2953, 0xff); diff --git a/src/util/imgui_fullscreen.h b/src/util/imgui_fullscreen.h index 987743c7a..228e2cfdc 100644 --- a/src/util/imgui_fullscreen.h +++ b/src/util/imgui_fullscreen.h @@ -50,6 +50,7 @@ struct ALIGN_TO_CACHE_LINE UIStyles ImVec4 BackgroundLineColor; ImVec4 BackgroundHighlight; ImVec4 PopupBackgroundColor; + ImVec4 PopupFrameBackgroundColor; ImVec4 DisabledColor; ImVec4 PrimaryColor; ImVec4 PrimaryLightColor; @@ -148,6 +149,8 @@ void UploadAsyncTextures(); void BeginLayout(); void EndLayout(); +bool BeginFixedPopupModal(const char* name, bool* p_open = nullptr); +void EndFixedPopupModal(); void RenderOverlays();