mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2024-11-23 11:17:06 +08:00
We can act on the screen
This commit is contained in:
parent
dea2d6408b
commit
e4a63318ad
@ -55,6 +55,9 @@ int main() {
|
|||||||
|
|
||||||
// Tweak how the component tree is rendered:
|
// Tweak how the component tree is rendered:
|
||||||
auto renderer = Renderer(component, [&] {
|
auto renderer = Renderer(component, [&] {
|
||||||
|
|
||||||
|
textToCopy = screen.getSelection();
|
||||||
|
|
||||||
return vbox({
|
return vbox({
|
||||||
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()),
|
||||||
|
@ -32,7 +32,6 @@ typedef struct {
|
|||||||
uint16_t endx = 0;
|
uint16_t endx = 0;
|
||||||
uint16_t starty = 0;
|
uint16_t starty = 0;
|
||||||
uint16_t endy = 0;
|
uint16_t endy = 0;
|
||||||
bool changed = false;
|
|
||||||
} Region;
|
} Region;
|
||||||
|
|
||||||
class ScreenInteractive : public Screen {
|
class ScreenInteractive : public Screen {
|
||||||
@ -77,6 +76,8 @@ class ScreenInteractive : public Screen {
|
|||||||
void ForceHandleCtrlC(bool force);
|
void ForceHandleCtrlC(bool force);
|
||||||
void ForceHandleCtrlZ(bool force);
|
void ForceHandleCtrlZ(bool force);
|
||||||
|
|
||||||
|
std::string getSelection(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void ExitNow();
|
void ExitNow();
|
||||||
|
|
||||||
@ -92,7 +93,7 @@ class ScreenInteractive : public Screen {
|
|||||||
|
|
||||||
void HandleTask(Component component, Task& task);
|
void HandleTask(Component component, Task& task);
|
||||||
bool selectableCatchEvent(Event event);
|
bool selectableCatchEvent(Event event);
|
||||||
std::string getSelection(void);
|
void refreshSelection(void);
|
||||||
void Draw(Component component);
|
void Draw(Component component);
|
||||||
void ResetCursorPosition();
|
void ResetCursorPosition();
|
||||||
|
|
||||||
|
@ -116,9 +116,6 @@ 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);
|
||||||
|
@ -853,15 +853,15 @@ bool ScreenInteractive::selectableCatchEvent(Event event) {
|
|||||||
selectedRegion.starty = mouse.y;
|
selectedRegion.starty = mouse.y;
|
||||||
selectedRegion.endx = mouse.x;
|
selectedRegion.endx = mouse.x;
|
||||||
selectedRegion.endy = mouse.y;
|
selectedRegion.endy = mouse.y;
|
||||||
selectedRegion.changed = true;
|
refreshSelection();
|
||||||
} else if (mouse.motion == Mouse::Released) {
|
} else if (mouse.motion == Mouse::Released) {
|
||||||
selectedRegion.endx = mouse.x;
|
selectedRegion.endx = mouse.x;
|
||||||
selectedRegion.endy = mouse.y;
|
selectedRegion.endy = mouse.y;
|
||||||
selectedRegion.changed = true;
|
refreshSelection();
|
||||||
} else if (mouse.motion == Mouse::Moved) {
|
} else if (mouse.motion == Mouse::Moved) {
|
||||||
selectedRegion.endx = mouse.x;
|
selectedRegion.endx = mouse.x;
|
||||||
selectedRegion.endy = mouse.y;
|
selectedRegion.endy = mouse.y;
|
||||||
selectedRegion.changed = true;
|
refreshSelection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -869,8 +869,18 @@ bool ScreenInteractive::selectableCatchEvent(Event event) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ScreenInteractive::refreshSelection(void) {
|
||||||
|
|
||||||
|
for (int y = std::min(selectedRegion.starty, selectedRegion.endy); y <= std::max(selectedRegion.starty, selectedRegion.endy); ++y) {
|
||||||
|
for (int x = std::min(selectedRegion.startx, selectedRegion.endx); x <= std::max(selectedRegion.startx, selectedRegion.endx)-1; ++x) {
|
||||||
|
PixelAt(x, y).inverted ^= true;
|
||||||
|
//selectedText += PixelAt(x, y).character;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::string ScreenInteractive::getSelection(void) {
|
std::string ScreenInteractive::getSelection(void) {
|
||||||
return "Selection";
|
return "Kikoo";
|
||||||
}
|
}
|
||||||
|
|
||||||
// private
|
// private
|
||||||
|
Loading…
Reference in New Issue
Block a user