mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-12-16 01:48:56 +08:00
Add recursive selection style.
This commit is contained in:
@@ -71,7 +71,6 @@ class ScreenInteractive : public Screen {
|
||||
|
||||
// Selection API.
|
||||
std::string GetSelectedContent(Component component);
|
||||
void setSelectionOptions(SelectionOption option);
|
||||
|
||||
private:
|
||||
void ExitNow();
|
||||
@@ -137,14 +136,12 @@ class ScreenInteractive : public Screen {
|
||||
int cursor_reset_shape_ = 1;
|
||||
|
||||
// Selection API:
|
||||
bool selection_enabled_ = false;
|
||||
CapturedMouse selection_pending_;
|
||||
int selection_start_x_ = 0;
|
||||
int selection_start_y_ = 0;
|
||||
int selection_end_x_ = 0;
|
||||
int selection_end_y_ = 0;
|
||||
bool selection_changed = false;
|
||||
SelectionOption selection_options_ = SelectionOption::Simple();
|
||||
|
||||
friend class Loop;
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -4,12 +4,14 @@
|
||||
#ifndef FTXUI_SCREEN_SCREEN_HPP
|
||||
#define FTXUI_SCREEN_SCREEN_HPP
|
||||
|
||||
#include <cstdint> // for uint8_t
|
||||
#include <string> // for string, basic_string, allocator
|
||||
#include <vector> // for vector
|
||||
#include <cstdint> // for uint8_t
|
||||
#include <functional> // for function
|
||||
#include <string> // for string, basic_string, allocator
|
||||
#include <vector> // for vector
|
||||
|
||||
#include "ftxui/screen/image.hpp" // for Pixel, Image
|
||||
#include "ftxui/screen/terminal.hpp" // for Dimensions
|
||||
#include "ftxui/util/autoreset.hpp" // for AutoReset
|
||||
|
||||
namespace ftxui {
|
||||
|
||||
@@ -67,9 +69,18 @@ class Screen : public Image {
|
||||
uint8_t RegisterHyperlink(const std::string& link);
|
||||
const std::string& Hyperlink(uint8_t id) const;
|
||||
|
||||
using SelectionStyle = std::function<void(Pixel&)>;
|
||||
const SelectionStyle& GetSelectionStyle() const;
|
||||
void SetSelectionStyle(SelectionStyle decorator);
|
||||
|
||||
protected:
|
||||
Cursor cursor_;
|
||||
std::vector<std::string> hyperlinks_ = {""};
|
||||
|
||||
// The current selection style. This is overridden by various dom elements.
|
||||
SelectionStyle selection_style_ = [](Pixel& pixel) {
|
||||
pixel.inverted ^= true;
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace ftxui
|
||||
|
||||
Reference in New Issue
Block a user