2019-01-07 00:10:35 +08:00
|
|
|
#ifndef FTXUI_COMPONENT_SCREEN_INTERACTIVE_HPP
|
|
|
|
#define FTXUI_COMPONENT_SCREEN_INTERACTIVE_HPP
|
2018-10-10 01:06:03 +08:00
|
|
|
|
2021-05-15 04:00:49 +08:00
|
|
|
#include <atomic> // for atomic
|
|
|
|
#include <ftxui/component/receiver.hpp> // for Receiver, Sender
|
|
|
|
#include <functional> // for function
|
|
|
|
#include <memory> // for shared_ptr
|
|
|
|
#include <string> // for string
|
2019-01-27 09:33:06 +08:00
|
|
|
|
2021-05-02 02:40:35 +08:00
|
|
|
#include "ftxui/component/captured_mouse.hpp" // for CapturedMouse
|
2019-01-27 09:33:06 +08:00
|
|
|
#include "ftxui/component/event.hpp"
|
2021-05-02 02:40:35 +08:00
|
|
|
#include "ftxui/screen/screen.hpp" // for Screen
|
2018-10-10 01:06:03 +08:00
|
|
|
|
2019-01-12 22:00:08 +08:00
|
|
|
namespace ftxui {
|
2021-05-10 02:32:27 +08:00
|
|
|
class ComponentBase;
|
|
|
|
|
|
|
|
using Component = std::shared_ptr<ComponentBase>;
|
2021-05-02 02:40:35 +08:00
|
|
|
struct Event;
|
2018-10-10 01:06:03 +08:00
|
|
|
|
2019-01-13 01:24:46 +08:00
|
|
|
class ScreenInteractive : public Screen {
|
2020-03-24 04:26:00 +08:00
|
|
|
public:
|
|
|
|
static ScreenInteractive FixedSize(int dimx, int dimy);
|
|
|
|
static ScreenInteractive Fullscreen();
|
|
|
|
static ScreenInteractive FitComponent();
|
|
|
|
static ScreenInteractive TerminalOutput();
|
|
|
|
|
|
|
|
~ScreenInteractive();
|
2021-05-10 02:32:27 +08:00
|
|
|
void Loop(Component);
|
2020-03-24 04:26:00 +08:00
|
|
|
std::function<void()> ExitLoopClosure();
|
|
|
|
|
|
|
|
void PostEvent(Event event);
|
2021-05-02 00:13:56 +08:00
|
|
|
CapturedMouse CaptureMouse();
|
2020-03-24 04:26:00 +08:00
|
|
|
|
|
|
|
private:
|
2021-05-10 02:32:27 +08:00
|
|
|
void Draw(Component component);
|
|
|
|
void EventLoop(Component component);
|
2020-03-24 04:26:00 +08:00
|
|
|
|
|
|
|
enum class Dimension {
|
|
|
|
FitComponent,
|
|
|
|
Fixed,
|
|
|
|
Fullscreen,
|
|
|
|
TerminalOutput,
|
|
|
|
};
|
|
|
|
Dimension dimension_ = Dimension::Fixed;
|
2020-05-03 02:39:56 +08:00
|
|
|
bool use_alternative_screen_ = false;
|
|
|
|
ScreenInteractive(int dimx,
|
|
|
|
int dimy,
|
|
|
|
Dimension dimension,
|
|
|
|
bool use_alternative_screen);
|
2020-03-24 04:26:00 +08:00
|
|
|
|
2020-03-25 07:07:41 +08:00
|
|
|
Sender<Event> event_sender_;
|
|
|
|
Receiver<Event> event_receiver_;
|
2020-03-24 04:26:00 +08:00
|
|
|
|
|
|
|
std::string set_cursor_position;
|
|
|
|
std::string reset_cursor_position;
|
2020-03-25 06:26:55 +08:00
|
|
|
|
2020-03-25 07:07:41 +08:00
|
|
|
std::atomic<bool> quit_ = false;
|
2021-04-25 00:16:13 +08:00
|
|
|
|
|
|
|
int cursor_x_ = 0;
|
|
|
|
int cursor_y_ = 0;
|
2021-05-02 00:13:56 +08:00
|
|
|
|
|
|
|
bool mouse_captured = false;
|
2018-10-10 01:06:03 +08:00
|
|
|
};
|
|
|
|
|
2019-01-12 22:00:08 +08:00
|
|
|
} // namespace ftxui
|
2018-10-10 01:06:03 +08:00
|
|
|
|
2019-01-07 00:10:35 +08:00
|
|
|
#endif /* end of include guard: FTXUI_COMPONENT_SCREEN_INTERACTIVE_HPP */
|
2020-08-16 06:24:18 +08:00
|
|
|
|
|
|
|
// 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.
|