Make component more functionnal

This commit is contained in:
ArthurSonzogni
2021-05-09 20:32:27 +02:00
parent 9d15d1c275
commit 6d75cb2748
70 changed files with 2182 additions and 1769 deletions

View File

@@ -1,10 +1,13 @@
#ifndef FTXUI_COMPONENT_CHECKBOX_HPP
#define FTXUI_COMPONENT_CHECKBOX_HPP
#include <string>
#include <functional> // for function
#include <string> // for wstring, allocator
#include "ftxui/component/component.hpp"
#include "ftxui/screen/box.hpp"
#include "ftxui/component/component.hpp" // for Component
#include "ftxui/component/component_base.hpp" // for ComponentBase
#include "ftxui/dom/elements.hpp" // for Element, Decorator, inverted, nothing
#include "ftxui/screen/box.hpp" // for Box
namespace ftxui {
struct Event;
@@ -12,14 +15,14 @@ struct Event;
/// @brief A Checkbox. It can be checked or unchecked.Display an element on a
/// ftxui::Screen.
/// @ingroup dom
class CheckBox : public Component {
class CheckboxBase : public ComponentBase {
public:
// Constructor.
CheckBox() = default;
~CheckBox() override = default;
// Access this interface from a Component
static CheckboxBase* From(Component component);
bool state = false; // The current state. true=checked, false:unchecked.
std::wstring label = L"label"; // The CheckBox label.
// Constructor.
CheckboxBase(const std::wstring* label, bool* state);
~CheckboxBase() override = default;
#if defined(_WIN32)
std::wstring checked = L"[X] "; /// Prefix for a "checked" state.
@@ -32,7 +35,7 @@ class CheckBox : public Component {
Decorator focused_style = inverted; /// Decorator used when focused.
Decorator unfocused_style = nothing; /// Decorator used when unfocused.
/// Called when the user change the state of the CheckBox.
/// Called when the user change the state of the CheckboxBase.
std::function<void()> on_change = []() {};
// Component implementation.
@@ -42,6 +45,8 @@ class CheckBox : public Component {
private:
bool OnMouseEvent(Event event);
const std::wstring* const label_;
bool* const state_;
int cursor_position = 0;
Box box_;
};