From ee43c9508c07fe58a6aa28f05a6509cd61249dd5 Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Thu, 14 Mar 2024 22:09:41 -0500 Subject: [PATCH] ControllerInterface: Add IsHidden function to Control interface. --- .../DolphinQt/Config/Mapping/IOWindow.cpp | 37 +++++++++---------- .../ControllerInterface/CoreDevice.cpp | 10 +++++ .../ControllerInterface/CoreDevice.h | 5 +++ 3 files changed, 32 insertions(+), 20 deletions(-) diff --git a/Source/Core/DolphinQt/Config/Mapping/IOWindow.cpp b/Source/Core/DolphinQt/Config/Mapping/IOWindow.cpp index b8281d376d..9c9dc3e3b6 100644 --- a/Source/Core/DolphinQt/Config/Mapping/IOWindow.cpp +++ b/Source/Core/DolphinQt/Config/Mapping/IOWindow.cpp @@ -587,28 +587,25 @@ void IOWindow::UpdateOptionList() if (m_selected_device == nullptr) return; + const auto add_rows = [this](auto& container) { + int row = 0; + for (ciface::Core::Device::Control* control : container) + { + m_option_list->insertRow(row); + + if (control->IsHidden()) + m_option_list->hideRow(row); + + m_option_list->setItem(row, 0, + new QTableWidgetItem(QString::fromStdString(control->GetName()))); + ++row; + } + }; + if (m_reference->IsInput()) - { - int row = 0; - for (const auto* input : m_selected_device->Inputs()) - { - m_option_list->insertRow(row); - m_option_list->setItem(row, 0, - new QTableWidgetItem(QString::fromStdString(input->GetName()))); - ++row; - } - } + add_rows(m_selected_device->Inputs()); else - { - int row = 0; - for (const auto* output : m_selected_device->Outputs()) - { - m_option_list->insertRow(row); - m_option_list->setItem(row, 0, - new QTableWidgetItem(QString::fromStdString(output->GetName()))); - ++row; - } - } + add_rows(m_selected_device->Outputs()); } void IOWindow::UpdateDeviceList() diff --git a/Source/Core/InputCommon/ControllerInterface/CoreDevice.cpp b/Source/Core/InputCommon/ControllerInterface/CoreDevice.cpp index 541dbdb5dd..720ea82735 100644 --- a/Source/Core/InputCommon/ControllerInterface/CoreDevice.cpp +++ b/Source/Core/InputCommon/ControllerInterface/CoreDevice.cpp @@ -125,6 +125,11 @@ bool Device::Control::IsMatchingName(std::string_view name) const return GetName() == name; } +bool Device::Control::IsHidden() const +{ + return false; +} + ControlState Device::FullAnalogSurface::GetState() const { return (1 + std::max(0.0, m_high.GetState()) - std::max(0.0, m_low.GetState())) / 2; @@ -141,6 +146,11 @@ bool Device::FullAnalogSurface::IsDetectable() const return m_low.IsDetectable() && m_high.IsDetectable(); } +bool Device::FullAnalogSurface::IsHidden() const +{ + return m_low.IsHidden() && m_high.IsHidden(); +} + bool Device::FullAnalogSurface::IsMatchingName(std::string_view name) const { if (Control::IsMatchingName(name)) diff --git a/Source/Core/InputCommon/ControllerInterface/CoreDevice.h b/Source/Core/InputCommon/ControllerInterface/CoreDevice.h index 4ed5866eff..5c7a8ed568 100644 --- a/Source/Core/InputCommon/ControllerInterface/CoreDevice.h +++ b/Source/Core/InputCommon/ControllerInterface/CoreDevice.h @@ -64,6 +64,10 @@ public: // May be overridden to allow multiple valid names. // Useful for backwards-compatible configurations when names change. virtual bool IsMatchingName(std::string_view name) const; + + // May be overridden to hide in UI. + // Useful for backwards-compatible configurations when names change. + virtual bool IsHidden() const; }; // @@ -164,6 +168,7 @@ protected: ControlState GetState() const override; std::string GetName() const override; bool IsDetectable() const override; + bool IsHidden() const override; bool IsMatchingName(std::string_view name) const override; private: