diff options
Diffstat (limited to 'Source')
4 files changed, 51 insertions, 8 deletions
diff --git a/Source/Core/DolphinQt/Config/GameConfigWidget.cpp b/Source/Core/DolphinQt/Config/GameConfigWidget.cpp index 32734a445f..6b256c2e22 100644 --- a/Source/Core/DolphinQt/Config/GameConfigWidget.cpp +++ b/Source/Core/DolphinQt/Config/GameConfigWidget.cpp @@ -144,8 +144,8 @@ void GameConfigWidget::CreateWidgets() new ConfigFloatSlider(100, 200, Config::GFX_STEREO_DEPTH_PERCENTAGE, 1.0f, layer); m_convergence_slider = new ConfigFloatSlider(0, 1000, Config::GFX_STEREO_CONVERGENCE, 0.01f, layer); - auto* const depth_slider_value = new QLabel(); - auto* const convergence_slider_value = new QLabel(); + auto* const depth_slider_value = new QtUtils::FixedSizeLabel(); + auto* const convergence_slider_value = new QtUtils::FixedSizeLabel(); m_use_monoscopic_shadows = new ConfigBool(tr("Monoscopic Shadows"), Config::GFX_STEREO_EFB_MONO_DEPTH, layer); @@ -168,6 +168,10 @@ void GameConfigWidget::CreateWidgets() depth_slider_value->setText(QString::asprintf("%.0f%%", m_depth_slider->GetValue())); convergence_slider_value->setText(QString::asprintf("%.2f", m_convergence_slider->GetValue())); + // Reserve space for the widest possible values so the changing label text doesn't resize the + // column and jiggle the sliders. + depth_slider_value->SetSizeHintText(QStringLiteral("999%")); + convergence_slider_value->SetSizeHintText(QStringLiteral("1000.00")); auto* general_layout = new QVBoxLayout; general_layout->addWidget(core_box); diff --git a/Source/Core/DolphinQt/Config/Graphics/EnhancementsWidget.cpp b/Source/Core/DolphinQt/Config/Graphics/EnhancementsWidget.cpp index 228cc348a8..8d8eb3f54a 100644 --- a/Source/Core/DolphinQt/Config/Graphics/EnhancementsWidget.cpp +++ b/Source/Core/DolphinQt/Config/Graphics/EnhancementsWidget.cpp @@ -24,6 +24,7 @@ #include "DolphinQt/Config/Graphics/PostProcessingConfigWindow.h" #include "DolphinQt/Config/ToolTipControls/ToolTipPushButton.h" #include "DolphinQt/QtUtils/NonDefaultQPushButton.h" +#include "DolphinQt/QtUtils/QtUtils.h" #include "VideoCommon/PostProcessing.h" #include "VideoCommon/VideoBackendBase.h" @@ -218,8 +219,8 @@ void EnhancementsWidget::CreateWidgets() 1.0f, m_game_layer); m_3d_convergence = new ConfigFloatSlider(0, Config::GFX_STEREO_CONVERGENCE_MAXIMUM, Config::GFX_STEREO_CONVERGENCE, 0.01f, m_game_layer); - m_3d_depth_value = new QLabel(); - m_3d_convergence_value = new QLabel(); + m_3d_depth_value = new QtUtils::FixedSizeLabel(); + m_3d_convergence_value = new QtUtils::FixedSizeLabel(); m_3d_swap_eyes = new ConfigBool(tr("Swap Eyes"), Config::GFX_STEREO_SWAP_EYES, m_game_layer); @@ -239,6 +240,10 @@ void EnhancementsWidget::CreateWidgets() m_3d_depth_value->setText(QString::asprintf("%.0f", m_3d_depth->GetValue())); m_3d_convergence_value->setText(QString::asprintf("%.2f", m_3d_convergence->GetValue())); + // Reserve space for the widest possible values so the changing label text doesn't resize the + // column and jiggle the sliders. + m_3d_depth_value->SetSizeHintText(QStringLiteral("999")); + m_3d_convergence_value->SetSizeHintText(QStringLiteral("999.99")); auto current_stereo_mode = Get(m_game_layer, Config::GFX_STEREO_MODE); if (current_stereo_mode != StereoMode::SideBySide && diff --git a/Source/Core/DolphinQt/Config/Graphics/EnhancementsWidget.h b/Source/Core/DolphinQt/Config/Graphics/EnhancementsWidget.h index 02205f526f..e0cf40fd97 100644 --- a/Source/Core/DolphinQt/Config/Graphics/EnhancementsWidget.h +++ b/Source/Core/DolphinQt/Config/Graphics/EnhancementsWidget.h @@ -12,9 +12,13 @@ class ConfigStringChoice; class ConfigFloatSlider; class GraphicsPane; class QPushButton; -class QLabel; class ToolTipPushButton; +namespace QtUtils +{ +class FixedSizeLabel; +} // namespace QtUtils + namespace Config { template <typename T> @@ -61,9 +65,9 @@ private: // Stereoscopy ConfigChoice* m_3d_mode; ConfigFloatSlider* m_3d_depth; - QLabel* m_3d_depth_value; + QtUtils::FixedSizeLabel* m_3d_depth_value; ConfigFloatSlider* m_3d_convergence; - QLabel* m_3d_convergence_value; + QtUtils::FixedSizeLabel* m_3d_convergence_value; ConfigBool* m_3d_swap_eyes; ConfigBool* m_3d_per_eye_resolution; diff --git a/Source/Core/DolphinQt/QtUtils/QtUtils.h b/Source/Core/DolphinQt/QtUtils/QtUtils.h index f6ba8036ca..9cffbb0ca0 100644 --- a/Source/Core/DolphinQt/QtUtils/QtUtils.h +++ b/Source/Core/DolphinQt/QtUtils/QtUtils.h @@ -4,11 +4,12 @@ #pragma once #include <string_view> +#include <utility> +#include <QLabel> #include <QStyle> class QDateTimeEdit; -class QLabel; class QWidget; namespace QtUtils @@ -39,6 +40,35 @@ public: QSize sizeHint() const override { return Widget::minimumSizeHint(); } }; +// A QLabel that determines its size hints from an alternate, fixed string instead of its text. +// Useful for labels whose displayed text changes (e.g. slider values) while the allocated space +// should remain stable. Call SetSizeHintText with the widest expected value. +class FixedSizeLabel : public QLabel +{ +public: + using QLabel::QLabel; + + void SetSizeHintText(QString text) + { + m_size_hint_text = std::move(text); + updateGeometry(); + } + + QSize sizeHint() const override + { + if (m_size_hint_text.isEmpty()) + return QLabel::sizeHint(); + return fontMetrics().boundingRect(m_size_hint_text).size(); + } + + // Pin the minimum size as well, otherwise the layout can still resize the label below the + // hinted width (a simple QLabel refuses to shrink below its text). + QSize minimumSizeHint() const override { return sizeHint(); } + +private: + QString m_size_hint_text; +}; + // Opens the folder of the given file (and also selects the file on supported platforms). void ShowFileInFolder(std::string_view file_path); |
