2019-01-13 05:25:49 +08:00
|
|
|
#include "ftxui/component/checkbox.hpp"
|
2020-03-23 05:32:44 +08:00
|
|
|
|
2019-01-13 05:25:49 +08:00
|
|
|
#include <functional>
|
|
|
|
|
|
|
|
namespace ftxui {
|
|
|
|
|
|
|
|
Element CheckBox::Render() {
|
2019-01-20 05:06:05 +08:00
|
|
|
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);
|
2019-01-13 05:25:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CheckBox::OnEvent(Event event) {
|
|
|
|
if (event == Event::Character(' ') || event == Event::Return) {
|
|
|
|
state = !state;
|
|
|
|
on_change();
|
|
|
|
return true;
|
|
|
|
}
|
2020-03-23 05:32:44 +08:00
|
|
|
return false;
|
2019-01-13 05:25:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace ftxui
|
2020-08-16 06:24:18 +08:00
|
|
|
|
|
|
|
// Copyright 2020 Arthur Sonzogni. All rights reserved.
|
|
|
|
// Use of this source code is governed by the MIT license that can be found in
|
|
|
|
// the LICENSE file.
|