FTXUI 6.1.9 C++ functional terminal UI.

Loading...
Searching...
No Matches
selection.hpp
Go to the documentation of this file.
1// Copyright 2024 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
5#ifndef FTXUI_DOM_SELECTION_HPP
6#define FTXUI_DOM_SELECTION_HPP
7
8#include <functional>
9
10#include <sstream>
11#include "ftxui/screen/box.hpp" // for Box
12#include "ftxui/screen/pixel.hpp" // for Pixel
13
14 namespace ftxui {
15
16/// @brief Represents a selection in a terminal user interface.
17///
18/// Selection is a class that represents the two endpoints of a selection in a
19/// terminal user interface.
20///
21/// @ingroup dom
22 class Selection {
23 public:
24 Selection(); // Empty selection.
25 Selection(int start_x, int start_y, int end_x, int end_y);
26
27 const Box& GetBox() const;
28
29 Selection SaturateHorizontal(Box box);
30 Selection SaturateVertical(Box box);
31 bool IsEmpty() const { return empty_; }
32
33 void AddPart(const std::string& part, int y, int left, int right);
34 std::string GetParts() { return parts_.str(); }
35
36 private:
37 Selection(int start_x, int start_y, int end_x, int end_y, Selection* parent);
38
39 const int start_x_ = 0;
40 const int start_y_ = 0;
41 const int end_x_ = 0;
42 const int end_y_ = 0;
43 const Box box_ = {};
44 Selection* const parent_ = this;
45 const bool empty_ = true;
46 std::stringstream parts_;
47
48 // The position of the last inserted part.
49 int x_ = 0;
50 int y_ = 0;
51};
52
53} // namespace ftxui
54
55#endif /* end of include guard: FTXUI_DOM_SELECTION_HPP */
box.hpp
ftxui::Selection::GetBox
const Box & GetBox() const
Get the box of the selection.
Definition src/ftxui/dom/selection.cpp:67
ftxui::Selection::GetParts
std::string GetParts()
Definition selection.hpp:34
ftxui::Selection::IsEmpty
bool IsEmpty() const
Definition selection.hpp:31
ftxui::Selection::AddPart
void AddPart(const std::string &part, int y, int left, int right)
Definition src/ftxui/dom/selection.cpp:146
ftxui::Selection::SaturateVertical
Selection SaturateVertical(Box box)
Saturate the selection to be inside the box. This is called by vbox to propagate the selection to its...
Definition src/ftxui/dom/selection.cpp:113
ftxui::Selection::Selection
Selection()
Create an empty selection.
ftxui::Selection::SaturateHorizontal
Selection SaturateHorizontal(Box box)
Saturate the selection to be inside the box. This is called by hbox to propagate the selection to its...
Definition src/ftxui/dom/selection.cpp:75
ftxui::Selection
Represents a selection in a terminal user interface.
Definition selection.hpp:22
ftxui::Box
Box is a structure that represents a rectangular area in a 2D space.
Definition box.hpp:16
ftxui
The FTXUI ftxui:: namespace.
Definition animation.hpp:10
pixel.hpp
left
std::uint8_t left
Definition screen.cpp:129
right
std::uint8_t right
Definition screen.cpp:131