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,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_;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user