FTXUI/src/ftxui/component/checkbox.cpp

29 lines
744 B
C++
Raw Normal View History

2020-04-20 03:00:37 +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.
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