From 21723879e7631b2d81d3c3ff14f93c834bc1cdd8 Mon Sep 17 00:00:00 2001 From: lat9nq <22451773+lat9nq@users.noreply.github.com> Date: Wed, 21 Jun 2023 03:29:20 -0400 Subject: [PATCH] configuration: Use specialization of settings Reduces some ugliness in frontend code. --- src/yuzu/configuration/configure_audio.cpp | 8 +---- src/yuzu/configuration/configure_graphics.cpp | 8 +---- src/yuzu/configuration/configure_system.cpp | 7 ++--- src/yuzu/configuration/shared_widget.cpp | 31 +++++++++++++++++++ 4 files changed, 36 insertions(+), 18 deletions(-) diff --git a/src/yuzu/configuration/configure_audio.cpp b/src/yuzu/configuration/configure_audio.cpp index 6db47fd61f..cdb89ccda2 100644 --- a/src/yuzu/configuration/configure_audio.cpp +++ b/src/yuzu/configuration/configure_audio.cpp @@ -44,18 +44,12 @@ void ConfigureAudio::Setup(const ConfigurationShared::Builder& builder) { for (auto* setting : settings) { auto* widget = [&]() { + // TODO (lat9nq): Let the system manage sink_id if (setting->Id() == Settings::values.volume.Id()) { // volume needs to be a slider (default is line edit) return builder.BuildWidget(setting, apply_funcs, nullptr, ConfigurationShared::RequestType::Slider, tr("%1%", "Volume percentage (e.g. 50%)")); - } else if (setting->Id() == Settings::values.audio_output_device_id.Id() || - setting->Id() == Settings::values.audio_input_device_id.Id() || - setting->Id() == Settings::values.sink_id.Id()) { - // These need to be unmanaged comboboxes, so we can populate them ourselves - // TODO (lat9nq): Let it manage sink_id - return builder.BuildWidget(setting, apply_funcs, - ConfigurationShared::RequestType::ComboBox, false); } else { return builder.BuildWidget(setting, apply_funcs); } diff --git a/src/yuzu/configuration/configure_graphics.cpp b/src/yuzu/configuration/configure_graphics.cpp index 18872fa694..74449e6d47 100644 --- a/src/yuzu/configuration/configure_graphics.cpp +++ b/src/yuzu/configuration/configure_graphics.cpp @@ -231,13 +231,7 @@ void ConfigureGraphics::Setup(const ConfigurationShared::Builder& builder) { for (const auto setting : Settings::values.linkage.by_category[Settings::Category::Renderer]) { ConfigurationShared::Widget* widget = [&]() { - // Set managed to false on these and set up the comboboxes ourselves - if (setting->Id() == Settings::values.vulkan_device.Id() || - setting->Id() == Settings::values.shader_backend.Id() || - setting->Id() == Settings::values.vsync_mode.Id()) { - return builder.BuildWidget(setting, apply_funcs, - ConfigurationShared::RequestType::ComboBox, false); - } else if (setting->Id() == Settings::values.fsr_sharpening_slider.Id()) { + if (setting->Id() == Settings::values.fsr_sharpening_slider.Id()) { // FSR needs a reversed slider return builder.BuildWidget( setting, apply_funcs, ConfigurationShared::RequestType::ReverseSlider, true, diff --git a/src/yuzu/configuration/configure_system.cpp b/src/yuzu/configuration/configure_system.cpp index 9be09244a2..796ebc44fa 100644 --- a/src/yuzu/configuration/configure_system.cpp +++ b/src/yuzu/configuration/configure_system.cpp @@ -125,13 +125,12 @@ void ConfigureSystem::Setup(const ConfigurationShared::Builder& builder) { // custom_rtc needs a DateTimeEdit (default is LineEdit), and a checkbox to manage // it and custom_rtc_enabled return builder.BuildWidget(setting, apply_funcs, - &Settings::values.custom_rtc_enabled, - ConfigurationShared::RequestType::DateTimeEdit); + &Settings::values.custom_rtc_enabled); } else if (setting->Id() == Settings::values.rng_seed.Id()) { // rng_seed needs a HexEdit (default is LineEdit), and a checkbox to manage // it and rng_seed_enabled - return builder.BuildWidget(setting, apply_funcs, &Settings::values.rng_seed_enabled, - ConfigurationShared::RequestType::HexEdit); + return builder.BuildWidget(setting, apply_funcs, + &Settings::values.rng_seed_enabled); } else if (setting->Id() == Settings::values.speed_limit.Id()) { // speed_limit needs a checkbox to set use_speed_limit, as well as a spinbox return builder.BuildWidget(setting, apply_funcs, &Settings::values.use_speed_limit, diff --git a/src/yuzu/configuration/shared_widget.cpp b/src/yuzu/configuration/shared_widget.cpp index dc8b312380..807d1d6686 100644 --- a/src/yuzu/configuration/shared_widget.cpp +++ b/src/yuzu/configuration/shared_widget.cpp @@ -376,6 +376,32 @@ void Widget::SetupComponent(const QString& label, std::function& load_fu layout->addWidget(qt_label); } + request = [&]() { + if (request != RequestType::Default) { + return request; + } + switch (setting.Specialization()) { + case Settings::Specialization::Default: + return RequestType::Default; + case Settings::Specialization::Time: + return RequestType::DateTimeEdit; + case Settings::Specialization::Hex: + return RequestType::HexEdit; + case Settings::Specialization::RuntimeList: + managed = false; + [[fallthrough]]; + case Settings::Specialization::List: + return RequestType::ComboBox; + case Settings::Specialization::Scalar: + return RequestType::Slider; + case Settings::Specialization::Countable: + return RequestType::SpinBox; + default: + break; + } + return request; + }(); + if (setting.TypeId() == typeid(bool)) { data_component = CreateCheckBox(&setting, label, serializer, restore_func, touch); } else if (setting.IsEnum()) { @@ -544,6 +570,11 @@ Widget* Builder::BuildWidget(Settings::BasicSetting* setting, return nullptr; } + if (setting->Specialization() == Settings::Specialization::Paired) { + LOG_DEBUG(Frontend, "\"{}\" has specialization Paired: ignoring", setting->GetLabel()); + return nullptr; + } + return new Widget(setting, *translations, *combobox_translations, parent, runtime_lock, apply_funcs, request, managed, multiplier, other_setting, string); }