mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
Based on beta test feedback, returning a pointer is more intuitive, as typically the return value is late bound to an instance variable.
50 lines
1.4 KiB
C++
50 lines
1.4 KiB
C++
// Copyright (c) FIRST and other WPILib contributors.
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
// the WPILib BSD license file in the root directory of this project.
|
|
|
|
#include "frc/shuffleboard/SimpleWidget.h"
|
|
|
|
#include "frc/shuffleboard/Shuffleboard.h"
|
|
#include "frc/shuffleboard/ShuffleboardLayout.h"
|
|
#include "frc/shuffleboard/ShuffleboardTab.h"
|
|
|
|
using namespace frc;
|
|
|
|
SimpleWidget::SimpleWidget(ShuffleboardContainer& parent,
|
|
std::string_view title)
|
|
: ShuffleboardValue(title), ShuffleboardWidget(parent, title), m_entry() {}
|
|
|
|
nt::GenericEntry* SimpleWidget::GetEntry() {
|
|
if (!m_entry) {
|
|
ForceGenerate();
|
|
}
|
|
return &m_entry;
|
|
}
|
|
|
|
nt::GenericEntry* SimpleWidget::GetEntry(std::string_view typeString) {
|
|
if (!m_entry) {
|
|
m_typeString = typeString;
|
|
ForceGenerate();
|
|
}
|
|
return &m_entry;
|
|
}
|
|
|
|
void SimpleWidget::BuildInto(std::shared_ptr<nt::NetworkTable> parentTable,
|
|
std::shared_ptr<nt::NetworkTable> metaTable) {
|
|
BuildMetadata(metaTable);
|
|
if (!m_entry) {
|
|
m_entry = parentTable->GetTopic(GetTitle()).GetGenericEntry(m_typeString);
|
|
}
|
|
}
|
|
|
|
void SimpleWidget::ForceGenerate() {
|
|
ShuffleboardContainer* parent = &GetParent();
|
|
|
|
while (parent->m_isLayout) {
|
|
parent = &(static_cast<ShuffleboardLayout*>(parent)->GetParent());
|
|
}
|
|
|
|
auto& tab = *static_cast<ShuffleboardTab*>(parent);
|
|
tab.GetRoot().Update();
|
|
}
|