SubZero Common
Common library components for an FRC CommandRobot
Loading...
Searching...
No Matches
TaggedChooser.h
Go to the documentation of this file.
1#pragma once
2
3#include <frc/shuffleboard/Shuffleboard.h>
4#include <frc/smartdashboard/SendableChooser.h>
5#include <frc/smartdashboard/SmartDashboard.h>
6
7#include <functional>
8#include <memory>
9#include <set>
10#include <string>
11#include <utility>
12#include <vector>
13
14#include "subzero/frc/smartdashboard/ModifiableChooser.cpp"
15
16namespace subzero {
17
27template <typename TKey> class TaggedChooser {
28public:
33 using TaggedChooserValue = std::pair<TKey, std::string>;
39 std::pair<TaggedChooserValue, std::set<std::string>>;
46 std::pair<std::string, std::set<std::string>>;
47
55 TaggedChooser(const std::vector<TaggedChooserEntry> &entries,
56 const std::vector<TaggedChooserSelectorGroup> &groups,
57 std::string chooserName);
58
63 void Initialize(void);
64
71 void SetOnChangeCallback(std::function<void(TKey)> cb);
72
78 std::vector<TaggedChooserValue> GetAvailableEntries(void);
79
84 void PopulateChooser(void);
85
91 inline TKey GetSelectedValue() { return m_chooser.GetSelected(); }
92
93private:
94 struct TaggedChooserSendableGroup {
96 std::unique_ptr<frc::SendableChooser<std::string>> chooser;
97 };
98 std::function<void(TKey)> m_onChangeCb;
99 std::vector<TaggedChooserEntry> m_entries;
100 std::vector<TaggedChooserSendableGroup> m_groups;
101 ModifiableChooser<TKey> m_chooser;
102 std::string m_chooserName;
103};
104} // namespace subzero
T GetSelected()
Get the selected option.
Each key of type T has a vector<string> of tags; accepts a list of groups that each have a name and l...
void PopulateChooser(void)
Repopulate the chooser based on the selected group filters.
TaggedChooser(const std::vector< TaggedChooserEntry > &entries, const std::vector< TaggedChooserSelectorGroup > &groups, std::string chooserName)
Construct a new TaggedChooser.
std::pair< TaggedChooserValue, std::set< std::string > > TaggedChooserEntry
A pair composed of TaggedChooserValue and a set of associated tags.
std::pair< TKey, std::string > TaggedChooserValue
A pair composed of the key and its name.
std::pair< std::string, std::set< std::string > > TaggedChooserSelectorGroup
Describes a single group which has a name and a set of available tags from which to choose.
TKey GetSelectedValue()
Get the currently-selected option.
void Initialize(void)
Call this one on startup to populate and push to SmartDashboard.
void SetOnChangeCallback(std::function< void(TKey)> cb)
Register a callback that gets executed each time the selected option changes.
std::vector< TaggedChooserValue > GetAvailableEntries(void)
Get the list of all available entries in the selector.