Add recursive selection style.

This commit is contained in:
ArthurSonzogni
2024-12-22 17:19:50 +01:00
parent d755ab31f1
commit 9f9effa683
12 changed files with 70 additions and 218 deletions

View File

@@ -113,7 +113,11 @@ Decorator focusPositionRelative(float x, float y);
Element automerge(Element child);
Decorator hyperlink(std::string link);
Element hyperlink(std::string link, Element child);
Element unselectable(Element child);
Element selectionStyleReset(Element);
Decorator selectionColor(Color foreground);
Decorator selectionBackgroundColor(Color foreground);
Decorator selectionForegroundColor(Color foreground);
Decorator selectionStyle(std::function<void(Pixel&)> style);
// --- Layout is
// Horizontal, Vertical or stacked set of elements.

View File

@@ -7,34 +7,16 @@
#include <functional>
#include "ftxui/screen/box.hpp" // for Box
#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 = [](Pixel& pixel) {
pixel.inverted = true;
};
// 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, SelectionOption option = SelectionOption::Simple());
Selection(int start_x, int start_y, int end_x, int end_y);
const Box& GetBox() const;
const SelectionOption& GetOption() const;
Selection SaturateHorizontal(Box box);
Selection SaturateVertical(Box box);
@@ -46,7 +28,6 @@ class Selection {
const int end_x_;
const int end_y_;
const Box box_;
const SelectionOption option;
};
} // namespace ftxui