FTXUI  5.0.0
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
14namespace ftxui {
15
16/// @brief Represent a selection in the terminal.
17class Selection {
18 public:
19 Selection(); // Empty selection.
20 Selection(int start_x, int start_y, int end_x, int end_y);
21
22 const Box& GetBox() const;
23
26 bool IsEmpty() const { return empty_; }
27
28 void AddPart(const std::string& part, int y, int left, int right);
29 std::string GetParts() { return parts_.str(); }
30
31 private:
32 Selection(int start_x, int start_y, int end_x, int end_y, Selection* parent);
33
34 const int start_x_ = 0;
35 const int start_y_ = 0;
36 const int end_x_ = 0;
37 const int end_y_ = 0;
38 const Box box_ = {};
39 Selection* const parent_ = this;
40 const bool empty_ = true;
41 std::stringstream parts_;
42
43 // The position of the last inserted part.
44 int x_ = 0;
45 int y_ = 0;
46};
47
48} // namespace ftxui
49
50#endif /* end of include guard: FTXUI_DOM_SELECTION_HPP */
Represent a selection in the terminal.
Definition selection.hpp:17
const Box & GetBox() const
Get the box of the selection.
Definition selection.cpp:65
std::string GetParts()
Definition selection.hpp:29
bool IsEmpty() const
Definition selection.hpp:26
void AddPart(const std::string &part, int y, int left, int right)
Selection SaturateVertical(Box box)
Saturate the selection to be inside the box. This is called by vbox to propagate the selection to its...
Selection()
Create an empty selection.
Definition selection.cpp:25
Selection SaturateHorizontal(Box box)
Saturate the selection to be inside the box. This is called by hbox to propagate the selection to its...
Definition selection.cpp:73
std::shared_ptr< T > Make(Args &&... args)
Definition component.hpp:26