mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-09-28 16:29:34 +08:00
23
src/ftxui/component/checkbox.cpp
Normal file
23
src/ftxui/component/checkbox.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
#include "ftxui/component/checkbox.hpp"
|
||||
#include <functional>
|
||||
|
||||
namespace ftxui {
|
||||
|
||||
Element CheckBox::Render() {
|
||||
bool is_focused = Focused();
|
||||
auto style = is_focused ? focused_style : unfocused_style;
|
||||
auto focus_management = is_focused ? focus : state ? select : nothing;
|
||||
return hbox(text(state ? checked : unchecked),
|
||||
text(label) | style | focus_management);
|
||||
}
|
||||
|
||||
bool CheckBox::OnEvent(Event event) {
|
||||
if (event == Event::Character(' ') || event == Event::Return) {
|
||||
state = !state;
|
||||
on_change();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace ftxui
|
Reference in New Issue
Block a user