mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2024-11-26 04:31:34 +08:00
Added on_enter() method to toggle
component
This commit is contained in:
parent
a4d72c4d50
commit
33a970530b
@ -27,7 +27,8 @@ class Toggle : public Component {
|
|||||||
|
|
||||||
// Callback.
|
// Callback.
|
||||||
std::function<void()> on_change = []() {};
|
std::function<void()> on_change = []() {};
|
||||||
|
std::function<void()> on_enter = []() {};
|
||||||
|
|
||||||
// Component implementation.
|
// Component implementation.
|
||||||
Element Render() override;
|
Element Render() override;
|
||||||
bool OnEvent(Event) override;
|
bool OnEvent(Event) override;
|
||||||
|
@ -40,10 +40,17 @@ bool Toggle::OnEvent(Event event) {
|
|||||||
|
|
||||||
selected = std::max(0, std::min(int(entries.size()) - 1, selected));
|
selected = std::max(0, std::min(int(entries.size()) - 1, selected));
|
||||||
|
|
||||||
if (old_selected != selected)
|
if (old_selected != selected) {
|
||||||
on_change();
|
on_change();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return old_selected != selected;
|
if (event == Event::Return) {
|
||||||
|
on_enter();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ftxui
|
} // namespace ftxui
|
||||||
|
Loading…
Reference in New Issue
Block a user