FTXUI 6.1.9
C++ functional terminal UI.
载入中...
搜索中...
未找到
image.cpp
浏览该文件的文档.
1// Copyright 2020 Arthur Sonzogni. All rights reserved.
2// 本源代码受 MIT 许可证的约束,该许可证可在 LICENSE 文件中找到。
3#include <sstream> // IWYU pragma: keep
4#include <string>
5#include <vector>
6
9
10namespace ftxui {
11
12namespace {
13Pixel& dev_null_pixel() {
14 static Pixel pixel;
15 return pixel;
16}
17} // namespace
18
19Image::Image(int dimx, int dimy)
20 : stencil{0, dimx - 1, 0, dimy - 1},
21 dimx_(dimx),
22 dimy_(dimy),
23 pixels_(dimy, std::vector<Pixel>(dimx)) {}
24
25/// @brief 访问给定位置单元格中的字符。
26/// @param x 沿 x 轴的单元格位置。
27/// @param y 沿 y 轴的单元格位置。
28std::string& Image::at(int x, int y) {
29 return PixelAt(x, y).character;
30}
31
32/// @brief 访问给定位置单元格中的字符。
33/// @param x 沿 x 轴的单元格位置。
34/// @param y 沿 y 轴的单元格位置。
35const std::string& Image::at(int x, int y) const {
36 return PixelAt(x, y).character;
37}
38
39/// @brief 访问给定位置的单元格 (Pixel)。
40/// @param x 沿 x 轴的单元格位置。
41/// @param y 沿 y 轴的单元格位置。
42Pixel& Image::PixelAt(int x, int y) {
43 return stencil.Contain(x, y) ? pixels_[y][x] : dev_null_pixel();
44}
45
46/// @brief 访问给定位置的单元格 (Pixel)。
47/// @param x 沿 x 轴的单元格位置。
48/// @param y 沿 y 轴的单元格位置。
49const Pixel& Image::PixelAt(int x, int y) const {
50 return stencil.Contain(x, y) ? pixels_[y][x] : dev_null_pixel();
51}
52
53/// @brief 清除屏幕上的所有像素。
55 for (auto& line : pixels_) {
56 for (auto& cell : line) {
57 cell = Pixel();
58 }
59 }
60}
61
62} // namespace ftxui
bool Contain(int x, int y) const
定义 box.cpp:42
std::string character
Pixel & PixelAt(int x, int y)
访问给定位置的单元格 (Pixel)。
std::string & at(int x, int y)
访问给定位置单元格中的字符。
Image()=delete
void Clear()
清除屏幕上的所有像素。
std::vector< std::vector< Pixel > > pixels_
一个 Unicode 字符及其相关样式。
#include "ftxui/component/component_base.hpp" // 用于 ComponentBase