Add option for input.

This commit is contained in:
ArthurSonzogni
2021-07-08 00:01:42 +02:00
committed by Arthur Sonzogni
parent 2b7daf061f
commit 33b3d1c7ab
5 changed files with 33 additions and 22 deletions

View File

@@ -30,7 +30,9 @@ Component Button(ConstStringRef label,
Component Checkbox(ConstStringRef label,
bool* checked,
ConstRef<CheckboxOption> option = {});
Component Input(StringRef content, ConstStringRef placeholder);
Component Input(StringRef content,
ConstStringRef placeholder,
ConstRef<InputOption> option = {});
Component Menu(const std::vector<std::wstring>* entries,
int* selected_,
ConstRef<MenuOption> = {});

View File

@@ -31,6 +31,11 @@ struct CheckboxOption {
std::function<void()> on_change = []() {};
};
struct InputOption {
std::function<void()> on_change = [] {};
std::function<void()> on_enter = [] {};
};
}; // namespace ftxui
#endif /* end of include guard: FTXUI_COMPONENT_COMPONENT_OPTIONS_HPP */

View File

@@ -21,16 +21,14 @@ class InputBase : public ComponentBase {
static InputBase* From(Component component);
// Constructor.
InputBase(StringRef content, ConstStringRef placeholder);
InputBase(StringRef content,
ConstStringRef placeholder,
ConstRef<InputOption> option = {});
~InputBase() override = default;
// State.
int cursor_position = 0;
// State update callback.
std::function<void()> on_change = [] {};
std::function<void()> on_enter = [] {};
// Component implementation.
Element Render() override;
bool OnEvent(Event) override;
@@ -42,6 +40,7 @@ class InputBase : public ComponentBase {
bool OnMouseEvent(Event);
Box input_box_;
Box cursor_box_;
ConstRef<InputOption> option_;
};
} // namespace ftxui