mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-09-16 08:04:21 +08:00
Add option for input.
This commit is contained in:

committed by
Arthur Sonzogni

parent
2b7daf061f
commit
33b3d1c7ab
@@ -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> = {});
|
||||
|
@@ -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 */
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user