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,36 +1,35 @@
#ifndef FTXUI_COMPONENT_BUTTON_HPP
#define FTXUI_COMPONENT_BUTTON_HPP
#include <functional>
#include <string>
#include <functional> // for function
#include <string> // for wstring
#include "ftxui/component/component.hpp"
#include "ftxui/dom/elements.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
#include "ftxui/screen/box.hpp" // for Box
namespace ftxui {
struct Event;
/// @brief A button. An action is associated to the click event.
/// @ingroup dom
class Button : public Component {
class ButtonBase : public ComponentBase {
public:
// Access this interface from a Component
static ButtonBase* From(Component);
// Constructor.
Button() = default;
Button(std::wstring label) : label(label) {}
~Button() override = default;
/// The Button label.
std::wstring label = L"button";
/// Called when the user press the "enter" button.
std::function<void()> on_click = [] {};
ButtonBase(const std::wstring* label, std::function<void()> on_click);
~ButtonBase() override = default;
// Component implementation.
Element Render() override;
bool OnEvent(Event) override;
private:
const std::wstring* label_;
std::function<void()> on_click_;
Box box_;
};