Added a option to set the style of the selection

This commit is contained in:
Clement Roblot
2024-12-02 19:34:27 +07:00
committed by ArthurSonzogni
parent d62dc6e305
commit cbd28403af
6 changed files with 63 additions and 20 deletions

View File

@@ -5,15 +5,33 @@
#ifndef FTXUI_DOM_SELECTION_HPP
#define FTXUI_DOM_SELECTION_HPP
#include <functional>
#include "ftxui/screen/box.hpp" // for Box
#include "ftxui/screen/pixel.hpp" // for Pixel
namespace ftxui {
/// @brief Option for the selection of content.
/// @ingroup component
struct SelectionOption {
/// @brief Selection is simply inverted:
static SelectionOption Simple();
// Style:
std::function<void(Pixel& pixel)> transform ;
// Observers:
/// Called when the selection changed.
std::function<void()> on_change = [] {};
};
/// @brief Represent a selection in the terminal.
class Selection {
public:
Selection(int start_x, int start_y, int end_x, int end_y);
Selection(int start_x, int start_y, int end_x, int end_y, SelectionOption option = SelectionOption::Simple());
const Box& GetBox() const;
const SelectionOption& GetOption() const;
Selection SaturateHorizontal(Box box);
Selection SaturateVertical(Box box);
@@ -25,6 +43,7 @@ class Selection {
const int end_x_;
const int end_y_;
const Box box_;
const SelectionOption option;
};
} // namespace ftxui