mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[wpilibc] ShuffleboardInstance: Store ShuffleboardTab by value
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
using namespace frc::detail;
|
||||
|
||||
struct ShuffleboardInstance::Impl {
|
||||
wpi::StringMap<std::unique_ptr<ShuffleboardTab>> tabs;
|
||||
wpi::StringMap<ShuffleboardTab> tabs;
|
||||
|
||||
bool tabsChanged = false;
|
||||
std::shared_ptr<nt::NetworkTable> rootTable;
|
||||
@@ -44,25 +44,24 @@ frc::ShuffleboardTab& ShuffleboardInstance::GetTab(std::string_view title) {
|
||||
HAL_Report(HALUsageReporting::kResourceType_Shuffleboard, 0);
|
||||
gReported = true;
|
||||
}
|
||||
if (m_impl->tabs.find(title) == m_impl->tabs.end()) {
|
||||
m_impl->tabs.try_emplace(title,
|
||||
std::make_unique<ShuffleboardTab>(*this, title));
|
||||
auto [it, added] = m_impl->tabs.try_emplace(title, *this, title);
|
||||
if (added) {
|
||||
m_impl->tabsChanged = true;
|
||||
}
|
||||
return *m_impl->tabs.find(title)->second;
|
||||
return it->second;
|
||||
}
|
||||
|
||||
void ShuffleboardInstance::Update() {
|
||||
if (m_impl->tabsChanged) {
|
||||
wpi::SmallVector<std::string, 16> tabTitles;
|
||||
for (auto& entry : m_impl->tabs) {
|
||||
tabTitles.emplace_back(entry.second->GetTitle());
|
||||
tabTitles.emplace_back(entry.second.GetTitle());
|
||||
}
|
||||
m_impl->rootMetaTable->GetEntry("Tabs").SetStringArray(tabTitles);
|
||||
m_impl->tabsChanged = false;
|
||||
}
|
||||
for (auto& entry : m_impl->tabs) {
|
||||
auto& tab = *entry.second;
|
||||
auto& tab = entry.second;
|
||||
tab.BuildInto(m_impl->rootTable,
|
||||
m_impl->rootMetaTable->GetSubTable(tab.GetTitle()));
|
||||
}
|
||||
@@ -70,7 +69,7 @@ void ShuffleboardInstance::Update() {
|
||||
|
||||
void ShuffleboardInstance::EnableActuatorWidgets() {
|
||||
for (auto& entry : m_impl->tabs) {
|
||||
auto& tab = *entry.second;
|
||||
auto& tab = entry.second;
|
||||
for (auto& component : tab.GetComponents()) {
|
||||
component->EnableIfActuator();
|
||||
}
|
||||
@@ -79,7 +78,7 @@ void ShuffleboardInstance::EnableActuatorWidgets() {
|
||||
|
||||
void ShuffleboardInstance::DisableActuatorWidgets() {
|
||||
for (auto& entry : m_impl->tabs) {
|
||||
auto& tab = *entry.second;
|
||||
auto& tab = entry.second;
|
||||
for (auto& component : tab.GetComponents()) {
|
||||
component->DisableIfActuator();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user