FullscreenUI: Highlight menu item when dropdown open

Make it clearer which option we are modifying.
pull/3718/head
Stenzek 5 months ago
parent 423e5fd627
commit eb52ba3634
No known key found for this signature in database

@ -731,27 +731,28 @@ void FullscreenUI::DrawIntListSetting(SettingsInterface* bsi, std::string_view t
}
else
{
OpenDropdownDialog(std::move(cd_options), [game_settings, section = TinyString(section), key = TinyString(key),
option_offset](s32 index, const std::string& title) {
if (index < 0)
return;
OpenDropdownDialog(title, std::move(cd_options),
[game_settings, section = TinyString(section), key = TinyString(key),
option_offset](s32 index, const std::string& title) {
if (index < 0)
return;
const auto lock = Core::GetSettingsLock();
SettingsInterface* bsi = GetEditingSettingsInterface(game_settings);
if (game_settings)
{
if (index == 0)
bsi->DeleteValue(section, key);
else
bsi->SetIntValue(section, key, index - 1 + option_offset);
}
else
{
bsi->SetIntValue(section, key, index + option_offset);
}
const auto lock = Core::GetSettingsLock();
SettingsInterface* bsi = GetEditingSettingsInterface(game_settings);
if (game_settings)
{
if (index == 0)
bsi->DeleteValue(section, key);
else
bsi->SetIntValue(section, key, index - 1 + option_offset);
}
else
{
bsi->SetIntValue(section, key, index + option_offset);
}
SetSettingsChanged(bsi);
});
SetSettingsChanged(bsi);
});
}
}
}
@ -1411,33 +1412,34 @@ void FullscreenUI::DrawStringListSetting(SettingsInterface* bsi, std::string_vie
if (use_dropdown)
{
OpenDropdownDialog(std::move(cd_options), [game_settings, section, key, default_value, option_values,
changed_callback](s32 index, const std::string& title) {
if (index < 0)
return;
OpenDropdownDialog(title, std::move(cd_options),
[game_settings, section, key, default_value, option_values,
changed_callback](s32 index, const std::string& title) {
if (index < 0)
return;
const auto lock = Core::GetSettingsLock();
SettingsInterface* bsi = GetEditingSettingsInterface(game_settings);
if (game_settings)
{
if (index == 0)
bsi->DeleteValue(section, key);
else
bsi->SetStringValue(section, key, option_values[index - 1]);
const auto lock = Core::GetSettingsLock();
SettingsInterface* bsi = GetEditingSettingsInterface(game_settings);
if (game_settings)
{
if (index == 0)
bsi->DeleteValue(section, key);
else
bsi->SetStringValue(section, key, option_values[index - 1]);
if (changed_callback)
changed_callback(Core::GetStringSettingValue(section, key, default_value));
}
else
{
bsi->SetStringValue(section, key, option_values[index]);
if (changed_callback)
changed_callback(Core::GetStringSettingValue(section, key, default_value));
}
else
{
bsi->SetStringValue(section, key, option_values[index]);
if (changed_callback)
changed_callback(option_values[index]);
}
if (changed_callback)
changed_callback(option_values[index]);
}
SetSettingsChanged(bsi);
});
SetSettingsChanged(bsi);
});
}
else
{
@ -1501,27 +1503,28 @@ void FullscreenUI::DrawEnumSetting(SettingsInterface* bsi, std::string_view titl
for (u32 i = 0; i < static_cast<u32>(option_count); i++)
cd_options.emplace_back(to_display_string_function(static_cast<DataType>(i)),
(typed_value.has_value() && i == static_cast<u32>(typed_value.value())));
OpenDropdownDialog(std::move(cd_options), [section = TinyString(section), key = TinyString(key), to_string_function,
game_settings](s32 index, const std::string& title) {
if (index < 0)
return;
OpenDropdownDialog(title, std::move(cd_options),
[section = TinyString(section), key = TinyString(key), to_string_function,
game_settings](s32 index, const std::string& title) {
if (index < 0)
return;
const auto lock = Core::GetSettingsLock();
SettingsInterface* bsi = GetEditingSettingsInterface(game_settings);
if (game_settings)
{
if (index == 0)
bsi->DeleteValue(section, key);
else
bsi->SetStringValue(section, key, to_string_function(static_cast<DataType>(index - 1)));
}
else
{
bsi->SetStringValue(section, key, to_string_function(static_cast<DataType>(index)));
}
const auto lock = Core::GetSettingsLock();
SettingsInterface* bsi = GetEditingSettingsInterface(game_settings);
if (game_settings)
{
if (index == 0)
bsi->DeleteValue(section, key);
else
bsi->SetStringValue(section, key, to_string_function(static_cast<DataType>(index - 1)));
}
else
{
bsi->SetStringValue(section, key, to_string_function(static_cast<DataType>(index)));
}
SetSettingsChanged(bsi);
});
SetSettingsChanged(bsi);
});
}
}
@ -3974,25 +3977,26 @@ void FullscreenUI::DrawGraphicsSettingsPage()
options.emplace_back(adapter.name, checked);
}
OpenDropdownDialog(std::move(options), [game_settings](s32 index, const std::string& title) {
if (index < 0)
return;
OpenDropdownDialog(FSUI_ICONVSTR(ICON_PF_GPU_GRAPHICS_CARD, "GPU Adapter"), std::move(options),
[game_settings](s32 index, const std::string& title) {
if (index < 0)
return;
const char* value;
if (game_settings && index == 0)
value = nullptr;
else if ((!game_settings && index == 0) || (game_settings && index == 1))
value = "";
else
value = title.c_str();
const char* value;
if (game_settings && index == 0)
value = nullptr;
else if ((!game_settings && index == 0) || (game_settings && index == 1))
value = "";
else
value = title.c_str();
SettingsInterface* bsi = GetEditingSettingsInterface(game_settings);
if (!value)
bsi->DeleteValue("GPU", "Adapter");
else
bsi->SetStringValue("GPU", "Adapter", value);
SetSettingsChanged(bsi);
});
SettingsInterface* bsi = GetEditingSettingsInterface(game_settings);
if (!value)
bsi->DeleteValue("GPU", "Adapter");
else
bsi->SetStringValue("GPU", "Adapter", value);
SetSettingsChanged(bsi);
});
}
const bool pgxp_enabled = (is_hardware && GetEffectiveBoolSetting(bsi, "GPU", "PGXPEnable", false));
@ -5169,7 +5173,7 @@ void FullscreenUI::DrawAchievementsSettingsPage(std::unique_lock<std::mutex>& se
options.emplace_back(FSUI_STR("Use OSD Scale"), value.has_value() && value.value() < 0);
options.emplace_back(FSUI_STR("Custom"), is_custom);
OpenDropdownDialog(std::move(options), [key, game_settings](s32 index, const std::string& title) {
OpenDropdownDialog(title, std::move(options), [key, game_settings](s32 index, const std::string& title) {
if (index < 0)
return;

@ -245,7 +245,10 @@ public:
DropdownDialog();
~DropdownDialog();
void Open(DropdownDialogOptions options, DropdownDialogCallback callback, float min_width);
std::string_view GetHiddenTitle() const;
void Open(std::string_view hidden_title, DropdownDialogOptions options, DropdownDialogCallback callback,
float min_width);
void ClearState();
void SetAnchorBounds(const ImRect& value_bb, const ImRect& frame_bb);
@ -3668,6 +3671,14 @@ bool FullscreenUI::MenuActionButton(std::string_view title, std::string_view sum
if (!visible)
return false;
if (!hovered && dropdown_icon && s_state.dropdown_dialog.IsOpen() &&
s_state.dropdown_dialog.GetHiddenTitle() == title)
{
ImGui::RenderFrame(bb.frame_bb.Min, bb.frame_bb.Max,
ImGui::GetColorU32(DarkerColor(UIStyle.BackgroundColor, UIStyle.IsDarkTheme ? 1.4f : 0.2f)),
false, LayoutScale(LAYOUT_MENU_ITEM_BORDER_ROUNDING));
}
const ImVec4& color = ImGui::GetStyle().Colors[enabled ? ImGuiCol_Text : ImGuiCol_TextDisabled];
RenderShadowedTextClipped(UIStyle.Font, UIStyle.LargeFontSize, UIStyle.BoldFontWeight, bb.title_bb.Min,
@ -5086,7 +5097,17 @@ FullscreenUI::DropdownDialog::DropdownDialog() = default;
FullscreenUI::DropdownDialog::~DropdownDialog() = default;
void FullscreenUI::DropdownDialog::Open(DropdownDialogOptions options, DropdownDialogCallback callback, float min_width)
std::string_view FullscreenUI::DropdownDialog::GetHiddenTitle() const
{
const size_t chop_length = 18; // length of "##dropdown_dialog_"
if (m_title.length() < chop_length) [[unlikely]]
return {};
return std::string_view(m_title).substr(chop_length);
}
void FullscreenUI::DropdownDialog::Open(std::string_view hidden_title, DropdownDialogOptions options,
DropdownDialogCallback callback, float min_width)
{
m_options = std::move(options);
m_callback = std::move(callback);
@ -5152,7 +5173,7 @@ void FullscreenUI::DropdownDialog::Open(DropdownDialogOptions options, DropdownD
m_reverse_animation = false;
}
SetTitleAndOpen("##dropdown_dialog");
SetTitleAndOpen(fmt::format("##dropdown_dialog_{}", hidden_title));
}
void FullscreenUI::DropdownDialog::ClearState()
@ -5249,10 +5270,15 @@ bool FullscreenUI::IsDropdownDialogOpen()
return s_state.dropdown_dialog.IsOpen();
}
void FullscreenUI::OpenDropdownDialog(DropdownDialogOptions options, DropdownDialogCallback callback,
float min_width /* = 0.0f */)
std::string_view FullscreenUI::GetDropdownDialogHiddenTitle()
{
return s_state.dropdown_dialog.GetHiddenTitle();
}
void FullscreenUI::OpenDropdownDialog(std::string_view hidden_title, DropdownDialogOptions options,
DropdownDialogCallback callback, float min_width /* = 0.0f */)
{
s_state.dropdown_dialog.Open(std::move(options), std::move(callback), min_width);
s_state.dropdown_dialog.Open(hidden_title, std::move(options), std::move(callback), min_width);
}
void FullscreenUI::CloseDropdownDialog()

@ -547,7 +547,9 @@ void CloseChoiceDialog();
using DropdownDialogCallback = std::function<void(s32 index, const std::string& title)>;
using DropdownDialogOptions = std::vector<std::pair<std::string, bool>>;
bool IsDropdownDialogOpen();
void OpenDropdownDialog(DropdownDialogOptions options, DropdownDialogCallback callback, float min_width = 0.0f);
std::string_view GetDropdownDialogHiddenTitle();
void OpenDropdownDialog(std::string_view hidden_title, DropdownDialogOptions options, DropdownDialogCallback callback,
float min_width = 0.0f);
void CloseDropdownDialog();
using InputStringDialogCallback = std::function<void(std::string text)>;

Loading…
Cancel
Save