19#include <AUI/Common/AString.h>
21#include <AUI/Font/AFontStyle.h>
22#include <AUI/Render/ATextLayoutHelper.h>
23#include <AUI/Render/RenderHints.h>
24#include <AUI/Platform/AInput.h>
25#include <AUI/View/AView.h>
37 bool operator==(
const Selection& rhs)
const noexcept =
default;
40 bool operator!=(
const Selection& rhs)
const noexcept =
default;
43 bool empty()
const noexcept {
61 [[nodiscard]]
virtual size_t length()
const = 0;
62 [[nodiscard]]
AString selectedText()
const
73 [[nodiscard]] Selection selection()
const;
78 [[nodiscard]]
bool hasSelection()
const;
85 [[nodiscard]]
virtual glm::ivec2 getPosByIndex(
size_t index) = 0;
106 void setSelection(
int cursorIndex) {
107 mCursorIndex = cursorIndex;
108 mCursorSelection.reset();
109 onSelectionChanged();
112 void setSelection(Selection selection) {
113 mCursorIndex = selection.begin;
114 mCursorSelection = selection.end;
115 onSelectionChanged();
119 unsigned mCursorIndex = 0;
120 AOptional<unsigned> mCursorSelection;
122 virtual bool isLButtonPressed() = 0;
123 virtual AString getDisplayText() = 0;
124 virtual void cursorSelectableRedraw() = 0;
125 virtual void onSelectionChanged() = 0;
128 void handleMouseDoubleClicked(
const APointerPressedEvent& event);
129 void handleMousePressed(
const APointerPressedEvent& event);
130 void handleMouseReleased(
const APointerReleasedEvent& event);
131 void handleMouseMove(
const glm::ivec2& pos);
133 template<aui::invocable Callback>
134 void drawSelectionBeforeAndAfter(IRenderer& render, std::span<ARect<int>> rects, Callback&& drawText) {
140 auto drawRects = [&] {
141 for (
auto r : rects) {
142 render.
rectangle(ASolidBrush{}, r.p1, r.size());
146 RenderHints::PushColor
c(render);
147 render.
setColor(AColor(1.f) - AColor(0x0078d700u));
159 bool mIgnoreSelection =
false;
166 o <<
"{" << e.begin <<
"}";
168 o <<
"[" << e.begin <<
";" << e.end <<
")";
Definition ACursorSelectable.h:27
virtual size_t length() const =0
virtual unsigned cursorIndexByPos(glm::ivec2 pos)=0
void clearSelection()
Remove selection from the text field.
Definition ACursorSelectable.cpp:68
virtual glm::ivec2 getCursorPosition()=0
Selection selection() const
Definition ACursorSelectable.cpp:23
bool hasSelection() const
Definition ACursorSelectable.cpp:27
virtual const AString & getText() const =0
void selectAll()
Select whole text in the text field.
Definition ACursorSelectable.cpp:59
Represents a Unicode character string.
Definition AString.h:37
void setColor(const AColor &color)
Sets the color which is multiplied with any brush. Unlike setColorForced, the new color is multiplied...
Definition IRenderer.h:432
virtual void setBlending(Blending blending)=0
Sets blending mode.
virtual void rectangle(const ABrush &brush, glm::vec2 position, glm::vec2 size)=0
Draws simple rectangle.
class_of c
Selects views that are of the specified classes.
Definition class_of.h:84
#define AUI_DEFER
Defers execution of the next block to the end of current block (RAII scope).
Definition kAUI.h:196
Definition ACursorSelectable.h:32