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 <memory> // for __shared_ptr_access, shared_ptr, make_shared
6#include <utility> // for move
7
8#include "ftxui/dom/elements.hpp" // for Element, dbox
9
10#include "ftxui/dom/node.hpp" // for Node, Elements
11#include "ftxui/dom/requirement.hpp" // for Requirement
12#include "ftxui/screen/box.hpp" // for Box
13
14namespace ftxui {
15
16namespace {
17class DBox : public Node {
18 public:
19 explicit DBox(Elements children) : Node(std::move(children)) {}
20
21 void ComputeRequirement() override {
22 requirement_ = Requirement{};
23 for (auto& child : children_) {
24 child->ComputeRequirement();
25
26 // Extend the min_x and min_y to contain all the children
27 requirement_.min_x =
28 std::max(requirement_.min_x, child->requirement().min_x);
29 requirement_.min_y =
30 std::max(requirement_.min_y, child->requirement().min_y);
31 }
32
33 // Propagate the focused requirement.
34 // We iterate in reverse order because children are rendered from first to
35 // last, meaning the last child is on top of the others. We want the
36 // top-most child to be prioritized for focus.
37 for (auto it = children_.rbegin(); it != children_.rend(); ++it) {
38 auto& child = *it;
39 if (requirement_.focused.Prefer(child->requirement().focused)) {
40 requirement_.focused = child->requirement().focused;
41 }
42 }
43 }
44
45 void SetBox(Box box) override {
46 Node::SetBox(box);
47
48 for (auto& child : children_) {
49 child->SetBox(box);
50 }
51 }
52};
53} // namespace
54
55/// @brief Stack several element on top of each other.
56/// @param children_ The input elements.
57/// @return The right aligned element.
58/// @ingroup dom
59Element dbox(Elements children_) {
60 return std::make_shared<DBox>(std::move(children_));
61}
62
63} // 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