AUI Framework  develop
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
ATextArea.h
    1/*
    2 * AUI Framework - Declarative UI toolkit for modern C++20
    3 * Copyright (C) 2020-2025 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& getText() 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    AAbstractSignal::AutoDestroyedConnection mUpdatedMaxScrollSignal;
   87
   88    struct EntityQueryResult {
   89        Iterator iterator;
   90        size_t relativeIndex;
   91    };
   92
   93private:
   94
   95    auto& entities() {
   96        return mEngine.entries();
   97    }
   98
   99    auto& entities() const {
  100        return mEngine.entries();
  101    }
  102
  103    void onCursorIndexChanged() override;
  104
  105    EntityQueryResult getLeftEntity(size_t indexRelativeToFrom, EntityQueryResult from);
  106    EntityQueryResult getLeftEntity(size_t index);
  107    Iterator splitIfNecessary(EntityQueryResult at);
  108
  109    AScrollArea* findScrollArea();
  110};
  111
  112template<>
  114public:
  115    static auto property(const _<ATextArea>& view) {
  116        return view->text();
  117    }
  118
  119    static void setup(const _<ATextArea>& view) {}
  120};
  121
  122
Utility wrapper implementing the stack-allocated (fast) optional idiom.
Definition AOptional.h:33
A scrollable container with vertical and horizontal scrollbars.
Definition AScrollArea.h:37
Represents a Unicode character string.
Definition AString.h:38
Multiline text input area.
Definition ATextArea.h:48
glm::ivec2 getCursorPosition() override
ATextInputType textInputType() const noexcept override
unsigned int cursorIndexByPos(glm::ivec2 pos) override
bool isPasswordField() const noexcept override
const AString & getText() const override
bool typeableInsert(size_t at, const AString &toInsert) override
AString toString() const override
size_t length() const override
Base class for rendering.
Definition IRenderer.h:149
Object that can be converted to string.
Definition IStringable.h:29
An std::weak_ptr with AUI extensions.
Definition SharedPtrTypes.h:179
ATextInputType
Controls IME text input type of the text field.
Definition ATextInputType.h:24
Connection owner which destroys the connection in destructor.
Definition AAbstractSignal.h:396
Defines how View handles properties of FieldType type.
Definition ADataBinding.h:37
static void setup(const _< View > &view)
Called then view linked with field.
Definition ADataBinding.h:43
static auto property(const _< View > &view)
Returns property definition for FieldType.
Definition ADataBinding.h:49
Render context passed to AView::render.
Definition ARenderContext.h:43