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-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#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 setEditable(bool isEditable) {
   52        mIsEditable = isEditable;
   53    }
   54
   55    void setPasswordMode(bool isPasswordField) {
   56        mIsPasswordTextField = isPasswordField;
   57        setCopyable(!isPasswordField);
   58    }
   59
   60    [[nodiscard]]
   61    bool isPasswordField() const noexcept override {
   62        return mIsPasswordTextField;
   63    }
   64
   65    bool handlesNonMouseNavigation() override;
   66
   67    const AString& getText() const override;
   68
   69    void onCharEntered(char16_t c) override;
   70
   71    void setSize(glm::ivec2 size) override;
   72
   73    glm::ivec2 getCursorPosition() override;
   74
   75protected:
   76    _<IRenderer::IPrerenderedString> mPrerenderedString;
   77    AString mContents;
   78    AString mSuffix;
   79
   80    virtual bool isValidText(const AString& text);
   81
   82    void prerenderStringIfNeeded(IRenderer& render);
   83
   84    void typeableErase(size_t begin, size_t end) override;
   85
   86    bool typeableInsert(size_t at, const AString& toInsert) override;
   87
   88    size_t typeableFind(char16_t c, size_t startPos) override;
   89
   90    size_t typeableReverseFind(char16_t c, size_t startPos) override;
   91
   92    size_t length() const override;
   93
   94    bool typeableInsert(size_t at, char16_t toInsert) override;
   95
   96    AString getDisplayText() override;
   97
   98    void cursorSelectableRedraw() override;
   99
  100    unsigned cursorIndexByPos(glm::ivec2 pos) override;
  101    glm::ivec2 getPosByIndex(size_t index) override;
  102
  103    void doDrawString(IRenderer& render);
  104
  105    void onCursorIndexChanged() override;
  106    void commitStyle() override;
  107
  108private:
  109    ATextInputType mTextInputType = ATextInputType::DEFAULT;
  110    bool mIsPasswordTextField = false;
  111    bool mIsEditable = true;
  112    int mTextAlignOffset = 0;
  113    int mHorizontalScroll = 0; // positive only
  114    unsigned mAbsoluteCursorPos = 0;
  115    ATextLayoutHelper mTextLayoutHelper;
  116
  117    void invalidateFont() override;
  118
  119    void updateTextAlignOffset();
  120
  121    int getPosByIndexAbsolute(size_t index);
  122};
bool isPasswordField() const noexcept override
Definition AAbstractTextField.h:61
bool typeableInsert(size_t at, char16_t toInsert) override
AString toString() const override
const AString & getText() const override
bool typeableInsert(size_t at, const AString &toInsert) override
ATextInputType textInputType() const noexcept override
Definition AAbstractTextField.h:47
unsigned cursorIndexByPos(glm::ivec2 pos) override
glm::ivec2 getCursorPosition() override
size_t length() const override
auto text() const
Definition AAbstractTypeableView.h:48
Represents a Unicode character string.
Definition AString.h:38
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
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
@ DEFAULT
Optimize for textual information.
Definition ATextInputType.h:28
Render context passed to AView::render.
Definition ARenderContext.h:43