ImGuiFullscreen: Display checkmark on right of choice dialog

This commit is contained in:
Stenzek 2024-08-13 18:09:16 +10:00
parent 05f9f33ec6
commit f5815f3183
No known key found for this signature in database
2 changed files with 23 additions and 10 deletions

View File

@ -1120,6 +1120,12 @@ bool ImGuiFullscreen::MenuHeadingButton(const char* title, const char* value /*=
}
bool ImGuiFullscreen::ActiveButton(const char* title, bool is_active, bool enabled, float height, ImFont* font)
{
return ActiveButtonWithRightText(title, nullptr, is_active, enabled, height, font);
}
bool ImGuiFullscreen::ActiveButtonWithRightText(const char* title, const char* right_title, bool is_active,
bool enabled, float height, ImFont* font)
{
if (is_active)
{
@ -1144,6 +1150,15 @@ bool ImGuiFullscreen::ActiveButton(const char* title, bool is_active, bool enabl
ImGui::PushFont(font);
ImGui::RenderTextClipped(title_bb.Min, title_bb.Max, title, nullptr, nullptr, ImVec2(0.0f, 0.0f), &title_bb);
if (right_title && *right_title)
{
const ImVec2 right_text_size = font->CalcTextSizeA(font->FontSize, title_bb.GetWidth(), 0.0f, right_title);
const ImVec2 right_text_start = ImVec2(title_bb.Max.x - right_text_size.x, title_bb.Min.y);
ImGui::RenderTextClipped(right_text_start, title_bb.Max, right_title, nullptr, &right_text_size, ImVec2(0.0f, 0.0f),
&title_bb);
}
ImGui::PopFont();
if (!enabled)
@ -2187,8 +2202,8 @@ void ImGuiFullscreen::DrawFileSelector()
if (!s_file_selector_current_directory.empty())
{
MenuButton(fmt::format(ICON_FA_FOLDER_OPEN " {}", s_file_selector_current_directory).c_str(), nullptr, false,
LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY);
MenuButton(SmallString::from_format(ICON_FA_FOLDER_OPEN " {}", s_file_selector_current_directory).c_str(),
nullptr, false, LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY);
}
if (s_file_selector_directory && !s_file_selector_current_directory.empty())
@ -2332,8 +2347,8 @@ void ImGuiFullscreen::DrawChoiceDialog()
{
auto& option = s_choice_dialog_options[i];
const std::string title(
fmt::format("{0} {1}", option.second ? ICON_FA_CHECK_SQUARE : ICON_FA_SQUARE, option.first));
const SmallString title =
SmallString::from_format("{0} {1}", option.second ? ICON_FA_CHECK_SQUARE : ICON_FA_SQUARE, option.first);
if (MenuButton(title.c_str(), nullptr, true, LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY))
{
choice = i;
@ -2346,12 +2361,8 @@ void ImGuiFullscreen::DrawChoiceDialog()
for (s32 i = 0; i < static_cast<s32>(s_choice_dialog_options.size()); i++)
{
auto& option = s_choice_dialog_options[i];
std::string title;
if (option.second)
title += ICON_FA_CHECK " ";
title += option.first;
if (ActiveButton(title.c_str(), option.second, true, LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY))
if (ActiveButtonWithRightText(option.first.c_str(), option.second ? ICON_FA_CHECK : nullptr, option.second,
true, LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY))
{
choice = i;
for (s32 j = 0; j < static_cast<s32>(s_choice_dialog_options.size()); j++)

View File

@ -200,6 +200,8 @@ void MenuHeading(const char* title, bool draw_line = true);
bool MenuHeadingButton(const char* title, const char* value = nullptr, bool enabled = true, bool draw_line = true);
bool ActiveButton(const char* title, bool is_active, bool enabled = true,
float height = LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY, ImFont* font = g_large_font);
bool ActiveButtonWithRightText(const char* title, const char* right_title, bool is_active, bool enabled = true,
float height = LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY, ImFont* font = g_large_font);
bool MenuButton(const char* title, const char* summary, bool enabled = true, float height = LAYOUT_MENU_BUTTON_HEIGHT,
ImFont* font = g_large_font, ImFont* summary_font = g_medium_font);
bool MenuButtonWithoutSummary(const char* title, bool enabled = true,