AUI Framework  master
Cross-platform module-based framework for developing C++20 desktop applications
AAbstractTypeable.h
1/*
2 * AUI Framework - Declarative UI toolkit for modern C++20
3 * Copyright (C) 2020-2024 Alex2772 and Contributors
4 *
5 * SPDX-License-Identifier: MPL-2.0
6 *
7 * This Source Code Form is subject to the terms of the Mozilla Public
8 * License, v. 2.0. If a copy of the MPL was not distributed with this
9 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 */
11
12#pragma once
13
14
15#include <AUI/Util/ACursorSelectable.h>
16#include <AUI/Enum/ATextInputActionIcon.h>
17#include <AUI/Enum/ATextInputType.h>
18#include "AUI/Common/ATimer.h"
19#include "AUI/Render/IRenderer.h"
20#include "AUI/Font/IFontView.h"
21
25class API_AUI_VIEWS AAbstractTypeable: public ACursorSelectable {
26public:
28 ~AAbstractTypeable() override;
29
30 void clear() {
31 setText({});
32 }
33 void setMaxTextLength(size_t newTextLength) {
34 mMaxTextLength = newTextLength;
35 }
36
37 void trimText() {
38 setText(text().trim());
39 }
40
41 void setCopyable(bool isCopyable) {
42 mIsCopyable = isCopyable;
43 }
44
45 virtual void setText(const AString& t);
46
50 [[nodiscard]]
51 virtual bool isPasswordField() const noexcept = 0;
52
57 [[nodiscard]]
58 virtual ATextInputType textInputType() const noexcept = 0;
59
63 void setTextInputActionIcon(ATextInputActionIcon textInputActionIcon) noexcept {
64 mTextInputActionIcon = textInputActionIcon;
65 }
66
71 [[nodiscard]]
73 return mTextInputActionIcon;
74 }
75
79 void copyToClipboard() const;
80
84 void cutToClipboard();
85
94 void pasteFromClipboard();
95
105 void paste(AString content);
106
110 void moveCursorLeft();
111
115 void moveCursorRight();
116
117 virtual void emitTextChanged(const AString& text) = 0;
118 virtual void emitTextChanging(const AString& text) = 0;
119 virtual void emitActionButtonPressed() = 0;
120
121signals:
130
138
146
154
155protected:
156 size_t mMaxTextLength = 0x200;
157 bool mIsMultiline = false;
158
159protected:
160 bool isCursorBlinkVisible() const {
161 return mCursorBlinkVisible;
162 }
163
164 void updateCursorBlinking();
165
166 virtual void typeableErase(size_t begin, size_t end) = 0;
167
174 [[nodiscard]]
175 virtual bool typeableInsert(size_t at, const AString& toInsert) = 0;
176
183 [[nodiscard]]
184 virtual bool typeableInsert(size_t at, char16_t toInsert) = 0;
185 virtual size_t typeableFind(char16_t c, size_t startPos = -1) = 0;
186 virtual size_t typeableReverseFind(char16_t c, size_t startPos = -1) = 0;
187 virtual void updateSelectionOnTextSet(const AString& t);
188
189 virtual void onCursorIndexChanged() = 0;
190
191
196 void enterChar(char16_t c);
197
198 AString getDisplayText() override;
199 AMenuModel composeContextMenuImpl();
200 void handleKey(AInput::Key key);
201
202private:
203 _<ATimer> mBlinkTimer = blinkTimer();
204
209 unsigned mCursorBlinkCount = 0;
210 bool mCursorBlinkVisible = true;
211 bool mTextChangedFlag = false;
212 bool mIsCopyable = true;
213
214private:
215 static _<ATimer> blinkTimer();
216
217 template<aui::derived_from<AView> Super>
218 friend class AAbstractTypeableView;
219
220 virtual void typeableInvalidateFont() = 0;
221 void drawCursorImpl(IRenderer& renderer, glm::ivec2 position, unsigned lineHeight);
222
223 void fastenSelection();
224};
225
226
Basic implementation of type shortcuts and selection for editable text fields.
Definition: AAbstractTypeableView.h:31
Base class for AAbstractTypeableView which is template class.
Definition: AAbstractTypeable.h:25
emits< Selection > selectionChanged
Definition: AAbstractTypeable.h:145
virtual bool typeableInsert(size_t at, const AString &toInsert)=0
ATextInputActionIcon textInputActionIcon() const noexcept
Definition: AAbstractTypeable.h:72
emits actionButtonPressed
Definition: AAbstractTypeable.h:153
emits< AString > textChanged
Definition: AAbstractTypeable.h:129
emits< AString > textChanging
Definition: AAbstractTypeable.h:137
virtual bool isPasswordField() const noexcept=0
virtual bool typeableInsert(size_t at, char16_t toInsert)=0
Definition: ACursorSelectable.h:27
virtual const AString & text() const =0
Represents a Unicode character string.
Definition: AString.h:37
A std::vector with AUI extensions.
Definition: AVector.h:38
Base class for rendering.
Definition: IRenderer.h:149
An std::weak_ptr with AUI extensions.
Definition: SharedPtrTypes.h:177
ATextInputType
Controls IME text input type of the text field.
Definition: ATextInputType.h:24
ATextInputActionIcon
Controls icons representing IME text input action the user is requested to perform.
Definition: ATextInputActionIcon.h:26
@ DEFAULT
There's no concrete input action. Let the OS decide which action is the most appropriate.
Definition: Text.h:21