FTXUI
5.0.0
C++ functional terminal UI.
Loading...
Searching...
No Matches
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.
4
#include "
ftxui/screen/box.hpp
"
5
6
#include <algorithm>
7
8
namespace
ftxui
{
9
/// @return the biggest Box contained in both |a| and |b|.
10
/// @ingroup screen
11
// static
12
Box
Box::Intersection
(
Box
a,
Box
b) {
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
24
Box
Box::Union
(
Box
a,
Box
b) {
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
35
bool
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 the box is empty.
43
/// @ingroup screen
44
bool
Box::IsEmpty
()
const
{
45
return
x_min
>
x_max
||
y_min
>
y_max
;
46
}
47
48
/// @return whether |other| is the same as |this|
49
/// @ingroup screen
50
bool
Box::operator==
(
const
Box
&
other
)
const
{
51
return
(
x_min
==
other
.x_min) && (
x_max
==
other
.x_max) &&
52
(
y_min
==
other
.y_min) && (
y_max
==
other
.y_max);
53
}
54
55
/// @return whether |other| and |this| are different.
56
/// @ingroup screen
57
bool
Box::operator!=
(
const
Box
&
other
)
const
{
58
return
!
operator==
(
other
);
59
}
60
61
}
// namespace ftxui
box.hpp
ftxui
Definition
animation.hpp:10
ftxui::Make
std::shared_ptr< T > Make(Args &&... args)
Definition
component.hpp:26
ftxui::Box
Definition
box.hpp:9
ftxui::Box::operator!=
bool operator!=(const Box &other) const
Definition
box.cpp:57
ftxui::Box::Contain
bool Contain(int x, int y) const
Definition
box.cpp:35
ftxui::Box::x_max
int x_max
Definition
box.hpp:11
ftxui::Box::y_min
int y_min
Definition
box.hpp:12
ftxui::Box::Intersection
static auto Intersection(Box a, Box b) -> Box
Definition
box.cpp:12
ftxui::Box::IsEmpty
bool IsEmpty() const
Definition
box.cpp:44
ftxui::Box::y_max
int y_max
Definition
box.hpp:13
ftxui::Box::operator==
bool operator==(const Box &other) const
Definition
box.cpp:50
ftxui::Box::Union
static auto Union(Box a, Box b) -> Box
Definition
box.cpp:24
ftxui::Box::x_min
int x_min
Definition
box.hpp:10