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/pixel.hpp" // for Pixel
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 // Propagate the focused requirement.
29 if (requirement_.focused.Prefer(child->requirement().focused)) {
30 requirement_.focused = child->requirement().focused;
31 }
32
33 // Extend the min_x and min_y to contain all the children
34 requirement_.min_x =
35 std::max(requirement_.min_x, child->requirement().min_x);
36 requirement_.min_y =
37 std::max(requirement_.min_y, child->requirement().min_y);
38 }
39 }
40
41 void SetBox(Box box) override {
42 Node::SetBox(box);
43
44 for (auto& child : children_) {
45 child->SetBox(box);
46 }
47 }
48};
49} // namespace
50
51/// @brief Stack several element on top of each other.
52/// @param children_ The input element.
53/// @return The right aligned element.
54/// @ingroup dom
55Element dbox(Elements children_) {
56 return std::make_shared<DBox>(std::move(children_));
57}
58
59} // 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:22
std::vector< Element > Elements
Definition elements.hpp:23