mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-02 02:51:42 +00:00
[wpilib] SendableChooser: Add onChange listener (#5458)
This commit is contained in:
@@ -31,7 +31,7 @@ template <class T>
|
||||
requires std::copy_constructible<T> && std::default_initializable<T>
|
||||
class SendableChooser : public SendableChooserBase {
|
||||
wpi::StringMap<T> m_choices;
|
||||
|
||||
std::function<void(T)> m_listener;
|
||||
template <class U>
|
||||
static U _unwrap_smart_ptr(const U& value);
|
||||
|
||||
@@ -82,6 +82,14 @@ class SendableChooser : public SendableChooserBase {
|
||||
*/
|
||||
auto GetSelected() -> decltype(_unwrap_smart_ptr(m_choices[""]));
|
||||
|
||||
/**
|
||||
* Bind a listener that's called when the selected value changes.
|
||||
* Only one listener can be bound. Calling this function will replace the
|
||||
* previous listener.
|
||||
* @param listener The function to call that accepts the new value
|
||||
*/
|
||||
void OnChange(std::function<void(T)>);
|
||||
|
||||
void InitSendable(nt::NTSendableBuilder& builder) override;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user