mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-09-28 16:29:34 +08:00
24 lines
588 B
C++
24 lines
588 B
C++
#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
|