FTXUI/include/ftxui/component/input.hpp

44 lines
963 B
C++
Raw Normal View History

2018-10-19 04:58:38 +08:00
#ifndef FTXUI_COMPONENT_INPUT_H_
#define FTXUI_COMPONENT_INPUT_H_
#include <functional>
#include "ftxui/component/component.hpp"
namespace ftxui {
2018-10-19 04:58:38 +08:00
2020-08-16 08:24:50 +08:00
/// @brief An input box. The user can type text into it.
/// @ingroup component.
2018-10-19 04:58:38 +08:00
class Input : public Component {
public:
// Constructor.
2019-01-13 01:24:46 +08:00
Input() = default;
~Input() override = default;
2018-10-19 04:58:38 +08:00
// State.
2018-10-21 20:18:11 +08:00
std::wstring content;
std::wstring placeholder;
int cursor_position = 0;
2018-10-19 04:58:38 +08:00
// State update callback.
2020-09-20 17:47:06 +08:00
std::function<void()> on_change = [] {};
std::function<void()> on_enter = [] {};
2018-10-19 04:58:38 +08:00
// Component implementation.
Element Render() override;
bool OnEvent(Event) override;
private:
bool OnMouseEvent(Event);
Box input_box_;
Box cursor_box_;
2018-10-19 04:58:38 +08:00
};
} // namespace ftxui
2018-10-19 04:58:38 +08:00
#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.