Pipeable decoration and the package_manager example.

- Pipeable decorator.
- package_manager example.
This commit is contained in:
Arthur Sonzogni
2019-01-05 02:03:49 +01:00
parent 178feaa6a9
commit 961e3dcb50
32 changed files with 351 additions and 128 deletions

View File

@@ -22,7 +22,7 @@
## Level 3: ftxui::component::Component
A hierarchical set of component. A component render itself by producing
ftxui::dom::Node in Component::Render().
Some component can handle events:
* keyboard
* mouse

View File

@@ -18,17 +18,17 @@ using Children = std::vector<Child>;
Element vbox(Children);
Element hbox(Children);
Element dbox(Children);
Element flex();
Element filler();
Element flex(Element);
// --- Widget --
Element text(std::wstring text);
Element separator();
Element gauge(float ratio);
Element frame(Child);
Element frame(Child title, Child content);
Element frame(Element);
Element window(Child title, Child content);
// -- Style ---
// -- Decorator ---
Element bold(Element);
Element dim(Element);
Element inverted(Element);
@@ -46,8 +46,13 @@ Element center(Element);
// --- Util ---
Element nothing(Element element);
Decorator compose(Decorator, Decorator);
// Pipe elements into decorator togethers.
// Examples: text("ftxui") | bold | underlined;
Element operator|(Element, Decorator);
Decorator operator|(Decorator, Decorator);
// Make container able to take several children.
template <class... Args>
Children unpack(Args... args) {
Children vec;
@@ -55,20 +60,15 @@ Children unpack(Args... args) {
return vec;
}
template <class... Args>
Element vbox(Args... children) {
return vbox(unpack(std::forward<Args>(children)...));
}
#define TAKE_ANY_ARGS(container) \
template <class... Args> \
Element container(Args... children) { \
return container(unpack(std::forward<Args>(children)...)); \
} \
template <class... Args>
Element hbox(Args... children) {
return hbox(unpack(std::forward<Args>(children)...));
}
template <class... Args>
Element dbox(Args... children) {
return dbox(unpack(std::forward<Args>(children)...));
}
TAKE_ANY_ARGS(vbox)
TAKE_ANY_ARGS(hbox)
TAKE_ANY_ARGS(dbox)
}; // namespace dom
}; // namespace ftxui

View File

@@ -49,7 +49,7 @@ class Screen {
// Fill with space.
void Clear();
private:
protected:
size_t dimx_;
size_t dimy_;
std::vector<std::vector<Pixel>> pixels_;

View File

@@ -14,7 +14,10 @@ namespace component {
class ScreenInteractive : public Screen {
public:
ScreenInteractive(size_t dimx, size_t dimy);
static ScreenInteractive FixedSize(size_t dimx, size_t dimy);
static ScreenInteractive Fullscreen();
static ScreenInteractive TerminalOutput();
~ScreenInteractive();
component::Delegate* delegate();
void Loop();
@@ -27,6 +30,15 @@ class ScreenInteractive : public Screen {
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