FTXUI
6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
box.cpp
Go to the documentation of this file.
1
// 版權所有 2020 Arthur Sonzogni. 保留所有權利。
2
// 本原始碼的使用受 MIT 授權約束,詳見
3
// LICENSE 文件。
4
#include "
ftxui/screen/box.hpp
"
5
6
#include <algorithm>
7
8
namespace
ftxui
{
9
/// @return 包含在 |a| 和 |b| 中的最大 Box。
10
// static
11
Box
Box::Intersection
(
Box
a,
Box
b) {
12
return
Box
{
13
std::max(a.
x_min
, b.
x_min
),
14
std::min(a.
x_max
, b.
x_max
),
15
std::max(a.
y_min
, b.
y_min
),
16
std::min(a.
y_max
, b.
y_max
),
17
};
18
}
19
20
/// @return 包含 |a| 和 |b| 的最小 Box。
21
// static
22
Box
Box::Union
(
Box
a,
Box
b) {
23
return
Box
{
24
std::min(a.
x_min
, b.
x_min
),
25
std::max(a.
x_max
, b.
x_max
),
26
std::min(a.
y_min
, b.
y_min
),
27
std::max(a.
y_max
, b.
y_max
),
28
};
29
}
30
31
/// 將 Box 依據 (x,y) 進行位移。
32
/// @param x 水平位移。
33
/// @param y 垂直位移。
34
void
Box::Shift
(
int
x,
int
y) {
35
x_min
+= x;
36
x_max
+= x;
37
y_min
+= y;
38
y_max
+= y;
39
}
40
41
/// @return (x,y) 是否包含在 Box 內。
42
bool
Box::Contain
(
int
x,
int
y)
const
{
43
return
x_min
<= x &&
//
44
x_max
>= x &&
//
45
y_min
<= y &&
//
46
y_max
>= y;
47
}
48
49
/// @return Box 是否為空。
50
bool
Box::IsEmpty
()
const
{
51
return
x_min
>
x_max
||
y_min
>
y_max
;
52
}
53
54
/// @return |other| 是否與 |this| 相同。
55
bool
Box::operator==
(
const
Box
& other)
const
{
56
return
(
x_min
== other.
x_min
) && (
x_max
== other.
x_max
) &&
57
(
y_min
== other.
y_min
) && (
y_max
== other.
y_max
);
58
}
59
60
/// @return |other| 和 |this| 是否不同。
61
bool
Box::operator!=
(
const
Box
& other)
const
{
62
return
!
operator==
(other);
63
}
64
65
}
// namespace ftxui
box.hpp
ftxui::Box::operator!=
bool operator!=(const Box &other) const
Definition
box.cpp:61
ftxui::Box::Contain
bool Contain(int x, int y) const
Definition
box.cpp:42
ftxui::Box::Shift
void Shift(int x, int y)
Definition
box.cpp:34
ftxui::Box::x_max
int x_max
Definition
box.hpp:16
ftxui::Box::y_min
int y_min
Definition
box.hpp:17
ftxui::Box::Intersection
static auto Intersection(Box a, Box b) -> Box
Definition
box.cpp:11
ftxui::Box::IsEmpty
bool IsEmpty() const
Definition
box.cpp:50
ftxui::Box::y_max
int y_max
Definition
box.hpp:18
ftxui::Box::operator==
bool operator==(const Box &other) const
Definition
box.cpp:55
ftxui::Box::Union
static auto Union(Box a, Box b) -> Box
Definition
box.cpp:22
ftxui::Box::x_min
int x_min
Definition
box.hpp:15
ftxui::Box
Box 是一個表示二維空間中矩形區域的結構。
Definition
box.hpp:14
ftxui
FTXUI 的 ftxui:: 命名空間
Definition
animation.hpp:10