ImGuiFullscreen: Display checkmark on right of choice dialog

Backport from: f5815f3183
This commit is contained in:
KamFretoZ 2024-08-18 22:31:28 +07:00 committed by lightningterror
parent 69574aecc6
commit 04fdd09d1e
2 changed files with 26 additions and 6 deletions

View File

@ -1088,10 +1088,16 @@ bool ImGuiFullscreen::MenuHeadingButton(
}
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)
{
// don't draw over a prerendered border
// don't draw over a prerendered border
const float border_size = ImGui::GetStyle().FrameBorderSize;
const ImVec2 border_size_v = ImVec2(border_size, border_size);
ImVec2 pos, size;
@ -1112,6 +1118,16 @@ 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)
@ -1983,8 +1999,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())
@ -2124,7 +2140,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;
@ -2142,7 +2159,8 @@ void ImGuiFullscreen::DrawChoiceDialog()
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++)
@ -2307,7 +2325,7 @@ void ImGuiFullscreen::OpenConfirmMessageDialog(
s_message_dialog_callback = std::move(callback);
s_message_dialog_buttons[0] = std::move(yes_button_text);
s_message_dialog_buttons[1] = std::move(no_button_text);
QueueResetFocus(FocusResetType::PopupOpened);
QueueResetFocus(FocusResetType::PopupOpened);
}
void ImGuiFullscreen::OpenInfoMessageDialog(

View File

@ -167,6 +167,8 @@ namespace ImGuiFullscreen
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, float height = LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY,