mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2024-12-05 01:11:46 +08:00
Cleanup
This commit is contained in:
parent
f9b47f427d
commit
b22241ec52
@ -69,8 +69,7 @@ class ScreenInteractive : public Screen {
|
|||||||
void ForceHandleCtrlZ(bool force);
|
void ForceHandleCtrlZ(bool force);
|
||||||
|
|
||||||
// Selection API.
|
// Selection API.
|
||||||
//void OnSelectionChange(std::function<void(std::
|
// TODO: Implement somethings here.
|
||||||
//void ClearSelection();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void ExitNow();
|
void ExitNow();
|
||||||
|
@ -113,8 +113,6 @@ Decorator focusPositionRelative(float x, float y);
|
|||||||
Element automerge(Element child);
|
Element automerge(Element child);
|
||||||
Decorator hyperlink(std::string link);
|
Decorator hyperlink(std::string link);
|
||||||
Element hyperlink(std::string link, Element child);
|
Element hyperlink(std::string link, Element child);
|
||||||
Element selectable(Element child);
|
|
||||||
Decorator selectable(void);
|
|
||||||
|
|
||||||
// --- Layout is
|
// --- Layout is
|
||||||
// Horizontal, Vertical or stacked set of elements.
|
// Horizontal, Vertical or stacked set of elements.
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
#ifndef FTXUI_DOM_NODE_HPP
|
#ifndef FTXUI_DOM_NODE_HPP
|
||||||
#define FTXUI_DOM_NODE_HPP
|
#define FTXUI_DOM_NODE_HPP
|
||||||
|
|
||||||
#include <list> // for list
|
|
||||||
#include <memory> // for shared_ptr
|
#include <memory> // for shared_ptr
|
||||||
#include <vector> // for vector
|
#include <vector> // for vector
|
||||||
|
|
||||||
@ -58,7 +57,6 @@ class Node {
|
|||||||
};
|
};
|
||||||
virtual void Check(Status* status);
|
virtual void Check(Status* status);
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Elements children_;
|
Elements children_;
|
||||||
Requirement requirement_;
|
Requirement requirement_;
|
||||||
|
@ -18,7 +18,6 @@ class Selection {
|
|||||||
Selection SaturateHorizontal(Box box);
|
Selection SaturateHorizontal(Box box);
|
||||||
Selection SaturateVertical(Box box);
|
Selection SaturateVertical(Box box);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Selection* const parent_ = nullptr;
|
Selection* const parent_ = nullptr;
|
||||||
const int start_x_;
|
const int start_x_;
|
||||||
|
@ -21,7 +21,6 @@ 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:
|
||||||
@ -31,7 +30,6 @@ 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;
|
||||||
|
|
||||||
|
@ -10,7 +10,6 @@
|
|||||||
|
|
||||||
#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 {
|
||||||
|
|
||||||
|
@ -850,10 +850,10 @@ bool ScreenInteractive::HandleSelection(Event event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (mouse.motion == Mouse::Moved) {
|
if (mouse.motion == Mouse::Moved) {
|
||||||
selection_end_x_ = mouse.x;
|
selection_end_x_ = mouse.x;
|
||||||
selection_end_y_ = mouse.y;
|
selection_end_y_ = mouse.y;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mouse.motion == Mouse::Released) {
|
if (mouse.motion == Mouse::Released) {
|
||||||
selection_pending_ = nullptr;
|
selection_pending_ = nullptr;
|
||||||
|
@ -1,23 +1,24 @@
|
|||||||
#include "ftxui/dom/elements.hpp" // for Element, Decorator
|
// Copyright 2024 Arthur Sonzogni. All rights reserved.
|
||||||
#include "ftxui/dom/node_decorator.hpp" // for NodeDecorator
|
// Use of this source code is governed by the MIT license that can be found in
|
||||||
#include "ftxui/component/event.hpp" // for Event
|
// the LICENSE file.
|
||||||
|
|
||||||
|
#include "ftxui/component/event.hpp" // for Event
|
||||||
|
#include "ftxui/dom/elements.hpp" // for Element, Decorator
|
||||||
|
#include "ftxui/dom/node_decorator.hpp" // for NodeDecorator
|
||||||
|
|
||||||
namespace ftxui {
|
namespace ftxui {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
class Selectable : public NodeDecorator {
|
class Selectable : public NodeDecorator {
|
||||||
public:
|
public:
|
||||||
explicit Selectable(Element child)
|
explicit Selectable(Element child) : NodeDecorator(std::move(child)) {}
|
||||||
: NodeDecorator(std::move(child)) {}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void Render(Screen& screen) override {
|
void Render(Screen& screen) override {
|
||||||
|
|
||||||
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).selectable = true;
|
screen.PixelAt(x, y).selectable = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeDecorator::Render(screen);
|
NodeDecorator::Render(screen);
|
||||||
@ -26,14 +27,12 @@ class Selectable : public NodeDecorator {
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
|
||||||
Element selectable(Element child) {
|
Element selectable(Element child) {
|
||||||
return std::make_shared<Selectable>(std::move(child));
|
return std::make_shared<Selectable>(std::move(child));
|
||||||
}
|
}
|
||||||
|
|
||||||
Decorator selectable(void) {
|
Decorator selectable(void) {
|
||||||
return
|
return [](Element child) { return selectable(std::move(child)); };
|
||||||
[](Element child) { return selectable(std::move(child)); };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ftxui
|
} // namespace ftxui
|
||||||
|
@ -39,7 +39,7 @@ Selection Selection::SaturateHorizontal(Box box) {
|
|||||||
int start_y = start_y_;
|
int start_y = start_y_;
|
||||||
int end_x = end_x_;
|
int end_x = end_x_;
|
||||||
int end_y = end_y_;
|
int end_y = end_y_;
|
||||||
|
|
||||||
const bool start_outside = !box.Contain(start_x, start_y);
|
const bool start_outside = !box.Contain(start_x, start_y);
|
||||||
const bool end_outside = !box.Contain(end_x, end_y);
|
const bool end_outside = !box.Contain(end_x, end_y);
|
||||||
const bool properly_ordered =
|
const bool properly_ordered =
|
||||||
@ -75,11 +75,11 @@ Selection Selection::SaturateVertical(Box box) {
|
|||||||
int start_y = start_y_;
|
int start_y = start_y_;
|
||||||
int end_x = end_x_;
|
int end_x = end_x_;
|
||||||
int end_y = end_y_;
|
int end_y = end_y_;
|
||||||
|
|
||||||
const bool start_outside = !box.Contain(start_x, start_y);
|
const bool start_outside = !box.Contain(start_x, start_y);
|
||||||
const bool end_outside = !box.Contain(end_x, end_y);
|
const bool end_outside = !box.Contain(end_x, end_y);
|
||||||
const bool properly_ordered =
|
const bool properly_ordered =
|
||||||
start_y < end_y || (start_y == end_y && start_x <= end_x);
|
start_y < end_y || (start_y == end_y && start_x <= end_x);
|
||||||
|
|
||||||
if (properly_ordered) {
|
if (properly_ordered) {
|
||||||
if (start_outside) {
|
if (start_outside) {
|
||||||
|
@ -40,7 +40,7 @@ class Text : public Node {
|
|||||||
selection_start_ = selection_saturated.GetBox().x_min;
|
selection_start_ = selection_saturated.GetBox().x_min;
|
||||||
selection_end_ = selection_saturated.GetBox().x_max;
|
selection_end_ = selection_saturated.GetBox().x_max;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Render(Screen& screen) override {
|
void Render(Screen& screen) override {
|
||||||
int x = box_.x_min;
|
int x = box_.x_min;
|
||||||
const int y = box_.y_min;
|
const int y = box_.y_min;
|
||||||
@ -58,7 +58,7 @@ class Text : public Node {
|
|||||||
screen.PixelAt(x, y).character = cell;
|
screen.PixelAt(x, y).character = cell;
|
||||||
|
|
||||||
if (has_selection) {
|
if (has_selection) {
|
||||||
if((x >= selection_start_) && (x <= selection_end_)) {
|
if ((x >= selection_start_) && (x <= selection_end_)) {
|
||||||
screen.PixelAt(x, y).inverted = true;
|
screen.PixelAt(x, y).inverted = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Copyright 2023 Arthur Sonzogni. All rights reserved.
|
// Copyright 2024 Arthur Sonzogni. All rights reserved.
|
||||||
// Use of this source code is governed by the MIT license that can be found in
|
// Use of this source code is governed by the MIT license that can be found in
|
||||||
// the LICENSE file.
|
// the LICENSE file.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user