mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2024-11-26 04:31:34 +08:00
21d746e858
From CppCoreGuidelines: Rule of Zero: C.20: If you can avoid defining default operations, do. C.52: Use inheriting constructors to import constructors into a derived class that does not need further explicit initialization. DRY forward and using declarations. Miscellaneous: Fix format.sh to output examples with normalised paths in sorted order. Co-authored-by: ArthurSonzogni <sonzogniarthur@gmail.com>
59 lines
1.7 KiB
C++
59 lines
1.7 KiB
C++
#include <algorithm> // for max
|
|
#include <memory> // for __shared_ptr_access, shared_ptr, make_shared
|
|
#include <utility> // for move
|
|
#include <vector> // for vector
|
|
|
|
#include "ftxui/dom/elements.hpp" // for Element, Elements, dbox
|
|
#include "ftxui/dom/node.hpp" // for Node
|
|
#include "ftxui/dom/requirement.hpp" // for Requirement
|
|
#include "ftxui/screen/box.hpp" // for Box
|
|
|
|
namespace ftxui {
|
|
|
|
class DBox : public Node {
|
|
public:
|
|
DBox(Elements children) : Node(std::move(children)) {}
|
|
|
|
void ComputeRequirement() override {
|
|
requirement_.min_x = 0;
|
|
requirement_.min_y = 0;
|
|
requirement_.flex_grow_x = 0;
|
|
requirement_.flex_grow_y = 0;
|
|
requirement_.flex_shrink_x = 0;
|
|
requirement_.flex_shrink_y = 0;
|
|
for (auto& child : children_) {
|
|
child->ComputeRequirement();
|
|
requirement_.min_x =
|
|
std::max(requirement_.min_x, child->requirement().min_x);
|
|
requirement_.min_y =
|
|
std::max(requirement_.min_y, child->requirement().min_y);
|
|
|
|
if (requirement_.selection < child->requirement().selection) {
|
|
requirement_.selection = child->requirement().selection;
|
|
requirement_.selected_box = child->requirement().selected_box;
|
|
}
|
|
}
|
|
}
|
|
|
|
void SetBox(Box box) override {
|
|
Node::SetBox(box);
|
|
|
|
for (auto& child : children_)
|
|
child->SetBox(box);
|
|
}
|
|
};
|
|
|
|
/// @brief Stack several element on top of each other.
|
|
/// @param children_ The input element.
|
|
/// @return The right aligned element.
|
|
/// @ingroup dom
|
|
Element dbox(Elements children_) {
|
|
return std::make_shared<DBox>(std::move(children_));
|
|
}
|
|
|
|
} // namespace ftxui
|
|
|
|
// 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.
|