mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-09-28 16:29:34 +08:00
Make component more functionnal
This commit is contained in:
@@ -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_;
|
||||
};
|
||||
|
Reference in New Issue
Block a user