mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-09-28 16:29:34 +08:00
Flatten the namespaces.
Remove: * ftxui::screen * ftxui::dom * ftxui::component Keep: * ftxui
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
#
|
||||
* Level 0: terminal output.
|
||||
* Level 1: ftxui::Screen
|
||||
* Level 2: ftxui::dom::Node
|
||||
* Level 3: ftxui::component::Component
|
||||
* Level 2: ftxui::Node
|
||||
* Level 3: ftxui::Component
|
||||
|
||||
## Level 0: terminal output.
|
||||
The terminal you know, you can append text on it. It is represented by
|
||||
@@ -12,16 +12,16 @@
|
||||
A rectangular grid of characters.
|
||||
Use Terminal::ToString() to append its content into the console.
|
||||
|
||||
## Level 2: ftxui::dom::Node
|
||||
## Level 2: ftxui::Node
|
||||
A hierarchical set of element.
|
||||
They handle layout and Render themself on the screen.
|
||||
See ftxui/dom/elements.hpp
|
||||
|
||||
You can make implement your own.
|
||||
|
||||
## Level 3: ftxui::component::Component
|
||||
## Level 3: ftxui::Component
|
||||
A hierarchical set of component. A component render itself by producing
|
||||
ftxui::dom::Node in Component::Render().
|
||||
ftxui::Node in Component::Render().
|
||||
|
||||
Some component can handle events:
|
||||
* keyboard
|
||||
|
@@ -5,19 +5,40 @@
|
||||
#include "ftxui/component/event.hpp"
|
||||
#include "ftxui/dom/elements.hpp"
|
||||
|
||||
namespace ftxui::component {
|
||||
namespace ftxui {
|
||||
|
||||
class Delegate;
|
||||
class Focus;
|
||||
|
||||
class Component {
|
||||
public:
|
||||
|
||||
class Delegate {
|
||||
public:
|
||||
Delegate() {}
|
||||
virtual ~Delegate() {}
|
||||
|
||||
// A Delegate shadows a component.
|
||||
virtual void Register(Component* component) = 0;
|
||||
virtual Component* component() = 0;
|
||||
|
||||
// Create new children.
|
||||
virtual Delegate* NewChild() = 0;
|
||||
virtual std::vector<Delegate*> children() = 0;
|
||||
|
||||
// Navigate in the tree.
|
||||
virtual Delegate* PreviousSibling() = 0;
|
||||
virtual Delegate* NextSibling() = 0;
|
||||
virtual Delegate* Parent() = 0;
|
||||
virtual Delegate* Root() = 0;
|
||||
};
|
||||
|
||||
// Constructor/Destructor.
|
||||
Component(Delegate* delegate);
|
||||
virtual ~Component();
|
||||
|
||||
// Render the component.
|
||||
virtual dom::Element Render();
|
||||
virtual Element Render();
|
||||
|
||||
// Handle an event. By default, it calls this function on each children.
|
||||
virtual bool OnEvent(Event even);
|
||||
@@ -38,6 +59,6 @@ class Component {
|
||||
Delegate* delegate_;
|
||||
};
|
||||
|
||||
} // namespace ftxui::component
|
||||
} // namespace ftxui
|
||||
|
||||
#endif /* end of include guard: FTXUI_COMPONENT_COMPONENT_HPP */
|
||||
|
@@ -4,7 +4,6 @@
|
||||
#include "ftxui/component/component.hpp"
|
||||
|
||||
namespace ftxui {
|
||||
namespace component {
|
||||
|
||||
// A component where focus and events are automatically handled for you.
|
||||
// Please use ComponentVertical or ComponentHorizontal.
|
||||
@@ -20,7 +19,6 @@ class ComponentDirection : public Component {
|
||||
Component* active_child_;
|
||||
};
|
||||
|
||||
} // namespace component
|
||||
} // namespace ftxui
|
||||
|
||||
#endif /* end of include guard: FTXUI_COMPONENT_COMPONENT_DIRECTION_H_ */
|
||||
|
@@ -3,7 +3,7 @@
|
||||
|
||||
#include "ftxui/component/component_direction.hpp"
|
||||
|
||||
namespace ftxui::component {
|
||||
namespace ftxui {
|
||||
|
||||
// A component where focus and events are automatically handled for you.
|
||||
// It assumes its children are put in the horizontal direction.
|
||||
@@ -13,6 +13,6 @@ class ComponentHorizontal : public ComponentDirection {
|
||||
bool HandleDirection(Event) override;
|
||||
};
|
||||
|
||||
} // namespace ftxui::component
|
||||
} // namespace ftxui
|
||||
|
||||
#endif /* end of include guard: FTXUI_COMPONENT_COMPONENT_HORIZONTAL_H_ */
|
||||
|
@@ -3,7 +3,7 @@
|
||||
|
||||
#include "ftxui/component/component_direction.hpp"
|
||||
|
||||
namespace ftxui::component {
|
||||
namespace ftxui {
|
||||
|
||||
// A component where focus and events are automatically handled for you.
|
||||
// It assumes its children are put in the vertical direction.
|
||||
@@ -13,6 +13,6 @@ class ComponentVertical : public ComponentDirection {
|
||||
bool HandleDirection(Event) override;
|
||||
};
|
||||
|
||||
} // namespace ftxui::component
|
||||
} // namespace ftxui
|
||||
|
||||
#endif /* end of include guard: FTXUI_COMPONENT_COMPONENT_VERTICAL_H_ */
|
||||
|
@@ -3,30 +3,11 @@
|
||||
|
||||
#include "ftxui/dom/elements.hpp"
|
||||
|
||||
namespace ftxui::component {
|
||||
namespace ftxui {
|
||||
|
||||
class Component;
|
||||
|
||||
class Delegate {
|
||||
public:
|
||||
Delegate() {}
|
||||
virtual ~Delegate() {}
|
||||
|
||||
// A Delegate shadows a component.
|
||||
virtual void Register(Component* component) = 0;
|
||||
virtual Component* component() = 0;
|
||||
|
||||
// Create new children.
|
||||
virtual Delegate* NewChild() = 0;
|
||||
virtual std::vector<Delegate*> children() = 0;
|
||||
|
||||
// Navigate in the tree.
|
||||
virtual Delegate* PreviousSibling() = 0;
|
||||
virtual Delegate* NextSibling() = 0;
|
||||
virtual Delegate* Parent() = 0;
|
||||
virtual Delegate* Root() = 0;
|
||||
};
|
||||
|
||||
} // namespace ftxui::component
|
||||
} // namespace ftxui
|
||||
|
||||
#endif /* end of include guard: FTXUI_COMPONENT_DELEGATE_HPP */
|
||||
|
@@ -4,7 +4,7 @@
|
||||
#include <vector>
|
||||
#include <array>
|
||||
|
||||
namespace ftxui::component {
|
||||
namespace ftxui {
|
||||
|
||||
struct Event{
|
||||
public:
|
||||
@@ -31,7 +31,7 @@ struct Event{
|
||||
};
|
||||
|
||||
|
||||
} // namespace ftxui::component
|
||||
} // namespace ftxui
|
||||
|
||||
|
||||
#endif /* end of include guard: FTXUI_COMPONENT_EVENT_HPP */
|
||||
|
@@ -4,7 +4,7 @@
|
||||
#include "ftxui/component/component.hpp"
|
||||
#include <functional>
|
||||
|
||||
namespace ftxui::component {
|
||||
namespace ftxui {
|
||||
|
||||
class Input : public Component {
|
||||
public:
|
||||
@@ -21,13 +21,13 @@ class Input : public Component {
|
||||
std::function<void()> on_enter = [](){};
|
||||
|
||||
// Component implementation.
|
||||
dom::Element Render() override;
|
||||
Element Render() override;
|
||||
bool OnEvent(Event) override;
|
||||
|
||||
private:
|
||||
int cursor_position = 0;
|
||||
};
|
||||
|
||||
} // namespace ftxui::component
|
||||
} // namespace ftxui
|
||||
|
||||
#endif /* end of include guard: FTXUI_COMPONENT_INPUT_H_ */
|
||||
|
@@ -5,7 +5,7 @@
|
||||
#include "ftxui/dom/elements.hpp"
|
||||
#include <functional>
|
||||
|
||||
namespace ftxui::component {
|
||||
namespace ftxui {
|
||||
|
||||
class Menu : public Component {
|
||||
public:
|
||||
@@ -16,16 +16,16 @@ class Menu : public Component {
|
||||
std::vector<std::wstring> entries = {};
|
||||
int selected = 0;
|
||||
|
||||
dom::Decorator active_style = dom::inverted;
|
||||
dom::Decorator selected_style = dom::bold;
|
||||
dom::Decorator normal_style = dom::nothing;
|
||||
Decorator active_style = inverted;
|
||||
Decorator selected_style = bold;
|
||||
Decorator normal_style = nothing;
|
||||
|
||||
// State update callback.
|
||||
std::function<void()> on_change = [](){};
|
||||
std::function<void()> on_enter = [](){};
|
||||
|
||||
// Component implementation.
|
||||
dom::Element Render() override;
|
||||
Element Render() override;
|
||||
bool OnEvent(Event) override;
|
||||
};
|
||||
|
||||
|
@@ -1,26 +1,26 @@
|
||||
#ifndef FTXUI_COMPONENT_SCREEN_INTERACTIVE_HPP
|
||||
#define FTXUI_COMPONENT_SCREEN_INTERACTIVE_HPP
|
||||
|
||||
#include "ftxui/component/component.hpp"
|
||||
#include "ftxui/screen/screen.hpp"
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
namespace ftxui::component {
|
||||
namespace ftxui {
|
||||
|
||||
class Delegate;
|
||||
class Component;
|
||||
|
||||
class ScreenInteractive : public ftxui::screen::Screen {
|
||||
class ScreenInteractive : public ftxui::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();
|
||||
|
||||
Component::Delegate* delegate();
|
||||
|
||||
private:
|
||||
class Delegate;
|
||||
std::unique_ptr<Delegate> delegate_;
|
||||
@@ -38,6 +38,6 @@ class ScreenInteractive : public ftxui::screen::Screen {
|
||||
ScreenInteractive(size_t dimx, size_t dimy, Dimension dimension);
|
||||
};
|
||||
|
||||
} // namespace ftxui::component
|
||||
} // namespace ftxui
|
||||
|
||||
#endif /* end of include guard: FTXUI_COMPONENT_SCREEN_INTERACTIVE_HPP */
|
||||
|
@@ -5,7 +5,7 @@
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
namespace ftxui::component {
|
||||
namespace ftxui {
|
||||
|
||||
class Toggle : public Component {
|
||||
public:
|
||||
@@ -20,7 +20,7 @@ class Toggle : public Component {
|
||||
std::function<void()> on_change = [](){};
|
||||
|
||||
// Component implementation.
|
||||
dom::Element Render() override;
|
||||
Element Render() override;
|
||||
bool OnEvent(Event) override;
|
||||
};
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#ifndef FTXUI_DOM_BOX_HPP
|
||||
#define FTXUI_DOM_BOX_HPP
|
||||
|
||||
namespace ftxui::dom {
|
||||
namespace ftxui {
|
||||
|
||||
struct Box {
|
||||
int left;
|
||||
@@ -10,6 +10,6 @@ struct Box {
|
||||
int bottom;
|
||||
};
|
||||
|
||||
}; // namespace ftxui::dom
|
||||
}; // namespace ftxui
|
||||
|
||||
#endif /* end of include guard: FTXUI_DOM_BOX_HPP */
|
||||
|
@@ -6,13 +6,13 @@
|
||||
#include "ftxui/dom/node.hpp"
|
||||
#include "ftxui/screen/color.hpp"
|
||||
|
||||
namespace ftxui::dom {
|
||||
namespace ftxui {
|
||||
|
||||
using Element = std::unique_ptr<Node>;
|
||||
using Decorator = std::function<Element(Element)>;
|
||||
using Child = std::unique_ptr<Node>;
|
||||
using Children = std::vector<Child>;
|
||||
using Color = ftxui::screen::Color;
|
||||
using Color = ftxui::Color;
|
||||
|
||||
// --- Layout ----
|
||||
Element vbox(Children);
|
||||
@@ -64,6 +64,6 @@ TAKE_ANY_ARGS(vbox)
|
||||
TAKE_ANY_ARGS(hbox)
|
||||
TAKE_ANY_ARGS(dbox)
|
||||
|
||||
}; // namespace ftxui::dom
|
||||
}; // namespace ftxui
|
||||
|
||||
#endif /* end of include guard: FTXUI_DOM_ELEMENTS_HPP */
|
||||
|
@@ -8,7 +8,7 @@
|
||||
#include "ftxui/dom/requirement.hpp"
|
||||
#include "ftxui/screen/screen.hpp"
|
||||
|
||||
namespace ftxui::dom {
|
||||
namespace ftxui {
|
||||
|
||||
class Node {
|
||||
public:
|
||||
@@ -27,7 +27,7 @@ class Node {
|
||||
virtual void SetBox(Box box);
|
||||
|
||||
// Step 3: Draw this element.
|
||||
virtual void Render(screen::Screen& screen);
|
||||
virtual void Render(Screen& screen);
|
||||
|
||||
std::vector<std::unique_ptr<Node>> children;
|
||||
protected:
|
||||
@@ -35,8 +35,8 @@ class Node {
|
||||
Box box_;
|
||||
};
|
||||
|
||||
void Render(screen::Screen& screen, Node* node);
|
||||
void Render(Screen& screen, Node* node);
|
||||
|
||||
}; // namespace ftxui::dom
|
||||
}; // namespace ftxui
|
||||
|
||||
#endif /* end of include guard: FTXUI_DOM_NODE_HPP */
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#ifndef FTXUI_DOM_REQUIREMENT_HPP
|
||||
#define FTXUI_DOM_REQUIREMENT_HPP
|
||||
|
||||
namespace ftxui::dom {
|
||||
namespace ftxui {
|
||||
|
||||
struct Requirement {
|
||||
// The required size to fully draw the element.
|
||||
@@ -11,6 +11,6 @@ struct Requirement {
|
||||
struct { int x = 0; int y = 0; } flex;
|
||||
};
|
||||
|
||||
}; // namespace ftxui::dom
|
||||
}; // namespace ftxui
|
||||
|
||||
#endif /* end of include guard: FTXUI_REQUIREMENT_HPP */
|
||||
|
@@ -3,7 +3,7 @@
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace ftxui::screen {
|
||||
namespace ftxui {
|
||||
|
||||
enum class Color : uint8_t {
|
||||
// --- Transparent -----
|
||||
@@ -35,6 +35,6 @@ enum class Color : uint8_t {
|
||||
YellowLight = 93,
|
||||
};
|
||||
|
||||
}; // namespace ftxui::screen
|
||||
}; // namespace ftxui
|
||||
|
||||
#endif /* end of include guard: FTXUI_COLOR_H_ */
|
||||
|
@@ -7,11 +7,11 @@
|
||||
|
||||
#include "ftxui/screen/color.hpp"
|
||||
|
||||
namespace ftxui::dom {
|
||||
namespace ftxui {
|
||||
class Node;
|
||||
}
|
||||
|
||||
namespace ftxui::screen {
|
||||
namespace ftxui {
|
||||
|
||||
struct Pixel {
|
||||
wchar_t character = U' ';
|
||||
@@ -31,9 +31,9 @@ class Screen {
|
||||
|
||||
// Constructor using the terminal.
|
||||
static Screen TerminalFullscreen();
|
||||
static Screen TerminalOutput(std::unique_ptr<dom::Node>& element);
|
||||
static Screen TerminalOutput(std::unique_ptr<Node>& element);
|
||||
|
||||
// dom::Node write into the screen using Screen::at.
|
||||
// Node write into the screen using Screen::at.
|
||||
wchar_t& at(size_t x, size_t y);
|
||||
Pixel& PixelAt(size_t x, size_t y);
|
||||
|
||||
@@ -56,6 +56,6 @@ class Screen {
|
||||
std::vector<std::vector<Pixel>> pixels_;
|
||||
};
|
||||
|
||||
}; // namespace ftxui::screen
|
||||
}; // namespace ftxui
|
||||
|
||||
#endif /* end of include guard: FTXUI_SCREEN_SCREEN */
|
||||
|
Reference in New Issue
Block a user