Files
FTXUI/include/ftxui/dom/node.hpp

53 lines
1.2 KiB
C++
Raw Normal View History

#ifndef FTXUI_DOM_NODE_HPP
#define FTXUI_DOM_NODE_HPP
2018-09-18 08:48:40 +02:00
#include <memory>
#include <vector>
#include "ftxui/dom/requirement.hpp"
2019-01-19 22:06:05 +01:00
#include "ftxui/screen/box.hpp"
#include "ftxui/screen/screen.hpp"
2018-09-18 08:48:40 +02:00
namespace ftxui {
2018-09-18 08:48:40 +02:00
2020-05-25 01:34:13 +02:00
class Node;
using Element = std::shared_ptr<Node>;
using Elements = std::vector<std::shared_ptr<Node>>;
2018-09-18 08:48:40 +02:00
class Node {
public:
Node();
Node(Elements children);
2018-09-18 08:48:40 +02:00
virtual ~Node();
2019-01-02 22:33:59 +01:00
// Step 1: Compute layout requirement. Tell parent what dimensions this
2018-09-18 08:48:40 +02:00
// element wants to be.
2019-01-02 22:33:59 +01:00
// Propagated from Children to Parents.
2018-09-18 08:48:40 +02:00
virtual void ComputeRequirement();
Requirement requirement() { return requirement_; }
2019-01-02 22:33:59 +01:00
// Step 2: Assign this element its final dimensions.
// Propagated from Parents to Children.
2018-09-18 08:48:40 +02:00
virtual void SetBox(Box box);
// Step 3: Draw this element.
virtual void Render(Screen& screen);
2018-09-18 08:48:40 +02:00
std::vector<Element> children;
2018-09-18 08:48:40 +02:00
protected:
Requirement requirement_;
Box box_;
};
void Render(Screen& screen, const Element& node);
void Render(Screen& screen, Node* node);
2018-09-18 08:48:40 +02:00
2020-02-11 21:44:55 +01:00
} // namespace ftxui
2018-09-18 08:48:40 +02:00
#endif /* end of include guard: FTXUI_DOM_NODE_HPP */
// 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.