FTXUI  6.0.2
C++ functional terminal UI.
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
box.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.
5
6#include <algorithm>
7
8namespace ftxui {
9/// @return the biggest Box contained in both |a| and |b|.
10/// @ingroup screen
11// static
13 return Box{
14 std::max(a.x_min, b.x_min),
15 std::min(a.x_max, b.x_max),
16 std::max(a.y_min, b.y_min),
17 std::min(a.y_max, b.y_max),
18 };
19}
20
21/// @return the smallest Box containing both |a| and |b|.
22/// @ingroup screen
23// static
25 return Box{
26 std::min(a.x_min, b.x_min),
27 std::max(a.x_max, b.x_max),
28 std::min(a.y_min, b.y_min),
29 std::max(a.y_max, b.y_max),
30 };
31}
32
33/// Shift the box by (x,y).
34/// @param x horizontal shift.
35/// @param y vertical shift.
36/// @ingroup screen
37void Box::Shift(int x, int y) {
38 x_min += x;
39 x_max += x;
40 y_min += y;
41 y_max += y;
42}
43
44/// @return whether (x,y) is contained inside the box.
45/// @ingroup screen
46bool Box::Contain(int x, int y) const {
47 return x_min <= x && //
48 x_max >= x && //
49 y_min <= y && //
50 y_max >= y;
51}
52
53/// @return whether the box is empty.
54/// @ingroup screen
55bool Box::IsEmpty() const {
56 return x_min > x_max || y_min > y_max;
57}
58
59/// @return whether |other| is the same as |this|
60/// @ingroup screen
61bool Box::operator==(const Box& other) const {
62 return (x_min == other.x_min) && (x_max == other.x_max) &&
63 (y_min == other.y_min) && (y_max == other.y_max);
64}
65
66/// @return whether |other| and |this| are different.
67/// @ingroup screen
68bool Box::operator!=(const Box& other) const {
69 return !operator==(other);
70}
71
72} // namespace ftxui
std::shared_ptr< T > Make(Args &&... args)
Definition component.hpp:26
bool operator!=(const Box &other) const
Definition box.cpp:68
bool Contain(int x, int y) const
Definition box.cpp:46
void Shift(int x, int y)
Definition box.cpp:37
int x_max
Definition box.hpp:11
int y_min
Definition box.hpp:12
static auto Intersection(Box a, Box b) -> Box
Definition box.cpp:12
bool IsEmpty() const
Definition box.cpp:55
int y_max
Definition box.hpp:13
bool operator==(const Box &other) const
Definition box.cpp:61
static auto Union(Box a, Box b) -> Box
Definition box.cpp:24
int x_min
Definition box.hpp:10