FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
surface.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 <sstream> // IWYU pragma: keep
5#include <string>
6#include <vector>
7
10
11namespace ftxui {
12
13namespace {
14Cell& dev_null_cell() {
15 static Cell cell;
16 return cell;
17}
18} // namespace
19
20Surface::Surface(int dimx, int dimy)
21 : stencil{0, dimx - 1, 0, dimy - 1},
22 dimx_(dimx),
23 dimy_(dimy),
24 cells_(dimy, std::vector<Cell>(dimx)) {}
25
26/// @brief Access a character in a cell at a given position.
27/// @param x The cell position along the x-axis.
28/// @param y The cell position along the y-axis.
29std::string& Surface::at(int x, int y) {
30 return CellAt(x, y).character;
31}
32
33/// @brief Access a character in a cell at a given position.
34/// @param x The cell position along the x-axis.
35/// @param y The cell position along the y-axis.
36const std::string& Surface::at(int x, int y) const {
37 return CellAt(x, y).character;
38}
39
40/// @brief Access a cell (Cell) at a given position.
41/// @param x The cell position along the x-axis.
42/// @param y The cell position along the y-axis.
43Cell& Surface::CellAt(int x, int y) {
44 return stencil.Contain(x, y) ? cells_[y][x] : dev_null_cell();
45}
46
47/// @brief Access a cell (Cell) at a given position.
48/// @param x The cell position along the x-axis.
49/// @param y The cell position along the y-axis.
50const Cell& Surface::CellAt(int x, int y) const {
51 return stencil.Contain(x, y) ? cells_[y][x] : dev_null_cell();
52}
53
54/// @brief Clear all the cells from the surface.
56 for (auto& line : cells_) {
57 for (auto& cell : line) {
58 cell = Cell();
59 }
60 }
61}
62
63} // namespace ftxui
bool Contain(int x, int y) const
Definition box.cpp:42
std::string character
Definition cell.hpp:45
std::string & at(int x, int y)
Access a character in a cell at a given position.
Definition surface.cpp:29
Cell & CellAt(int x, int y)
Access a cell (Cell) at a given position.
Definition surface.cpp:43
void Clear()
Clear all the cells from the surface.
Definition surface.cpp:55
std::vector< std::vector< Cell > > cells_
Definition surface.hpp:50
Surface()=delete
A Unicode character and its associated style.
Definition cell.hpp:15
The FTXUI ftxui:: namespace.
Definition animation.hpp:10