Remove input.hpp

This commit is contained in:
ArthurSonzogni
2021-07-10 12:29:39 +02:00
committed by Arthur Sonzogni
parent 7ee6edfd1f
commit 26db8228f9
16 changed files with 240 additions and 252 deletions

View File

@@ -26,22 +26,22 @@ std::shared_ptr<T> Make(Args&&... args) {
Component Button(ConstStringRef label,
std::function<void()> on_click,
ConstRef<ButtonOption> = {});
Ref<ButtonOption> = {});
Component Checkbox(ConstStringRef label,
bool* checked,
ConstRef<CheckboxOption> option = {});
Ref<CheckboxOption> option = {});
Component Input(StringRef content,
ConstStringRef placeholder,
ConstRef<InputOption> option = {});
Ref<InputOption> option = {});
Component Menu(const std::vector<std::wstring>* entries,
int* selected_,
ConstRef<MenuOption> = {});
Ref<MenuOption> = {});
Component Radiobox(const std::vector<std::wstring>* entries,
int* selected_,
ConstRef<RadioboxOption> option = {});
Ref<RadioboxOption> option = {});
Component Toggle(const std::vector<std::wstring>* entries,
int* selected,
ConstRef<ToggleOption> option = {});
Ref<ToggleOption> option = {});
template <class T> // T = {int, float, long}
Component Slider(StringRef label, T* value, T min, T max, T increment);
Component Renderer(Component child, std::function<Element()>);

View File

@@ -2,6 +2,7 @@
#define FTXUI_COMPONENT_COMPONENT_OPTIONS_HPP
#include <ftxui/dom/elements.hpp>
#include <ftxui/util/ref.hpp>
namespace ftxui {
@@ -42,6 +43,8 @@ struct InputOption {
std::function<void()> on_change = [] {};
/// Called when the user presses enter.
std::function<void()> on_enter = [] {};
Ref<int> cursor_position = 0;
};
/// @brief Option for the Radiobox component.

View File

@@ -1,52 +0,0 @@
#ifndef FTXUI_COMPONENT_INPUT_H_
#define FTXUI_COMPONENT_INPUT_H_
#include <functional> // for function
#include <string> // for wstring
#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, StringRef
namespace ftxui {
struct Event;
/// @brief An input box. The user can type text into it.
/// @ingroup component.
class InputBase : public ComponentBase {
public:
// Access this interface from a Component
static InputBase* From(Component component);
// Constructor.
InputBase(StringRef content,
ConstStringRef placeholder,
ConstRef<InputOption> option = {});
~InputBase() override = default;
// State.
int cursor_position = 0;
// Component implementation.
Element Render() override;
bool OnEvent(Event) override;
private:
StringRef content_;
ConstStringRef placeholder_;
bool OnMouseEvent(Event);
Box input_box_;
Box cursor_box_;
ConstRef<InputOption> option_;
};
} // namespace ftxui
#endif /* end of include guard: FTXUI_COMPONENT_INPUT_H_ */
// 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.

View File

@@ -24,7 +24,7 @@ class MenuBase : public ComponentBase {
// Constructor.
MenuBase(const std::vector<std::wstring>* entries,
int* selected_,
ConstRef<MenuOption> option = {});
Ref<MenuOption> option = {});
~MenuBase() override = default;
// State.
@@ -37,7 +37,7 @@ class MenuBase : public ComponentBase {
protected:
const std::vector<std::wstring>* const entries_;
int* selected_ = 0;
ConstRef<MenuOption> option_;
Ref<MenuOption> option_;
bool OnMouseEvent(Event);

View File

@@ -24,7 +24,7 @@ class RadioboxBase : public ComponentBase {
// Constructor.
RadioboxBase(const std::vector<std::wstring>* entries,
int* selected,
ConstRef<RadioboxOption> option = {});
Ref<RadioboxOption> option = {});
~RadioboxBase() override = default;
int focused = 0;
@@ -40,7 +40,7 @@ class RadioboxBase : public ComponentBase {
bool OnMouseEvent(Event event);
int cursor_position = 0;
std::vector<Box> boxes_;
ConstRef<RadioboxOption> option_;
Ref<RadioboxOption> option_;
};
} // namespace ftxui

View File

@@ -23,7 +23,7 @@ class ToggleBase : public ComponentBase {
// Constructor.
ToggleBase(const std::vector<std::wstring>* entries,
int* selected,
ConstRef<ToggleOption> option = {});
Ref<ToggleOption> option = {});
~ToggleBase() override = default;
// State.
@@ -39,7 +39,7 @@ class ToggleBase : public ComponentBase {
bool OnMouseEvent(Event event);
std::vector<Box> boxes_;
ConstRef<ToggleOption> option_;
Ref<ToggleOption> option_;
};
} // namespace ftxui

View File

@@ -6,7 +6,7 @@
namespace ftxui {
/// @brief An adapter. Own or reference a constant object.
/// @brief An adapter. Own or reference an immutable object.
template <typename T>
class ConstRef {
public:
@@ -14,6 +14,7 @@ class ConstRef {
ConstRef(T t) : owned_(t) {}
ConstRef(const T* t) : address_(t) {}
const T& operator*() { return address_ ? *address_ : owned_; }
const T& operator()() { return address_ ? *address_ : owned_; }
const T* operator->() { return address_ ? address_ : &owned_; }
private:
@@ -21,6 +22,22 @@ class ConstRef {
const T* address_ = nullptr;
};
/// @brief An adapter. Own or reference an mutable object.
template <typename T>
class Ref{
public:
Ref() {}
Ref(T t) : owned_(t) {}
Ref(T* t) : address_(t) {}
T& operator*() { return address_ ? *address_ : owned_; }
T& operator()() { return address_ ? *address_ : owned_; }
T* operator->() { return address_ ? address_ : &owned_; }
private:
T owned_;
T* address_ = nullptr;
};
/// @brief An adapter. Own or reference a constant string. For convenience, this
/// class convert multiple mutable string toward a shared representation.
class StringRef {