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.
|
2021-05-02 02:40:35 +08:00
|
|
|
|
2021-05-10 02:32:27 +08:00
|
|
|
#include <utility> // for move
|
|
|
|
|
|
|
|
#include "ftxui/dom/elements.hpp" // for Element, filler, operator|, hbox, flex_grow, vbox, xflex_grow, yflex_grow, align_right, center, hcenter, vcenter
|
2018-09-20 03:52:25 +08:00
|
|
|
|
2019-01-12 22:00:08 +08:00
|
|
|
namespace ftxui {
|
2018-09-20 03:52:25 +08:00
|
|
|
|
2020-05-25 07:34:13 +08:00
|
|
|
/// @brief Center an element horizontally.
|
2021-07-10 20:23:46 +08:00
|
|
|
/// @param child The decorated element.
|
2020-05-25 07:34:13 +08:00
|
|
|
/// @return The centered element.
|
|
|
|
/// @ingroup dom
|
2020-05-21 02:36:47 +08:00
|
|
|
Element hcenter(Element child) {
|
2021-10-16 05:04:11 +08:00
|
|
|
return hbox(filler(), std::move(child), filler());
|
2018-09-20 03:52:25 +08:00
|
|
|
}
|
|
|
|
|
2020-05-25 07:34:13 +08:00
|
|
|
/// @brief Center an element vertically.
|
2021-07-10 20:23:46 +08:00
|
|
|
/// @param child The decorated element.
|
2020-05-25 07:34:13 +08:00
|
|
|
/// @return The centered element.
|
|
|
|
/// @ingroup dom
|
2020-05-21 02:36:47 +08:00
|
|
|
Element vcenter(Element child) {
|
2021-10-16 05:04:11 +08:00
|
|
|
return vbox(filler(), std::move(child), filler());
|
2018-09-20 03:52:25 +08:00
|
|
|
}
|
|
|
|
|
2020-05-25 07:34:13 +08:00
|
|
|
/// @brief Center an element horizontally and vertically.
|
2021-07-10 20:23:46 +08:00
|
|
|
/// @param child The decorated element.
|
2020-05-25 07:34:13 +08:00
|
|
|
/// @return The centered element.
|
|
|
|
/// @ingroup dom
|
2020-05-21 02:36:47 +08:00
|
|
|
Element center(Element child) {
|
2021-10-16 05:04:11 +08:00
|
|
|
return hcenter(vcenter(std::move(child)));
|
2018-09-20 03:52:25 +08:00
|
|
|
}
|
|
|
|
|
2020-05-25 07:34:13 +08:00
|
|
|
/// @brief Align an element on the right side.
|
2021-07-10 20:23:46 +08:00
|
|
|
/// @param child The decorated element.
|
2020-05-25 07:34:13 +08:00
|
|
|
/// @return The right aligned element.
|
|
|
|
/// @ingroup dom
|
2020-05-21 02:36:47 +08:00
|
|
|
Element align_right(Element child) {
|
2021-10-16 05:04:11 +08:00
|
|
|
return hbox(filler(), std::move(child));
|
2019-01-07 01:53:02 +08:00
|
|
|
}
|
|
|
|
|
2020-03-23 05:32:44 +08:00
|
|
|
} // namespace ftxui
|