Add CheckBox.

This commit is contained in:
Arthur Sonzogni
2019-01-12 22:25:49 +01:00
parent dba019139b
commit a6040bc360
21 changed files with 371 additions and 108 deletions

View File

@@ -0,0 +1,34 @@
#ifndef FTXUI_COMPONENT_CHECKBOX_HPP
#define FTXUI_COMPONENT_CHECKBOX_HPP
#include "ftxui/component/component.hpp"
#include <functional>
namespace ftxui {
class CheckBox : public Component {
public:
// Constructor.
CheckBox() = default;
~CheckBox() override = default;
bool state = false;
std::wstring label = L"label";
std::wstring checked = L"[X] ";
std::wstring unchecked = L"[ ] ";
// State update callback.
std::function<void()> on_change = [](){};
// Component implementation.
Element Render() override;
bool OnEvent(Event) override;
private:
int cursor_position = 0;
};
} // namespace ftxui
#endif /* end of include guard: FTXUI_COMPONENT_CHECKBOX_HPP */

View File

@@ -1,7 +1,6 @@
#ifndef FTXUI_COMPONENT_COMPONENT_HPP
#define FTXUI_COMPONENT_COMPONENT_HPP
#include "ftxui/component/delegate.hpp"
#include "ftxui/component/event.hpp"
#include "ftxui/dom/elements.hpp"

View File

@@ -13,22 +13,31 @@ class Container : public Component {
public:
static Container Vertical();
static Container Horizontal();
static Container Tab(size_t* selector);
~Container() override = default;
// Component override.
bool OnEvent(Event event) override;
Element Render() override;
Component* ActiveChild() override;
protected:
// Handlers
using Handler = bool (Container::*)(Event);
Handler handler_;
bool Vertical(Event event);
bool Horizontal(Event event);
using EventHandler = bool (Container::*)(Event);
bool VerticalEvent(Event event);
bool HorizontalEvent(Event event);
bool TabEvent(Event event) { return false; }
EventHandler event_handler_;
using RenderHandler = Element (Container::*)();
Element VerticalRender();
Element HorizontalRender();
Element TabRender();
RenderHandler render_handler_;
size_t selected_ = 0;
Container(Handler);
size_t* selector_ = &selected_;
};
} // namespace ftxui

View File

@@ -1,13 +0,0 @@
#ifndef FTXUI_COMPONENT_DELEGATE_HPP
#define FTXUI_COMPONENT_DELEGATE_HPP
#include "ftxui/dom/elements.hpp"
namespace ftxui {
class Component;
} // namespace ftxui
#endif /* end of include guard: FTXUI_COMPONENT_DELEGATE_HPP */

View File

@@ -15,7 +15,7 @@ class Menu : public Component {
// State.
std::vector<std::wstring> entries = {};
int selected = 0;
size_t selected = 0;
Decorator active_style = inverted;
Decorator selected_style = bold;

View File

@@ -13,8 +13,8 @@ class Toggle : public Component {
~Toggle() override = default;
// State.
size_t activated = 0;
std::vector<std::wstring> options = {L"On", L"Off"};
size_t selected = 0;
std::vector<std::wstring> entries = {L"On", L"Off"};
// Callback.
std::function<void()> on_change = [](){};