FTXUI  5.0.0
C++ functional terminal UI.
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/// @return whether (x,y) is contained inside the box.
34/// @ingroup screen
35bool Box::Contain(int x, int y) const {
36 return x_min <= x && //
37 x_max >= x && //
38 y_min <= y && //
39 y_max >= y;
40}
41
42/// @return whether |other| is the same as |this|
43/// @ingroup screen
44bool Box::operator==(const Box& other) const {
45 return (x_min == other.x_min) && (x_max == other.x_max) &&
46 (y_min == other.y_min) && (y_max == other.y_max);
47}
48
49/// @return whether |other| and |this| are different.
50/// @ingroup screen
51bool Box::operator!=(const Box& other) const {
52 return !operator==(other);
53}
54
55} // namespace ftxui
bool operator!=(const Box &other) const
Definition: box.cpp:51
bool Contain(int x, int y) const
Definition: box.cpp:35
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
int y_max
Definition: box.hpp:13
bool operator==(const Box &other) const
Definition: box.cpp:44
static auto Union(Box a, Box b) -> Box
Definition: box.cpp:24
int x_min
Definition: box.hpp:10