diff --git a/include/ftxui/component/screen_interactive.hpp b/include/ftxui/component/screen_interactive.hpp index b1eb7f7..38d2e50 100644 --- a/include/ftxui/component/screen_interactive.hpp +++ b/include/ftxui/component/screen_interactive.hpp @@ -69,8 +69,7 @@ class ScreenInteractive : public Screen { void ForceHandleCtrlZ(bool force); // Selection API. - //void OnSelectionChange(std::function // for list #include // for shared_ptr #include // for vector @@ -58,7 +57,6 @@ class Node { }; virtual void Check(Status* status); - protected: Elements children_; Requirement requirement_; diff --git a/include/ftxui/dom/selection.hpp b/include/ftxui/dom/selection.hpp index d795e2b..588e367 100644 --- a/include/ftxui/dom/selection.hpp +++ b/include/ftxui/dom/selection.hpp @@ -18,7 +18,6 @@ class Selection { Selection SaturateHorizontal(Box box); Selection SaturateVertical(Box box); - private: Selection* const parent_ = nullptr; const int start_x_; diff --git a/include/ftxui/screen/pixel.hpp b/include/ftxui/screen/pixel.hpp index 817778b..cbc7cc2 100644 --- a/include/ftxui/screen/pixel.hpp +++ b/include/ftxui/screen/pixel.hpp @@ -21,7 +21,6 @@ struct Pixel { underlined(false), underlined_double(false), strikethrough(false), - selectable(false), automerge(false) {} // A bit field representing the style: @@ -31,7 +30,6 @@ struct Pixel { bool inverted : 1; bool underlined : 1; bool underlined_double : 1; - bool selectable : 1; bool strikethrough : 1; bool automerge : 1; diff --git a/include/ftxui/screen/screen.hpp b/include/ftxui/screen/screen.hpp index 39cc4ea..51b83a0 100644 --- a/include/ftxui/screen/screen.hpp +++ b/include/ftxui/screen/screen.hpp @@ -10,7 +10,6 @@ #include "ftxui/screen/image.hpp" // for Pixel, Image #include "ftxui/screen/terminal.hpp" // for Dimensions -#include "ftxui/component/captured_mouse.hpp" // for CapturedMouse namespace ftxui { diff --git a/src/ftxui/component/screen_interactive.cpp b/src/ftxui/component/screen_interactive.cpp index 6537959..07afb5d 100644 --- a/src/ftxui/component/screen_interactive.cpp +++ b/src/ftxui/component/screen_interactive.cpp @@ -850,10 +850,10 @@ bool ScreenInteractive::HandleSelection(Event event) { } if (mouse.motion == Mouse::Moved) { - selection_end_x_ = mouse.x; - selection_end_y_ = mouse.y; - return true; - } + selection_end_x_ = mouse.x; + selection_end_y_ = mouse.y; + return true; + } if (mouse.motion == Mouse::Released) { selection_pending_ = nullptr; diff --git a/src/ftxui/dom/selectable.cpp b/src/ftxui/dom/selectable.cpp index 191c5f4..c7831c0 100644 --- a/src/ftxui/dom/selectable.cpp +++ b/src/ftxui/dom/selectable.cpp @@ -1,23 +1,24 @@ -#include "ftxui/dom/elements.hpp" // for Element, Decorator -#include "ftxui/dom/node_decorator.hpp" // for NodeDecorator -#include "ftxui/component/event.hpp" // for Event +// Copyright 2024 Arthur Sonzogni. All rights reserved. +// Use of this source code is governed by the MIT license that can be found in +// 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 { class Selectable : public NodeDecorator { public: - explicit Selectable(Element child) - : NodeDecorator(std::move(child)) {} + explicit Selectable(Element child) : NodeDecorator(std::move(child)) {} private: void Render(Screen& screen) override { - for (int y = box_.y_min; y <= box_.y_max; ++y) { - for (int x = box_.x_min; x <= box_.x_max; ++x) { - screen.PixelAt(x, y).selectable = true; - } + for (int x = box_.x_min; x <= box_.x_max; ++x) { + screen.PixelAt(x, y).selectable = true; + } } NodeDecorator::Render(screen); @@ -26,14 +27,12 @@ class Selectable : public NodeDecorator { } // namespace - Element selectable(Element child) { return std::make_shared(std::move(child)); } Decorator selectable(void) { - return - [](Element child) { return selectable(std::move(child)); }; + return [](Element child) { return selectable(std::move(child)); }; } } // namespace ftxui diff --git a/src/ftxui/dom/selection.cpp b/src/ftxui/dom/selection.cpp index f5f5966..c45df40 100644 --- a/src/ftxui/dom/selection.cpp +++ b/src/ftxui/dom/selection.cpp @@ -39,7 +39,7 @@ Selection Selection::SaturateHorizontal(Box box) { int start_y = start_y_; int end_x = end_x_; int end_y = end_y_; - + const bool start_outside = !box.Contain(start_x, start_y); const bool end_outside = !box.Contain(end_x, end_y); const bool properly_ordered = @@ -75,11 +75,11 @@ Selection Selection::SaturateVertical(Box box) { int start_y = start_y_; int end_x = end_x_; int end_y = end_y_; - + const bool start_outside = !box.Contain(start_x, start_y); const bool end_outside = !box.Contain(end_x, end_y); 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 (start_outside) { diff --git a/src/ftxui/dom/text.cpp b/src/ftxui/dom/text.cpp index ff52e24..68b5cfe 100644 --- a/src/ftxui/dom/text.cpp +++ b/src/ftxui/dom/text.cpp @@ -40,7 +40,7 @@ class Text : public Node { selection_start_ = selection_saturated.GetBox().x_min; selection_end_ = selection_saturated.GetBox().x_max; } - + void Render(Screen& screen) override { int x = box_.x_min; const int y = box_.y_min; @@ -58,7 +58,7 @@ class Text : public Node { screen.PixelAt(x, y).character = cell; if (has_selection) { - if((x >= selection_start_) && (x <= selection_end_)) { + if ((x >= selection_start_) && (x <= selection_end_)) { screen.PixelAt(x, y).inverted = true; } } diff --git a/tools/license_headers.cpp b/tools/license_headers.cpp index 851e894..aa00321 100644 --- a/tools/license_headers.cpp +++ b/tools/license_headers.cpp @@ -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 // the LICENSE file.