2023-08-19 19:56:36 +08:00
|
|
|
// 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.
|
2019-01-07 00:10:35 +08:00
|
|
|
#ifndef FTXUI_DOM_NODE_HPP
|
|
|
|
#define FTXUI_DOM_NODE_HPP
|
2018-09-18 14:48:40 +08:00
|
|
|
|
2021-05-02 02:40:35 +08:00
|
|
|
#include <memory> // for shared_ptr
|
|
|
|
#include <vector> // for vector
|
2018-09-18 14:48:40 +08:00
|
|
|
|
2021-05-02 02:40:35 +08:00
|
|
|
#include "ftxui/dom/requirement.hpp" // for Requirement
|
|
|
|
#include "ftxui/screen/box.hpp" // for Box
|
2019-01-07 00:10:35 +08:00
|
|
|
#include "ftxui/screen/screen.hpp"
|
2018-09-18 14:48:40 +08:00
|
|
|
|
2019-01-12 22:00:08 +08:00
|
|
|
namespace ftxui {
|
2018-09-18 14:48:40 +08:00
|
|
|
|
2020-05-25 07:34:13 +08:00
|
|
|
class Node;
|
2021-05-02 02:40:35 +08:00
|
|
|
class Screen;
|
|
|
|
|
2020-05-21 02:36:47 +08:00
|
|
|
using Element = std::shared_ptr<Node>;
|
2021-07-17 18:02:08 +08:00
|
|
|
using Elements = std::vector<Element>;
|
2020-05-21 02:36:47 +08:00
|
|
|
|
2018-09-18 14:48:40 +08:00
|
|
|
class Node {
|
|
|
|
public:
|
|
|
|
Node();
|
2020-05-21 02:36:47 +08:00
|
|
|
Node(Elements children);
|
2022-03-31 08:17:43 +08:00
|
|
|
Node(const Node&) = delete;
|
|
|
|
Node(const Node&&) = delete;
|
|
|
|
Node& operator=(const Node&) = delete;
|
|
|
|
Node& operator=(const Node&&) = delete;
|
|
|
|
|
2018-09-18 14:48:40 +08:00
|
|
|
virtual ~Node();
|
|
|
|
|
2019-01-03 05:33:59 +08:00
|
|
|
// Step 1: Compute layout requirement. Tell parent what dimensions this
|
2018-09-18 14:48:40 +08:00
|
|
|
// element wants to be.
|
2019-01-03 05:33:59 +08:00
|
|
|
// Propagated from Children to Parents.
|
2018-09-18 14:48:40 +08:00
|
|
|
virtual void ComputeRequirement();
|
|
|
|
Requirement requirement() { return requirement_; }
|
|
|
|
|
2019-01-03 05:33:59 +08:00
|
|
|
// Step 2: Assign this element its final dimensions.
|
|
|
|
// Propagated from Parents to Children.
|
2018-09-18 14:48:40 +08:00
|
|
|
virtual void SetBox(Box box);
|
|
|
|
|
|
|
|
// Step 3: Draw this element.
|
2019-01-12 22:00:08 +08:00
|
|
|
virtual void Render(Screen& screen);
|
2018-09-18 14:48:40 +08:00
|
|
|
|
2021-12-12 00:58:25 +08:00
|
|
|
// Layout may not resolve within a single iteration for some elements. This
|
|
|
|
// allows them to request additionnal iterations. This signal must be
|
|
|
|
// forwarded to children at least once.
|
|
|
|
struct Status {
|
|
|
|
int iteration = 0;
|
|
|
|
bool need_iteration = false;
|
|
|
|
};
|
|
|
|
virtual void Check(Status* status);
|
|
|
|
|
2018-09-18 14:48:40 +08:00
|
|
|
protected:
|
2021-07-20 15:59:47 +08:00
|
|
|
Elements children_;
|
2018-09-18 14:48:40 +08:00
|
|
|
Requirement requirement_;
|
|
|
|
Box box_;
|
|
|
|
};
|
|
|
|
|
2022-03-31 08:17:43 +08:00
|
|
|
void Render(Screen& screen, const Element& element);
|
2019-01-12 22:00:08 +08:00
|
|
|
void Render(Screen& screen, Node* node);
|
2018-09-18 14:48:40 +08:00
|
|
|
|
2020-02-12 04:44:55 +08:00
|
|
|
} // namespace ftxui
|
2018-09-18 14:48:40 +08:00
|
|
|
|
2022-03-31 08:17:43 +08:00
|
|
|
#endif // FTXUI_DOM_NODE_HPP
|