Support for inverted selections.

This commit is contained in:
ArthurSonzogni
2024-12-01 17:40:19 +01:00
parent fa742c7a34
commit c1c4caf24f
11 changed files with 196 additions and 93 deletions

View File

@@ -138,7 +138,10 @@ class ScreenInteractive : public Screen {
// Selection API:
bool selection_enabled_ = false;
CapturedMouse selection_pending_;
Box selection_box_;
int selection_start_x_ = 0;
int selection_start_y_ = 0;
int selection_end_x_ = 0;
int selection_end_y_ = 0;
friend class Loop;

View File

@@ -9,6 +9,7 @@
#include <vector> // for vector
#include "ftxui/dom/requirement.hpp" // for Requirement
#include "ftxui/dom/selection.hpp" // for Selection
#include "ftxui/screen/box.hpp" // for Box
#include "ftxui/screen/screen.hpp"
@@ -43,7 +44,7 @@ class Node {
// Step 3: (optional) Selection
// Propagated from Parents to Children.
virtual void Selection(Box selection, std::vector<Box>* selected);
virtual void Select(Selection& selection);
// Step 4: Draw this element.
virtual void Render(Screen& screen);
@@ -66,7 +67,7 @@ class Node {
void Render(Screen& screen, const Element& element);
void Render(Screen& screen, Node* node);
void Render(Screen& screen, Node* node, Box selection);
void Render(Screen& screen, Node* node, Selection& selection);
} // namespace ftxui

View File

@@ -0,0 +1,33 @@
// 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.
#ifndef FTXUI_DOM_SELECTION_HPP
#define FTXUI_DOM_SELECTION_HPP
#include "ftxui/screen/box.hpp" // for Box
namespace ftxui {
/// @brief Represent a selection in the terminal.
class Selection {
public:
Selection(int start_x, int start_y, int end_x, int end_y);
const Box& GetBox() const;
Selection SaturateHorizontal(Box box);
Selection SaturateVertical(Box box);
private:
Selection* const parent_ = nullptr;
const int start_x_;
const int start_y_;
const int end_x_;
const int end_y_;
const Box box_;
};
} // namespace ftxui
#endif /* end of include guard: FTXUI_DOM_SELECTION_HPP */