configuration: Use specialization of settings

Reduces some ugliness in frontend code.
This commit is contained in:
lat9nq 2023-06-21 03:29:20 -04:00
parent b2438f1fb7
commit 21723879e7
4 changed files with 36 additions and 18 deletions

View file

@ -44,18 +44,12 @@ void ConfigureAudio::Setup(const ConfigurationShared::Builder& builder) {
for (auto* setting : settings) { for (auto* setting : settings) {
auto* widget = [&]() { auto* widget = [&]() {
// TODO (lat9nq): Let the system manage sink_id
if (setting->Id() == Settings::values.volume.Id()) { if (setting->Id() == Settings::values.volume.Id()) {
// volume needs to be a slider (default is line edit) // volume needs to be a slider (default is line edit)
return builder.BuildWidget(setting, apply_funcs, nullptr, return builder.BuildWidget(setting, apply_funcs, nullptr,
ConfigurationShared::RequestType::Slider, ConfigurationShared::RequestType::Slider,
tr("%1%", "Volume percentage (e.g. 50%)")); 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 { } else {
return builder.BuildWidget(setting, apply_funcs); return builder.BuildWidget(setting, apply_funcs);
} }

View file

@ -231,13 +231,7 @@ void ConfigureGraphics::Setup(const ConfigurationShared::Builder& builder) {
for (const auto setting : Settings::values.linkage.by_category[Settings::Category::Renderer]) { for (const auto setting : Settings::values.linkage.by_category[Settings::Category::Renderer]) {
ConfigurationShared::Widget* widget = [&]() { ConfigurationShared::Widget* widget = [&]() {
// Set managed to false on these and set up the comboboxes ourselves if (setting->Id() == Settings::values.fsr_sharpening_slider.Id()) {
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()) {
// FSR needs a reversed slider // FSR needs a reversed slider
return builder.BuildWidget( return builder.BuildWidget(
setting, apply_funcs, ConfigurationShared::RequestType::ReverseSlider, true, setting, apply_funcs, ConfigurationShared::RequestType::ReverseSlider, true,

View file

@ -125,13 +125,12 @@ void ConfigureSystem::Setup(const ConfigurationShared::Builder& builder) {
// custom_rtc needs a DateTimeEdit (default is LineEdit), and a checkbox to manage // custom_rtc needs a DateTimeEdit (default is LineEdit), and a checkbox to manage
// it and custom_rtc_enabled // it and custom_rtc_enabled
return builder.BuildWidget(setting, apply_funcs, return builder.BuildWidget(setting, apply_funcs,
&Settings::values.custom_rtc_enabled, &Settings::values.custom_rtc_enabled);
ConfigurationShared::RequestType::DateTimeEdit);
} else if (setting->Id() == Settings::values.rng_seed.Id()) { } else if (setting->Id() == Settings::values.rng_seed.Id()) {
// rng_seed needs a HexEdit (default is LineEdit), and a checkbox to manage // rng_seed needs a HexEdit (default is LineEdit), and a checkbox to manage
// it and rng_seed_enabled // it and rng_seed_enabled
return builder.BuildWidget(setting, apply_funcs, &Settings::values.rng_seed_enabled, return builder.BuildWidget(setting, apply_funcs,
ConfigurationShared::RequestType::HexEdit); &Settings::values.rng_seed_enabled);
} else if (setting->Id() == Settings::values.speed_limit.Id()) { } else if (setting->Id() == Settings::values.speed_limit.Id()) {
// speed_limit needs a checkbox to set use_speed_limit, as well as a spinbox // 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, return builder.BuildWidget(setting, apply_funcs, &Settings::values.use_speed_limit,

View file

@ -376,6 +376,32 @@ void Widget::SetupComponent(const QString& label, std::function<void()>& load_fu
layout->addWidget(qt_label); 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)) { if (setting.TypeId() == typeid(bool)) {
data_component = CreateCheckBox(&setting, label, serializer, restore_func, touch); data_component = CreateCheckBox(&setting, label, serializer, restore_func, touch);
} else if (setting.IsEnum()) { } else if (setting.IsEnum()) {
@ -544,6 +570,11 @@ Widget* Builder::BuildWidget(Settings::BasicSetting* setting,
return nullptr; 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, return new Widget(setting, *translations, *combobox_translations, parent, runtime_lock,
apply_funcs, request, managed, multiplier, other_setting, string); apply_funcs, request, managed, multiplier, other_setting, string);
} }