AUI Framework  develop
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
AAbstractTypeable.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
   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:
   27    AAbstractTypeable();
   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(getText().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
   64        mTextInputActionIcon = textInputActionIcon;
   65    }
   66
   71    [[nodiscard]]
   73        return mTextInputActionIcon;
   74    }
   75
   79    void copyToClipboard() const;
   80
   84    void cutToClipboard();
   85
   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:
  126
  131
  136
  141
  142protected:
  143    size_t mMaxTextLength = 0x200;
  144    bool mIsMultiline = false;
  145
  146protected:
  147    bool isCursorBlinkVisible() const {
  148        return mCursorBlinkVisible;
  149    }
  150
  151    void updateCursorBlinking();
  152
  153    virtual void typeableErase(size_t begin, size_t end) = 0;
  154
  161    [[nodiscard]]
  162    virtual bool typeableInsert(size_t at, const AString& toInsert) = 0;
  163
  170    [[nodiscard]]
  171    virtual bool typeableInsert(size_t at, char16_t toInsert) = 0;
  172    virtual size_t typeableFind(char16_t c, size_t startPos = -1) = 0;
  173    virtual size_t typeableReverseFind(char16_t c, size_t startPos = -1) = 0;
  174    virtual void updateSelectionOnTextSet(const AString& t);
  175
  176    virtual void onCursorIndexChanged() = 0;
  177
  178
  183    void enterChar(char16_t c);
  184
  185    AString getDisplayText() override;
  186    AMenuModel composeContextMenuImpl();
  187    void handleKey(AInput::Key key);
  188
  189private:
  190    _<ATimer> mBlinkTimer = blinkTimer();
  191
  195    ATextInputActionIcon mTextInputActionIcon = ATextInputActionIcon::DEFAULT;
  196    unsigned mCursorBlinkCount = 0;
  197    bool mCursorBlinkVisible = true;
  198    bool mTextChangedFlag = false;
  199    bool mIsCopyable = true;
  200
  201private:
  202    static _<ATimer> blinkTimer();
  203
  204    template<aui::derived_from<AView> Super>
  205    friend class AAbstractTypeableView;
  206
  207    virtual void typeableInvalidateFont() = 0;
  208    void drawCursorImpl(IRenderer& renderer, glm::ivec2 position, unsigned lineHeight);
  209
  210    void fastenSelection();
  211};
  212
  213
virtual ATextInputType textInputType() const noexcept=0
void moveCursorRight()
Performs move right operation (like AInput::RIGHT)
void enterChar(char16_t c)
emits< Selection > selectionChanged
Selection is changed due to user's action or code operation.
Definition AAbstractTypeable.h:135
virtual bool typeableInsert(size_t at, const AString &toInsert)=0
void cutToClipboard()
Performs cut operation (CTRL+X) to system clipboard.
void copyToClipboard() const
Performs copy operation (CTRL+C) to system clipboard.
void setTextInputActionIcon(ATextInputActionIcon textInputActionIcon) noexcept
Definition AAbstractTypeable.h:63
ATextInputActionIcon textInputActionIcon() const noexcept
Definition AAbstractTypeable.h:72
emits actionButtonPressed
When action button of touchscreen keyboard or AInput::RETURN is pressed.
Definition AAbstractTypeable.h:140
emits< AString > textChanged
The user changed text and focused another view or AAbstractTextField::updateText is called.
Definition AAbstractTypeable.h:125
emits< AString > textChanging
When the user changed one or more symbols.
Definition AAbstractTypeable.h:130
virtual bool isPasswordField() const noexcept=0
void pasteFromClipboard()
Performs paste operation (CTRL+V) from system clipboard.
void moveCursorLeft()
Performs move left operation (like AInput::LEFT)
void paste(AString content)
Performs paste operation (CTRL+V).
virtual bool typeableInsert(size_t at, char16_t toInsert)=0
Definition ACursorSelectable.h:27
virtual const AString & getText() const =0
Represents a Unicode character string.
Definition AString.h:38
Base class for rendering.
Definition IRenderer.h:149
An std::weak_ptr with AUI extensions.
Definition SharedPtrTypes.h:179
ASignal< Args... > emits
A signal declaration.
Definition ASignal.h:572
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 ATextInputActionIcon.h:36