mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-08-11 02:46:39 +08:00
Make use of Box instead of my custom Region struct
This commit is contained in:
parent
b352e13253
commit
011b9a1426
@ -26,13 +26,6 @@ struct Event;
|
|||||||
using Component = std::shared_ptr<ComponentBase>;
|
using Component = std::shared_ptr<ComponentBase>;
|
||||||
class ScreenInteractivePrivate;
|
class ScreenInteractivePrivate;
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
uint16_t startx = 0;
|
|
||||||
uint16_t endx = 0;
|
|
||||||
uint16_t starty = 0;
|
|
||||||
uint16_t endy = 0;
|
|
||||||
} Region;
|
|
||||||
|
|
||||||
class ScreenInteractive : public Screen {
|
class ScreenInteractive : public Screen {
|
||||||
public:
|
public:
|
||||||
// Constructors:
|
// Constructors:
|
||||||
@ -137,11 +130,6 @@ class ScreenInteractive : public Screen {
|
|||||||
bool force_handle_ctrl_c_ = true;
|
bool force_handle_ctrl_c_ = true;
|
||||||
bool force_handle_ctrl_z_ = true;
|
bool force_handle_ctrl_z_ = true;
|
||||||
|
|
||||||
bool selection_enabled = false;
|
|
||||||
CapturedMouse selection_pending;
|
|
||||||
Region selection_region;
|
|
||||||
std::string selection_text;
|
|
||||||
|
|
||||||
// The style of the cursor to restore on exit.
|
// The style of the cursor to restore on exit.
|
||||||
int cursor_reset_shape_ = 1;
|
int cursor_reset_shape_ = 1;
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
#include "ftxui/screen/image.hpp" // for Pixel, Image
|
#include "ftxui/screen/image.hpp" // for Pixel, Image
|
||||||
#include "ftxui/screen/terminal.hpp" // for Dimensions
|
#include "ftxui/screen/terminal.hpp" // for Dimensions
|
||||||
|
#include "ftxui/component/captured_mouse.hpp" // for CapturedMouse
|
||||||
|
|
||||||
namespace ftxui {
|
namespace ftxui {
|
||||||
|
|
||||||
@ -62,6 +63,11 @@ class Screen : public Image {
|
|||||||
Cursor cursor() const { return cursor_; }
|
Cursor cursor() const { return cursor_; }
|
||||||
void SetCursor(Cursor cursor) { cursor_ = cursor; }
|
void SetCursor(Cursor cursor) { cursor_ = cursor; }
|
||||||
|
|
||||||
|
bool selection_enabled = false;
|
||||||
|
CapturedMouse selection_pending;
|
||||||
|
Box selection_region;
|
||||||
|
std::string selection_text;
|
||||||
|
|
||||||
// Store an hyperlink in the screen. Return the id of the hyperlink. The id is
|
// Store an hyperlink in the screen. Return the id of the hyperlink. The id is
|
||||||
// used to identify the hyperlink when the user click on it.
|
// used to identify the hyperlink when the user click on it.
|
||||||
uint8_t RegisterHyperlink(const std::string& link);
|
uint8_t RegisterHyperlink(const std::string& link);
|
||||||
|
@ -351,8 +351,7 @@ ScreenInteractive::ScreenInteractive(int dimx,
|
|||||||
bool use_alternative_screen)
|
bool use_alternative_screen)
|
||||||
: Screen(dimx, dimy),
|
: Screen(dimx, dimy),
|
||||||
dimension_(dimension),
|
dimension_(dimension),
|
||||||
use_alternative_screen_(use_alternative_screen),
|
use_alternative_screen_(use_alternative_screen) {
|
||||||
selection_text("") {
|
|
||||||
task_receiver_ = MakeReceiver<Task>();
|
task_receiver_ = MakeReceiver<Task>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -844,10 +843,10 @@ bool ScreenInteractive::HandleSelection(Event event) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
selection_enabled = true;
|
selection_enabled = true;
|
||||||
selection_region.startx = mouse.x;
|
selection_region.x_min = mouse.x;
|
||||||
selection_region.starty = mouse.y;
|
selection_region.y_min = mouse.y;
|
||||||
selection_region.endx = mouse.x;
|
selection_region.x_max = mouse.x;
|
||||||
selection_region.endy = mouse.y;
|
selection_region.y_max = mouse.y;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -856,18 +855,18 @@ bool ScreenInteractive::HandleSelection(Event event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (mouse.motion == Mouse::Moved) {
|
if (mouse.motion == Mouse::Moved) {
|
||||||
selection_region.endx = mouse.x;
|
selection_region.x_max = mouse.x;
|
||||||
selection_region.endy = mouse.y;
|
selection_region.y_max = mouse.y;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mouse.motion == Mouse::Released) {
|
if (mouse.motion == Mouse::Released) {
|
||||||
selection_region.endx = mouse.x;
|
selection_region.x_max = mouse.x;
|
||||||
selection_region.endy = mouse.y;
|
selection_region.y_max = mouse.y;
|
||||||
selection_pending = nullptr;
|
selection_pending = nullptr;
|
||||||
|
|
||||||
if (selection_region.startx == selection_region.endx &&
|
if (selection_region.x_min == selection_region.x_max &&
|
||||||
selection_region.starty == selection_region.endy) {
|
selection_region.y_min == selection_region.y_max) {
|
||||||
selection_enabled = false;
|
selection_enabled = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -884,10 +883,10 @@ void ScreenInteractive::RefreshSelection() {
|
|||||||
}
|
}
|
||||||
selection_text = "";
|
selection_text = "";
|
||||||
|
|
||||||
for (int y = std::min(selection_region.starty, selection_region.endy);
|
for (int y = std::min(selection_region.y_min, selection_region.y_max);
|
||||||
y <= std::max(selection_region.starty, selection_region.endy); ++y) {
|
y <= std::max(selection_region.y_min, selection_region.y_max); ++y) {
|
||||||
for (int x = std::min(selection_region.startx, selection_region.endx);
|
for (int x = std::min(selection_region.x_min, selection_region.x_max);
|
||||||
x <= std::max(selection_region.startx, selection_region.endx) - 1;
|
x <= std::max(selection_region.x_min, selection_region.x_max) - 1;
|
||||||
++x) {
|
++x) {
|
||||||
if (PixelAt(x, y).selectable == true) {
|
if (PixelAt(x, y).selectable == true) {
|
||||||
PixelAt(x, y).inverted ^= true;
|
PixelAt(x, y).inverted ^= true;
|
||||||
|
@ -389,7 +389,9 @@ Screen Screen::Create(Dimensions dimension) {
|
|||||||
return {dimension.dimx, dimension.dimy};
|
return {dimension.dimx, dimension.dimy};
|
||||||
}
|
}
|
||||||
|
|
||||||
Screen::Screen(int dimx, int dimy) : Image{dimx, dimy} {
|
Screen::Screen(int dimx, int dimy) :
|
||||||
|
Image{dimx, dimy},
|
||||||
|
selection_text("") {
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
// The placement of this call is a bit weird, however we can assume that
|
// The placement of this call is a bit weird, however we can assume that
|
||||||
// anybody who instantiates a Screen object eventually wants to output
|
// anybody who instantiates a Screen object eventually wants to output
|
||||||
|
Loading…
Reference in New Issue
Block a user