mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-09-29 16:39:34 +08:00
Implement a lot of new features.
This commit deserve to be cut into at least 8 sub commit. Sorry, I acknowledge this is bad... Here are the new features: * dom decorator: bold, dim, underlined, inverted. * component mechanism * components * menu * toogle
This commit is contained in:
57
ftxui/include/ftxui/dom/elements.hpp
Normal file
57
ftxui/include/ftxui/dom/elements.hpp
Normal file
@@ -0,0 +1,57 @@
|
||||
#ifndef FTXUI_DOM_ELEMENTS_HPP
|
||||
#define FTXUI_DOM_ELEMENTS_HPP
|
||||
|
||||
#include "ftxui/dom/node.hpp"
|
||||
|
||||
namespace ftxui {
|
||||
namespace dom {
|
||||
|
||||
using Element = std::unique_ptr<Node>;
|
||||
using Child = std::unique_ptr<Node>;
|
||||
using Children = std::vector<Child>;
|
||||
|
||||
// --- Layout ----
|
||||
Element vbox(Children);
|
||||
Element hbox(Children);
|
||||
Element flex();
|
||||
|
||||
// --- Widget --
|
||||
Element text(std::wstring text);
|
||||
Element separator();
|
||||
Element gauge(float ratio);
|
||||
Element frame(Child);
|
||||
Element frame(Child title, Child content);
|
||||
|
||||
// -- Decorator (Style) ---
|
||||
Element bold(Element);
|
||||
Element dim(Element);
|
||||
Element inverted(Element);
|
||||
Element underlined(Element);
|
||||
|
||||
// --- Decorator ---
|
||||
Element hcenter(Element);
|
||||
Element vcenter(Element);
|
||||
Element center(Element);
|
||||
Element flex(Element);
|
||||
|
||||
template <class... Args>
|
||||
Children unpack(Args... args) {
|
||||
Children vec;
|
||||
(vec.push_back(std::forward<Args>(args)), ...);
|
||||
return vec;
|
||||
}
|
||||
|
||||
template <class... Args>
|
||||
Element vbox(Args... children) {
|
||||
return vbox(unpack(std::forward<Args>(children)...));
|
||||
}
|
||||
|
||||
template <class... Args>
|
||||
Element hbox(Args... children) {
|
||||
return hbox(unpack(std::forward<Args>(children)...));
|
||||
}
|
||||
|
||||
}; // namespace dom
|
||||
}; // namespace ftxui
|
||||
|
||||
#endif /* end of include guard: FTXUI_DOM_ELEMENTS_HPP */
|
44
ftxui/include/ftxui/dom/node.hpp
Normal file
44
ftxui/include/ftxui/dom/node.hpp
Normal file
@@ -0,0 +1,44 @@
|
||||
#ifndef DOM_NODE_HPP
|
||||
#define DOM_NODE_HPP
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "ftxui/requirement.hpp"
|
||||
#include "ftxui/screen.hpp"
|
||||
#include "ftxui/box.hpp"
|
||||
|
||||
namespace ftxui {
|
||||
namespace dom {
|
||||
|
||||
class Node {
|
||||
public:
|
||||
Node();
|
||||
Node(std::vector<std::unique_ptr<Node>> children);
|
||||
virtual ~Node();
|
||||
|
||||
// Step 1: Direction parent <= children.
|
||||
// Compute layout requirement. Tell parent what dimensions this
|
||||
// element wants to be.
|
||||
virtual void ComputeRequirement();
|
||||
Requirement requirement() { return requirement_; }
|
||||
|
||||
// Step 2: Direction parent => children.
|
||||
// Assign this element its final dimensions.
|
||||
virtual void SetBox(Box box);
|
||||
|
||||
// Step 3: Draw this element.
|
||||
virtual void Render(Screen& screen);
|
||||
|
||||
std::vector<std::unique_ptr<Node>> children;
|
||||
protected:
|
||||
Requirement requirement_;
|
||||
Box box_;
|
||||
};
|
||||
|
||||
void Render(Screen& screen, Node* node);
|
||||
|
||||
}; // namespace dom
|
||||
}; // namespace ftxui
|
||||
|
||||
#endif /* end of include guard: DOM_NODE_HPP */
|
Reference in New Issue
Block a user