mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-12-16 01:48:56 +08:00
Added a option to set the style of the selection
This commit is contained in:
committed by
ArthurSonzogni
parent
d62dc6e305
commit
cbd28403af
@@ -15,6 +15,7 @@
|
||||
#include "ftxui/component/animation.hpp" // for TimePoint
|
||||
#include "ftxui/component/captured_mouse.hpp" // for CapturedMouse
|
||||
#include "ftxui/component/event.hpp" // for Event
|
||||
#include "ftxui/dom/selection.hpp" // for SelectionOption
|
||||
#include "ftxui/component/task.hpp" // for Task, Closure
|
||||
#include "ftxui/screen/screen.hpp" // for Screen
|
||||
|
||||
@@ -70,7 +71,7 @@ class ScreenInteractive : public Screen {
|
||||
|
||||
// Selection API.
|
||||
std::string GetSelectedContent(Component component);
|
||||
void onSelectionModified(std::function<void(void)> callback);
|
||||
void setSelectionOptions(SelectionOption option);
|
||||
|
||||
private:
|
||||
void ExitNow();
|
||||
@@ -143,7 +144,7 @@ class ScreenInteractive : public Screen {
|
||||
int selection_end_x_ = 0;
|
||||
int selection_end_y_ = 0;
|
||||
bool selection_changed = false;
|
||||
std::function<void(void)> selection_changed_callback_ = nullptr;
|
||||
SelectionOption selection_options_ = SelectionOption::Simple();
|
||||
|
||||
friend class Loop;
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user