mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-07-23 12:41:15 +08:00
We can catch mouse events
This commit is contained in:
parent
75abd75b67
commit
1325256aa9
@ -59,7 +59,7 @@ int main() {
|
|||||||
hbox(text(" First name : "), input_first_name->Render()),
|
hbox(text(" First name : "), input_first_name->Render()),
|
||||||
hbox(text(" Last name : ") | selectable(), input_last_name->Render()),
|
hbox(text(" Last name : ") | selectable(), input_last_name->Render()),
|
||||||
hbox(text(" Password : "), input_password->Render()),
|
hbox(text(" Password : "), input_password->Render()),
|
||||||
hbox(text(" Phone num : "), input_phone_number->Render()),
|
hbox(text(" Phone num : "), input_phone_number->Render()) | selectable(),
|
||||||
separator(),
|
separator(),
|
||||||
text("Hello " + first_name + " " + last_name),
|
text("Hello " + first_name + " " + last_name),
|
||||||
text("Your password is " + password),
|
text("Your password is " + password),
|
||||||
|
@ -26,6 +26,15 @@ 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;
|
||||||
|
bool changed = false;
|
||||||
|
} Region;
|
||||||
|
|
||||||
class ScreenInteractive : public Screen {
|
class ScreenInteractive : public Screen {
|
||||||
public:
|
public:
|
||||||
// Constructors:
|
// Constructors:
|
||||||
@ -82,6 +91,8 @@ class ScreenInteractive : public Screen {
|
|||||||
void RunOnceBlocking(Component component);
|
void RunOnceBlocking(Component component);
|
||||||
|
|
||||||
void HandleTask(Component component, Task& task);
|
void HandleTask(Component component, Task& task);
|
||||||
|
bool selectableCatchEvent(Event event);
|
||||||
|
std::string getSelection(void);
|
||||||
void Draw(Component component);
|
void Draw(Component component);
|
||||||
void ResetCursorPosition();
|
void ResetCursorPosition();
|
||||||
|
|
||||||
@ -126,6 +137,8 @@ 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;
|
||||||
|
|
||||||
|
Region selectedRegion;
|
||||||
|
|
||||||
// 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;
|
||||||
|
|
||||||
|
@ -116,6 +116,9 @@ Element hyperlink(std::string link, Element child);
|
|||||||
Element selectable(Element child);
|
Element selectable(Element child);
|
||||||
Decorator selectable(void);
|
Decorator selectable(void);
|
||||||
|
|
||||||
|
// -- Selection --
|
||||||
|
std::string getSelection(void);
|
||||||
|
|
||||||
// --- Layout is
|
// --- Layout is
|
||||||
// Horizontal, Vertical or stacked set of elements.
|
// Horizontal, Vertical or stacked set of elements.
|
||||||
Element hbox(Elements);
|
Element hbox(Elements);
|
||||||
|
@ -21,6 +21,7 @@ struct Pixel {
|
|||||||
underlined(false),
|
underlined(false),
|
||||||
underlined_double(false),
|
underlined_double(false),
|
||||||
strikethrough(false),
|
strikethrough(false),
|
||||||
|
selectable(false),
|
||||||
automerge(false) {}
|
automerge(false) {}
|
||||||
|
|
||||||
// A bit field representing the style:
|
// A bit field representing the style:
|
||||||
@ -30,6 +31,7 @@ struct Pixel {
|
|||||||
bool inverted : 1;
|
bool inverted : 1;
|
||||||
bool underlined : 1;
|
bool underlined : 1;
|
||||||
bool underlined_double : 1;
|
bool underlined_double : 1;
|
||||||
|
bool selectable : 1;
|
||||||
bool strikethrough : 1;
|
bool strikethrough : 1;
|
||||||
bool automerge : 1;
|
bool automerge : 1;
|
||||||
|
|
||||||
|
@ -35,6 +35,12 @@
|
|||||||
#include "ftxui/screen/pixel.hpp" // for Pixel
|
#include "ftxui/screen/pixel.hpp" // for Pixel
|
||||||
#include "ftxui/screen/terminal.hpp" // for Dimensions, Size
|
#include "ftxui/screen/terminal.hpp" // for Dimensions, Size
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
#define DEFINE_CONSOLEV2_PROPERTIES
|
#define DEFINE_CONSOLEV2_PROPERTIES
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
@ -781,7 +787,15 @@ void ScreenInteractive::HandleTask(Component component, Task& task) {
|
|||||||
|
|
||||||
arg.screen_ = this;
|
arg.screen_ = this;
|
||||||
|
|
||||||
const bool handled = component->OnEvent(arg);
|
bool handled = component->OnEvent(arg);
|
||||||
|
|
||||||
|
if(handled == false)
|
||||||
|
{
|
||||||
|
if(selectableCatchEvent(arg))
|
||||||
|
{
|
||||||
|
handled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (arg == Event::CtrlC && (!handled || force_handle_ctrl_c_)) {
|
if (arg == Event::CtrlC && (!handled || force_handle_ctrl_c_)) {
|
||||||
RecordSignal(SIGABRT);
|
RecordSignal(SIGABRT);
|
||||||
@ -824,6 +838,41 @@ void ScreenInteractive::HandleTask(Component component, Task& task) {
|
|||||||
// clang-format on
|
// clang-format on
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ScreenInteractive::selectableCatchEvent(Event event) {
|
||||||
|
|
||||||
|
// std::ofstream MyFile("debug.log", std::ios_base::app);
|
||||||
|
// MyFile << "Top dog!" << std::endl;
|
||||||
|
// MyFile.close();
|
||||||
|
|
||||||
|
if (event.is_mouse()) {
|
||||||
|
auto& mouse = event.mouse();
|
||||||
|
if (mouse.button == Mouse::Left) {
|
||||||
|
|
||||||
|
if (mouse.motion == Mouse::Pressed) {
|
||||||
|
selectedRegion.startx = mouse.x;
|
||||||
|
selectedRegion.starty = mouse.y;
|
||||||
|
selectedRegion.endx = mouse.x;
|
||||||
|
selectedRegion.endy = mouse.y;
|
||||||
|
selectedRegion.changed = true;
|
||||||
|
} else if (mouse.motion == Mouse::Released) {
|
||||||
|
selectedRegion.endx = mouse.x;
|
||||||
|
selectedRegion.endy = mouse.y;
|
||||||
|
selectedRegion.changed = true;
|
||||||
|
} else if (mouse.motion == Mouse::Moved) {
|
||||||
|
selectedRegion.endx = mouse.x;
|
||||||
|
selectedRegion.endy = mouse.y;
|
||||||
|
selectedRegion.changed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string ScreenInteractive::getSelection(void) {
|
||||||
|
return "Selection";
|
||||||
|
}
|
||||||
|
|
||||||
// private
|
// private
|
||||||
// NOLINTNEXTLINE
|
// NOLINTNEXTLINE
|
||||||
void ScreenInteractive::Draw(Component component) {
|
void ScreenInteractive::Draw(Component component) {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#include "ftxui/dom/elements.hpp" // for Element, Decorator
|
#include "ftxui/dom/elements.hpp" // for Element, Decorator
|
||||||
#include "ftxui/dom/node_decorator.hpp" // for NodeDecorator
|
#include "ftxui/dom/node_decorator.hpp" // for NodeDecorator
|
||||||
|
#include "ftxui/component/event.hpp" // for Event
|
||||||
|
|
||||||
|
|
||||||
namespace ftxui {
|
namespace ftxui {
|
||||||
@ -16,7 +16,7 @@ class Selectable : public NodeDecorator {
|
|||||||
|
|
||||||
for (int y = box_.y_min; y <= box_.y_max; ++y) {
|
for (int y = box_.y_min; y <= box_.y_max; ++y) {
|
||||||
for (int x = box_.x_min; x <= box_.x_max; ++x) {
|
for (int x = box_.x_min; x <= box_.x_max; ++x) {
|
||||||
screen.PixelAt(x, y).inverted = true;
|
screen.PixelAt(x, y).selectable = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user