mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-10-17 00:38:09 +08:00
Refactor directory structure.
The goal is to increase the separation in between: * ftxui::screen * ftxui::dom * ftxui::component
This commit is contained in:
@@ -2,11 +2,10 @@
|
||||
#define FTXUI_COMPONENT_COMPONENT_HPP
|
||||
|
||||
#include "ftxui/component/delegate.hpp"
|
||||
#include "ftxui/component/event.hpp"
|
||||
#include "ftxui/dom/elements.hpp"
|
||||
#include "ftxui/event.hpp"
|
||||
|
||||
namespace ftxui {
|
||||
namespace component {
|
||||
namespace ftxui::component {
|
||||
|
||||
class Delegate;
|
||||
class Focus;
|
||||
@@ -39,7 +38,6 @@ class Component {
|
||||
Delegate* delegate_;
|
||||
};
|
||||
|
||||
} // namespace component
|
||||
} // namespace ftxui
|
||||
} // namespace ftxui::component
|
||||
|
||||
#endif /* end of include guard: FTXUI_COMPONENT_COMPONENT_HPP */
|
||||
|
@@ -3,8 +3,7 @@
|
||||
|
||||
#include "ftxui/component/component_direction.hpp"
|
||||
|
||||
namespace ftxui {
|
||||
namespace component {
|
||||
namespace ftxui::component {
|
||||
|
||||
// A component where focus and events are automatically handled for you.
|
||||
// It assumes its children are put in the horizontal direction.
|
||||
@@ -14,7 +13,6 @@ class ComponentHorizontal : public ComponentDirection {
|
||||
bool HandleDirection(Event) override;
|
||||
};
|
||||
|
||||
} // namespace component
|
||||
} // namespace ftxui
|
||||
} // namespace ftxui::component
|
||||
|
||||
#endif /* end of include guard: FTXUI_COMPONENT_COMPONENT_HORIZONTAL_H_ */
|
||||
|
@@ -3,8 +3,7 @@
|
||||
|
||||
#include "ftxui/component/component_direction.hpp"
|
||||
|
||||
namespace ftxui {
|
||||
namespace component {
|
||||
namespace ftxui::component {
|
||||
|
||||
// A component where focus and events are automatically handled for you.
|
||||
// It assumes its children are put in the vertical direction.
|
||||
@@ -14,7 +13,6 @@ class ComponentVertical : public ComponentDirection {
|
||||
bool HandleDirection(Event) override;
|
||||
};
|
||||
|
||||
} // namespace component
|
||||
} // namespace ftxui
|
||||
} // namespace ftxui::component
|
||||
|
||||
#endif /* end of include guard: FTXUI_COMPONENT_COMPONENT_VERTICAL_H_ */
|
||||
|
@@ -3,8 +3,7 @@
|
||||
|
||||
#include "ftxui/dom/elements.hpp"
|
||||
|
||||
namespace ftxui {
|
||||
namespace component {
|
||||
namespace ftxui::component {
|
||||
|
||||
class Component;
|
||||
|
||||
@@ -28,7 +27,6 @@ class Delegate {
|
||||
virtual Delegate* Root() = 0;
|
||||
};
|
||||
|
||||
} // namespace component
|
||||
} // namespace ftxui
|
||||
} // namespace ftxui::component
|
||||
|
||||
#endif /* end of include guard: FTXUI_COMPONENT_DELEGATE_HPP */
|
||||
|
37
ftxui/include/ftxui/component/event.hpp
Normal file
37
ftxui/include/ftxui/component/event.hpp
Normal file
@@ -0,0 +1,37 @@
|
||||
#ifndef FTXUI_COMPONENT_EVENT_HPP
|
||||
#define FTXUI_COMPONENT_EVENT_HPP
|
||||
|
||||
#include <vector>
|
||||
#include <array>
|
||||
|
||||
namespace ftxui::component {
|
||||
|
||||
struct Event{
|
||||
public:
|
||||
// --- Character ---
|
||||
static Event Character(int);
|
||||
|
||||
// --- Arrow ---
|
||||
static Event ArrowLeft;
|
||||
static Event ArrowRight;
|
||||
static Event ArrowUp;
|
||||
static Event ArrowDown;
|
||||
|
||||
// --- Other ---
|
||||
static Event Backspace;
|
||||
static Event Delete;
|
||||
static Event Return;
|
||||
static Event Escape;
|
||||
static Event F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12;
|
||||
|
||||
bool operator==(const Event& other) { return values == other.values; }
|
||||
|
||||
// Internal representation.
|
||||
std::array<int, 5> values = {0, 0, 0, 0, 0};
|
||||
};
|
||||
|
||||
|
||||
} // namespace ftxui::component
|
||||
|
||||
|
||||
#endif /* end of include guard: FTXUI_COMPONENT_EVENT_HPP */
|
@@ -4,8 +4,7 @@
|
||||
#include "ftxui/component/component.hpp"
|
||||
#include <functional>
|
||||
|
||||
namespace ftxui {
|
||||
namespace component {
|
||||
namespace ftxui::component {
|
||||
|
||||
class Input : public Component {
|
||||
public:
|
||||
@@ -29,7 +28,6 @@ class Input : public Component {
|
||||
int cursor_position = 0;
|
||||
};
|
||||
|
||||
} // namespace component
|
||||
} // namespace ftxui
|
||||
} // namespace ftxui::component
|
||||
|
||||
#endif /* end of include guard: FTXUI_COMPONENT_INPUT_H_ */
|
||||
|
@@ -5,8 +5,7 @@
|
||||
#include "ftxui/dom/elements.hpp"
|
||||
#include <functional>
|
||||
|
||||
namespace ftxui {
|
||||
namespace component {
|
||||
namespace ftxui::component {
|
||||
|
||||
class Menu : public Component {
|
||||
public:
|
||||
@@ -30,7 +29,6 @@ class Menu : public Component {
|
||||
bool OnEvent(Event) override;
|
||||
};
|
||||
|
||||
} // namespace component
|
||||
} // namespace ftxui
|
||||
} // namespace ftxui::Component
|
||||
|
||||
#endif /* end of include guard: FTXUI_COMPONENT_MENU */
|
||||
|
44
ftxui/include/ftxui/component/screen_interactive.hpp
Normal file
44
ftxui/include/ftxui/component/screen_interactive.hpp
Normal file
@@ -0,0 +1,44 @@
|
||||
#ifndef FTXUI_COMPONENT_SCREEN_INTERACTIVE_HPP
|
||||
#define FTXUI_COMPONENT_SCREEN_INTERACTIVE_HPP
|
||||
|
||||
#include "ftxui/screen/screen.hpp"
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
namespace ftxui::component {
|
||||
|
||||
class Delegate;
|
||||
class Component;
|
||||
|
||||
class ScreenInteractive : public ftxui::screen::Screen {
|
||||
public:
|
||||
static ScreenInteractive FixedSize(size_t dimx, size_t dimy);
|
||||
static ScreenInteractive Fullscreen();
|
||||
static ScreenInteractive TerminalOutput();
|
||||
|
||||
~ScreenInteractive();
|
||||
component::Delegate* delegate();
|
||||
void Loop();
|
||||
std::function<void()> ExitLoopClosure();
|
||||
|
||||
private:
|
||||
class Delegate;
|
||||
std::unique_ptr<Delegate> delegate_;
|
||||
|
||||
void Clear();
|
||||
void Draw();
|
||||
bool quit_ = false;
|
||||
|
||||
enum class Dimension {
|
||||
Fixed,
|
||||
TerminalOutput,
|
||||
Fullscreen,
|
||||
};
|
||||
Dimension dimension_ = Dimension::Fixed;
|
||||
|
||||
ScreenInteractive(size_t dimx, size_t dimy, Dimension dimension);
|
||||
};
|
||||
|
||||
} // namespace ftxui::component
|
||||
|
||||
#endif /* end of include guard: FTXUI_COMPONENT_SCREEN_INTERACTIVE_HPP */
|
@@ -5,8 +5,7 @@
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
namespace ftxui {
|
||||
namespace component {
|
||||
namespace ftxui::component {
|
||||
|
||||
class Toggle : public Component {
|
||||
public:
|
||||
@@ -25,7 +24,6 @@ class Toggle : public Component {
|
||||
bool OnEvent(Event) override;
|
||||
};
|
||||
|
||||
} // namespace component
|
||||
} // namespace ftxui
|
||||
} // namespace ftxui::Component
|
||||
|
||||
#endif /* end of include guard: FTXUI_COMPONENT_TOGGLE_H_ */
|
||||
|
Reference in New Issue
Block a user