FTXUI/include/ftxui/component/button.hpp

47 lines
1.3 KiB
C++
Raw Normal View History

2020-08-26 22:26:09 +08:00
#ifndef FTXUI_COMPONENT_BUTTON_HPP
#define FTXUI_COMPONENT_BUTTON_HPP
2021-05-10 02:32:27 +08:00
#include <functional> // for function
#include <string> // for wstring
2020-08-26 22:26:09 +08:00
2021-05-10 02:32:27 +08:00
#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
#include "ftxui/screen/string.hpp" // for ConstStringRef
2020-08-26 22:26:09 +08:00
namespace ftxui {
2021-05-02 02:40:35 +08:00
struct Event;
2020-08-26 22:26:09 +08:00
/// @brief A button. An action is associated to the click event.
/// @ingroup dom
2021-05-10 02:32:27 +08:00
class ButtonBase : public ComponentBase {
2020-08-26 22:26:09 +08:00
public:
2021-05-10 02:32:27 +08:00
// Access this interface from a Component
static ButtonBase* From(Component);
2020-08-26 22:26:09 +08:00
2021-05-10 02:32:27 +08:00
// Constructor.
2021-07-08 04:23:07 +08:00
ButtonBase(ConstStringRef label,
std::function<void()> on_click,
2021-07-10 17:03:01 +08:00
ConstRef<ButtonOption> option = {});
2021-05-10 02:32:27 +08:00
~ButtonBase() override = default;
2020-08-26 22:26:09 +08:00
// Component implementation.
Element Render() override;
bool OnEvent(Event) override;
2021-05-02 02:40:35 +08:00
private:
ConstStringRef label_;
2021-05-10 02:32:27 +08:00
std::function<void()> on_click_;
Box box_;
2021-07-08 04:23:07 +08:00
ConstRef<ButtonOption> option_;
2020-08-26 22:26:09 +08:00
};
} // namespace ftxui
#endif /* end of include guard: FTXUI_COMPONENT_BUTTON_HPP */
// Copyright 2020 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in
// the LICENSE file.