2020-12-26 14:12:05 -08:00
|
|
|
// 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.
|
2018-09-28 04:18:18 -04:00
|
|
|
|
|
|
|
|
#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,
|
|
|
|
|
const wpi::Twine& title)
|
2018-10-02 20:55:03 -07:00
|
|
|
: ShuffleboardValue(title), ShuffleboardWidget(parent, title), m_entry() {}
|
2018-09-28 04:18:18 -04:00
|
|
|
|
|
|
|
|
nt::NetworkTableEntry SimpleWidget::GetEntry() {
|
2018-10-02 20:55:03 -07:00
|
|
|
if (!m_entry) {
|
2018-09-28 04:18:18 -04:00
|
|
|
ForceGenerate();
|
|
|
|
|
}
|
|
|
|
|
return m_entry;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SimpleWidget::BuildInto(std::shared_ptr<nt::NetworkTable> parentTable,
|
|
|
|
|
std::shared_ptr<nt::NetworkTable> metaTable) {
|
|
|
|
|
BuildMetadata(metaTable);
|
2018-10-02 20:55:03 -07:00
|
|
|
if (!m_entry) {
|
2018-09-28 04:18:18 -04:00
|
|
|
m_entry = parentTable->GetEntry(GetTitle());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
}
|