mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-06-28 02:41:11 +08:00
Added a decorator to prevent selectability
This commit is contained in:
parent
307d8b51bf
commit
d62dc6e305
@ -47,7 +47,7 @@ int main() {
|
||||
window(text("Vertical split"), vbox({
|
||||
LoremIpsum(),
|
||||
separator(),
|
||||
LoremIpsum(),
|
||||
LoremIpsum() | unselectable,
|
||||
separator(),
|
||||
LoremIpsum(),
|
||||
})),
|
||||
|
@ -113,6 +113,7 @@ Decorator focusPositionRelative(float x, float y);
|
||||
Element automerge(Element child);
|
||||
Decorator hyperlink(std::string link);
|
||||
Element hyperlink(std::string link, Element child);
|
||||
Element unselectable(Element child);
|
||||
|
||||
// --- Layout is
|
||||
// Horizontal, Vertical or stacked set of elements.
|
||||
|
@ -5,8 +5,22 @@
|
||||
#include "ftxui/dom/selection.hpp" // for Selection
|
||||
#include <algorithm> // for max, min
|
||||
|
||||
#include "ftxui/dom/elements.hpp" // for Element, inverted
|
||||
#include "ftxui/dom/node_decorator.hpp" // for NodeDecorator
|
||||
|
||||
namespace ftxui {
|
||||
|
||||
namespace {
|
||||
class Unselectable : public NodeDecorator {
|
||||
public:
|
||||
using NodeDecorator::NodeDecorator;
|
||||
|
||||
void Select(Selection& selection) override {
|
||||
// Overwrite the select method to do nothing.
|
||||
}
|
||||
};
|
||||
} // namespace
|
||||
|
||||
/// @brief Create a selection.
|
||||
/// @param start_x The x coordinate of the start of the selection.
|
||||
/// @param start_y The y coordinate of the start of the selection.
|
||||
@ -103,4 +117,11 @@ Selection Selection::SaturateVertical(Box box) {
|
||||
return Selection(start_x, start_y, end_x, end_y);
|
||||
}
|
||||
|
||||
/// @brief Add a filter that will invert the foreground and the background
|
||||
/// colors.
|
||||
/// @ingroup dom
|
||||
Element unselectable(Element child) {
|
||||
return std::make_shared<Unselectable>(std::move(child));
|
||||
}
|
||||
|
||||
} // namespace ftxui
|
||||
|
Loading…
Reference in New Issue
Block a user