FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
src/ftxui/dom/dbox.cpp
Go to the documentation of this file.
1// Copyright 2020 Arthur Sonzogni. All rights reserved.
2// Use of this source code is governed by the MIT license that can be found in
3// the LICENSE file.
4#include <algorithm> // for max
5#include <cstddef> // for size_t
6#include <memory> // for __shared_ptr_access, shared_ptr, make_shared
7#include <utility> // for move
8#include <vector>
9
10#include "ftxui/dom/elements.hpp" // for Element, Elements, dbox
11#include "ftxui/dom/node.hpp" // for Node, Elements
12#include "ftxui/dom/requirement.hpp" // for Requirement
13#include "ftxui/screen/box.hpp" // for Box
14#include "ftxui/screen/cell.hpp" // for Cell
15
16namespace ftxui {
17
18namespace {
19class DBox : public Node {
20 public:
21 explicit DBox(Elements children) : Node(std::move(children)) {}
22
23 void ComputeRequirement() override {
24 requirement_ = Requirement{};
25 for (auto& child : children_) {
26 child->ComputeRequirement();
27
28 // Extend the min_x and min_y to contain all the children
29 requirement_.min_x =
30 std::max(requirement_.min_x, child->requirement().min_x);
31 requirement_.min_y =
32 std::max(requirement_.min_y, child->requirement().min_y);
33 }
34
35 // Propagate the focused requirement.
36 // We iterate in reverse order because children are rendered from first to
37 // last, meaning the last child is on top of the others. We want the
38 // top-most child to be prioritized for focus.
39 for (auto it = children_.rbegin(); it != children_.rend(); ++it) {
40 auto& child = *it;
41 if (requirement_.focused.Prefer(child->requirement().focused)) {
42 requirement_.focused = child->requirement().focused;
43 }
44 }
45 }
46
47 void SetBox(Box box) override {
48 Node::SetBox(box);
49
50 for (auto& child : children_) {
51 child->SetBox(box);
52 }
53 }
54};
55} // namespace
56
57/// @brief Stack several element on top of each other.
58/// @param children_ The input element.
59/// @return The right aligned element.
60/// @ingroup dom
61Element dbox(Elements children_) {
62 return std::make_shared<DBox>(std::move(children_));
63}
64
65} // namespace ftxui
virtual void SetBox(Box box)
Assign a position and a dimension to an element for drawing.
Definition node.cpp:41
Element dbox(Elements)
Stack several element on top of each other.
The FTXUI ftxui:: namespace.
Definition animation.hpp:10
std::shared_ptr< Node > Element
Definition elements.hpp:23
std::vector< Element > Elements
Definition elements.hpp:24