6#include <frc/smartdashboard/SendableChooser.h>
7#include <frc/smartdashboard/SmartDashboard.h>
8#include <wpi/sendable/Sendable.h>
9#include <wpi/sendable/SendableBuilder.h>
10#include <wpi/sendable/SendableRegistry.h>
31 static inline const std::string kDefault =
"default";
32 static inline const std::string kSelected =
"selected";
33 static inline const std::string kActive =
"active";
34 static inline const std::string kOptions =
"options";
35 static inline const std::string kInstance =
".instance";
37 std::map<std::string, T> m_map;
39 std::string m_defaultChoice =
"";
41 std::string m_previousValue;
42 std::function<void(std::optional<T>)> m_listener;
43 std::atomic_int m_instances{0};
44 std::string m_selected;
45 std::recursive_mutex m_mutex;
95 void SetOptions(std::map<std::string, T> options, std::string defaultName,
122 void OnChange(std::function<
void(std::optional<T>)> listener);
A SmartDashboard drop-down that can have its options dynamically change.
std::string GetNtSelected()
std::string GetSelectedKey()
Get the selected key rather than the value.
void SetOptions(std::map< std::string, T > options, std::string defaultName, T defaultObject)
Set the options from an existing set along with a default.
void RemoveOption(std::string name)
Removes the option and updates the default option accoringly.
void InitSendable(wpi::SendableBuilder &builder) override
void ClearOptions()
Clears all options.
void AddOption(std::string name, T object)
Add a new option to the chooser.
void SetNtSelected(std::string val)
T GetSelected()
Get the selected option.
void SetOptions(std::map< std::string, T > options)
Populates options from an existing set.
void SetDefaultOption(std::string name, T object)
Set the default option to return.
void OnChange(std::function< void(std::optional< T >)> listener)
Register a callback that gets executed whenever the selection changes.