AUI Framework  master
Cross-platform module-based framework for developing C++20 desktop applications
ATextArea.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//
13// Created by alex2 on 5/22/2021.
14//
15
16
17#pragma once
18
19
20#include "AViewContainer.h"
21#include "AAbstractTextField.h"
22#include "AScrollbar.h"
23#include "ATextBase.h"
24
25class API_AUI_VIEWS AScrollArea;
26
48class API_AUI_VIEWS ATextArea: public AAbstractTypeableView<ATextBase<AWordWrappingEngine<std::list<_unique<aui::detail::TextBaseEntry>>>>>, public IStringable {
49public:
50 friend class UITextArea; // for testing
51
52 using Iterator = Entries::iterator;
53
54 ATextArea();
55 ATextArea(const AString& text);
56 ~ATextArea() override;
57
58 bool capturesFocus() override;
59
60 AString toString() const override;
61 const AString& text() const override;
62 unsigned int cursorIndexByPos(glm::ivec2 pos) override;
63 glm::ivec2 getPosByIndex(size_t index) override;
64 void setText(const AString& t) override;
65 void render(ARenderContext context) override;
66 void onCharEntered(char16_t c) override;
67 glm::ivec2 getCursorPosition() override;
68 void setSize(glm::ivec2 size) override;
69
70 bool isPasswordField() const noexcept override;
71
72 ATextInputType textInputType() const noexcept override;
73
74protected:
75 void typeableErase(size_t begin, size_t end) override;
76 bool typeableInsert(size_t at, const AString& toInsert) override;
77 bool typeableInsert(size_t at, char16_t toInsert) override;
78 size_t typeableFind(char16_t c, size_t startPos) override;
79 size_t typeableReverseFind(char16_t c, size_t startPos) override;
80 size_t length() const override;
81 void fillStringCanvas(const _<IRenderer::IMultiStringCanvas>& canvas) override;
82
83private:
84 mutable AOptional<AString> mCompiledText;
85 glm::ivec2 mCursorPosition{0, 0};
86
87 struct EntityQueryResult {
88 Iterator iterator;
89 size_t relativeIndex;
90 };
91
92private:
93
94 auto& entities() {
95 return mEngine.entries();
96 }
97
98 auto& entities() const {
99 return mEngine.entries();
100 }
101
102 void onCursorIndexChanged() override;
103
104 EntityQueryResult getLeftEntity(size_t indexRelativeToFrom, EntityQueryResult from);
105 EntityQueryResult getLeftEntity(size_t index);
106 Iterator splitIfNecessary(EntityQueryResult at);
107
108 AScrollArea* findScrollArea();
109};
110
111
Basic implementation of type shortcuts and selection for editable text fields.
Definition: AAbstractTypeableView.h:31
virtual ATextInputType textInputType() const noexcept=0
virtual bool typeableInsert(size_t at, const AString &toInsert)=0
virtual bool isPasswordField() const noexcept=0
virtual const AString & text() const =0
virtual size_t length() const =0
virtual unsigned cursorIndexByPos(glm::ivec2 pos)=0
virtual glm::ivec2 getCursorPosition()=0
Utility wrapper implementing the stack-allocated (fast) optional idiom.
Definition: AOptional.h:32
A scrollable container with vertical and horizontal scrollbars.
Definition: AScrollArea.h:37
Represents a Unicode character string.
Definition: AString.h:37
Multiline text input area.
Definition: ATextArea.h:48
Object that can be converted to string.
Definition: IStringable.h:29
virtual AString toString() const =0
Definition: UITextAreaTest.cpp:39
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
Render context passed to AView::render.
Definition: ARenderContext.h:43
Definition: Text.h:21