mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-10-01 17:29:07 +08:00
Add CheckBox.
This commit is contained in:
34
ftxui/include/ftxui/component/checkbox.hpp
Normal file
34
ftxui/include/ftxui/component/checkbox.hpp
Normal 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 */
|
@@ -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"
|
||||
|
||||
|
@@ -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
|
||||
|
@@ -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 */
|
@@ -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;
|
||||
|
@@ -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 = [](){};
|
||||
|
Reference in New Issue
Block a user