AUI Framework  develop
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
AAbstractTextField.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#include <AUI/View/AAbstractTypeableView.h>
15#include "AUI/Enum/ATextInputType.h"
16#include "AView.h"
17#include "AUI/Common/ATimer.h"
18#include <AUI/Common/IStringable.h>
19#include <AUI/Render/IRenderer.h>
20
26class API_AUI_VIEWS AAbstractTextField : public AAbstractTypeableView<AView>, public IStringable {
27public:
28 AAbstractTextField();
29
30 ~AAbstractTextField() override;
31
32 int getContentMinimumHeight() override;
33
34 void setText(const AString& t) override;
35
36 void setSuffix(const AString& s);
37
38 void render(ARenderContext ctx) override;
39
40 AString toString() const override;
41
42 void setTextInputType(ATextInputType textInputType) noexcept {
43 mTextInputType = textInputType;
44 }
45
46 [[nodiscard]]
47 ATextInputType textInputType() const noexcept override {
48 return mTextInputType;
49 }
50
51 void setPasswordMode(bool isPasswordField) {
52 mIsPasswordTextField = isPasswordField;
53 setCopyable(!isPasswordField);
54 }
55
56 [[nodiscard]]
57 bool isPasswordField() const noexcept override {
58 return mIsPasswordTextField;
59 }
60
61 bool handlesNonMouseNavigation() override;
62
63 const AString& getText() const override;
64
65 void onCharEntered(char16_t c) override;
66
67 void setSize(glm::ivec2 size) override;
68
69 glm::ivec2 getCursorPosition() override;
70
71protected:
72 _<IRenderer::IPrerenderedString> mPrerenderedString;
73 AString mContents;
74 AString mSuffix;
75
76 virtual bool isValidText(const AString& text);
77
78 void prerenderStringIfNeeded(IRenderer& render);
79
80 void typeableErase(size_t begin, size_t end) override;
81
82 bool typeableInsert(size_t at, const AString& toInsert) override;
83
84 size_t typeableFind(char16_t c, size_t startPos) override;
85
86 size_t typeableReverseFind(char16_t c, size_t startPos) override;
87
88 size_t length() const override;
89
90 bool typeableInsert(size_t at, char16_t toInsert) override;
91
92 AString getDisplayText() override;
93
94 void cursorSelectableRedraw() override;
95
96 unsigned cursorIndexByPos(glm::ivec2 pos) override;
97 glm::ivec2 getPosByIndex(size_t index) override;
98
99 void doDrawString(IRenderer& render);
100
101 void onCursorIndexChanged() override;
102 void commitStyle() override;
103
104private:
106 bool mIsPasswordTextField = false;
107 int mTextAlignOffset = 0;
108 int mHorizontalScroll = 0; // positive only
109 unsigned mAbsoluteCursorPos = 0;
110 ATextLayoutHelper mTextLayoutHelper;
111
112 void invalidateFont() override;
113
114 void updateTextAlignOffset();
115
116 int getPosByIndexAbsolute(size_t index);
117};
bool isPasswordField() const noexcept override
Definition AAbstractTextField.h:57
ATextInputType textInputType() const noexcept override
Definition AAbstractTextField.h:47
virtual bool typeableInsert(size_t at, const AString &toInsert)=0
virtual size_t length() const =0
virtual unsigned cursorIndexByPos(glm::ivec2 pos)=0
virtual glm::ivec2 getCursorPosition()=0
virtual const AString & getText() const =0
Represents a Unicode character string.
Definition AString.h:37
Helps mapping prerendered string with positions.
Definition ATextLayoutHelper.h:25
Base class for rendering.
Definition IRenderer.h:149
Object that can be converted to string.
Definition IStringable.h:29
virtual AString toString() const =0
An std::weak_ptr with AUI extensions.
Definition SharedPtrTypes.h:178
ATextInputType
Controls IME text input type of the text field.
Definition ATextInputType.h:24
@ DEFAULT
Optimize for textual information.
Definition ATextInputType.h:28
Render context passed to AView::render.
Definition ARenderContext.h:43