From d761ad8cc00d4f3631ab451d78a1dd039e126ebf Mon Sep 17 00:00:00 2001 From: halx99 Date: Sat, 16 May 2026 22:19:25 +0800 Subject: [PATCH 01/52] input-field-step1 --- axmol/2d/CMakeLists.txt | 2 - axmol/2d/TextFieldTTF.cpp | 773 ------------------ axmol/2d/TextFieldTTF.h | 293 ------- axmol/axmol.h | 3 - axmol/ui/CMakeLists.txt | 6 +- .../{UITextFieldEx.cpp => UIInputField.cpp} | 696 ++++++++++------ axmol/ui/{UITextFieldEx.h => UIInputField.h} | 51 +- axmol/ui/axmol-ui.h | 3 +- .../sceneext/src/sceneext/SGUIReader.cpp | 65 -- extensions/sceneext/src/sceneext/SGUIReader.h | 2 - .../WidgetReader/NodeReaderProtocol.cpp | 2 - .../WidgetReader/NodeReaderProtocol.h | 2 - extensions/sceneio/CMakeLists.txt | 1 + .../src/sceneio/ActionTimeline/CSLoader.cpp | 10 +- .../src/sceneio/FlatBuffersSerialize.cpp | 6 - .../TextFieldReader/TextFieldExReader.cpp | 8 +- extensions/sceneio/src/sceneio/sceneio.cpp | 4 - tests/cpp-tests/CMakeLists.txt | 4 - .../CocoStudioGUITest/CocosGUIScene.cpp | 2 - .../UIWebViewTest/UIWebViewTest.cpp | 5 +- tests/cpp-tests/Source/controller.cpp | 1 - tests/cpp-tests/Source/tests.h | 1 - 22 files changed, 519 insertions(+), 1421 deletions(-) delete mode 100644 axmol/2d/TextFieldTTF.cpp delete mode 100644 axmol/2d/TextFieldTTF.h rename axmol/ui/{UITextFieldEx.cpp => UIInputField.cpp} (55%) rename axmol/ui/{UITextFieldEx.h => UIInputField.h} (78%) diff --git a/axmol/2d/CMakeLists.txt b/axmol/2d/CMakeLists.txt index 4efa262ee799..1269307a8572 100644 --- a/axmol/2d/CMakeLists.txt +++ b/axmol/2d/CMakeLists.txt @@ -29,7 +29,6 @@ set(_AX_2D_HEADER 2d/ClippingRectangleNode.h 2d/ActionEase.h 2d/ProtectedNode.h - 2d/TextFieldTTF.h 2d/AnimationCache.h 2d/FastTMXLayer.h 2d/FontAtlasCache.h @@ -116,7 +115,6 @@ set(_AX_2D_SRC 2d/SpriteFrameCache.cpp 2d/SpriteFrame.cpp 2d/AutoPolygon.cpp - 2d/TextFieldTTF.cpp 2d/TileMapAtlas.cpp # 2d/TMXLayer.cpp diff --git a/axmol/2d/TextFieldTTF.cpp b/axmol/2d/TextFieldTTF.cpp deleted file mode 100644 index e2320d430c5b..000000000000 --- a/axmol/2d/TextFieldTTF.cpp +++ /dev/null @@ -1,773 +0,0 @@ -/**************************************************************************** -Copyright (c) 2010-2012 cocos2d-x.org -Copyright (c) 2013-2016 Chukong Technologies Inc. -Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. -Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md). - -https://axmol.dev/ - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ - -#include - -#include "axmol/2d/TextFieldTTF.h" - -#include "axmol/base/Director.h" -#include "axmol/platform/FileUtils.h" -#include "axmol/base/text_utils.h" -#include "axmol/2d/Sprite.h" - -namespace ax -{ - -#define CURSOR_TIME_SHOW_HIDE 0.5f -#define CURSOR_DEFAULT_CHAR '|' -#define PASSWORD_STYLE_TEXT_DEFAULT "\xe2\x80\xa2" -static std::size_t _calcCharCount(const char* text) -{ - int n = 0; - char ch = 0; - while ((ch = *text)) - { - AX_BREAK_IF(!ch); - - if (0x80 != (0xC0 & ch)) - { - ++n; - } - ++text; - } - return n; -} - -bool TextFieldDelegate::onTextFieldAttachWithIME(TextFieldTTF* /*sender*/) -{ - return false; -} - -bool TextFieldDelegate::onTextFieldDetachWithIME(TextFieldTTF* /*sender*/) -{ - return false; -} - -bool TextFieldDelegate::onTextFieldInsertText(TextFieldTTF* /*sender*/, const char* /*text*/, size_t /*nLen*/) -{ - return false; -} - -bool TextFieldDelegate::onTextFieldDeleteBackward(TextFieldTTF* /*sender*/, const char* /*delText*/, size_t /*nLen*/) -{ - return false; -} - -bool TextFieldDelegate::onVisit(TextFieldTTF* /*sender*/, - Renderer* /*renderer*/, - const Mat4& /*transform*/, - uint32_t /*flags*/) -{ - return false; -} - -////////////////////////////////////////////////////////////////////////// -// constructor and destructor -////////////////////////////////////////////////////////////////////////// - -TextFieldTTF::TextFieldTTF() - : _delegate(0) - , _charCount(0) - , _inputText("") - , _placeHolder("") // prevent Label initWithString assertion - , _colorText(Color32::WHITE) - , _secureTextEntry(false) - , _passwordStyleText(PASSWORD_STYLE_TEXT_DEFAULT) - , _cursorEnabled(false) - , _cursorPosition(0) - , _cursorChar(CURSOR_DEFAULT_CHAR) - , _cursorShowingTime(0.0f) - , _isAttachWithIME(false) -{ - _colorSpaceHolder.r = _colorSpaceHolder.g = _colorSpaceHolder.b = 127; - _colorSpaceHolder.a = 255; -} - -TextFieldTTF::~TextFieldTTF() {} - -////////////////////////////////////////////////////////////////////////// -// static constructor -////////////////////////////////////////////////////////////////////////// - -TextFieldTTF* TextFieldTTF::textFieldWithPlaceHolder(std::string_view placeholder, - const Vec2& dimensions, - TextHAlignment alignment, - std::string_view fontName, - float fontSize) -{ - TextFieldTTF* ret = new TextFieldTTF(); - if (ret->initWithPlaceHolder("", dimensions, alignment, fontName, fontSize)) - { - ret->autorelease(); - if (placeholder.size() > 0) - { - ret->setPlaceHolder(placeholder); - } - return ret; - } - AX_SAFE_DELETE(ret); - return nullptr; -} - -TextFieldTTF* TextFieldTTF::textFieldWithPlaceHolder(std::string_view placeholder, - std::string_view fontName, - float fontSize) -{ - TextFieldTTF* ret = new TextFieldTTF(); - if (ret->initWithPlaceHolder("", fontName, fontSize)) - { - ret->autorelease(); - if (placeholder.size() > 0) - { - ret->setPlaceHolder(placeholder); - } - return ret; - } - AX_SAFE_DELETE(ret); - return nullptr; -} - -////////////////////////////////////////////////////////////////////////// -// initialize -////////////////////////////////////////////////////////////////////////// - -bool TextFieldTTF::initWithPlaceHolder(std::string_view placeholder, - const Vec2& dimensions, - TextHAlignment alignment, - std::string_view fontName, - float fontSize) -{ - setDimensions(dimensions.width, dimensions.height); - setAlignment(alignment, TextVAlignment::CENTER); - - return initWithPlaceHolder(placeholder, fontName, fontSize); -} -bool TextFieldTTF::initWithPlaceHolder(std::string_view placeholder, std::string_view fontName, float fontSize) -{ - _placeHolder = placeholder; - - do - { - // If fontName is ttf file and it corrected, use TTFConfig - if (FileUtils::getInstance()->isFileExist(fontName)) - { - TTFConfig ttfConfig(fontName, fontSize, GlyphCollection::DYNAMIC); - if (setTTFConfig(ttfConfig)) - { - break; - } - } - - setSystemFontName(fontName); - setSystemFontSize(fontSize); - - } while (false); - - setTextColorInternally(_colorSpaceHolder); - Label::setString(_placeHolder); - -#if (AX_TARGET_PLATFORM == AX_PLATFORM_MAC || AX_TARGET_PLATFORM == AX_PLATFORM_WIN32 || \ - AX_TARGET_PLATFORM == AX_PLATFORM_LINUX) - // On desktop default enable cursor - if (_currentLabelType == LabelType::TTF) - { - setCursorEnabled(true); - } -#endif - - return true; -} - -////////////////////////////////////////////////////////////////////////// -// IMEDelegate -////////////////////////////////////////////////////////////////////////// - -bool TextFieldTTF::attachWithIME() -{ - bool ret = IMEDelegate::attachWithIME(); - if (ret) - { - // open keyboard - auto renderView = _director->getRenderView(); - if (renderView) - renderView->setIMEKeyboardState(true); - } - return ret; -} - -bool TextFieldTTF::detachWithIME() -{ - bool ret = IMEDelegate::detachWithIME(); - if (ret) - { - // close keyboard - auto renderView = _director->getRenderView(); - if (renderView) - renderView->setIMEKeyboardState(false); - } - return ret; -} - -void TextFieldTTF::onExit() -{ - detachWithIME(); - Label::onExit(); -} - -void TextFieldTTF::didAttachWithIME() -{ - setAttachWithIME(true); -} - -void TextFieldTTF::didDetachWithIME() -{ - setAttachWithIME(false); -} - -bool TextFieldTTF::canAttachWithIME() -{ - return (_delegate) ? (!_delegate->onTextFieldAttachWithIME(this)) : true; -} - -bool TextFieldTTF::canDetachWithIME() -{ - return (_delegate) ? (!_delegate->onTextFieldDetachWithIME(this)) : true; -} - -void TextFieldTTF::insertText(const char* text, size_t len) -{ - std::string insert(text, len); - - // insert \n means input end - int pos = static_cast(insert.find(text_utils::AsciiCharacters::NewLine)); - if ((int)insert.npos != pos) - { - len = pos; - insert.erase(pos); - } - - if (len > 0) - { - if (_delegate && _delegate->onTextFieldInsertText(this, insert.c_str(), len)) - { - // delegate doesn't want to insert text - return; - } - - std::size_t countInsertChar = text_utils::countUTF8Chars(insert); - _charCount += countInsertChar; - - if (_cursorEnabled) - { - std::string sText; - sText.reserve(_inputText.length() + insert.length()); - sText += _inputText; - auto pos = text_utils::getUTF8ByteOffset(sText, _cursorPosition); - if (pos != std::string::npos) - sText.insert(pos, insert); - else - sText += insert; - - setCursorPosition(_cursorPosition + countInsertChar); - - setString(sText); - } - else - { - std::string sText(_inputText); - sText.append(insert); - setString(sText); - } - } - - if ((int)insert.npos == pos) - { - return; - } - - // '\n' inserted, let delegate process first - if (_delegate && _delegate->onTextFieldInsertText(this, "\n", 1)) - { - return; - } - - // if delegate hasn't processed, detach from IME by default - detachWithIME(); -} - -void TextFieldTTF::deleteBackward(size_t numChars) -{ - size_t len = _inputText.length(); - if (!len) - { - // there is no string - return; - } - - // Length of characters to delete is based on input editor, but the actual - // length of the displayed text may be less - numChars = std::min(numChars, len); - - size_t totalDeleteLen = 0; - for (auto i = 0; i < numChars; ++i) - { - // get the delete byte number - size_t deleteLen = 1; // default, erase 1 byte - - // Calculate the actual number of bytes to delete for a specific character - while (0x80 == (0xC0 & _inputText.at(len - totalDeleteLen - deleteLen))) - { - ++deleteLen; - } - totalDeleteLen += deleteLen; - } - - if (_delegate && _delegate->onTextFieldDeleteBackward(this, _inputText.c_str() + len - totalDeleteLen, - static_cast(totalDeleteLen))) - { - // delegate doesn't want to delete backwards - return; - } - - // if all text deleted, show placeholder string - if (len <= totalDeleteLen) - { - _inputText = ""; - _charCount = 0; - setCursorPosition(0); - setString(_inputText); - return; - } - - // set new input text - if (_cursorEnabled) - { - if (_cursorPosition) - { - setCursorPosition(_cursorPosition - 1); - - std::string sText(_inputText); - auto nb = text_utils::eraseUTF8CharAt(sText, _cursorPosition); - if (nb) - --_charCount; - - setString(sText); - } - } - else - { - std::string text(_inputText.c_str(), len - totalDeleteLen); - setString(text); - } -} - -std::string_view TextFieldTTF::getContentText() -{ - return _inputText; -} - -void TextFieldTTF::setCursorPosition(std::size_t cursorPosition) -{ - if (_cursorEnabled && cursorPosition <= (std::size_t)_charCount) - { - _cursorPosition = cursorPosition; - _cursorShowingTime = CURSOR_TIME_SHOW_HIDE * 2.0f; - } -} - -void TextFieldTTF::setCursorFromPoint(const Vec2& point, const Camera* camera) -{ - if (_cursorEnabled) - { - // Reset Label, no cursor - bool oldIsAttachWithIME = _isAttachWithIME; - _isAttachWithIME = false; - updateCursorDisplayText(); - - Rect rect; - rect.size = getContentSize(); - if (isScreenPointInRect(point, camera, getWorldToNodeTransform(), rect, nullptr)) - { - int latterPosition = 0; - for (; latterPosition < _lengthOfString; ++latterPosition) - { - if (_lettersInfo[latterPosition].valid && _lettersInfo[latterPosition].atlasIndex >= 0) - { - auto sprite = getLetter(latterPosition); - if (sprite) - { - rect.size = Vec2(sprite->getContentSize().width, _lineHeight); - if (isScreenPointInRect(point, camera, sprite->getWorldToNodeTransform(), rect, nullptr)) - { - setCursorPosition(latterPosition); - break; - } - } - } - } - if (latterPosition == _lengthOfString) - { - setCursorPosition(latterPosition); - } - } - - // Set cursor - _isAttachWithIME = oldIsAttachWithIME; - updateCursorDisplayText(); - } -} - -void TextFieldTTF::setAttachWithIME(bool isAttachWithIME) -{ - if (isAttachWithIME != _isAttachWithIME) - { - _isAttachWithIME = isAttachWithIME; - - if (_isAttachWithIME) - { - setCursorPosition(_charCount); - } - updateCursorDisplayText(); - } -} - -void TextFieldTTF::setTextColorInternally(const Color32& color) -{ - if (_currentLabelType == LabelType::BMFONT) - { - Label::setColor(color); - return; - } - - Label::setTextColor(color); -} - -void TextFieldTTF::setTextColor(const Color32& color) -{ - _colorText = color; - if (!_inputText.empty()) - { - setTextColorInternally(color); - } -} - -void TextFieldTTF::visit(Renderer* renderer, const Mat4& parentTransform, uint32_t parentFlags) -{ - if (_delegate && _delegate->onVisit(this, renderer, parentTransform, parentFlags)) - { - return; - } - Label::visit(renderer, parentTransform, parentFlags); -} - -void TextFieldTTF::update(float delta) -{ - if (_cursorEnabled && _isAttachWithIME) - { - _cursorShowingTime -= delta; - if (_cursorShowingTime < -CURSOR_TIME_SHOW_HIDE) - { - _cursorShowingTime = CURSOR_TIME_SHOW_HIDE; - } - // before cursor inserted '\b', need next letter - auto sprite = getLetter((int)_cursorPosition + 1); - - if (sprite) - { - if (_currentLabelType == LabelType::BMFONT) - { - sprite->setColor(getColor()); - } - if (_cursorShowingTime >= 0.0f) - { - sprite->setOpacity(255); - } - else - { - sprite->setOpacity(0); - } - sprite->setDirty(true); - } - } -} - -const Color32& TextFieldTTF::getColorSpaceHolder() -{ - return _colorSpaceHolder; -} - -void TextFieldTTF::setColorSpaceHolder(const Color32& color) -{ - _colorSpaceHolder = color; - if (_inputText.empty()) - { - setTextColorInternally(_colorSpaceHolder); - } -} - -////////////////////////////////////////////////////////////////////////// -// properties -////////////////////////////////////////////////////////////////////////// - -// input text property -void TextFieldTTF::setString(std::string_view text) -{ - std::string displayText; - - std::size_t charCount = 0; - - if (!text.empty()) - { - _inputText = text; - displayText = _inputText; - charCount = _calcCharCount(_inputText.c_str()); - if (_secureTextEntry) - { - displayText = ""; - size_t length = charCount; - while (length) - { - displayText.append(_passwordStyleText); - --length; - } - } - } - else - { - _inputText = ""; - } - - if (_cursorEnabled && charCount != _charCount) - { - _cursorPosition = charCount; - } - - if (_cursorEnabled) - { - // Need for recreate all letters in Label - Label::removeAllChildrenWithCleanup(false); - } - - // if there is no input text, display placeholder instead - if (_inputText.empty() && (!_cursorEnabled || !_isAttachWithIME)) - { - setTextColorInternally(_colorSpaceHolder); - Label::setString(_placeHolder); - } - else - { - makeStringSupportCursor(displayText); - setTextColorInternally(_colorText); - Label::setString(displayText); - } - _charCount = charCount; -} - -void TextFieldTTF::appendString(std::string_view text) -{ - insertText(text.data(), text.length()); -} - -void TextFieldTTF::makeStringSupportCursor(std::string& displayText) -{ - if (_cursorEnabled && _isAttachWithIME) - { - if (displayText.empty()) - { - // \b - Next char not change x position - if (_currentLabelType == LabelType::TTF || _currentLabelType == LabelType::BMFONT) - displayText.push_back(text_utils::AsciiCharacters::NextCharNoChangeX); - displayText.push_back(_cursorChar); - } - else - { - auto numChars = text_utils::countUTF8Chars(displayText); - if (_cursorPosition > numChars) - _cursorPosition = numChars; - - std::string cursorChar; - // \b - Next char not change x position - if (_currentLabelType == LabelType::TTF || _currentLabelType == LabelType::BMFONT) - cursorChar.push_back(text_utils::AsciiCharacters::NextCharNoChangeX); - cursorChar.push_back(_cursorChar); - - auto offset = text_utils::getUTF8ByteOffset(displayText, _cursorPosition); - if (offset != std::string::npos) - displayText.insert(offset, cursorChar); - else - displayText += cursorChar; - } - } -} - -void TextFieldTTF::updateCursorDisplayText() -{ - // Update Label content - setString(_inputText); -} - -void TextFieldTTF::setCursorChar(char cursor) -{ - if (_cursorChar != cursor) - { - _cursorChar = cursor; - updateCursorDisplayText(); - } -} - -void TextFieldTTF::controlKey(EventKeyboard::KeyCode keyCode) -{ - if (_cursorEnabled) - { - switch (keyCode) - { - case EventKeyboard::KeyCode::KEY_HOME: - case EventKeyboard::KeyCode::KEY_KP_HOME: - setCursorPosition(0); - updateCursorDisplayText(); - break; - case EventKeyboard::KeyCode::KEY_END: - setCursorPosition(_charCount); - updateCursorDisplayText(); - break; - case EventKeyboard::KeyCode::KEY_DELETE: - case EventKeyboard::KeyCode::KEY_KP_DELETE: - if (_cursorPosition < (std::size_t)_charCount) - { - std::string sText(_inputText); - auto nb = text_utils::eraseUTF8CharAt(sText, _cursorPosition); - if (nb) - --_charCount; - setCursorPosition(_cursorPosition); - - setString(sText); - } - break; - case EventKeyboard::KeyCode::KEY_LEFT_ARROW: - if (_cursorPosition) - { - setCursorPosition(_cursorPosition - 1); - updateCursorDisplayText(); - } - break; - case EventKeyboard::KeyCode::KEY_RIGHT_ARROW: - if (_cursorPosition < (std::size_t)_charCount) - { - setCursorPosition(_cursorPosition + 1); - updateCursorDisplayText(); - } - break; - case EventKeyboard::KeyCode::KEY_ESCAPE: - detachWithIME(); - break; - default: - break; - } - } -} - -std::string_view TextFieldTTF::getString() const -{ - return _inputText; -} - -// place holder text property -void TextFieldTTF::setPlaceHolder(std::string_view text) -{ - _placeHolder = text; - if (_inputText.empty() && !_isAttachWithIME) - { - setTextColorInternally(_colorSpaceHolder); - Label::setString(_placeHolder); - } -} - -std::string_view TextFieldTTF::getPlaceHolder() const -{ - return _placeHolder; -} - -void TextFieldTTF::setCursorEnabled(bool enabled) -{ - if (_cursorEnabled == enabled) - { - return; - } - - _cursorEnabled = enabled; - if (_cursorEnabled) - { - _cursorPosition = _charCount; - if (_currentLabelType == LabelType::TTF || _currentLabelType == LabelType::BMFONT) - { - scheduleUpdate(); - } - return; - } - - _cursorPosition = 0; - if (_currentLabelType == LabelType::TTF || _currentLabelType == LabelType::BMFONT) - { - unscheduleUpdate(); - } -} - -// secureTextEntry -void TextFieldTTF::setSecureTextEntry(bool value) -{ - if (_secureTextEntry != value) - { - _secureTextEntry = value; - setString(_inputText); - } -} - -void TextFieldTTF::setPasswordTextStyle(std::string_view text) -{ - if (text.length() < 1) - { - return; - } - - if (text != _passwordStyleText) - { - _passwordStyleText = text; - setString(_inputText); - } -} - -std::string_view TextFieldTTF::getPasswordTextStyle() const -{ - return _passwordStyleText; -} - -bool TextFieldTTF::isSecureTextEntry() const -{ - return _secureTextEntry; -} - -} // namespace ax diff --git a/axmol/2d/TextFieldTTF.h b/axmol/2d/TextFieldTTF.h deleted file mode 100644 index 83994b2ce362..000000000000 --- a/axmol/2d/TextFieldTTF.h +++ /dev/null @@ -1,293 +0,0 @@ -/**************************************************************************** -Copyright (c) 2010-2012 cocos2d-x.org -Copyright (c) 2013-2016 Chukong Technologies Inc. -Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. -Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md). - -https://axmol.dev/ - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ - -#pragma once - -#include "axmol/2d/Label.h" -#include "axmol/base/IMEDelegate.h" - -/** - * @addtogroup ui - * @{ - */ -namespace ax -{ - -class TextFieldTTF; - -/** - * A input protocol for TextField. - * !!!DEPRECATED since axmol-2.1.3 - * Why DPRECATED? - * 1. lack of cursor support, cursor will overlap with text due to cursor share display text with input text. - * 2. many memory allocations when insert,delete text - * 3. ui::TextField depends on this class, it's not a good design, future we should implement a new ui::TextField which - * is don't depend on this class - * 4. The ui::TextFieldEx maybe a good start point to solve these problems. - */ -class AX_DLL TextFieldDelegate -{ -public: - /** - * Destructor for TextFieldDelegate. - */ - virtual ~TextFieldDelegate() {} - - /** - *@brief If the sender doesn't want to attach to the IME, return true. - */ - virtual bool onTextFieldAttachWithIME(TextFieldTTF* sender); - /** - *@brief If the sender doesn't want to detach from the IME, return true. - */ - virtual bool onTextFieldDetachWithIME(TextFieldTTF* sender); - - /** - *@brief If the sender doesn't want to insert the text, return true. - */ - virtual bool onTextFieldInsertText(TextFieldTTF* sender, const char* text, size_t nLen); - - /** - *@brief If the sender doesn't want to delete the delText, return true. - */ - virtual bool onTextFieldDeleteBackward(TextFieldTTF* sender, const char* delText, size_t nLen); - - /** - *@brief If the sender doesn't want to draw, return true. - */ - virtual bool onVisit(TextFieldTTF* sender, Renderer* renderer, const Mat4& transform, uint32_t flags); -}; - -/** - *@brief A simple text input field with TTF font. - */ -class AX_DLL TextFieldTTF : public Label, public IMEDelegate -{ -public: - /** - * Default constructor. - */ - TextFieldTTF(); - - /** - * Default destructor. - * @lua NA - */ - virtual ~TextFieldTTF(); - - /** Creates a TextFieldTTF from a fontname, alignment, dimension and font size. - */ - static TextFieldTTF* textFieldWithPlaceHolder(std::string_view placeholder, - const Vec2& dimensions, - TextHAlignment alignment, - std::string_view fontName, - float fontSize); - - /** Creates a TextFieldTTF from a fontname and font size. - */ - static TextFieldTTF* textFieldWithPlaceHolder(std::string_view placeholder, - std::string_view fontName, - float fontSize); - - /** Initializes the TextFieldTTF with a font name, alignment, dimension and font size. */ - bool initWithPlaceHolder(std::string_view placeholder, - const Vec2& dimensions, - TextHAlignment alignment, - std::string_view fontName, - float fontSize); - - /** Initializes the TextFieldTTF with a font name and font size. */ - bool initWithPlaceHolder(std::string_view placeholder, std::string_view fontName, float fontSize); - - /** - *@brief Open keyboard and receive input text. - */ - bool attachWithIME() override; - - /** - *@brief End text input and close keyboard. - */ - bool detachWithIME() override; - - ////////////////////////////////////////////////////////////////////////// - // properties - ////////////////////////////////////////////////////////////////////////// - /** - * @lua NA - */ - TextFieldDelegate* getDelegate() const { return _delegate; } - /** - * @lua NA - */ - void setDelegate(TextFieldDelegate* delegate) { _delegate = delegate; } - - /** - * Query the currently inputed character count. - *@return The total input character count. - */ - std::size_t getCharCount() const { return _charCount; } - - /** - * Query the color of place holder. - *@return The place holder color. - */ - virtual const Color32& getColorSpaceHolder(); - - /** - * Change the placeholder color. - *@param color The placeholder color in Color32. - */ - virtual void setColorSpaceHolder(const Color32& color); - - /** - * Change the color of input text. - *@param textColor The text color in Color32. - */ - void setTextColor(const Color32& textColor) override; - - /** - * Change input text of TextField. - *@param text The input text of TextField. - */ - void setString(std::string_view text) override; - - /** - * Append to input text of TextField. - *@param text The append text of TextField. - */ - virtual void appendString(std::string_view text); - - /** - * Query the input text of TextField. - *@return Get the input text of TextField. - */ - std::string_view getString() const override; - - /** - * Change placeholder text. - * place holder text displayed when there is no text in the text field. - *@param text The placeholder string. - */ - virtual void setPlaceHolder(std::string_view text); - - /** - * Query the placeholder string. - *@return The placeholder string. - */ - virtual std::string_view getPlaceHolder() const; - - /** - * Set enable secure text entry representation. - * If you want to display password in TextField, this option is very helpful. - *@param value Whether or not to display text with secure text entry. - */ - virtual void setSecureTextEntry(bool value); - virtual void setPasswordTextStyle(std::string_view text); - std::string_view getPasswordTextStyle() const; - - /** - * Query whether the currently display mode is secure text entry or not. - *@return Whether current text is displayed as secure text entry. - */ - virtual bool isSecureTextEntry() const; - - void visit(Renderer* renderer, const Mat4& parentTransform, uint32_t parentFlags) override; - - void update(float delta) override; - - /** - * Set enable cursor use. - */ - void setCursorEnabled(bool enabled); - - /** - * Set char showing cursor. - */ - void setCursorChar(char cursor); - - /** - * Set cursor position, if enabled - */ - void setCursorPosition(std::size_t cursorPosition); - - /** - * Set cursor position to hit letter, if enabled - */ - void setCursorFromPoint(const Vec2& point, const Camera* camera); - -protected: - void onExit() override; - - ////////////////////////////////////////////////////////////////////////// - // IMEDelegate interface - ////////////////////////////////////////////////////////////////////////// - - bool canAttachWithIME() override; - bool canDetachWithIME() override; - void didAttachWithIME() override; - void didDetachWithIME() override; - void insertText(const char* text, size_t len) override; - void deleteBackward(size_t numChars) override; - std::string_view getContentText() override; - void controlKey(EventKeyboard::KeyCode keyCode) override; - - TextFieldDelegate* _delegate; - std::size_t _charCount; - - std::string _inputText; - - std::string _placeHolder; - Color32 _colorSpaceHolder; - Color32 _colorText; - - bool _secureTextEntry; - std::string _passwordStyleText; - - // Need use cursor - bool _cursorEnabled; - // Current position cursor - std::size_t _cursorPosition; - // Char showing cursor - char _cursorChar; - // >0 - show, <0 - hide - float _cursorShowingTime; - - bool _isAttachWithIME; - - void makeStringSupportCursor(std::string& displayText); - void updateCursorDisplayText(); - void setAttachWithIME(bool isAttachWithIME); - void setTextColorInternally(const Color32& color); - -private: - class LengthStack; - LengthStack* _lens; -}; - -} // namespace ax -// end of ui group -/// @} diff --git a/axmol/axmol.h b/axmol/axmol.h index d7e04c434a8f..992239ec54d5 100644 --- a/axmol/axmol.h +++ b/axmol/axmol.h @@ -220,9 +220,6 @@ THE SOFTWARE. #include "axmol/2d/SpriteFrame.h" #include "axmol/2d/SpriteFrameCache.h" -// text_input_node -#include "axmol/2d/TextFieldTTF.h" - // textures #include "axmol/renderer/TextureAtlas.h" diff --git a/axmol/ui/CMakeLists.txt b/axmol/ui/CMakeLists.txt index 869b1fafefc6..28bcf525271d 100644 --- a/axmol/ui/CMakeLists.txt +++ b/axmol/ui/CMakeLists.txt @@ -146,8 +146,7 @@ set(_AX_UI_HEADER ui/UIText.h ui/UITextAtlas.h ui/UITextBMFont.h - ui/UITextField.h - ui/UITextFieldEx.h + ui/UIInputField.h ui/UIVBox.h ui/UIWidget.h ) @@ -178,12 +177,11 @@ set(_AX_UI_SRC ui/UIText.cpp ui/UITextAtlas.cpp ui/UITextBMFont.cpp - ui/UITextField.cpp + ui/UIInputField.cpp ui/UIVBox.cpp ui/UIWidget.cpp ui/UIEditBox/UIEditBox.cpp ui/UILayoutComponent.cpp ui/UIEditBox/UIEditBoxImpl-common.cpp ui/UITabControl.cpp - ui/UITextFieldEx.cpp ) diff --git a/axmol/ui/UITextFieldEx.cpp b/axmol/ui/UIInputField.cpp similarity index 55% rename from axmol/ui/UITextFieldEx.cpp rename to axmol/ui/UIInputField.cpp index 8901666731ab..26bca51ee2bd 100644 --- a/axmol/ui/UITextFieldEx.cpp +++ b/axmol/ui/UIInputField.cpp @@ -22,8 +22,18 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ -#include "axmol/ui/UITextFieldEx.h" +#include "axmol/ui/UIInputField.h" #include "axmol/base/Director.h" +#include "axmol/base/text_utils.h" + +#include +#include +#include + +#if (AX_TARGET_PLATFORM == AX_PLATFORM_WIN32 || AX_TARGET_PLATFORM == AX_PLATFORM_MAC || \ + AX_TARGET_PLATFORM == AX_PLATFORM_LINUX) +# include "axmol/platform/desktop/RenderViewImpl.h" +#endif namespace ax { @@ -127,6 +137,53 @@ static Sprite* engine_inj_create_lump(const Color32& color, int height, int widt namespace ui { +static std::string s_clipboardFallback; +static InputField::ClipboardGetter s_clipboardGetter; +static InputField::ClipboardSetter s_clipboardSetter; + +#if (AX_TARGET_PLATFORM == AX_PLATFORM_WIN32 || AX_TARGET_PLATFORM == AX_PLATFORM_MAC || \ + AX_TARGET_PLATFORM == AX_PLATFORM_LINUX) +static GLFWwindow* getClipboardWindow() +{ + auto renderView = dynamic_cast(Director::getInstance()->getRenderView()); + return renderView ? renderView->getWindow() : nullptr; +} +#endif + +static std::string readClipboardText() +{ + if (s_clipboardGetter) + return s_clipboardGetter(); + +#if (AX_TARGET_PLATFORM == AX_PLATFORM_WIN32 || AX_TARGET_PLATFORM == AX_PLATFORM_MAC || \ + AX_TARGET_PLATFORM == AX_PLATFORM_LINUX) + if (auto window = getClipboardWindow()) + { + if (auto text = glfwGetClipboardString(window)) + return text; + } +#endif + + return s_clipboardFallback; +} + +static void writeClipboardText(std::string_view text) +{ + if (s_clipboardSetter) + { + s_clipboardSetter(text); + return; + } + + s_clipboardFallback = text; + +#if (AX_TARGET_PLATFORM == AX_PLATFORM_WIN32 || AX_TARGET_PLATFORM == AX_PLATFORM_MAC || \ + AX_TARGET_PLATFORM == AX_PLATFORM_LINUX) + if (auto window = getClipboardWindow()) + glfwSetClipboardString(window, s_clipboardFallback.c_str()); +#endif +} + /// calculate the UTF-8 string's char count. static int _truncateUTF8String(const char* text, int limit, int& nb) { @@ -170,53 +227,11 @@ static float internalCalcStringWidth(std::string_view s, std::string_view fontNa return label->getContentSize().width; } -static std::string internalUTF8MoveLeft(std::string_view utf8Text, int length /* default utf8Text.length() */) -{ - if (!utf8Text.empty() && length > 0) - { - - // get the delete byte number - int deleteLen = 1; // default, erase 1 byte - - while (length >= deleteLen && 0x80 == (0xC0 & utf8Text.at(length - deleteLen))) - { - ++deleteLen; - } - - return std::string{utf8Text.data(), static_cast(length - deleteLen)}; - } - else - { - return std::string{utf8Text}; - } -} - -static std::string internalUTF8MoveRight(std::string_view utf8Text, int length /* default utf8Text.length() */) -{ - if (!utf8Text.empty() && length >= 0) - { - - // get the delete byte number - size_t addLen = 1; // default, erase 1 byte - - while ((length + addLen) < utf8Text.size() && 0x80 == (0xC0 & utf8Text.at(length + addLen))) - { - ++addLen; - } - - return std::string{utf8Text.data(), static_cast(length + addLen)}; - } - else - { - return std::string{utf8Text}; - } -} - ////////////////////////////////////////////////////////////////////////// // constructor and destructor ////////////////////////////////////////////////////////////////////////// -bool TextFieldEx::s_keyboardVisible = false; -TextFieldEx::TextFieldEx() +bool InputField::s_keyboardVisible = false; +InputField::InputField() : _editable(true) , _renderLabel(nullptr) , _charCount(0) @@ -226,6 +241,11 @@ TextFieldEx::TextFieldEx() , _colorSpaceHolder(Color32::GRAY) , _secureTextEntry(false) , _cursor(nullptr) + , _selectionLayer(nullptr) + , _selectionColor(0.26f, 0.52f, 1.0f, 0.35f) + , _selectionStartUtf8(0) + , _selectionEndUtf8(0) + , _selectionAnchorUtf8(0) , _touchListener(nullptr) , _kbdListener(nullptr) , onTextModify(nullptr) @@ -233,17 +253,23 @@ TextFieldEx::TextFieldEx() , onCloseIME(nullptr) , _charLimit(std::numeric_limits::max()) , _systemFontUsed(false) + , _fontType(0) , _fontSize(24) , _insertPosUtf8(0) , _insertPos(0) , _cursorPos(0) , _touchCursorControlEnabled(true) + , _selectingByTouch(false) + , _selectionTouchMoved(false) + , _ctrlKeyPressed(false) + , _shiftKeyPressed(false) + , _asteriskWidth(0) , _cursorVisible(false) , _continuousTouchDelayTimerID(nullptr) , _continuousTouchDelayTime(0.6) {} -TextFieldEx::~TextFieldEx() +InputField::~InputField() { if (_kbdListener != nullptr) _eventDispatcher->removeEventListener(_kbdListener); @@ -254,13 +280,13 @@ TextFieldEx::~TextFieldEx() ////////////////////////////////////////////////////////////////////////// // static constructor ////////////////////////////////////////////////////////////////////////// -TextFieldEx* TextFieldEx::create(std::string_view placeholder, +InputField* InputField::create(std::string_view placeholder, std::string_view fontName, float fontSize, float cursorWidth, const Color32& cursorColor) { - TextFieldEx* ret = new TextFieldEx(); + InputField* ret = new InputField(); if (ret && ret->initWithPlaceHolder("", fontName, fontSize, cursorWidth, cursorColor)) { ret->autorelease(); @@ -277,7 +303,7 @@ TextFieldEx* TextFieldEx::create(std::string_view placeholder, ////////////////////////////////////////////////////////////////////////// // initialize ////////////////////////////////////////////////////////////////////////// -bool TextFieldEx::initWithPlaceHolder(std::string_view placeholder, +bool InputField::initWithPlaceHolder(std::string_view placeholder, std::string_view fontName, float fontSize, float cursorWidth, @@ -285,6 +311,9 @@ bool TextFieldEx::initWithPlaceHolder(std::string_view placeholder, { _placeHolder = placeholder; + _selectionLayer = DrawNode::create(); + this->addChild(_selectionLayer); + _renderLabel = _createLabel(placeholder, fontName, fontSize, Vec2::ZERO, TextHAlignment::CENTER, TextVAlignment::CENTER); _renderLabel->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT); @@ -298,16 +327,20 @@ bool TextFieldEx::initWithPlaceHolder(std::string_view placeholder, _fontName = fontName; _fontSize = fontSize; _systemFontUsed = !FileUtils::getInstance()->isFileExist(fontName); + _fontType = _systemFontUsed ? 0 : 1; + + using namespace std::string_view_literals; + _asteriskWidth = internalCalcStringWidth("*"sv, _fontName, _fontSize); return true; } -std::string_view TextFieldEx::getTextFontName() const +std::string_view InputField::getTextFontName() const { return _fontName; } -void TextFieldEx::setTextFontName(std::string_view fontName) +void InputField::setTextFontName(std::string_view fontName) { if (FileUtils::getInstance()->isFileExist(fontName)) { @@ -333,9 +366,11 @@ void TextFieldEx::setTextFontName(std::string_view fontName) using namespace std::string_view_literals; _asteriskWidth = internalCalcStringWidth("*"sv, _fontName, _fontSize); + __updateCursorPosition(); + __updateSelectionLayer(); } -void TextFieldEx::setTextFontSize(float size) +void InputField::setTextFontSize(float size) { if (_systemFontUsed) { @@ -352,14 +387,16 @@ void TextFieldEx::setTextFontSize(float size) using namespace std::string_view_literals; _asteriskWidth = internalCalcStringWidth("*"sv, _fontName, _fontSize); + __updateCursorPosition(); + __updateSelectionLayer(); } -float TextFieldEx::getTextFontSize() const +float InputField::getTextFontSize() const { return _fontSize; } -void TextFieldEx::enableIME(Node* control) +void InputField::enableIME(Node* control) { if (_touchListener != nullptr) { @@ -388,8 +425,28 @@ void TextFieldEx::enableIME(Node* control) this->_continuousTouchDelayTime, [=, this]() { this->_continuousTouchCallback(worldPoint); }); } } + + _selectingByTouch = focus; + _selectionTouchMoved = false; + _selectionAnchorUtf8 = _insertPosUtf8; + if (focus && _touchCursorControlEnabled) + { + auto renderLabelPoint = _renderLabel->convertToNodeSpace(touch->getLocation()); + _selectionAnchorUtf8 = __getCursorPositionFromX(renderLabelPoint.x); + } return true; }; + _touchListener->onTouchMoved = [control, this](Touch* touch, Event*) { + if (!_selectingByTouch || !_touchCursorControlEnabled || + !(_checkVisibility(this) && _editable && this->_enabled && _containsTouchPoint(control, touch))) + { + return; + } + + auto renderLabelPoint = _renderLabel->convertToNodeSpace(touch->getLocation()); + __setCursorPosition(__getCursorPositionFromX(renderLabelPoint.x), true); + _selectionTouchMoved = hasSelection(); + }; _touchListener->onTouchEnded = [control, this](Touch* touch, Event* e) { if (this->_continuousTouchDelayTimerID != nullptr) { @@ -406,13 +463,14 @@ void TextFieldEx::enableIME(Node* control) if (_touchCursorControlEnabled) { auto renderLabelPoint = _renderLabel->convertToNodeSpace(touch->getLocation()); - __moveCursorTo(renderLabelPoint.x); + __moveCursorTo(renderLabelPoint.x, _selectionTouchMoved); } } else { closeIME(); } + _selectingByTouch = false; }; _eventDispatcher->addEventListenerWithSceneGraphPriority(_touchListener, this); @@ -420,15 +478,55 @@ void TextFieldEx::enableIME(Node* control) /// enable use keyboard <- -> to move cursor. _kbdListener = EventListenerKeyboard::create(); _kbdListener->onKeyPressed = [this](EventKeyboard::KeyCode code, Event*) { + switch (code) + { + case EventKeyboard::KeyCode::KEY_CTRL: + case EventKeyboard::KeyCode::KEY_RIGHT_CTRL: + case EventKeyboard::KeyCode::KEY_HYPER: + _ctrlKeyPressed = true; + return; + case EventKeyboard::KeyCode::KEY_SHIFT: + case EventKeyboard::KeyCode::KEY_RIGHT_SHIFT: + _shiftKeyPressed = true; + return; + default: + break; + } + if (_cursorVisible) { + if (_ctrlKeyPressed) + { + switch (code) + { + case EventKeyboard::KeyCode::KEY_A: + case EventKeyboard::KeyCode::KEY_CAPITAL_A: + this->selectAll(); + return; + case EventKeyboard::KeyCode::KEY_C: + case EventKeyboard::KeyCode::KEY_CAPITAL_C: + this->copySelectionToClipboard(); + return; + case EventKeyboard::KeyCode::KEY_X: + case EventKeyboard::KeyCode::KEY_CAPITAL_X: + this->cutSelectionToClipboard(); + return; + case EventKeyboard::KeyCode::KEY_V: + case EventKeyboard::KeyCode::KEY_CAPITAL_V: + this->pasteFromClipboard(); + return; + default: + break; + } + } + switch (code) { case EventKeyboard::KeyCode::KEY_LEFT_ARROW: - this->__moveCursor(-1); + this->__moveCursor(-1, _shiftKeyPressed); break; case EventKeyboard::KeyCode::KEY_RIGHT_ARROW: - this->__moveCursor(1); + this->__moveCursor(1, _shiftKeyPressed); break; case EventKeyboard::KeyCode::KEY_DELETE: case EventKeyboard::KeyCode::KEY_KP_DELETE: @@ -438,11 +536,27 @@ void TextFieldEx::enableIME(Node* control) } } }; + _kbdListener->onKeyReleased = [this](EventKeyboard::KeyCode code, Event*) { + switch (code) + { + case EventKeyboard::KeyCode::KEY_CTRL: + case EventKeyboard::KeyCode::KEY_RIGHT_CTRL: + case EventKeyboard::KeyCode::KEY_HYPER: + _ctrlKeyPressed = false; + break; + case EventKeyboard::KeyCode::KEY_SHIFT: + case EventKeyboard::KeyCode::KEY_RIGHT_SHIFT: + _shiftKeyPressed = false; + break; + default: + break; + } + }; _eventDispatcher->addEventListenerWithSceneGraphPriority(_kbdListener, this); } -void TextFieldEx::disableIME(void) +void InputField::disableIME(void) { _eventDispatcher->removeEventListener(_kbdListener); _eventDispatcher->removeEventListener(_touchListener); @@ -452,7 +566,7 @@ void TextFieldEx::disableIME(void) closeIME(); } -Label* TextFieldEx::getRenderLabel() +Label* InputField::getRenderLabel() { return _renderLabel; } @@ -461,7 +575,7 @@ Label* TextFieldEx::getRenderLabel() // IMEDelegate ////////////////////////////////////////////////////////////////////////// -bool TextFieldEx::attachWithIME() +bool InputField::attachWithIME() { bool ret = IMEDelegate::attachWithIME(); if (ret) @@ -474,7 +588,7 @@ bool TextFieldEx::attachWithIME() return ret; } -bool TextFieldEx::detachWithIME() +bool InputField::detachWithIME() { bool ret = IMEDelegate::detachWithIME(); if (ret) @@ -487,19 +601,19 @@ bool TextFieldEx::detachWithIME() return ret; } -void TextFieldEx::keyboardDidShow(IMEKeyboardNotificationInfo& /*info*/) +void InputField::keyboardDidShow(IMEKeyboardNotificationInfo& /*info*/) { s_keyboardVisible = true; } -void TextFieldEx::keyboardDidHide(IMEKeyboardNotificationInfo& /*info*/) +void InputField::keyboardDidHide(IMEKeyboardNotificationInfo& /*info*/) { s_keyboardVisible = false; } -void TextFieldEx::openIME(void) +void InputField::openIME(void) { - AXLOGD("TextFieldEx:: openIME"); + AXLOGD("InputField:: openIME"); this->attachWithIME(); __updateCursorPosition(); __showCursor(); @@ -508,9 +622,9 @@ void TextFieldEx::openIME(void) this->onOpenIME(); } -void TextFieldEx::closeIME(void) +void InputField::closeIME(void) { - AXLOGD("TextFieldEx:: closeIME"); + AXLOGD("InputField:: closeIME"); __hideCursor(); this->detachWithIME(); @@ -518,23 +632,26 @@ void TextFieldEx::closeIME(void) this->onCloseIME(); } -bool TextFieldEx::canAttachWithIME() +bool InputField::canAttachWithIME() { return true; //(_delegate) ? (! _delegate->onTextFieldAttachWithIME(this)) : true; } -bool TextFieldEx::canDetachWithIME() +bool InputField::canDetachWithIME() { return true; //(_delegate) ? (! _delegate->onTextFieldDetachWithIME(this)) : true; } -void TextFieldEx::insertText(const char* text, size_t len) +void InputField::insertText(const char* text, size_t len) { if (!_editable || !this->_enabled) { return; } + if (hasSelection()) + __deleteSelection(false); + if (_charLimit > 0 && _charCount >= _charLimit) { // regard zero as unlimited axbeep(0); @@ -542,7 +659,8 @@ void TextFieldEx::insertText(const char* text, size_t len) } int nb; - auto n = _truncateUTF8String(text, static_cast(_charLimit - _charCount), nb); + auto limit = (_charLimit > 0) ? static_cast(_charLimit - _charCount) : std::numeric_limits::max(); + auto n = _truncateUTF8String(text, limit, nb); std::string insert(text, nb); @@ -562,14 +680,13 @@ void TextFieldEx::insertText(const char* text, size_t len) // return; // } - _charCount += n; // _calcCharCount(insert.c_str()); std::string sText(_inputText); + auto cursorPosition = static_cast(_insertPosUtf8); sText.insert(_insertPos, insert); // original is: sText.append(insert); // bool needUpdatePos this->setString(sText); - while (n-- > 0) - __moveCursor(1); + __setCursorPosition(cursorPosition + n, false); // this->contentDirty = true; // __updateCursorPosition(); @@ -593,8 +710,14 @@ void TextFieldEx::insertText(const char* text, size_t len) this->closeIME(); } -void TextFieldEx::deleteBackward(size_t numChars) +void InputField::deleteBackward(size_t numChars) { + if (hasSelection()) + { + __deleteSelection(true); + return; + } + if (!_editable || !this->_enabled || 0 == _charCount) { axbeep(0); @@ -610,23 +733,10 @@ void TextFieldEx::deleteBackward(size_t numChars) return; } - // Length of characters to delete is based on input editor, but the actual - // length of the displayed text may be less - numChars = std::min(numChars, len); - - size_t totalDeleteLen = 0; - for (auto i = 0; i < numChars; ++i) - { - // get the delete byte number - size_t deleteLen = 1; // default, erase 1 byte - - // Calculate the actual number of bytes to delete for a specific character - while (0x80 == (0xC0 & _inputText.at(_insertPos - totalDeleteLen - deleteLen))) - { - ++deleteLen; - } - totalDeleteLen += deleteLen; - } + auto deleteChars = std::min(numChars, static_cast(_insertPosUtf8)); + auto startUtf8 = static_cast(_insertPosUtf8) - deleteChars; + auto startByte = __getByteOffset(startUtf8); + auto totalDeleteLen = static_cast(_insertPos) - startByte; // if (_delegate && _delegate->onTextFieldDeleteBackward(this, _inputText.c_str() + len - deleteLen, // static_cast(deleteLen))) @@ -638,16 +748,8 @@ void TextFieldEx::deleteBackward(size_t numChars) // if all text deleted, show placeholder string if (len <= totalDeleteLen) { - __moveCursor(-1); - - _inputText.clear(); - _charCount = 0; - _renderLabel->setTextColor(_colorSpaceHolder); - _renderLabel->setString(_placeHolder); - - // __updateCursorPosition(); - - // this->contentDirty = true; + this->setString(""); + __setCursorPosition(0, false); if (this->onTextModify) this->onTextModify(); @@ -656,11 +758,10 @@ void TextFieldEx::deleteBackward(size_t numChars) // set new input text std::string text = _inputText; // (inputText.c_str(), len - deleteLen); - text.erase(_insertPos - totalDeleteLen, totalDeleteLen); - - __moveCursor(-1); + text.erase(startByte, totalDeleteLen); this->setString(text); + __setCursorPosition(startUtf8, false); //__updateCursorPosition(); // __moveCursor(-1); @@ -669,8 +770,14 @@ void TextFieldEx::deleteBackward(size_t numChars) this->onTextModify(); } -void TextFieldEx::handleDeleteKeyEvent() +void InputField::handleDeleteKeyEvent() { + if (hasSelection()) + { + __deleteSelection(true); + return; + } + if (!_editable || !this->_enabled || 0 == _charCount) { axbeep(0); @@ -686,13 +793,8 @@ void TextFieldEx::handleDeleteKeyEvent() return; } - // get the delete byte number - size_t deleteLen = 1; // default, erase 1 byte - - while ((_inputText.length() > _insertPos + deleteLen) && 0x80 == (0xC0 & _inputText.at(_insertPos + deleteLen))) - { - ++deleteLen; - } + auto nextByte = __getByteOffset(static_cast(_insertPosUtf8) + 1); + auto deleteLen = nextByte - static_cast(_insertPos); // if (_delegate && _delegate->onTextFieldDeleteBackward(this, _inputText.c_str() + len - deleteLen, // static_cast(deleteLen))) @@ -704,12 +806,8 @@ void TextFieldEx::handleDeleteKeyEvent() // if all text deleted, show placeholder string if (len <= deleteLen) { - _inputText.clear(); - _charCount = 0; - _renderLabel->setTextColor(_colorSpaceHolder); - _renderLabel->setString(_placeHolder); - - __updateCursorPosition(); + this->setString(""); + __setCursorPosition(0, false); // this->contentDirty = true; @@ -725,44 +823,45 @@ void TextFieldEx::handleDeleteKeyEvent() // __moveCursor(-1); this->setString(text); + __setCursorPosition(_insertPosUtf8, false); if (this->onTextModify) this->onTextModify(); } -std::string_view TextFieldEx::getContentText() +std::string_view InputField::getContentText() { return _inputText; } -void TextFieldEx::setTextColor(const Color32& color) +void InputField::setTextColor(const Color32& color) { _colorText = color; if (!_inputText.empty()) _renderLabel->setTextColor(_colorText); } -const Color32& TextFieldEx::getTextColor(void) const +const Color32& InputField::getTextColor(void) const { return _colorText; } -void TextFieldEx::setCursorColor(const Color32& color) +void InputField::setCursorColor(const Color32& color) { _cursor->setColor(color); } -const Color32& TextFieldEx::getCursorColor(void) const +const Color32& InputField::getCursorColor(void) const { return _cursor->getColor(); } -const Color32& TextFieldEx::getPlaceholderColor() const +const Color32& InputField::getPlaceholderColor() const { return _colorSpaceHolder; } -void TextFieldEx::setPlaceholderColor(const Color32& color) +void InputField::setPlaceholderColor(const Color32& color) { _colorSpaceHolder = color; if (_inputText.empty()) @@ -774,11 +873,14 @@ void TextFieldEx::setPlaceholderColor(const Color32& color) ////////////////////////////////////////////////////////////////////////// // input text property -void TextFieldEx::setString(std::string_view text) +void InputField::setString(std::string_view text) { static char bulletString[] = {(char)0xe2, (char)0x80, (char)0xa2, (char)0x00}; + auto oldInsertPosUtf8 = static_cast(_insertPosUtf8); + bool bInsertAtEnd = (oldInsertPosUtf8 == _charCount); _inputText = text; + auto newCharCount = text_utils::countUTF8Chars(_inputText); std::string secureText; @@ -788,7 +890,7 @@ void TextFieldEx::setString(std::string_view text) { if (_secureTextEntry) { - size_t length = _inputText.length(); + size_t length = newCharCount; displayText = &secureText; while (length > 0) @@ -811,30 +913,35 @@ void TextFieldEx::setString(std::string_view text) _renderLabel->setString(*displayText); } - bool bInsertAtEnd = (_insertPosUtf8 == _charCount); - - _charCount = text_utils::countUTF8Chars(_inputText); + _charCount = newCharCount; if (bInsertAtEnd) { - _insertPosUtf8 = static_cast(_charCount); - _insertPos = static_cast(_inputText.length()); - _cursorPos = static_cast(displayText->length()); + __setCursorPosition(_charCount, false); } + else + { + __setCursorPosition(std::min(oldInsertPosUtf8, _charCount), hasSelection()); + } + + _selectionStartUtf8 = std::min(_selectionStartUtf8, _charCount); + _selectionEndUtf8 = std::min(_selectionEndUtf8, _charCount); + __updateSelectionLayer(); } -void TextFieldEx::updateContentSize(void) +void InputField::updateContentSize(void) { this->setContentSize(_renderLabel->getContentSize()); + __updateSelectionLayer(); } -std::string_view TextFieldEx::getString() const +std::string_view InputField::getString() const { return _inputText; } // place holder text property -void TextFieldEx::setPlaceholderText(std::string_view text) +void InputField::setPlaceholderText(std::string_view text) { _placeHolder = text; if (_inputText.empty()) @@ -844,13 +951,13 @@ void TextFieldEx::setPlaceholderText(std::string_view text) } } -std::string_view TextFieldEx::getPlaceholderText() const +std::string_view InputField::getPlaceholderText() const { return _placeHolder; } // secureTextEntry -void TextFieldEx::setPasswordEnabled(bool value) +void InputField::setPasswordEnabled(bool value) { if (_secureTextEntry != value) { @@ -860,12 +967,12 @@ void TextFieldEx::setPasswordEnabled(bool value) } } -bool TextFieldEx::isPasswordEnabled() const +bool InputField::isPasswordEnabled() const { return _secureTextEntry; } -void TextFieldEx::setEnabled(bool bEnabled) +void InputField::setEnabled(bool bEnabled) { if (this->_enabled != bEnabled) { @@ -877,12 +984,104 @@ void TextFieldEx::setEnabled(bool bEnabled) } } -int TextFieldEx::getFontType() const +int InputField::getFontType() const { return _fontType; } -void TextFieldEx::__initCursor(int height, int width, const Color32& color) +bool InputField::hasSelection() const +{ + return _selectionStartUtf8 != _selectionEndUtf8; +} + +void InputField::selectAll() +{ + __setSelection(0, _charCount); + _selectionAnchorUtf8 = 0; + __setCursorPosition(_charCount, true); +} + +void InputField::clearSelection() +{ + _selectionStartUtf8 = _selectionEndUtf8 = static_cast(_insertPosUtf8); + _selectionAnchorUtf8 = static_cast(_insertPosUtf8); + __updateSelectionLayer(); +} + +std::string InputField::getSelectedText() const +{ + if (!hasSelection()) + return {}; + + auto startByte = __getByteOffset(_selectionStartUtf8); + auto endByte = __getByteOffset(_selectionEndUtf8); + + return _inputText.substr(startByte, endByte - startByte); +} + +bool InputField::copySelectionToClipboard() const +{ + auto selectedText = getSelectedText(); + if (selectedText.empty() || _secureTextEntry) + return false; + + setClipboardText(selectedText); + return true; +} + +bool InputField::cutSelectionToClipboard() +{ + if (!_editable || !this->_enabled || !copySelectionToClipboard()) + return false; + + return __deleteSelection(true); +} + +bool InputField::pasteFromClipboard() +{ + if (!_editable || !this->_enabled) + return false; + + auto text = getClipboardText(); + if (text.empty()) + return false; + + insertText(text.c_str(), text.size()); + return true; +} + +void InputField::setSelectionColor(const Color& color) +{ + _selectionColor = color; + __updateSelectionLayer(); +} + +const Color& InputField::getSelectionColor() const +{ + return _selectionColor; +} + +void InputField::setClipboardGetter(ClipboardGetter getter) +{ + s_clipboardGetter = std::move(getter); +} + +void InputField::setClipboardSetter(ClipboardSetter setter) +{ + s_clipboardSetter = std::move(setter); +} + +std::string InputField::getClipboardText() +{ + return readClipboardText(); +} + +void InputField::setClipboardText(std::string_view text) +{ + writeClipboardText(text); +} + +void InputField::__initCursor(int height, int width, const Color32& color) { _cursor = engine_inj_create_lump(Color32(color), height, width); @@ -896,7 +1095,7 @@ void TextFieldEx::__initCursor(int height, int width, const Color32& color) __updateCursorPosition(); } -void TextFieldEx::__showCursor(void) +void InputField::__showCursor(void) { if (_cursor) { @@ -906,7 +1105,7 @@ void TextFieldEx::__showCursor(void) } } -void TextFieldEx::__hideCursor(void) +void InputField::__hideCursor(void) { if (_cursor) { @@ -916,120 +1115,149 @@ void TextFieldEx::__hideCursor(void) } } -void TextFieldEx::__updateCursorPosition(void) +void InputField::__updateCursorPosition(void) { - if (_cursor && _insertPosUtf8 == _charCount) - { - if (0 == this->getCharCount()) - { - _cursor->setPosition(Point(0, this->getContentSize().height / 2)); - } - else - { - _cursor->setPosition(Point(_renderLabel->getContentSize().width, this->getContentSize().height / 2)); - } - } + __setCursorPosition(static_cast(_insertPosUtf8), hasSelection()); } -void TextFieldEx::__moveCursor(int direction) +void InputField::__moveCursor(int direction) { - auto newOffset = _insertPosUtf8 + direction; - - if (newOffset > 0 && newOffset <= _charCount) - { - - std::string_view displayText; - if (!_secureTextEntry) - displayText = this->getString(); - else if (!_inputText.empty()) - displayText = _renderLabel->getString(); + __moveCursor(direction, false); +} - if (direction < 0) - { - _insertPos = static_cast(internalUTF8MoveLeft(_inputText, _insertPos).size()); +void InputField::__moveCursor(int direction, bool keepSelection) +{ + auto cursorPosition = static_cast(_insertPosUtf8) + direction; + cursorPosition = std::clamp(cursorPosition, 0, static_cast(_charCount)); + __setCursorPosition(static_cast(cursorPosition), keepSelection); +} - auto s = internalUTF8MoveLeft(displayText, _cursorPos); +void InputField::__moveCursorTo(float x) +{ + __moveCursorTo(x, false); +} - auto width = internalCalcStringWidth(s, _fontName, _fontSize); - _cursor->setPosition(Point(width, this->getContentSize().height / 2)); - _cursorPos = static_cast(s.length()); - } - else - { - _insertPos = static_cast(internalUTF8MoveRight(_inputText, _insertPos).size()); +void InputField::__moveCursorTo(float x, bool keepSelection) +{ + __setCursorPosition(__getCursorPositionFromX(x), keepSelection); +} - auto s = internalUTF8MoveRight(displayText, _cursorPos); - auto width = internalCalcStringWidth(s, _fontName, _fontSize); - _cursor->setPosition(Point(width, this->getContentSize().height / 2)); - _cursorPos = static_cast(s.length()); - } +void InputField::__setCursorPosition(std::size_t cursorPosition, bool keepSelection) +{ + cursorPosition = std::min(cursorPosition, _charCount); - _insertPosUtf8 = newOffset; - } - else if (newOffset == 0) + if (keepSelection) { - _cursor->setPosition(Point(0, this->getContentSize().height / 2)); - _insertPosUtf8 = newOffset; - _insertPos = 0; - _cursorPos = 0; + __setSelection(_selectionAnchorUtf8, cursorPosition); } else { - // MessageBeep(0); + _selectionAnchorUtf8 = cursorPosition; + _selectionStartUtf8 = cursorPosition; + _selectionEndUtf8 = cursorPosition; } + + _insertPosUtf8 = static_cast(cursorPosition); + _insertPos = static_cast(__getByteOffset(cursorPosition)); + _cursorPos = _secureTextEntry ? static_cast(cursorPosition * strlen("\xe2\x80\xa2")) : _insertPos; + + if (_cursor) + _cursor->setPosition(Point(__getCursorX(cursorPosition), this->getContentSize().height / 2)); + + __updateSelectionLayer(); } -void TextFieldEx::__moveCursorTo(float x) -{ // test - // normalized x - float normalizedX = 0; +float InputField::__getCursorX(std::size_t cursorPosition) const +{ + cursorPosition = std::min(cursorPosition, _charCount); + if (cursorPosition == 0 || _inputText.empty()) + return 0; - std::string_view displayText; - if (!_secureTextEntry) - { - displayText = _inputText; - } - else + if (_secureTextEntry) + return _asteriskWidth * cursorPosition; + + auto byteOffset = text_utils::getUTF8ByteOffset(_inputText, cursorPosition); + if (byteOffset == std::string::npos) + byteOffset = _inputText.length(); + + return internalCalcStringWidth(std::string_view(_inputText.data(), byteOffset), _fontName, _fontSize); +} + +std::size_t InputField::__getCursorPositionFromX(float x) const +{ + if (x <= 0 || _charCount == 0) + return 0; + + float previousX = 0; + for (std::size_t i = 1; i <= _charCount; ++i) { - if (!_inputText.empty()) - { - displayText = _renderLabel->getString(); - } + auto currentX = __getCursorX(i); + if (x < (previousX + currentX) * 0.5f) + return i - 1; + previousX = currentX; } - int length = static_cast(displayText.length()); - int n = static_cast(_charCount); // UTF8 char counter + return _charCount; +} - int insertWhere = 0; - int insertWhereUtf8 = 0; - while (length > 0) - { - auto checkX = internalCalcStringWidth(displayText, _fontName, _fontSize); - if (x >= checkX) - { - insertWhere = length; - insertWhereUtf8 = n; - normalizedX = checkX; - break; - } +std::size_t InputField::__getByteOffset(std::size_t cursorPosition) const +{ + if (cursorPosition >= _charCount) + return _inputText.length(); - // clamp backward - size_t backwardLen = 1; // default, erase 1 byte - while (0x80 == (0xC0 & displayText.at(displayText.length() - backwardLen))) - { - ++backwardLen; - } + auto byteOffset = text_utils::getUTF8ByteOffset(_inputText, cursorPosition); + return byteOffset == std::string::npos ? _inputText.length() : byteOffset; +} - --n; - displayText.remove_suffix(backwardLen); +void InputField::__setSelection(std::size_t start, std::size_t end) +{ + _selectionStartUtf8 = std::min(start, _charCount); + _selectionEndUtf8 = std::min(end, _charCount); + if (_selectionStartUtf8 > _selectionEndUtf8) + std::swap(_selectionStartUtf8, _selectionEndUtf8); + __updateSelectionLayer(); +} - length -= backwardLen; - } +void InputField::__updateSelectionLayer(void) +{ + if (!_selectionLayer) + return; + + _selectionLayer->clear(); + if (!hasSelection()) + return; + + auto startX = __getCursorX(_selectionStartUtf8); + auto endX = __getCursorX(_selectionEndUtf8); + if (endX <= startX) + return; + + auto height = std::max(_renderLabel->getContentSize().height, this->getContentSize().height); + if (height <= 0) + height = _fontSize; + + _selectionLayer->drawSolidRect(Vec2(startX, (this->getContentSize().height - height) * 0.5f), + Vec2(endX, (this->getContentSize().height + height) * 0.5f), _selectionColor); +} + +bool InputField::__deleteSelection(bool notify) +{ + if (!_editable || !this->_enabled || !hasSelection()) + return false; + + auto startByte = __getByteOffset(_selectionStartUtf8); + auto endByte = __getByteOffset(_selectionEndUtf8); + auto newCursor = _selectionStartUtf8; + + std::string text = _inputText; + text.erase(startByte, endByte - startByte); + this->setString(text); + __setCursorPosition(newCursor, false); - _insertPos = !_secureTextEntry ? insertWhere : insertWhereUtf8; - _cursorPos = insertWhere; - _insertPosUtf8 = insertWhereUtf8; - _cursor->setPosition(Point(normalizedX, this->getContentSize().height / 2)); + if (notify && this->onTextModify) + this->onTextModify(); + + return true; } }; // namespace ui diff --git a/axmol/ui/UITextFieldEx.h b/axmol/ui/UIInputField.h similarity index 78% rename from axmol/ui/UITextFieldEx.h rename to axmol/ui/UIInputField.h index 05ef2eba3b2d..609749608873 100644 --- a/axmol/ui/UITextFieldEx.h +++ b/axmol/ui/UIInputField.h @@ -27,6 +27,7 @@ THE SOFTWARE. #include "axmol/ui/UIWidget.h" #include "axmol/base/IMEDelegate.h" #include "axmol/base/SimpleTimer.h" +#include "axmol/2d/DrawNode.h" #include "axmol/2d/Label.h" #include "axmol/base/EventListenerKeyboard.h" @@ -37,21 +38,23 @@ namespace ui { /** -@brief The ui::TextFieldEx, better design, better cursor support than ui::TextField -will replace ui::TextField, currently, ui::TextField, 2d/TextFieldTTF were maked as deprecated +@brief Modern editable text input implementation used by ui::InputField. */ -class AX_DLL TextFieldEx : public Widget, public IMEDelegate +class AX_DLL InputField : public Widget, public IMEDelegate { public: + using ClipboardGetter = std::function; + using ClipboardSetter = std::function; + /** */ - TextFieldEx(); + InputField(); /** * @lua NA */ - virtual ~TextFieldEx(); + virtual ~InputField(); - static TextFieldEx* create(std::string_view placeholder, + static InputField* create(std::string_view placeholder, std::string_view fontName, float fontSize, float cursorWidth = 2, @@ -110,6 +113,23 @@ class AX_DLL TextFieldEx : public Widget, public IMEDelegate int getFontType() const; + bool hasSelection() const; + void selectAll(); + void clearSelection(); + std::string getSelectedText() const; + + bool copySelectionToClipboard() const; + bool cutSelectionToClipboard(); + bool pasteFromClipboard(); + + void setSelectionColor(const Color& color); + const Color& getSelectionColor() const; + + static void setClipboardGetter(ClipboardGetter getter); + static void setClipboardSetter(ClipboardSetter setter); + static std::string getClipboardText(); + static void setClipboardText(std::string_view text); + /// fonts void setTextFontSize(float size); float getTextFontSize() const; @@ -163,8 +183,18 @@ class AX_DLL TextFieldEx : public Widget, public IMEDelegate void __updateCursorPosition(void); void __moveCursor(int direction); + void __moveCursor(int direction, bool keepSelection); void __moveCursorTo(float x); + void __moveCursorTo(float x, bool keepSelection); + void __setCursorPosition(std::size_t cursorPosition, bool keepSelection); + float __getCursorX(std::size_t cursorPosition) const; + std::size_t __getCursorPositionFromX(float x) const; + std::size_t __getByteOffset(std::size_t cursorPosition) const; + + void __setSelection(std::size_t start, std::size_t end); + void __updateSelectionLayer(void); + bool __deleteSelection(bool notify); protected: bool _systemFontUsed; @@ -186,6 +216,11 @@ class AX_DLL TextFieldEx : public Widget, public IMEDelegate Sprite* _cursor; bool _cursorVisible; + DrawNode* _selectionLayer; + Color _selectionColor; + std::size_t _selectionStartUtf8; + std::size_t _selectionEndUtf8; + std::size_t _selectionAnchorUtf8; int _insertPosUtf8; int _insertPos; // The actual input content insertPos, step: bytes @@ -195,6 +230,10 @@ class AX_DLL TextFieldEx : public Widget, public IMEDelegate EventListenerKeyboard* _kbdListener; bool _touchCursorControlEnabled; + bool _selectingByTouch; + bool _selectionTouchMoved; + bool _ctrlKeyPressed; + bool _shiftKeyPressed; float _asteriskWidth; int _fontType; diff --git a/axmol/ui/axmol-ui.h b/axmol/ui/axmol-ui.h index 037731188547..91a143d5622e 100644 --- a/axmol/ui/axmol-ui.h +++ b/axmol/ui/axmol-ui.h @@ -38,8 +38,7 @@ THE SOFTWARE. #include "axmol/ui/UIScrollView.h" #include "axmol/ui/UIListView.h" #include "axmol/ui/UISlider.h" -#include "axmol/ui/UITextField.h" -#include "axmol/ui/UITextFieldEx.h" +#include "axmol/ui/UIInputField.h" #include "axmol/ui/UITextBMFont.h" #include "axmol/ui/UIPageView.h" #include "axmol/ui/UIHelper.h" diff --git a/extensions/sceneext/src/sceneext/SGUIReader.cpp b/extensions/sceneext/src/sceneext/SGUIReader.cpp index 9242c660d69c..c4701030597f 100644 --- a/extensions/sceneext/src/sceneext/SGUIReader.cpp +++ b/extensions/sceneext/src/sceneext/SGUIReader.cpp @@ -56,7 +56,6 @@ GUIReader::GUIReader() : m_strFilePath("") factoryCreate->registerType(CREATE_CLASS_GUI_INFO(TextBMFont)); factoryCreate->registerType(CREATE_CLASS_GUI_INFO(LoadingBar)); factoryCreate->registerType(CREATE_CLASS_GUI_INFO(Slider)); - factoryCreate->registerType(CREATE_CLASS_GUI_INFO(TextField)); factoryCreate->registerType(CREATE_CLASS_GUI_INFO(Layout)); factoryCreate->registerType(CREATE_CLASS_GUI_INFO(ListView)); factoryCreate->registerType(CREATE_CLASS_GUI_INFO(PageView)); @@ -254,10 +253,6 @@ std::string WidgetPropertiesReader::getWidgetReaderClassName(Widget* widget) { readerName = "SliderReader"; } - else if (dynamic_cast(widget)) - { - readerName = "TextFieldReader"; - } else if (dynamic_cast(widget)) { readerName = "ListViewReader"; @@ -557,11 +552,6 @@ Widget* WidgetPropertiesReader0250::widgetFromJsonDictionary(const rapidjson::Va widget = ax::ui::Button::create(); setPropsForButtonFromJsonDictionary(widget, uiOptions); } - else if (classname && strcmp(classname, "TextField") == 0) - { - widget = ax::ui::TextField::create(); - setPropsForTextFieldFromJsonDictionary(widget, uiOptions); - } else if (classname && strcmp(classname, "ImageView") == 0) { widget = ax::ui::ImageView::create(); @@ -1109,61 +1099,6 @@ void WidgetPropertiesReader0250::setPropsForSliderFromJsonDictionary(Widget* wid setColorPropsForWidgetFromJsonDictionary(widget, options); } -void WidgetPropertiesReader0250::setPropsForTextFieldFromJsonDictionary(Widget* widget, const rapidjson::Value& options) -{ - setPropsForWidgetFromJsonDictionary(widget, options); - ax::ui::TextField* textField = static_cast(widget); - bool ph = DICTOOL->checkObjectExist_json(options, "placeHolder"); - if (ph) - { - textField->setPlaceHolder(DICTOOL->getStringValue_json(options, "placeHolder")); - } - textField->setString(DICTOOL->getStringValue_json(options, "text")); - bool fs = DICTOOL->checkObjectExist_json(options, "fontSize"); - if (fs) - { - textField->setFontSize(DICTOOL->getIntValue_json(options, "fontSize")); - } - bool fn = DICTOOL->checkObjectExist_json(options, "fontName"); - if (fn) - { - const char* szTemp = DICTOOL->getStringValue_json(options, "fontName"); - if (szTemp && *szTemp) - textField->setFontName(szTemp); - else - textField->setFontName(std::string("")); - } - bool tsw = DICTOOL->checkObjectExist_json(options, "touchSizeWidth"); - bool tsh = DICTOOL->checkObjectExist_json(options, "touchSizeHeight"); - if (tsw && tsh) - { - textField->setTouchSize(Size(DICTOOL->getFloatValue_json(options, "touchSizeWidth"), - DICTOOL->getFloatValue_json(options, "touchSizeHeight"))); - } - - float dw = DICTOOL->getFloatValue_json(options, "width"); - float dh = DICTOOL->getFloatValue_json(options, "height"); - if (dw > 0.0f || dh > 0.0f) - { - // textField->setSize(Size(dw, dh)); - } - bool maxLengthEnable = DICTOOL->getBooleanValue_json(options, "maxLengthEnable"); - textField->setMaxLengthEnabled(maxLengthEnable); - - if (maxLengthEnable) - { - int maxLength = DICTOOL->getIntValue_json(options, "maxLength"); - textField->setMaxLength(maxLength); - } - bool passwordEnable = DICTOOL->getBooleanValue_json(options, "passwordEnable"); - textField->setPasswordEnabled(passwordEnable); - if (passwordEnable) - { - textField->setPasswordStyleText(DICTOOL->getStringValue_json(options, "passwordStyleText")); - } - setColorPropsForWidgetFromJsonDictionary(widget, options); -} - void WidgetPropertiesReader0250::setPropsForLoadingBarFromJsonDictionary(Widget* widget, const rapidjson::Value& options) { diff --git a/extensions/sceneext/src/sceneext/SGUIReader.h b/extensions/sceneext/src/sceneext/SGUIReader.h index 3e9d5dbab53a..cbea68fb3c1e 100644 --- a/extensions/sceneext/src/sceneext/SGUIReader.h +++ b/extensions/sceneext/src/sceneext/SGUIReader.h @@ -174,8 +174,6 @@ class SCNEXT_API WidgetPropertiesReader0250 : public WidgetPropertiesReader virtual void setPropsForLabelBMFontFromJsonDictionary(ax::ui::Widget* widget, const rapidjson::Value& options); virtual void setPropsForLoadingBarFromJsonDictionary(ax::ui::Widget* widget, const rapidjson::Value& options); virtual void setPropsForSliderFromJsonDictionary(ax::ui::Widget* widget, const rapidjson::Value& options); - virtual void setPropsForTextFieldFromJsonDictionary(ax::ui::Widget* widget, const rapidjson::Value& options); - virtual void setPropsForLayoutFromJsonDictionary(ax::ui::Widget* widget, const rapidjson::Value& options); virtual void setPropsForScrollViewFromJsonDictionary(ax::ui::Widget* widget, const rapidjson::Value& options); diff --git a/extensions/sceneext/src/sceneext/WidgetReader/NodeReaderProtocol.cpp b/extensions/sceneext/src/sceneext/WidgetReader/NodeReaderProtocol.cpp index 4f36d95d964f..5994f8c24ab8 100644 --- a/extensions/sceneext/src/sceneext/WidgetReader/NodeReaderProtocol.cpp +++ b/extensions/sceneext/src/sceneext/WidgetReader/NodeReaderProtocol.cpp @@ -71,7 +71,6 @@ ax::ui::CheckBox* (*aCheckBox)(); ax::ui::Slider* (*aSlider)(); ax::ui::LoadingBar* (*aLoadingBar)(); ax::ui::Text* (*aText)(); -ax::ui::TextField* (*aTextField)(); ax::ui::TextAtlas* (*aTextAtlas)(); ax::ui::TextBMFont* (*aTextBMFont)(); ax::ui::Layout* (*aLayout)(); @@ -109,7 +108,6 @@ void resetReaderAllHooks() aSlider = object_create_func; aLoadingBar = object_create_func; aText = object_create_func; - aTextField = object_create_func; aTextAtlas = object_create_func; aTextBMFont = object_create_func; aLayout = object_create_func; diff --git a/extensions/sceneext/src/sceneext/WidgetReader/NodeReaderProtocol.h b/extensions/sceneext/src/sceneext/WidgetReader/NodeReaderProtocol.h index a5bd7bf8fe6d..0a159c94b202 100644 --- a/extensions/sceneext/src/sceneext/WidgetReader/NodeReaderProtocol.h +++ b/extensions/sceneext/src/sceneext/WidgetReader/NodeReaderProtocol.h @@ -120,7 +120,6 @@ class Slider; class LoadingBar; class Text; -class TextField; class TextAtlas; class TextBMFont; @@ -158,7 +157,6 @@ SCNEXT_API extern ax::ui::CheckBox* (*aCheckBox)(); SCNEXT_API extern ax::ui::Slider* (*aSlider)(); SCNEXT_API extern ax::ui::LoadingBar* (*aLoadingBar)(); SCNEXT_API extern ax::ui::Text* (*aText)(); -SCNEXT_API extern ax::ui::TextField* (*aTextField)(); SCNEXT_API extern ax::ui::TextAtlas* (*aTextAtlas)(); SCNEXT_API extern ax::ui::TextBMFont* (*aTextBMFont)(); SCNEXT_API extern ax::ui::Layout* (*aLayout)(); diff --git a/extensions/sceneio/CMakeLists.txt b/extensions/sceneio/CMakeLists.txt index b490d077b2f5..9a3d4b593599 100644 --- a/extensions/sceneio/CMakeLists.txt +++ b/extensions/sceneio/CMakeLists.txt @@ -1,6 +1,7 @@ set(target_name sceneio) FILE(GLOB_RECURSE sceneio_SOURCES ./*.h;./*.cpp) +list(FILTER sceneio_SOURCES EXCLUDE REGEX "TextFieldReader/TextFieldReader\\.(h|cpp)$") add_library(${target_name} ${sceneio_SOURCES}) diff --git a/extensions/sceneio/src/sceneio/ActionTimeline/CSLoader.cpp b/extensions/sceneio/src/sceneio/ActionTimeline/CSLoader.cpp index f33693e1d5a0..a79a9c386ff3 100644 --- a/extensions/sceneio/src/sceneio/ActionTimeline/CSLoader.cpp +++ b/extensions/sceneio/src/sceneio/ActionTimeline/CSLoader.cpp @@ -59,7 +59,6 @@ #include "sceneio/WidgetReader/ImageViewReader/ImageViewReader.h" #include "sceneio/WidgetReader/TextBMFontReader/TextBMFontReader.h" #include "sceneio/WidgetReader/TextReader/TextReader.h" -#include "sceneio/WidgetReader/TextFieldReader/TextFieldReader.h" #include "sceneio/WidgetReader/TextAtlasReader/TextAtlasReader.h" #include "sceneio/WidgetReader/LoadingBarReader/LoadingBarReader.h" #include "sceneio/WidgetReader/SliderReader/SliderReader.h" @@ -122,7 +121,6 @@ static const char* ClassName_LabelBMFont = "LabelBMFont"; static const char* ClassName_TextBMFont = "TextBMFont"; static const char* ClassName_Text = "Text"; static const char* ClassName_LoadingBar = "LoadingBar"; -static const char* ClassName_TextField = "TextField"; static const char* ClassName_Slider = "Slider"; static const char* ClassName_Layout = "Layout"; static const char* ClassName_ScrollView = "ScrollView"; @@ -216,7 +214,6 @@ CSLoader::CSLoader() CREATE_CLASS_NODE_READER_INFO(ImageViewReader); CREATE_CLASS_NODE_READER_INFO(TextBMFontReader); CREATE_CLASS_NODE_READER_INFO(TextReader); - CREATE_CLASS_NODE_READER_INFO(TextFieldReader); CREATE_CLASS_NODE_READER_INFO(TextAtlasReader); CREATE_CLASS_NODE_READER_INFO(LoadingBarReader); CREATE_CLASS_NODE_READER_INFO(SliderReader); @@ -271,7 +268,6 @@ void CSLoader::init() _funcs.insert(Pair(ClassName_TextBMFont, std::bind(&CSLoader::loadWidget, this, _1))); _funcs.insert(Pair(ClassName_Text, std::bind(&CSLoader::loadWidget, this, _1))); _funcs.insert(Pair(ClassName_LoadingBar, std::bind(&CSLoader::loadWidget, this, _1))); - _funcs.insert(Pair(ClassName_TextField, std::bind(&CSLoader::loadWidget, this, _1))); _funcs.insert(Pair(ClassName_Slider, std::bind(&CSLoader::loadWidget, this, _1))); _funcs.insert(Pair(ClassName_Layout, std::bind(&CSLoader::loadWidget, this, _1))); _funcs.insert(Pair(ClassName_ScrollView, std::bind(&CSLoader::loadWidget, this, _1))); @@ -1277,7 +1273,7 @@ bool CSLoader::isWidget(std::string_view type) return (type == ClassName_Panel || type == ClassName_Button || type == ClassName_CheckBox || type == ClassName_ImageView || type == ClassName_TextAtlas || type == ClassName_LabelAtlas || type == ClassName_LabelBMFont || type == ClassName_TextBMFont || type == ClassName_Text || - type == ClassName_LoadingBar || type == ClassName_TextField || type == ClassName_Slider || + type == ClassName_LoadingBar || type == ClassName_Slider || type == ClassName_Layout || type == ClassName_ScrollView || type == ClassName_ListView || type == ClassName_PageView || type == ClassName_Widget || type == ClassName_Label); } @@ -1364,10 +1360,6 @@ std::string_view CSLoader::getWidgetReaderClassName(Widget* widget) { readerName = "SliderReader"; } - else if (dynamic_cast(widget)) - { - readerName = "TextFieldReader"; - } else if (dynamic_cast(widget)) { readerName = "ListViewReader"; diff --git a/extensions/sceneio/src/sceneio/FlatBuffersSerialize.cpp b/extensions/sceneio/src/sceneio/FlatBuffersSerialize.cpp index a474a62ec035..eef3a53d08a1 100644 --- a/extensions/sceneio/src/sceneio/FlatBuffersSerialize.cpp +++ b/extensions/sceneio/src/sceneio/FlatBuffersSerialize.cpp @@ -50,7 +50,6 @@ #include "sceneio/WidgetReader/ImageViewReader/ImageViewReader.h" #include "sceneio/WidgetReader/TextBMFontReader/TextBMFontReader.h" #include "sceneio/WidgetReader/TextReader/TextReader.h" -#include "sceneio/WidgetReader/TextFieldReader/TextFieldReader.h" #include "sceneio/WidgetReader/TextAtlasReader/TextAtlasReader.h" #include "sceneio/WidgetReader/LoadingBarReader/LoadingBarReader.h" #include "sceneio/WidgetReader/SliderReader/SliderReader.h" @@ -100,7 +99,6 @@ FlatBuffersSerialize::FlatBuffersSerialize() : _isSimulator(false), _builder(nul CREATE_CLASS_NODE_READER_INFO(ImageViewReader); CREATE_CLASS_NODE_READER_INFO(TextBMFontReader); CREATE_CLASS_NODE_READER_INFO(TextReader); - CREATE_CLASS_NODE_READER_INFO(TextFieldReader); CREATE_CLASS_NODE_READER_INFO(TextAtlasReader); CREATE_CLASS_NODE_READER_INFO(LoadingBarReader); CREATE_CLASS_NODE_READER_INFO(SliderReader); @@ -514,10 +512,6 @@ std::string FlatBuffersSerialize::getWidgetReaderClassName(Widget* widget) { readerName = "SliderReader"; } - else if (dynamic_cast(widget)) - { - readerName = "TextFieldReader"; - } else if (dynamic_cast(widget)) { readerName = "ListViewReader"; diff --git a/extensions/sceneio/src/sceneio/WidgetReader/TextFieldReader/TextFieldExReader.cpp b/extensions/sceneio/src/sceneio/WidgetReader/TextFieldReader/TextFieldExReader.cpp index f9413c79ca87..b2ea1613adae 100644 --- a/extensions/sceneio/src/sceneio/WidgetReader/TextFieldReader/TextFieldExReader.cpp +++ b/extensions/sceneio/src/sceneio/WidgetReader/TextFieldReader/TextFieldExReader.cpp @@ -24,7 +24,7 @@ #include "sceneio/WidgetReader/TextFieldReader/TextFieldExReader.h" -#include "axmol/ui/UITextFieldEx.h" +#include "axmol/ui/UIInputField.h" #include "axmol/platform/FileUtils.h" #include "sceneext/CocoLoader.h" #include "sceneio/CSParseBinary_generated.h" @@ -290,7 +290,7 @@ Offset TextFieldExReader::createOptionsWithFlatBuffers(pugi::xml_node obj void TextFieldExReader::setPropsWithFlatBuffers(ax::Node* node, const flatbuffers::Table* textFieldOptions) { - TextFieldEx** pTextField = (TextFieldEx**)(node); + InputField** pTextField = (InputField**)(node); auto options = (TextFieldExOptions*)textFieldOptions; std::string placeholder = options->placeholderText()->c_str(); @@ -334,7 +334,7 @@ void TextFieldExReader::setPropsWithFlatBuffers(ax::Node* node, const flatbuffer // bool maxLengthEnabled = options->maxLengthEnabled() != 0; // textField->setMaxLengthEnabled(maxLengthEnabled); - auto textField = TextFieldEx::create(placeholder, fontName, fontSize); + auto textField = InputField::create(placeholder, fontName, fontSize); *pTextField = textField; @@ -378,7 +378,7 @@ void TextFieldExReader::setPropsWithFlatBuffers(ax::Node* node, const flatbuffer Node* TextFieldExReader::createNodeWithFlatBuffers(const flatbuffers::Table* textFieldOptions) { - TextFieldEx* textField = nullptr; // TextFieldEx::create("dummy", "Courier New", 18); + InputField* textField = nullptr; setPropsWithFlatBuffers((Node*)&textField, (Table*)textFieldOptions); diff --git a/extensions/sceneio/src/sceneio/sceneio.cpp b/extensions/sceneio/src/sceneio/sceneio.cpp index cea643eee4e0..c9c28a728387 100644 --- a/extensions/sceneio/src/sceneio/sceneio.cpp +++ b/extensions/sceneio/src/sceneio/sceneio.cpp @@ -15,7 +15,6 @@ #include "sceneio/WidgetReader/ImageViewReader/ImageViewReader.h" #include "sceneio/WidgetReader/TextBMFontReader/TextBMFontReader.h" #include "sceneio/WidgetReader/TextReader/TextReader.h" -#include "sceneio/WidgetReader/TextFieldReader/TextFieldReader.h" #include "sceneio/WidgetReader/TextAtlasReader/TextAtlasReader.h" #include "sceneio/WidgetReader/LoadingBarReader/LoadingBarReader.h" #include "sceneio/WidgetReader/SliderReader/SliderReader.h" @@ -49,7 +48,6 @@ SCNIO_API void initializeSceneIO() factoryCreate->registerType(CREATE_CLASS_WIDGET_READER_INFO(TextAtlasReader)); factoryCreate->registerType(CREATE_CLASS_WIDGET_READER_INFO(TextReader)); factoryCreate->registerType(CREATE_CLASS_WIDGET_READER_INFO(TextBMFontReader)); - factoryCreate->registerType(CREATE_CLASS_WIDGET_READER_INFO(TextFieldReader)); factoryCreate->registerType(CREATE_CLASS_WIDGET_READER_INFO(LayoutReader)); factoryCreate->registerType(CREATE_CLASS_WIDGET_READER_INFO(PageViewReader)); factoryCreate->registerType(CREATE_CLASS_WIDGET_READER_INFO(ScrollViewReader)); @@ -72,7 +70,6 @@ SCNIO_API void cleanupSceneIO() factoryCreate->unregisterType(_AXSTR(TextAtlasReader)); factoryCreate->unregisterType(_AXSTR(TextReader)); factoryCreate->unregisterType(_AXSTR(TextBMFontReader)); - factoryCreate->unregisterType(_AXSTR(TextFieldReader)); factoryCreate->unregisterType(_AXSTR(LayoutReader)); factoryCreate->unregisterType(_AXSTR(PageViewReader)); factoryCreate->unregisterType(_AXSTR(ScrollViewReader)); @@ -92,7 +89,6 @@ SCNIO_API void cleanupSceneIO() ImageViewReader::destroyInstance(); TextBMFontReader::destroyInstance(); TextReader::destroyInstance(); - TextFieldReader::destroyInstance(); TextAtlasReader::destroyInstance(); LoadingBarReader::destroyInstance(); SliderReader::destroyInstance(); diff --git a/tests/cpp-tests/CMakeLists.txt b/tests/cpp-tests/CMakeLists.txt index a67026f1d323..e2dc501b8444 100644 --- a/tests/cpp-tests/CMakeLists.txt +++ b/tests/cpp-tests/CMakeLists.txt @@ -163,7 +163,6 @@ list(APPEND GAME_HEADER Source/ActionsProgressTest/ActionsProgressTest.h Source/RotateWorldTest/RotateWorldTest.h Source/Camera3DTest/Camera3DTest.h - Source/TextInputTest/TextInputTest.h Source/Texture2dTest/Texture2dTest.h Source/TerrainTest/TerrainTest.h Source/controller.h @@ -189,7 +188,6 @@ list(APPEND GAME_HEADER Source/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest.h Source/UITest/CocoStudioGUITest/CocosGUIScene.h Source/UITest/CocoStudioGUITest/UITabControlTest/UITabControlTest.h - Source/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.h Source/UITest/CocoStudioGUITest/UITextBMFontTest/UITextBMFontTest.h Source/UITest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.h Source/UITest/CocoStudioGUITest/UISliderTest/UISliderTest.h @@ -312,7 +310,6 @@ list(APPEND GAME_SOURCE Source/SpritePolygonTest/SpritePolygonTest.cpp Source/SpriteTest/SpriteTest.cpp Source/TerrainTest/TerrainTest.cpp - Source/TextInputTest/TextInputTest.cpp Source/Texture2dTest/Texture2dTest.cpp Source/TextureCacheTest/TextureCacheTest.cpp Source/TexturePackerEncryptionTest/TextureAtlasEncryptionTest.cpp @@ -341,7 +338,6 @@ list(APPEND GAME_SOURCE Source/UITest/CocoStudioGUITest/UISliderTest/UISliderTest.cpp Source/UITest/CocoStudioGUITest/UITextAtlasTest/UITextAtlasTest.cpp Source/UITest/CocoStudioGUITest/UITextBMFontTest/UITextBMFontTest.cpp - Source/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp Source/UITest/CocoStudioGUITest/UITextTest/UITextTest.cpp Source/UITest/CocoStudioGUITest/UIWidgetAddNodeTest/UIWidgetAddNodeTest.cpp Source/UITest/CocoStudioGUITest/UITabControlTest/UITabControlTest.cpp diff --git a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/CocosGUIScene.cpp b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/CocosGUIScene.cpp index bc02ba34e255..bd8c4eee2198 100644 --- a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/CocosGUIScene.cpp +++ b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/CocosGUIScene.cpp @@ -34,7 +34,6 @@ #include "UITextAtlasTest/UITextAtlasTest.h" #include "UITextTest/UITextTest.h" #include "UITextBMFontTest/UITextBMFontTest.h" -#include "UITextFieldTest/UITextFieldTest.h" #include "UILayoutTest/UILayoutTest.h" #include "UIScrollViewTest/UIScrollViewTest.h" #include "UIPageViewTest/UIPageViewTest.h" @@ -91,7 +90,6 @@ GUIDynamicCreateTests::GUIDynamicCreateTests() addTest("Text Test", []() { return new UITextTests; }); addTest("TextBMFont Test", []() { return new UITextBMFontTests; }); - addTest("TextField Test", []() { return new UITextFieldTests; }); addTest("Layout Test", []() { return new UILayoutTests; }); addTest("ScrollView Test", []() { return new UIScrollViewTests; }); diff --git a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIWebViewTest/UIWebViewTest.cpp b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIWebViewTest/UIWebViewTest.cpp index 069c69be589d..d9e5447b8066 100644 --- a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIWebViewTest/UIWebViewTest.cpp +++ b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIWebViewTest/UIWebViewTest.cpp @@ -55,11 +55,12 @@ bool WebViewTest::init() spriteHello->setPosition(canvasSize / 2); this->addChild(spriteHello); - TextField* urlTextField = TextField::create("Input a URL here", "Arial", 20); - urlTextField->setPlaceHolderColor(Color32::RED); + InputField* urlTextField = InputField::create("Input a URL here", "Arial", 20); + urlTextField->setPlaceholderColor(Color32::RED); urlTextField->setPosition(Vec2(canvasSize / 2) + Vec2(-80, _webView->getContentSize().height / 2 + urlTextField->getContentSize().height / 2 + 10)); this->addChild(urlTextField); + urlTextField->enableIME(nullptr); Text* httpLabel = Text::create("https:// ", "Arial", 20); httpLabel->setTextColor(Color32::GREEN); diff --git a/tests/cpp-tests/Source/controller.cpp b/tests/cpp-tests/Source/controller.cpp index 4138ede1f563..1e7405b0cddd 100644 --- a/tests/cpp-tests/Source/controller.cpp +++ b/tests/cpp-tests/Source/controller.cpp @@ -116,7 +116,6 @@ class RootTests : public TestList addTest("SpritePolygon", []() { return new SpritePolygonTest(); }); addTest("Terrain", []() { return new TerrainTests(); }); addTest("FastTileMap", []() { return new FastTileMapTests(); }); - addTest("Text Input", []() { return new TextInputTests(); }); addTest("UI", []() { return new UITests(); }); addTest("Mouse", []() { return new MouseTests(); }); addTest("MultiTouch", []() { return new MultiTouchTests(); }); diff --git a/tests/cpp-tests/Source/tests.h b/tests/cpp-tests/Source/tests.h index 87a655b01d04..9434c7ccc9a6 100644 --- a/tests/cpp-tests/Source/tests.h +++ b/tests/cpp-tests/Source/tests.h @@ -110,7 +110,6 @@ #include "SpritePolygonTest/SpritePolygonTest.h" #include "SpriteTest/SpriteTest.h" #include "TerrainTest/TerrainTest.h" -#include "TextInputTest/TextInputTest.h" #include "Texture2dTest/Texture2dTest.h" #include "TextureCacheTest/TextureCacheTest.h" #include "TexturePackerEncryptionTest/TextureAtlasEncryptionTest.h" From d0759580cfe408aec6b7cd968b10e8f554ea6b04 Mon Sep 17 00:00:00 2001 From: halx99 Date: Sat, 16 May 2026 22:40:49 +0800 Subject: [PATCH 02/52] up --- axmol/ui/UIInputField.cpp | 96 +++++++++++++++++++ axmol/ui/UIInputField.h | 28 ++++++ .../TextFieldReader/TextFieldReader.cpp | 47 +++++---- 3 files changed, 147 insertions(+), 24 deletions(-) diff --git a/axmol/ui/UIInputField.cpp b/axmol/ui/UIInputField.cpp index 26bca51ee2bd..ff7fb2b68878 100644 --- a/axmol/ui/UIInputField.cpp +++ b/axmol/ui/UIInputField.cpp @@ -267,6 +267,12 @@ InputField::InputField() , _cursorVisible(false) , _continuousTouchDelayTimerID(nullptr) , _continuousTouchDelayTime(0.6) + , _touchWidth(0.0f) + , _touchHeight(0.0f) + , _useTouchArea(false) + , _textHAlignment(TextHAlignment::LEFT) + , _textVAlignment(TextVAlignment::TOP) + , _textAreaSize(Vec2::ZERO) {} InputField::~InputField() @@ -1259,6 +1265,96 @@ bool InputField::__deleteSelection(bool notify) return true; } + +////////////////////////////////////////////////////////////////////////// +// Touch Area and Hit Test +////////////////////////////////////////////////////////////////////////// +void InputField::setTouchSize(const Vec2& size) +{ + _touchWidth = size.width; + _touchHeight = size.height; +} + +Vec2 InputField::getTouchSize() const +{ + return Vec2(_touchWidth, _touchHeight); +} + +void InputField::setTouchAreaEnabled(bool enable) +{ + _useTouchArea = enable; +} + +bool InputField::hitTest(const Vec2& pt, const Camera* camera, Vec3* /*p*/) const +{ + if (false == _useTouchArea) + { + return Widget::hitTest(pt, camera, nullptr); + } + + auto size = getContentSize(); + auto anch = getAnchorPoint(); + Rect rect((size.width - _touchWidth) * anch.x, (size.height - _touchHeight) * anch.y, _touchWidth, _touchHeight); + return isScreenPointInRect(pt, camera, getWorldToNodeTransform(), rect, nullptr); +} + +////////////////////////////////////////////////////////////////////////// +// Text Alignment +////////////////////////////////////////////////////////////////////////// +void InputField::setTextHorizontalAlignment(TextHAlignment alignment) +{ + if (_textHAlignment != alignment) + { + _textHAlignment = alignment; + if (_renderLabel) + { + _renderLabel->setHorizontalAlignment(alignment); + } + } +} + +TextHAlignment InputField::getTextHorizontalAlignment() const +{ + return _textHAlignment; +} + +void InputField::setTextVerticalAlignment(TextVAlignment alignment) +{ + if (_textVAlignment != alignment) + { + _textVAlignment = alignment; + if (_renderLabel) + { + _renderLabel->setVerticalAlignment(alignment); + } + } +} + +TextVAlignment InputField::getTextVerticalAlignment() const +{ + return _textVAlignment; +} + +////////////////////////////////////////////////////////////////////////// +// Text Area Size +////////////////////////////////////////////////////////////////////////// +void InputField::setTextAreaSize(const Vec2& size) +{ + _textAreaSize = size; + if (_renderLabel) + { + _renderLabel->setDimensions(size.width, size.height); + } +} + +Vec2 InputField::getAutoRenderSize() +{ + if (_renderLabel) + { + return _renderLabel->getContentSize(); + } + return this->getContentSize(); +} }; // namespace ui } // namespace ax diff --git a/axmol/ui/UIInputField.h b/axmol/ui/UIInputField.h index 609749608873..5667a4e14988 100644 --- a/axmol/ui/UIInputField.h +++ b/axmol/ui/UIInputField.h @@ -136,6 +136,22 @@ class AX_DLL InputField : public Widget, public IMEDelegate void setTextFontName(std::string_view fontName); std::string_view getTextFontName() const; + /// text alignment + void setTextHorizontalAlignment(TextHAlignment alignment); + TextHAlignment getTextHorizontalAlignment() const; + void setTextVerticalAlignment(TextVAlignment alignment); + TextVAlignment getTextVerticalAlignment() const; + + /// text area size + void setTextAreaSize(const Vec2& size); + Vec2 getAutoRenderSize(); + + /// touch area + void setTouchSize(const Vec2& size); + Vec2 getTouchSize() const; + void setTouchAreaEnabled(bool enable); + bool hitTest(const Vec2& pt, const Camera* camera, Vec3* p) const override; + AX_SYNTHESIZE(size_t, _charLimit, CharLimit); bool isSystemFont(void) const { return _systemFontUsed; } @@ -242,6 +258,18 @@ class AX_DLL InputField : public Widget, public IMEDelegate float _continuousTouchDelayTime; std::function _continuousTouchCallback; + /// Touch area + float _touchWidth; + float _touchHeight; + bool _useTouchArea; + + /// Text alignment + TextHAlignment _textHAlignment; + TextVAlignment _textVAlignment; + + /// Text area size + Vec2 _textAreaSize; + static bool s_keyboardVisible; }; diff --git a/extensions/sceneio/src/sceneio/WidgetReader/TextFieldReader/TextFieldReader.cpp b/extensions/sceneio/src/sceneio/WidgetReader/TextFieldReader/TextFieldReader.cpp index 089c189e784d..c55bba907927 100644 --- a/extensions/sceneio/src/sceneio/WidgetReader/TextFieldReader/TextFieldReader.cpp +++ b/extensions/sceneio/src/sceneio/WidgetReader/TextFieldReader/TextFieldReader.cpp @@ -24,7 +24,7 @@ #include "sceneio/WidgetReader/TextFieldReader/TextFieldReader.h" -#include "axmol/ui/UITextField.h" +#include "axmol/ui/UIInputField.h" #include "axmol/platform/FileUtils.h" #include "sceneext/CocoLoader.h" #include "sceneio/CSParseBinary_generated.h" @@ -74,7 +74,7 @@ void TextFieldReader::setPropsFromBinary(ax::ui::Widget* widget, CocoLoader* coc { this->beginSetBasicProperties(widget); - TextField* textField = static_cast(widget); + InputField* textField = static_cast(widget); stExpCocoNode* stChildArray = cocoNode->GetChildArray(cocoLoader); @@ -90,7 +90,7 @@ void TextFieldReader::setPropsFromBinary(ax::ui::Widget* widget, CocoLoader* coc else if (key == P_PlaceHolder) { - textField->setPlaceHolder(value); + textField->setPlaceholderText(value); } else if (key == P_Text) { @@ -98,11 +98,11 @@ void TextFieldReader::setPropsFromBinary(ax::ui::Widget* widget, CocoLoader* coc } else if (key == P_FontSize) { - textField->setFontSize(valueToInt(value)); + textField->setTextFontSize(valueToInt(value)); } else if (key == P_FontName) { - textField->setFontName(value); + textField->setTextFontName(value); } else if (key == P_TouchSizeWidth) { @@ -114,7 +114,7 @@ void TextFieldReader::setPropsFromBinary(ax::ui::Widget* widget, CocoLoader* coc } else if (key == P_MaxLengthEnable) { - textField->setMaxLengthEnabled(valueToBool(value)); + // InputField doesn't have setMaxLengthEnabled, only setMaxLength } else if (key == P_MaxLength) { @@ -126,7 +126,7 @@ void TextFieldReader::setPropsFromBinary(ax::ui::Widget* widget, CocoLoader* coc } else if (key == P_PasswordStyleText) { - textField->setPasswordStyleText(value); + // InputField doesn't support custom password style text } } // end of for loop this->endSetBasicProperties(widget); @@ -136,23 +136,23 @@ void TextFieldReader::setPropsFromJsonDictionary(Widget* widget, const rapidjson { WidgetReader::setPropsFromJsonDictionary(widget, options); - TextField* textField = static_cast(widget); + InputField* textField = static_cast(widget); bool ph = DICTOOL->checkObjectExist_json(options, P_PlaceHolder); if (ph) { - textField->setPlaceHolder(DICTOOL->getStringValue_json(options, P_PlaceHolder, "input words here")); + textField->setPlaceholderText(DICTOOL->getStringValue_json(options, P_PlaceHolder, "input words here")); } textField->setString(DICTOOL->getStringValue_json(options, P_Text, "Text Tield")); - textField->setFontSize(DICTOOL->getIntValue_json(options, P_FontSize, 20)); + textField->setTextFontSize(DICTOOL->getIntValue_json(options, P_FontSize, 20)); std::string fontFilePath{GUIReader::getInstance()->getFilePath()}; auto fontName = DICTOOL->getStringValue_json(options, P_FontName, ""); fontFilePath.append(fontName); if (FileUtils::getInstance()->isFileExist(fontFilePath)) - textField->setFontName(fontFilePath); + textField->setTextFontName(fontFilePath); else - textField->setFontName(fontName); + textField->setTextFontName(fontName); bool tsw = DICTOOL->checkObjectExist_json(options, P_TouchSizeWidth); bool tsh = DICTOOL->checkObjectExist_json(options, P_TouchSizeHeight); @@ -169,8 +169,7 @@ void TextFieldReader::setPropsFromJsonDictionary(Widget* widget, const rapidjson // //textField->setSize(Size(dw, dh)); // } bool maxLengthEnable = DICTOOL->getBooleanValue_json(options, P_MaxLengthEnable); - textField->setMaxLengthEnabled(maxLengthEnable); - + // InputField doesn't have setMaxLengthEnabled, only setMaxLength if (maxLengthEnable) { int maxLength = DICTOOL->getIntValue_json(options, P_MaxLength, 10); @@ -178,9 +177,10 @@ void TextFieldReader::setPropsFromJsonDictionary(Widget* widget, const rapidjson } bool passwordEnable = DICTOOL->getBooleanValue_json(options, P_PasswordEnable); textField->setPasswordEnabled(passwordEnable); + // InputField doesn't support custom password style text if (passwordEnable) { - textField->setPasswordStyleText(DICTOOL->getStringValue_json(options, P_PasswordStyleText, "*")); + // setPasswordStyleText is not available in InputField } WidgetReader::setColorPropsFromJsonDictionary(widget, options); @@ -307,11 +307,11 @@ Offset
TextFieldReader::createOptionsWithFlatBuffers(pugi::xml_node objec void TextFieldReader::setPropsWithFlatBuffers(ax::Node* node, const flatbuffers::Table* textFieldOptions) { - TextField* textField = static_cast(node); + InputField* textField = static_cast(node); auto options = (TextFieldOptions*)textFieldOptions; std::string placeholder = options->placeHolder()->c_str(); - textField->setPlaceHolder(placeholder); + textField->setPlaceholderText(placeholder); std::string text = options->text()->c_str(); bool isLocalized = options->isLocalized() != 0; @@ -330,14 +330,13 @@ void TextFieldReader::setPropsWithFlatBuffers(ax::Node* node, const flatbuffers: } int fontSize = options->fontSize(); - textField->setFontSize(fontSize); + textField->setTextFontSize(fontSize); std::string fontName = options->fontName()->c_str(); - textField->setFontName(fontName); + textField->setTextFontName(fontName); bool maxLengthEnabled = options->maxLengthEnabled() != 0; - textField->setMaxLengthEnabled(maxLengthEnabled); - + // InputField doesn't have setMaxLengthEnabled, only setMaxLength if (maxLengthEnabled) { int maxLength = options->maxLength(); @@ -345,10 +344,10 @@ void TextFieldReader::setPropsWithFlatBuffers(ax::Node* node, const flatbuffers: } bool passwordEnabled = options->passwordEnabled() != 0; textField->setPasswordEnabled(passwordEnabled); + // InputField doesn't support custom password style text if (passwordEnabled) { - std::string passwordStyleText = options->passwordStyleText()->c_str(); - textField->setPasswordStyleText(passwordStyleText.c_str()); + // setPasswordStyleText is not available in InputField } bool fileExist = false; @@ -368,7 +367,7 @@ void TextFieldReader::setPropsWithFlatBuffers(ax::Node* node, const flatbuffers: } if (fileExist) { - textField->setFontName(path); + textField->setTextFontName(path); } } From 4eb10db768ff24eee5059b1b952d48a87354e8f9 Mon Sep 17 00:00:00 2001 From: halx99 Date: Sun, 17 May 2026 20:14:11 +0800 Subject: [PATCH 03/52] up --- axmol/ui/UIAbstractCheckButton.cpp | 10 +- axmol/ui/UIButton.cpp | 94 +- axmol/ui/UIButton.h | 2 +- axmol/ui/UIEditBox/UIEditBox.cpp | 2 +- axmol/ui/UIImageView.cpp | 30 +- axmol/ui/UIImageView.h | 2 +- axmol/ui/UIInputField.cpp | 151 ++-- axmol/ui/UIInputField.h | 78 +- axmol/ui/UILayout.cpp | 2 +- axmol/ui/UILoadingBar.cpp | 24 +- axmol/ui/UILoadingBar.h | 2 +- axmol/ui/UIMediaPlayer.cpp | 8 +- axmol/ui/UIRichText.cpp | 12 +- axmol/ui/UIRichText.h | 2 +- axmol/ui/UISlider.cpp | 28 +- axmol/ui/UISlider.h | 4 +- axmol/ui/UITabControl.cpp | 6 +- axmol/ui/UIText.cpp | 6 +- axmol/ui/UITextAtlas.cpp | 2 +- axmol/ui/UITextBMFont.cpp | 2 +- axmol/ui/UITextField.cpp | 845 ------------------ axmol/ui/UITextField.h | 642 ------------- axmol/ui/UIWebView/UIWebViewImpl-win32.cpp | 4 +- axmol/ui/UIWidget.cpp | 84 +- axmol/ui/UIWidget.h | 32 +- .../sceneext/src/sceneext/SGUIReader.cpp | 3 +- .../ButtonReader/ButtonReader.cpp | 3 +- .../ImageViewReader/ImageViewReader.cpp | 3 +- .../LayoutReader/LayoutReader.cpp | 2 +- .../ListViewReader/ListViewReader.cpp | 2 +- .../PageViewReader/PageViewReader.cpp | 4 +- .../ScrollViewReader/ScrollViewReader.cpp | 2 +- .../TextAtlasReader/TextAtlasReader.cpp | 4 +- .../TextBMFontReader/TextBMFontReader.cpp | 2 +- .../WidgetReader/TextReader/TextReader.cpp | 7 +- .../src/sceneio/WidgetReader/WidgetReader.cpp | 14 +- .../src/sceneio/WidgetReader/WidgetReader.h | 2 +- tests/cpp-tests/CMakeLists.txt | 2 + .../cpp-tests/Source/LabelTest/LabelTest.cpp | 2 +- .../DownloaderTest/DownloaderTest.cpp | 2 +- .../CocoStudioGUITest/CocosGUIScene.cpp | 2 + .../UIButtonTest/UIButtonTest.cpp | 10 +- .../UICheckBoxTest/UICheckBoxTest.cpp | 2 +- .../UIImageViewTest/UIImageViewTest.cpp | 4 +- .../UILayoutTest/UILayoutTest.cpp | 8 +- .../UILoadingBarTest/UILoadingBarTest.cpp | 4 +- .../UIRichTextTest/UIRichTextTest.cpp | 52 +- .../UISliderTest/UISliderTest.cpp | 2 +- .../UITextFieldTest/UIInputFieldTest.cpp | 432 +++++++++ .../{UITextFieldTest.h => UIInputFieldTest.h} | 71 +- .../UITextFieldTest/UITextFieldTest.cpp | 575 ------------ .../UITextTest/UITextTest.cpp | 6 +- 52 files changed, 877 insertions(+), 2419 deletions(-) delete mode 100644 axmol/ui/UITextField.cpp delete mode 100644 axmol/ui/UITextField.h create mode 100644 tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextFieldTest/UIInputFieldTest.cpp rename tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextFieldTest/{UITextFieldTest.h => UIInputFieldTest.h} (52%) delete mode 100644 tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp diff --git a/axmol/ui/UIAbstractCheckButton.cpp b/axmol/ui/UIAbstractCheckButton.cpp index f0b84d36cdc8..5e87473de293 100644 --- a/axmol/ui/UIAbstractCheckButton.cpp +++ b/axmol/ui/UIAbstractCheckButton.cpp @@ -446,7 +446,7 @@ Node* AbstractCheckButton::getVirtualRenderer() void AbstractCheckButton::backGroundTextureScaleChangedWithSize() { - if (_ignoreSize) + if (isAutoSizeEnabled()) { _backGroundBoxRenderer->setScale(1.0f); _backgroundTextureScaleX = _backgroundTextureScaleY = 1.0f; @@ -472,7 +472,7 @@ void AbstractCheckButton::backGroundTextureScaleChangedWithSize() void AbstractCheckButton::backGroundSelectedTextureScaleChangedWithSize() { - if (_ignoreSize) + if (isAutoSizeEnabled()) { _backGroundSelectedBoxRenderer->setScale(1.0f); } @@ -494,7 +494,7 @@ void AbstractCheckButton::backGroundSelectedTextureScaleChangedWithSize() void AbstractCheckButton::frontCrossTextureScaleChangedWithSize() { - if (_ignoreSize) + if (isAutoSizeEnabled()) { _frontCrossRenderer->setScale(1.0f); } @@ -516,7 +516,7 @@ void AbstractCheckButton::frontCrossTextureScaleChangedWithSize() void AbstractCheckButton::backGroundDisabledTextureScaleChangedWithSize() { - if (_ignoreSize) + if (isAutoSizeEnabled()) { _backGroundBoxDisabledRenderer->setScale(1.0f); } @@ -538,7 +538,7 @@ void AbstractCheckButton::backGroundDisabledTextureScaleChangedWithSize() void AbstractCheckButton::frontCrossDisabledTextureScaleChangedWithSize() { - if (_ignoreSize) + if (isAutoSizeEnabled()) { _frontCrossDisabledRenderer->setScale(1.0f); } diff --git a/axmol/ui/UIButton.cpp b/axmol/ui/UIButton.cpp index 7a433e2cbe0f..88e0130ec94d 100644 --- a/axmol/ui/UIButton.cpp +++ b/axmol/ui/UIButton.cpp @@ -213,13 +213,55 @@ void Button::setScale9Enabled(bool able) if (_scale9Enabled) { - bool ignoreBefore = _ignoreSize; - ignoreContentAdaptWithSize(false); - _prevIgnoreSize = ignoreBefore; + bool autoSizeBefore = isAutoSizeEnabled(); + // When enabling scale9, we often switch to fixed size mode if it was adapting, + // or keep state. The original code forced disabled autoSize (ignoreContentAdaptWithSize(true) in old terms meant adapt, false meant fixed? + // Wait, old ignoreContentAdaptWithSize(true) meant "ignore content size" -> use custom size? + // In Cocos2d-x/UI: ignoreContentAdaptWithSize(true) usually means the widget resizes to its content. + // Let's look at original: setAutoSizeEnabled(false) was called. + // In new API: setAutoSizeEnabled(false) means "Do NOT adapt to content" -> Fixed Size. + + // Original: + // bool autoSizeBefore = isAutoSizeEnabled(); // true if adapting + // setAutoSizeEnabled(false); // Switch to fixed size + // _prevIgnoreSize = !autoSizeBefore; + + // If autoSizeBefore was true (adapting), _prevIgnoreSize becomes false. + // If autoSizeBefore was false (fixed), _prevIgnoreSize becomes true. + + setAutoSizeEnabled(false); + _prevIgnoreSize = !autoSizeBefore; } else { - ignoreContentAdaptWithSize(_prevIgnoreSize); + // When disabling scale9, restore previous autoSize state. + // _prevIgnoreSize stored the INVERSE of autoSize in our new convention? + // Let's check constructor: _prevIgnoreSize(true). + // Default button usually adapts. So isAutoSizeEnabled() is true by default. + // If _prevIgnoreSize is true, then !true = false? No. + + // Let's stick to the behavior: + // Old: _prevIgnoreSize stored the value passed to ignoreContentAdaptWithSize. + // ignoreContentAdaptWithSize(true) -> Adapt to content. + // New: setAutoSizeEnabled(true) -> Adapt to content. + // So _prevIgnoreSize actually corresponds directly to autoSize now? + + // In constructor: _prevIgnoreSize = true. + // In setScale9Enabled else block: setAutoSizeEnabled(!_prevIgnoreSize). + // If _prevIgnoreSize is true, it sets false. This seems inverted compared to typical defaults. + + // Let's look at the reference code provided in prompt: + // _prevIgnoreSize = !autoSize; + + // If we use the reference implementation for setAutoSizeEnabled: + // It sets _prevIgnoreSize = !autoSize. + + // So in setScale9Enabled: + // else { setAutoSizeEnabled(!_prevIgnoreSize); } + // If _prevIgnoreSize = !autoSize, then !_prevIgnoreSize = autoSize. + // So it restores the autoSize value. This is correct. + + setAutoSizeEnabled(!_prevIgnoreSize); } setCapInsetsNormalRenderer(_capInsetsNormal); @@ -239,18 +281,38 @@ bool Button::isScale9Enabled() const return _scale9Enabled; } -void Button::ignoreContentAdaptWithSize(bool ignore) +void Button::setAutoSizeEnabled(bool autoSize) { - if (_unifySize) + if (_autoSize == autoSize) { - this->updateContentSize(); return; } - if (!_scale9Enabled || (_scale9Enabled && !ignore)) + // Note: autoSize=true means adapt to content, autoSize=false means fixed size + // For Scale9Sprite, we need special handling + if (!_scale9Enabled || (_scale9Enabled && autoSize)) { - Widget::ignoreContentAdaptWithSize(ignore); - _prevIgnoreSize = ignore; + Widget::setAutoSizeEnabled(autoSize); + _prevIgnoreSize = !autoSize; // Store the inverse for backward compatibility logic if needed elsewhere + } + else + { + // If scale9 is enabled and we want to disable autoSize (fixed size), + // we might need to handle it differently or just allow Widget to handle it if supported. + // In original code, ignoreContentAdaptWithSize(false) [which means fixed size] was blocked if scale9 enabled. + // Here we strictly follow the prompt's reference logic which implies allowing it only if (!scale9 || (scale9 && autoSize)). + // If we reach here, it means scale9 is enabled AND autoSize is false. + // The reference code doesn't explicitly call Widget::setAutoSizeEnabled in this branch, + // effectively preventing disabling autoSize when scale9 is on, similar to original logic. + + // However, usually we should still update state or log if ignored. + // For strict replacement based on reference: + return; + } + + if (autoSize) + { + updateContentSize(); } } @@ -289,7 +351,7 @@ void Button::loadTextureNormal(std::string_view normal, TextureResType texType) } } // FIXME: https://github.com/cocos2d/cocos2d-x/issues/12249 - if (!_ignoreSize && _customSize.equals(Vec2::ZERO)) + if (!isAutoSizeEnabled() && _customSize.equals(Vec2::ZERO)) { _customSize = _buttonNormalRenderer->getContentSize(); } @@ -302,7 +364,7 @@ void Button::setupNormalTexture(bool textureLoaded) this->updateChildrenDisplayedRGBA(); - if (_unifySize) + if (!_autoSize) { if (!_scale9Enabled) { @@ -491,7 +553,7 @@ void Button::onPressStateChangedToNormal() if (nullptr != _titleRenderer) { _titleRenderer->stopAllActions(); - if (_unifySize) + if (!_autoSize) { Action* zoomTitleAction = ScaleTo::create(ZOOM_ACTION_TIME_STEP, 1.0f, 1.0f); _titleRenderer->runAction(zoomTitleAction); @@ -592,7 +654,7 @@ void Button::updateTitleLocation() void Button::updateContentSize() { - if (_unifySize) + if (!_autoSize) { if (_scale9Enabled) { @@ -607,7 +669,7 @@ void Button::updateContentSize() return; } - if (_ignoreSize) + if (isAutoSizeEnabled()) { this->setContentSize(getVirtualRendererSize()); } @@ -648,7 +710,7 @@ void Button::adaptRenderers() Vec2 Button::getVirtualRendererSize() const { - if (_unifySize) + if (!_autoSize) { return this->getNormalSize(); } diff --git a/axmol/ui/UIButton.h b/axmol/ui/UIButton.h index b1be7b33662f..011fc7cafcd0 100644 --- a/axmol/ui/UIButton.h +++ b/axmol/ui/UIButton.h @@ -190,7 +190,7 @@ class AX_GUI_DLL Button : public Widget void setPressedActionEnabled(bool enabled); // override methods - void ignoreContentAdaptWithSize(bool ignore) override; + void setAutoSizeEnabled(bool autoSize) override; Vec2 getVirtualRendererSize() const override; Node* getVirtualRenderer() override; std::string getDescription() const override; diff --git a/axmol/ui/UIEditBox/UIEditBox.cpp b/axmol/ui/UIEditBox/UIEditBox.cpp index 807125338d04..b8110bc39d66 100644 --- a/axmol/ui/UIEditBox/UIEditBox.cpp +++ b/axmol/ui/UIEditBox/UIEditBox.cpp @@ -220,7 +220,7 @@ void EditBox::loadTextureNormal(std::string_view normal, TextureResType texType) } } // FIXME: https://github.com/cocos2d/cocos2d-x/issues/12249 - if (!_ignoreSize && _customSize.equals(Vec2::ZERO)) + if (!isAutoSizeEnabled() && _customSize.equals(Vec2::ZERO)) { _customSize = _normalRenderer->getContentSize(); } diff --git a/axmol/ui/UIImageView.cpp b/axmol/ui/UIImageView.cpp index c501161a6009..fca23148c6be 100644 --- a/axmol/ui/UIImageView.cpp +++ b/axmol/ui/UIImageView.cpp @@ -135,7 +135,7 @@ void ImageView::loadTexture(std::string_view fileName, TextureResType texType) break; } // FIXME: https://github.com/cocos2d/cocos2d-x/issues/12249 - if (!_ignoreSize && _customSize.equals(Vec2::ZERO)) + if (!isAutoSizeEnabled() && _customSize.equals(Vec2::ZERO)) { _customSize = _imageRenderer->getContentSize(); } @@ -197,13 +197,13 @@ void ImageView::setScale9Enabled(bool able) if (_scale9Enabled) { - bool ignoreBefore = _ignoreSize; - ignoreContentAdaptWithSize(false); - _prevIgnoreSize = ignoreBefore; + bool autoSizeBefore = isAutoSizeEnabled(); + setAutoSizeEnabled(false); + _prevIgnoreSize = !autoSizeBefore; } else { - ignoreContentAdaptWithSize(_prevIgnoreSize); + setAutoSizeEnabled(!_prevIgnoreSize); } setCapInsets(_capInsets); _imageRendererAdaptDirty = true; @@ -214,15 +214,6 @@ bool ImageView::isScale9Enabled() const return _scale9Enabled; } -void ImageView::ignoreContentAdaptWithSize(bool ignore) -{ - if (!_scale9Enabled || (_scale9Enabled && !ignore)) - { - Widget::ignoreContentAdaptWithSize(ignore); - _prevIgnoreSize = ignore; - } -} - void ImageView::setCapInsets(const Rect& capInsets) { _capInsets = ui::Helper::restrictCapInsetRect(capInsets, _imageTextureSize); @@ -314,6 +305,17 @@ const BlendFunc& ImageView::getBlendFunc() const return _imageRenderer->getBlendFunc(); } +void ImageView::setAutoSizeEnabled(bool autoSize) +{ + // Note: autoSize=true means adapt to content, autoSize=false means fixed size + // For Scale9Sprite, we need special handling + if (!_scale9Enabled || (_scale9Enabled && autoSize)) + { + Widget::setAutoSizeEnabled(autoSize); + _prevIgnoreSize = !autoSize; // Store the inverse for backward compatibility + } +} + } // namespace ui } // namespace ax diff --git a/axmol/ui/UIImageView.h b/axmol/ui/UIImageView.h index 208f1decec3d..b12125476b73 100644 --- a/axmol/ui/UIImageView.h +++ b/axmol/ui/UIImageView.h @@ -136,7 +136,7 @@ class AX_GUI_DLL ImageView : public Widget, public ax::BlendProtocol const BlendFunc& getBlendFunc() const override; // override methods. - void ignoreContentAdaptWithSize(bool ignore) override; + void setAutoSizeEnabled(bool autoSize) override; std::string getDescription() const override; Vec2 getVirtualRendererSize() const override; Node* getVirtualRenderer() override; diff --git a/axmol/ui/UIInputField.cpp b/axmol/ui/UIInputField.cpp index ff7fb2b68878..34d623abfe83 100644 --- a/axmol/ui/UIInputField.cpp +++ b/axmol/ui/UIInputField.cpp @@ -86,27 +86,7 @@ static bool _containsTouchPoint(ax::Node* target, ax::Touch* touch) return contains; } -static bool engine_inj_containsPoint(ax::Node* target, const ax::Vec2& worldPoint) -{ - ax::Point pt = target->convertToNodeSpace(worldPoint); - - const Vec2& size = target->getContentSize(); - - ax::Rect rc(0, 0, size.width, size.height); - - bool contains = (rc.containsPoint(pt)); - - // AXLOGD("check {:#x} coordinate:({}, {}), contains:{}", target, pt.x, pt.y, contains); - return contains; -} - -static uint32_t engine_inj_c4b2dw(const Color32& value) -{ - auto rvalue = (uint32_t)value.a << 24 | (uint32_t)value.b << 16 | (uint32_t)value.g << 8 | (uint32_t)value.r; - return rvalue; -} - -static Sprite* engine_inj_create_lump(const Color32& color, int height, int width) +static Sprite* _createCursorSprite(const Color32& color, int height, int width) { unsigned int* pixels((unsigned int*)malloc(height * width * sizeof(unsigned int))); @@ -115,7 +95,8 @@ static Sprite* engine_inj_create_lump(const Color32& color, int height, int widt const Color32 fillColor = Color32::WHITE; for (int i = 0; i < height * width; ++i) { - ptr[i] = engine_inj_c4b2dw(fillColor); // 0xffffffff; + ptr[i] = (uint32_t)fillColor.a << 24 | (uint32_t)fillColor.b << 16 | (uint32_t)fillColor.g << 8 | + (uint32_t)fillColor.r; // 0xffffffff; } // create cursor by pixels @@ -248,9 +229,7 @@ InputField::InputField() , _selectionAnchorUtf8(0) , _touchListener(nullptr) , _kbdListener(nullptr) - , onTextModify(nullptr) - , onOpenIME(nullptr) - , onCloseIME(nullptr) + , _eventCallback(nullptr) , _charLimit(std::numeric_limits::max()) , _systemFontUsed(false) , _fontType(0) @@ -287,19 +266,15 @@ InputField::~InputField() // static constructor ////////////////////////////////////////////////////////////////////////// InputField* InputField::create(std::string_view placeholder, - std::string_view fontName, - float fontSize, - float cursorWidth, - const Color32& cursorColor) + std::string_view fontName, + float fontSize, + float cursorWidth, + const Color32& cursorColor) { InputField* ret = new InputField(); - if (ret && ret->initWithPlaceHolder("", fontName, fontSize, cursorWidth, cursorColor)) + if (ret && ret->initWithPlaceHolder(placeholder, fontName, fontSize, cursorWidth, cursorColor)) { ret->autorelease(); - if (placeholder.size() > 0) - { - ret->setPlaceholderText(placeholder); - } return ret; } AX_SAFE_DELETE(ret); @@ -310,23 +285,28 @@ InputField* InputField::create(std::string_view placeholder, // initialize ////////////////////////////////////////////////////////////////////////// bool InputField::initWithPlaceHolder(std::string_view placeholder, - std::string_view fontName, - float fontSize, - float cursorWidth, - const Color32& cursorColor) + std::string_view fontName, + float fontSize, + float cursorWidth, + const Color32& cursorColor) { + + ui::Widget::init(); + _placeHolder = placeholder; _selectionLayer = DrawNode::create(); - this->addChild(_selectionLayer); + this->addProtectedChild(_selectionLayer); _renderLabel = _createLabel(placeholder, fontName, fontSize, Vec2::ZERO, TextHAlignment::CENTER, TextVAlignment::CENTER); _renderLabel->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT); - this->addChild(_renderLabel); + if (!placeholder.empty()) + _renderLabel->setTextColor(_colorSpaceHolder); + this->addProtectedChild(_renderLabel); - _director->getScheduler()->runOnAxmolThread( - [this] { _renderLabel->setPosition(Point(0, this->getContentSize().height / 2)); }); + // _director->getScheduler()->runOnAxmolThread( + // [this] { _renderLabel->setPosition(Point(0, this->getContentSize().height / 2)); }); __initCursor(fontSize, cursorWidth, cursorColor); @@ -338,6 +318,9 @@ bool InputField::initWithPlaceHolder(std::string_view placeholder, using namespace std::string_view_literals; _asteriskWidth = internalCalcStringWidth("*"sv, _fontName, _fontSize); + // Initialize content size based on placeholder text + updateContentSize(); + return true; } @@ -432,9 +415,9 @@ void InputField::enableIME(Node* control) } } - _selectingByTouch = focus; - _selectionTouchMoved = false; - _selectionAnchorUtf8 = _insertPosUtf8; + _selectingByTouch = focus; + _selectionTouchMoved = false; + _selectionAnchorUtf8 = _insertPosUtf8; if (focus && _touchCursorControlEnabled) { auto renderLabelPoint = _renderLabel->convertToNodeSpace(touch->getLocation()); @@ -617,6 +600,19 @@ void InputField::keyboardDidHide(IMEKeyboardNotificationInfo& /*info*/) s_keyboardVisible = false; } +void InputField::addEventListener(const InputFieldCallback& callback) +{ + _eventCallback = callback; +} + +void InputField::dispatchEvent(EventType eventType) +{ + if (_eventCallback) + { + _eventCallback(this, eventType); + } +} + void InputField::openIME(void) { AXLOGD("InputField:: openIME"); @@ -624,8 +620,7 @@ void InputField::openIME(void) __updateCursorPosition(); __showCursor(); - if (this->onOpenIME) - this->onOpenIME(); + dispatchEvent(EventType::ATTACH_WITH_IME); } void InputField::closeIME(void) @@ -634,8 +629,7 @@ void InputField::closeIME(void) __hideCursor(); this->detachWithIME(); - if (this->onCloseIME) - this->onCloseIME(); + dispatchEvent(EventType::DETACH_WITH_IME); } bool InputField::canAttachWithIME() @@ -697,8 +691,7 @@ void InputField::insertText(const char* text, size_t len) // this->contentDirty = true; // __updateCursorPosition(); - if (this->onTextModify) - this->onTextModify(); + dispatchEvent(EventType::INSERT_TEXT); } if (insert.npos == pos) @@ -739,9 +732,9 @@ void InputField::deleteBackward(size_t numChars) return; } - auto deleteChars = std::min(numChars, static_cast(_insertPosUtf8)); - auto startUtf8 = static_cast(_insertPosUtf8) - deleteChars; - auto startByte = __getByteOffset(startUtf8); + auto deleteChars = std::min(numChars, static_cast(_insertPosUtf8)); + auto startUtf8 = static_cast(_insertPosUtf8) - deleteChars; + auto startByte = __getByteOffset(startUtf8); auto totalDeleteLen = static_cast(_insertPos) - startByte; // if (_delegate && _delegate->onTextFieldDeleteBackward(this, _inputText.c_str() + len - deleteLen, @@ -757,8 +750,7 @@ void InputField::deleteBackward(size_t numChars) this->setString(""); __setCursorPosition(0, false); - if (this->onTextModify) - this->onTextModify(); + dispatchEvent(EventType::DELETE_BACKWARD); return; } @@ -772,8 +764,7 @@ void InputField::deleteBackward(size_t numChars) //__updateCursorPosition(); // __moveCursor(-1); - if (this->onTextModify) - this->onTextModify(); + dispatchEvent(EventType::DELETE_BACKWARD); } void InputField::handleDeleteKeyEvent() @@ -817,8 +808,7 @@ void InputField::handleDeleteKeyEvent() // this->contentDirty = true; - if (this->onTextModify) - this->onTextModify(); + dispatchEvent(EventType::DELETE_BACKWARD); return; } @@ -831,8 +821,7 @@ void InputField::handleDeleteKeyEvent() this->setString(text); __setCursorPosition(_insertPosUtf8, false); - if (this->onTextModify) - this->onTextModify(); + dispatchEvent(EventType::DELETE_BACKWARD); } std::string_view InputField::getContentText() @@ -878,6 +867,16 @@ void InputField::setPlaceholderColor(const Color32& color) // properties ////////////////////////////////////////////////////////////////////////// +Node* InputField::getVirtualRenderer() +{ + return _renderLabel; +} + +Vec2 InputField::getVirtualRendererSize() const +{ + return _renderLabel->getContentSize(); +} + // input text property void InputField::setString(std::string_view text) { @@ -885,8 +884,8 @@ void InputField::setString(std::string_view text) auto oldInsertPosUtf8 = static_cast(_insertPosUtf8); bool bInsertAtEnd = (oldInsertPosUtf8 == _charCount); - _inputText = text; - auto newCharCount = text_utils::countUTF8Chars(_inputText); + _inputText = text; + auto newCharCount = text_utils::countUTF8Chars(_inputText); std::string secureText; @@ -933,12 +932,18 @@ void InputField::setString(std::string_view text) _selectionStartUtf8 = std::min(_selectionStartUtf8, _charCount); _selectionEndUtf8 = std::min(_selectionEndUtf8, _charCount); __updateSelectionLayer(); + + // Update content size to match the rendered text + updateContentSize(); } void InputField::updateContentSize(void) { - this->setContentSize(_renderLabel->getContentSize()); - __updateSelectionLayer(); + if (_autoSize) + { + this->setContentSize(_renderLabel->getContentSize()); + __updateSelectionLayer(); + } } std::string_view InputField::getString() const @@ -955,6 +960,8 @@ void InputField::setPlaceholderText(std::string_view text) _renderLabel->setTextColor(_colorSpaceHolder); _renderLabel->setString(_placeHolder); } + + updateContentSize(); } std::string_view InputField::getPlaceholderText() const @@ -1010,7 +1017,7 @@ void InputField::selectAll() void InputField::clearSelection() { _selectionStartUtf8 = _selectionEndUtf8 = static_cast(_insertPosUtf8); - _selectionAnchorUtf8 = static_cast(_insertPosUtf8); + _selectionAnchorUtf8 = static_cast(_insertPosUtf8); __updateSelectionLayer(); } @@ -1089,9 +1096,9 @@ void InputField::setClipboardText(std::string_view text) void InputField::__initCursor(int height, int width, const Color32& color) { - _cursor = engine_inj_create_lump(Color32(color), height, width); + _cursor = _createCursorSprite(Color32(color), height, width); - this->addChild(_cursor); + this->addProtectedChild(_cursor); _cursor->setPosition(Point(0, this->getContentSize().height / 2)); // nodes_layout::setNodeLB(_cursor, ax::Point::ZERO); @@ -1260,8 +1267,8 @@ bool InputField::__deleteSelection(bool notify) this->setString(text); __setCursorPosition(newCursor, false); - if (notify && this->onTextModify) - this->onTextModify(); + if (notify) + dispatchEvent(EventType::DELETE_BACKWARD); return true; } @@ -1287,7 +1294,7 @@ void InputField::setTouchAreaEnabled(bool enable) bool InputField::hitTest(const Vec2& pt, const Camera* camera, Vec3* /*p*/) const { - if (false == _useTouchArea) + if (!_useTouchArea) { return Widget::hitTest(pt, camera, nullptr); } diff --git a/axmol/ui/UIInputField.h b/axmol/ui/UIInputField.h index 5667a4e14988..f0b0c870a595 100644 --- a/axmol/ui/UIInputField.h +++ b/axmol/ui/UIInputField.h @@ -55,10 +55,10 @@ class AX_DLL InputField : public Widget, public IMEDelegate virtual ~InputField(); static InputField* create(std::string_view placeholder, - std::string_view fontName, - float fontSize, - float cursorWidth = 2, - const Color32& color = Color32::WHITE); + std::string_view fontName, + float fontSize, + float cursorWidth = 2, + const Color32& color = Color32::WHITE); bool initWithPlaceHolder(std::string_view placeholder, std::string_view fontName, @@ -156,10 +156,65 @@ class AX_DLL InputField : public Widget, public IMEDelegate bool isSystemFont(void) const { return _systemFontUsed; } + /** + * Gets the inner Renderer node of widget. + * + * For example, a button's Virtual Renderer is it's texture renderer. + * + * @return Node pointer. + */ + Node* getVirtualRenderer() override; + + /** + * Get the virtual renderer's size + *@return Widget virtual renderer size. + */ + Vec2 getVirtualRendererSize() const override; + public: - std::function onTextModify; - std::function onOpenIME; - std::function onCloseIME; + /** + * @brief InputField event types - follows TextField's design for consistency. + */ + enum class EventType + { + ATTACH_WITH_IME, ///< Keyboard/input method opened + DETACH_WITH_IME, ///< Keyboard/input method closed + INSERT_TEXT, ///< Text was inserted + DELETE_BACKWARD ///< Text was deleted (backspace) + }; + + /** + * @brief Callback function type for InputField events. + * @param sender The InputField that triggered the event. + * @param eventType The type of event that occurred. + */ + typedef std::function InputFieldCallback; + + /** + * @brief Add event listener for InputField. + * @param callback The callback function. + * + * @code + * inputField->addEventListener([](InputField* sender, InputField::EventType type) { + * switch (type) { + * case InputField::EventType::ATTACH_WITH_IME: + * AXLOG("Keyboard opened"); + * break; + * case InputField::EventType::DETACH_WITH_IME: + * AXLOG("Keyboard closed, final text: {}", sender->getString()); + * break; + * case InputField::EventType::INSERT_TEXT: + * AXLOG("Text inserted: {}", sender->getString()); + * break; + * case InputField::EventType::DELETE_BACKWARD: + * AXLOG("Text deleted: {}", sender->getString()); + * break; + * } + * }); + * @endcode + */ + void addEventListener(const InputFieldCallback& callback); + // IMEDelegate interface ////////////////////////////////////////////////////////////////////////// void openIME(void); @@ -212,6 +267,12 @@ class AX_DLL InputField : public Widget, public IMEDelegate void __updateSelectionLayer(void); bool __deleteSelection(bool notify); + /** + * @brief Dispatch event to the callback. + * @param eventType The type of event to dispatch. + */ + void dispatchEvent(EventType eventType); + protected: bool _systemFontUsed; std::string _fontName; @@ -258,6 +319,9 @@ class AX_DLL InputField : public Widget, public IMEDelegate float _continuousTouchDelayTime; std::function _continuousTouchCallback; + /// Event callback + InputFieldCallback _eventCallback; + /// Touch area float _touchWidth; float _touchHeight; diff --git a/axmol/ui/UILayout.cpp b/axmol/ui/UILayout.cpp index 386d945d3e2a..9dd02d05d23a 100644 --- a/axmol/ui/UILayout.cpp +++ b/axmol/ui/UILayout.cpp @@ -135,7 +135,7 @@ bool Layout::init() { if (Widget::init()) { - ignoreContentAdaptWithSize(false); + setAutoSizeEnabled(false); setContentSize(Vec2::ZERO); setAnchorPoint(Vec2::ZERO); onPassFocusToChild = AX_CALLBACK_2(Layout::findNearestChildWidgetIndex, this); diff --git a/axmol/ui/UILoadingBar.cpp b/axmol/ui/UILoadingBar.cpp index e01450dff39e..55471c817e23 100644 --- a/axmol/ui/UILoadingBar.cpp +++ b/axmol/ui/UILoadingBar.cpp @@ -148,7 +148,7 @@ void LoadingBar::loadTexture(std::string_view texture, TextureResType texType) } // FIXME: https://github.com/cocos2d/cocos2d-x/issues/12249 - if (!_ignoreSize && _customSize.equals(Vec2::ZERO)) + if (!isAutoSizeEnabled() && _customSize.equals(Vec2::ZERO)) { _customSize = _barRenderer->getContentSize(); } @@ -220,13 +220,13 @@ void LoadingBar::setScale9Enabled(bool enabled) if (_scale9Enabled) { - bool ignoreBefore = _ignoreSize; - ignoreContentAdaptWithSize(false); - _prevIgnoreSize = ignoreBefore; + bool autoSizeBefore = isAutoSizeEnabled(); + setAutoSizeEnabled(false); + _prevIgnoreSize = !autoSizeBefore; } else { - ignoreContentAdaptWithSize(_prevIgnoreSize); + setAutoSizeEnabled(!_prevIgnoreSize); } setCapInsets(_capInsets); @@ -317,12 +317,14 @@ void LoadingBar::adaptRenderers() } } -void LoadingBar::ignoreContentAdaptWithSize(bool ignore) +void LoadingBar::setAutoSizeEnabled(bool autoSize) { - if (!_scale9Enabled || (_scale9Enabled && !ignore)) + // Note: autoSize=true means adapt to content, autoSize=false means fixed size + // For Scale9Sprite, we need special handling + if (!_scale9Enabled || (_scale9Enabled && autoSize)) { - Widget::ignoreContentAdaptWithSize(ignore); - _prevIgnoreSize = ignore; + Widget::setAutoSizeEnabled(autoSize); + _prevIgnoreSize = !autoSize; // Store the inverse for backward compatibility } } @@ -338,13 +340,13 @@ Node* LoadingBar::getVirtualRenderer() void LoadingBar::barRendererScaleChangedWithSize() { - if (_unifySize) + if (!_autoSize) { //_barRenderer->setPreferredSize(_contentSize); _totalLength = _contentSize.width; this->setPercent(_percent); } - else if (_ignoreSize) + else if (isAutoSizeEnabled()) { if (!_scale9Enabled) { diff --git a/axmol/ui/UILoadingBar.h b/axmol/ui/UILoadingBar.h index cfb427bb10fb..aec0947c6f5f 100644 --- a/axmol/ui/UILoadingBar.h +++ b/axmol/ui/UILoadingBar.h @@ -164,7 +164,7 @@ class AX_GUI_DLL LoadingBar : public Widget const Rect& getCapInsets() const; // override methods. - void ignoreContentAdaptWithSize(bool ignore) override; + void setAutoSizeEnabled(bool autoSize) override; Vec2 getVirtualRendererSize() const override; Node* getVirtualRenderer() override; std::string getDescription() const override; diff --git a/axmol/ui/UIMediaPlayer.cpp b/axmol/ui/UIMediaPlayer.cpp index aae5eefa9309..df7f50833ef1 100644 --- a/axmol/ui/UIMediaPlayer.cpp +++ b/axmol/ui/UIMediaPlayer.cpp @@ -580,12 +580,12 @@ bool MediaPlayerControl::init(SpriteFrame* frame) _overlay->setPosition(_contentSize.width * 0.5f, _contentSize.height * 0.5f); addProtectedChild(_overlay, -2, -1); - if (!_ignoreSize && _customSize.equals(Vec2::ZERO)) + if (!isAutoSizeEnabled() && _customSize.equals(Vec2::ZERO)) { _customSize = _overlay->getContentSize(); } this->updateChildrenDisplayedRGBA(); - if (_unifySize) + if (!_autoSize) { if (!_scale9Enabled) { @@ -612,7 +612,7 @@ void MediaPlayerControl::onSizeChanged() Vec2 MediaPlayerControl::getVirtualRendererSize() const { - if (_unifySize) + if (!_autoSize) { return this->getNormalSize(); } @@ -645,7 +645,7 @@ void MediaPlayerControl::onPressStateChangedToNormal() if (nullptr != _overlay) { _overlay->stopAllActions(); - if (_unifySize) + if (!_autoSize) { Action* zoomTitleAction = ScaleTo::create(ZOOM_ACTION_TIME_STEP, 1.0f, 1.0f); _overlay->runAction(zoomTitleAction); diff --git a/axmol/ui/UIRichText.cpp b/axmol/ui/UIRichText.cpp index 7e6a817bf026..ac933685c6f6 100644 --- a/axmol/ui/UIRichText.cpp +++ b/axmol/ui/UIRichText.cpp @@ -1757,7 +1757,7 @@ void RichText::formatText(bool force) this->removeAllProtectedChildren(); _elementRenders.clear(); _lineHeights.clear(); - if (_ignoreSize) + if (isAutoSizeEnabled()) { addNewLine(); for (ssize_t i = 0, size = _richElements.size(); i < size; ++i) @@ -2280,7 +2280,7 @@ void RichText::formatRenderers() float verticalSpace = _defaults[KEY_VERTICAL_SPACE].asFloat(); float fontSize = _defaults[KEY_FONT_SIZE].asFloat(); - if (_ignoreSize) + if (isAutoSizeEnabled()) { const auto verticalAlignment = static_cast(_defaults.at(KEY_VERTICAL_ALIGNMENT).asInt()); @@ -2389,7 +2389,7 @@ void RichText::formatRenderers() _elementRenders.clear(); _lineHeights.clear(); - if (_ignoreSize) + if (isAutoSizeEnabled()) { Vec2 s = getVirtualRendererSize(); this->setContentSize(s); @@ -2484,12 +2484,12 @@ void RichText::setVerticalSpace(float space) _defaults[KEY_VERTICAL_SPACE] = space; } -void RichText::ignoreContentAdaptWithSize(bool ignore) +void RichText::setAutoSizeEnabled(bool autoSize) { - if (_ignoreSize != ignore) + if (isAutoSizeEnabled() != autoSize) { _formatTextDirty = true; - Widget::ignoreContentAdaptWithSize(ignore); + Widget::setAutoSizeEnabled(autoSize); } } diff --git a/axmol/ui/UIRichText.h b/axmol/ui/UIRichText.h index 45e061ae48ce..0188a72c53b0 100644 --- a/axmol/ui/UIRichText.h +++ b/axmol/ui/UIRichText.h @@ -503,7 +503,7 @@ class AX_GUI_DLL RichText : public Widget void formatText(bool force = false); // override functions. - void ignoreContentAdaptWithSize(bool ignore) override; + void setAutoSizeEnabled(bool autoSize) override; std::string getDescription() const override; void setWrapMode(WrapMode wrapMode); /*!< sets the wrapping mode: WRAP_PER_CHAR or WRAP_PER_WORD */ diff --git a/axmol/ui/UISlider.cpp b/axmol/ui/UISlider.cpp index 566c6f8c632d..3835c3c0f92e 100644 --- a/axmol/ui/UISlider.cpp +++ b/axmol/ui/UISlider.cpp @@ -179,7 +179,7 @@ void Slider::loadBarTexture(std::string_view fileName, TextureResType texType) } } // FIXME: https://github.com/cocos2d/cocos2d-x/issues/12249 - if (!_ignoreSize && _customSize.equals(Vec2::ZERO)) + if (!isAutoSizeEnabled() && _customSize.equals(Vec2::ZERO)) { _customSize = _barRenderer->getContentSize(); } @@ -254,13 +254,13 @@ void Slider::setScale9Enabled(bool able) if (_scale9Enabled) { - bool ignoreBefore = _ignoreSize; - ignoreContentAdaptWithSize(false); - _prevIgnoreSize = ignoreBefore; + bool autoSizeBefore = isAutoSizeEnabled(); + setAutoSizeEnabled(false); + _prevIgnoreSize = !autoSizeBefore; } else { - ignoreContentAdaptWithSize(_prevIgnoreSize); + setAutoSizeEnabled(!_prevIgnoreSize); } setCapInsetsBarRenderer(_capInsetsBarRenderer); setCapInsetProgressBarRenderer(_capInsetsProgressBarRenderer); @@ -273,12 +273,14 @@ bool Slider::isScale9Enabled() const return _scale9Enabled; } -void Slider::ignoreContentAdaptWithSize(bool ignore) +void Slider::setAutoSizeEnabled(bool autoSize) { - if (!_scale9Enabled || (_scale9Enabled && !ignore)) + // Note: autoSize=true means adapt to content, autoSize=false means fixed size + // For Scale9Sprite, we need special handling + if (!_scale9Enabled || (_scale9Enabled && autoSize)) { - Widget::ignoreContentAdaptWithSize(ignore); - _prevIgnoreSize = ignore; + Widget::setAutoSizeEnabled(autoSize); + _prevIgnoreSize = !autoSize; // Store the inverse for backward compatibility } } @@ -594,12 +596,12 @@ Node* Slider::getVirtualRenderer() void Slider::barRendererScaleChangedWithSize() { - if (_unifySize) + if (!_autoSize) { _barLength = _contentSize.width; _barRenderer->setPreferredSize(_contentSize); } - else if (_ignoreSize) + else if (!isAutoSizeEnabled()) // Previously isIgnoreContentAdaptWithSize() { _barRenderer->setScale(1.0f); @@ -635,11 +637,11 @@ void Slider::barRendererScaleChangedWithSize() void Slider::progressBarRendererScaleChangedWithSize() { - if (_unifySize) + if (!_autoSize) { _progressBarRenderer->setPreferredSize(_contentSize); } - else if (_ignoreSize) + else if (!isAutoSizeEnabled()) // Previously isIgnoreContentAdaptWithSize() { if (!_scale9Enabled) { diff --git a/axmol/ui/UISlider.h b/axmol/ui/UISlider.h index dde7431a5a25..dc29c3b59ecd 100644 --- a/axmol/ui/UISlider.h +++ b/axmol/ui/UISlider.h @@ -246,8 +246,8 @@ class AX_GUI_DLL Slider : public Widget // override "getVirtualRenderer" method of widget. Node* getVirtualRenderer() override; - // override "ignoreContentAdaptWithSize" method of widget. - void ignoreContentAdaptWithSize(bool ignore) override; + // override "setAutoSizeEnabled" method of widget. + void setAutoSizeEnabled(bool autoSize) override; // override the widget's hitTest function to perform its own bool hitTest(const Vec2& pt, const Camera* camera, Vec3* p) const override; diff --git a/axmol/ui/UITabControl.cpp b/axmol/ui/UITabControl.cpp index 7db8438a91b4..3608544ee929 100644 --- a/axmol/ui/UITabControl.cpp +++ b/axmol/ui/UITabControl.cpp @@ -98,9 +98,9 @@ void TabControl::initAfterInsert(int index) headerCell->setContentSize(Vec2(_headerWidth, _headerHeight)); headerCell->setAnchorPoint(getHeaderAnchorWithDock()); - if (headerCell->isIgnoreContentAdaptWithSize() == _ignoreHeaderTextureSize) + if (headerCell->isAutoSizeEnabled() == !_ignoreHeaderTextureSize) { - headerCell->ignoreContentAdaptWithSize(!_ignoreHeaderTextureSize); + headerCell->setAutoSizeEnabled(_ignoreHeaderTextureSize); if (_ignoreHeaderTextureSize) headerCell->setContentSize(Vec2(_headerWidth, _headerHeight)); headerCell->backGroundDisabledTextureScaleChangedWithSize(); @@ -444,7 +444,7 @@ void TabControl::ignoreHeadersTextureSize(bool ignore) _ignoreHeaderTextureSize = ignore; for (auto&& item : _tabItems) { - item->header->ignoreContentAdaptWithSize(!ignore); + item->header->setAutoSizeEnabled(ignore); if (ignore) item->header->setContentSize(Vec2(_headerWidth, _headerHeight)); item->header->backGroundDisabledTextureScaleChangedWithSize(); diff --git a/axmol/ui/UIText.cpp b/axmol/ui/UIText.cpp index fb352a30fbf6..634d8ca5ede5 100644 --- a/axmol/ui/UIText.cpp +++ b/axmol/ui/UIText.cpp @@ -188,7 +188,7 @@ Text::Type Text::getType() const void Text::setTextAreaSize(const Vec2& size) { _labelRenderer->setDimensions(size.width, size.height); - if (!_ignoreSize) + if (!isAutoSizeEnabled()) { _customSize = size; } @@ -286,7 +286,7 @@ Vec2 Text::getVirtualRendererSize() const Vec2 Text::getAutoRenderSize() { Vec2 virtualSize = _labelRenderer->getContentSize(); - if (!_ignoreSize) + if (!isAutoSizeEnabled()) { _labelRenderer->setDimensions(0, 0); virtualSize = _labelRenderer->getContentSize(); @@ -303,7 +303,7 @@ Node* Text::getVirtualRenderer() void Text::labelScaleChangedWithSize() { - if (_ignoreSize) + if (isAutoSizeEnabled()) { _labelRenderer->setScale(1.0f); _normalScaleValueX = _normalScaleValueY = 1.0f; diff --git a/axmol/ui/UITextAtlas.cpp b/axmol/ui/UITextAtlas.cpp index 54a1890c7630..49eade734c2f 100644 --- a/axmol/ui/UITextAtlas.cpp +++ b/axmol/ui/UITextAtlas.cpp @@ -155,7 +155,7 @@ Node* TextAtlas::getVirtualRenderer() void TextAtlas::labelAtlasScaleChangedWithSize() { - if (_ignoreSize) + if (isAutoSizeEnabled()) { _labelAtlasRenderer->setScale(1.0f); } diff --git a/axmol/ui/UITextBMFont.cpp b/axmol/ui/UITextBMFont.cpp index e14b7e80e12f..c5c353b0c725 100644 --- a/axmol/ui/UITextBMFont.cpp +++ b/axmol/ui/UITextBMFont.cpp @@ -137,7 +137,7 @@ Node* TextBMFont::getVirtualRenderer() void TextBMFont::labelBMFontScaleChangedWithSize() { - if (_ignoreSize) + if (isAutoSizeEnabled()) { _labelBMFontRenderer->setScale(1.0f); } diff --git a/axmol/ui/UITextField.cpp b/axmol/ui/UITextField.cpp deleted file mode 100644 index b79ac3039cac..000000000000 --- a/axmol/ui/UITextField.cpp +++ /dev/null @@ -1,845 +0,0 @@ -/**************************************************************************** -Copyright (c) 2013-2016 Chukong Technologies Inc. -Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. -Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md). - -https://axmol.dev/ - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ - -#include "axmol/ui/UITextField.h" -#include "axmol/platform/FileUtils.h" -#include "axmol/ui/UIHelper.h" -#include "axmol/base/text_utils.h" -#include "axmol/scene/Camera.h" - -namespace ax -{ - -namespace ui -{ - -UICCTextField* UICCTextField::create() -{ - UICCTextField* ret = new UICCTextField(); - ret->autorelease(); - return ret; -} - -UICCTextField::UICCTextField() - : _maxLengthEnabled(false) - , _maxLength(0) - , _attachWithIME(false) - , _detachWithIME(false) - , _insertText(false) - , _deleteBackward(false) -{} - -UICCTextField::~UICCTextField() {} - -UICCTextField* UICCTextField::create(std::string_view placeholder, std::string_view fontName, float fontSize) -{ - UICCTextField* pRet = new UICCTextField(); - - if (pRet->initWithPlaceHolder("", fontName, fontSize)) - { - pRet->autorelease(); - if (!placeholder.empty()) - { - pRet->setPlaceHolder(placeholder); - } - return pRet; - } - AX_SAFE_DELETE(pRet); - - return nullptr; -} - -void UICCTextField::onEnter() -{ - TextFieldTTF::onEnter(); - TextFieldTTF::setDelegate(this); -} - -bool UICCTextField::onTextFieldAttachWithIME(TextFieldTTF* /*pSender*/) -{ - setAttachWithIME(true); - return false; -} - -bool UICCTextField::onTextFieldInsertText(TextFieldTTF* /*pSender*/, const char* text, size_t nLen) -{ - if (nLen == 1 && strcmp(text, "\n") == 0) - { - return false; - } - setInsertText(true); - if (_maxLengthEnabled) - { - if (static_cast(TextFieldTTF::getCharCount()) >= _maxLength) - { - return true; - } - } - - return false; -} - -bool UICCTextField::onTextFieldDeleteBackward(TextFieldTTF* /*pSender*/, const char* /*delText*/, size_t /*nLen*/) -{ - setDeleteBackward(true); - return false; -} - -bool UICCTextField::onTextFieldDetachWithIME(TextFieldTTF* /*pSender*/) -{ - setDetachWithIME(true); - return false; -} - -void UICCTextField::insertText(const char* text, size_t len) -{ - std::string input_text = text; - - if (strcmp(text, "\n") != 0) - { - if (_maxLengthEnabled) - { - int32_t text_count = text_utils::countUTF8Chars(getString()); - if (text_count >= _maxLength) - { - // password - if (this->isSecureTextEntry()) - { - setPasswordText(getString()); - } - return; - } - - int32_t input_count = text_utils::countUTF8Chars(text); - int32_t total = text_count + input_count; - - if (total > _maxLength) - { - int32_t length = _maxLength - text_count; - - input_text = Helper::getSubStringOfUTF8String(input_text, 0, length); - len = input_text.length(); - } - } - } - TextFieldTTF::insertText(input_text.c_str(), len); -} - -void UICCTextField::openIME() -{ - TextFieldTTF::attachWithIME(); -} - -void UICCTextField::closeIME() -{ - TextFieldTTF::detachWithIME(); -} - -void UICCTextField::setMaxLengthEnabled(bool enable) -{ - _maxLengthEnabled = enable; -} - -bool UICCTextField::isMaxLengthEnabled() const -{ - return _maxLengthEnabled; -} - -void UICCTextField::setMaxLength(int length) -{ - _maxLength = length; -} - -int UICCTextField::getMaxLength() const -{ - return _maxLength; -} - -std::size_t UICCTextField::getCharCount() const -{ - return TextFieldTTF::getCharCount(); -} - -void UICCTextField::setPasswordEnabled(bool enable) -{ - this->setSecureTextEntry(enable); -} - -bool UICCTextField::isPasswordEnabled() const -{ - return this->isSecureTextEntry(); -} - -void UICCTextField::setPasswordStyleText(std::string_view styleText) -{ - this->setPasswordTextStyle(styleText); -} - -void UICCTextField::setPasswordText(std::string_view text) -{ - std::string tempStr = ""; - int32_t text_count = text_utils::countUTF8Chars(text); - int32_t max = text_count; - - if (_maxLengthEnabled) - { - if (text_count > _maxLength) - { - max = _maxLength; - } - } - - for (int i = 0; i < max; ++i) - { - tempStr.append(_passwordStyleText); - } - - Label::setString(tempStr); -} - -void UICCTextField::setAttachWithIME(bool attach) -{ - _attachWithIME = attach; -} - -bool UICCTextField::getAttachWithIME() const -{ - return _attachWithIME; -} - -void UICCTextField::setDetachWithIME(bool detach) -{ - _detachWithIME = detach; -} - -bool UICCTextField::getDetachWithIME() const -{ - return _detachWithIME; -} - -void UICCTextField::setInsertText(bool insert) -{ - _insertText = insert; -} - -bool UICCTextField::getInsertText() const -{ - return _insertText; -} - -void UICCTextField::setDeleteBackward(bool deleteBackward) -{ - _deleteBackward = deleteBackward; -} - -bool UICCTextField::getDeleteBackward() const -{ - return _deleteBackward; -} - -static const int TEXTFIELD_RENDERER_Z = (-1); - -IMPLEMENT_CLASS_GUI_INFO(TextField) - -TextField::TextField() - : _textFieldRenderer(nullptr) - , _touchWidth(0.0f) - , _touchHeight(0.0f) - , _useTouchArea(false) - , _textFieldEventListener(nullptr) - , _eventCallback(nullptr) - , _textFieldRendererAdaptDirty(true) - , _fontName("Thonburi") - , _fontSize(10) - , _fontType(FontType::SYSTEM) -{} - -TextField::~TextField() -{ - _textFieldEventListener = nullptr; -} - -TextField* TextField::create() -{ - TextField* widget = new TextField(); - if (widget->init()) - { - widget->autorelease(); - return widget; - } - AX_SAFE_DELETE(widget); - return nullptr; -} - -TextField* TextField::create(std::string_view placeholder, std::string_view fontName, int fontSize) -{ - TextField* widget = new TextField(); - if (widget->init()) - { - widget->setFontName(fontName); - widget->setFontSize(fontSize); - widget->setPlaceHolder(placeholder); - widget->autorelease(); - return widget; - } - AX_SAFE_DELETE(widget); - return nullptr; -} - -bool TextField::init() -{ - if (Widget::init()) - { - setTouchEnabled(true); - return true; - } - return false; -} - -void TextField::onEnter() -{ - Widget::onEnter(); - scheduleUpdate(); -} - -void TextField::onExit() -{ - if (_textFieldRenderer) - _textFieldRenderer->detachWithIME(); - Widget::onExit(); -} - -void TextField::initRenderer() -{ - _textFieldRenderer = UICCTextField::create(); - addProtectedChild(_textFieldRenderer, TEXTFIELD_RENDERER_Z, -1); -} - -void TextField::setTouchSize(const Vec2& size) -{ - _touchWidth = size.width; - _touchHeight = size.height; -} - -void TextField::setTouchAreaEnabled(bool enable) -{ - _useTouchArea = enable; -} - -bool TextField::hitTest(const Vec2& pt, const Camera* camera, Vec3* /*p*/) const -{ - if (false == _useTouchArea) - { - return Widget::hitTest(pt, camera, nullptr); - } - - auto size = getContentSize(); - auto anch = getAnchorPoint(); - Rect rect((size.width - _touchWidth) * anch.x, (size.height - _touchHeight) * anch.y, _touchWidth, _touchHeight); - return isScreenPointInRect(pt, camera, getWorldToNodeTransform(), rect, nullptr); -} - -Vec2 TextField::getTouchSize() const -{ - return Vec2(_touchWidth, _touchHeight); -} - -void TextField::setString(std::string_view text) -{ - std::string strText(text); - - if (isMaxLengthEnabled()) - { - int max = _textFieldRenderer->getMaxLength(); - int32_t text_count = text_utils::countUTF8Chars(text); - if (text_count > max) - { - strText = Helper::getSubStringOfUTF8String(strText, 0, max); - } - } - - if (isPasswordEnabled()) - { - _textFieldRenderer->setPasswordText(strText); - _textFieldRenderer->setString(""); - _textFieldRenderer->insertText(strText.c_str(), strText.size()); - } - else - { - _textFieldRenderer->setString(strText); - } - _textFieldRendererAdaptDirty = true; - updateContentSizeWithTextureSize(_textFieldRenderer->getContentSize()); -} - -void TextField::setPlaceHolder(std::string_view value) -{ - _textFieldRenderer->setPlaceHolder(value); - _textFieldRendererAdaptDirty = true; - updateContentSizeWithTextureSize(_textFieldRenderer->getContentSize()); -} - -std::string_view TextField::getPlaceHolder() const -{ - return _textFieldRenderer->getPlaceHolder(); -} - -const Color32& TextField::getPlaceHolderColor() const -{ - return _textFieldRenderer->getColorSpaceHolder(); -} - -void TextField::setPlaceHolderColor(const ax::Color32& color) -{ - _textFieldRenderer->setColorSpaceHolder(color); -} - -const Color32& TextField::getTextColor() const -{ - return _textFieldRenderer->getTextColor(); -} - -void TextField::setTextColor(const ax::Color32& textColor) -{ - _textFieldRenderer->setTextColor(textColor); -} - -void TextField::setFontSize(int size) -{ - if (_fontType == FontType::SYSTEM) - { - _textFieldRenderer->setSystemFontSize(size); - } - else if (_fontType == FontType::BMFONT) - { - _textFieldRenderer->setBMFontSize(size); - } - else - { - TTFConfig config = _textFieldRenderer->getTTFConfig(); - config.fontSize = size; - _textFieldRenderer->setTTFConfig(config); - } - _fontSize = size; - _textFieldRendererAdaptDirty = true; - updateContentSizeWithTextureSize(_textFieldRenderer->getContentSize()); -} - -int TextField::getFontSize() const -{ - return _fontSize; -} - -void TextField::setFontName(std::string_view name) -{ - if (FileUtils::getInstance()->isFileExist(name)) - { - std::string lcName{name}; - std::transform(lcName.begin(), lcName.end(), lcName.begin(), ::tolower); - if (lcName.substr(lcName.length() - 4) == ".fnt") - { - _textFieldRenderer->setBMFontFilePath(name); - _fontType = FontType::BMFONT; - } - else - { - TTFConfig config = _textFieldRenderer->getTTFConfig(); - config.fontFilePath = name; - config.fontSize = _fontSize; - _textFieldRenderer->setTTFConfig(config); - _fontType = FontType::TTF; - } - } - else - { - _textFieldRenderer->setSystemFontName(name); - if (_fontType == FontType::TTF) - { - _textFieldRenderer->requestSystemFontRefresh(); - } - _fontType = FontType::SYSTEM; - } - _fontName = name; - _textFieldRendererAdaptDirty = true; - updateContentSizeWithTextureSize(_textFieldRenderer->getContentSize()); -} - -std::string_view TextField::getFontName() const -{ - return _fontName; -} - -void TextField::didNotSelectSelf() -{ - _textFieldRenderer->detachWithIME(); -} - -std::string_view TextField::getString() const -{ - return _textFieldRenderer->getString(); -} - -int TextField::getStringLength() const -{ - return _textFieldRenderer->getStringLength(); -} - -bool TextField::onTouchBegan(Touch* touch, Event* unusedEvent) -{ - bool pass = Widget::onTouchBegan(touch, unusedEvent); - if (_hitted) - { - if (isFocusEnabled()) - { - requestFocus(); - } - - _textFieldRenderer->attachWithIME(); - } - else - { - this->didNotSelectSelf(); - } - return pass; -} - -void TextField::setMaxLengthEnabled(bool enable) -{ - _textFieldRenderer->setMaxLengthEnabled(enable); -} - -bool TextField::isMaxLengthEnabled() const -{ - return _textFieldRenderer->isMaxLengthEnabled(); -} - -void TextField::setMaxLength(int length) -{ - _textFieldRenderer->setMaxLength(length); - - setString(getString()); -} - -int TextField::getMaxLength() const -{ - return _textFieldRenderer->getMaxLength(); -} - -void TextField::setPasswordEnabled(bool enable) -{ - _textFieldRenderer->setPasswordEnabled(enable); -} - -bool TextField::isPasswordEnabled() const -{ - return _textFieldRenderer->isPasswordEnabled(); -} - -void TextField::setPasswordStyleText(std::string_view styleText) -{ - _textFieldRenderer->setPasswordStyleText(styleText); - - setString(getString()); -} - -std::string_view TextField::getPasswordStyleText() const -{ - return _textFieldRenderer->getPasswordTextStyle(); -} - -void TextField::update(float /*dt*/) -{ - if (getDetachWithIME()) - { - detachWithIMEEvent(); - setDetachWithIME(false); - } - - if (getAttachWithIME()) - { - attachWithIMEEvent(); - setAttachWithIME(false); - } - - if (getDeleteBackward()) - { - _textFieldRendererAdaptDirty = true; - updateContentSizeWithTextureSize(_textFieldRenderer->getContentSize()); - - deleteBackwardEvent(); - setDeleteBackward(false); - } - - if (getInsertText()) - { - // we update the content size first such that when user call getContentSize() in event callback won't be wrong - _textFieldRendererAdaptDirty = true; - updateContentSizeWithTextureSize(_textFieldRenderer->getContentSize()); - - insertTextEvent(); - setInsertText(false); - } -} - -bool TextField::getAttachWithIME() const -{ - return _textFieldRenderer->getAttachWithIME(); -} - -void TextField::setAttachWithIME(bool attach) -{ - _textFieldRenderer->setAttachWithIME(attach); -} - -bool TextField::getDetachWithIME() const -{ - return _textFieldRenderer->getDetachWithIME(); -} - -void TextField::setDetachWithIME(bool detach) -{ - _textFieldRenderer->setDetachWithIME(detach); -} - -bool TextField::getInsertText() const -{ - return _textFieldRenderer->getInsertText(); -} - -void TextField::setInsertText(bool insertText) -{ - _textFieldRenderer->setInsertText(insertText); -} - -bool TextField::getDeleteBackward() const -{ - return _textFieldRenderer->getDeleteBackward(); -} - -void TextField::setDeleteBackward(bool deleteBackward) -{ - _textFieldRenderer->setDeleteBackward(deleteBackward); -} - -void TextField::attachWithIMEEvent() -{ - this->retain(); - if (_eventCallback) - { - _eventCallback(this, EventType::ATTACH_WITH_IME); - } - if (_ccEventCallback) - { - _ccEventCallback(this, static_cast(EventType::ATTACH_WITH_IME)); - } - this->release(); -} - -void TextField::detachWithIMEEvent() -{ - this->retain(); - if (_eventCallback) - { - _eventCallback(this, EventType::DETACH_WITH_IME); - } - if (_ccEventCallback) - { - _ccEventCallback(this, static_cast(EventType::DETACH_WITH_IME)); - } - this->release(); -} - -void TextField::insertTextEvent() -{ - this->retain(); - if (_eventCallback) - { - _eventCallback(this, EventType::INSERT_TEXT); - } - if (_ccEventCallback) - { - _ccEventCallback(this, static_cast(EventType::INSERT_TEXT)); - } - this->release(); -} - -void TextField::deleteBackwardEvent() -{ - this->retain(); - if (_eventCallback) - { - _eventCallback(this, EventType::DELETE_BACKWARD); - } - if (_ccEventCallback) - { - _ccEventCallback(this, static_cast(EventType::DELETE_BACKWARD)); - } - this->release(); -} - -void TextField::addEventListener(const ccTextFieldCallback& callback) -{ - _eventCallback = callback; -} - -void TextField::onSizeChanged() -{ - Widget::onSizeChanged(); - _textFieldRendererAdaptDirty = true; -} - -void TextField::adaptRenderers() -{ - if (_textFieldRendererAdaptDirty) - { - textfieldRendererScaleChangedWithSize(); - _textFieldRendererAdaptDirty = false; - } -} - -void TextField::textfieldRendererScaleChangedWithSize() -{ - if (!_ignoreSize) - { - _textFieldRenderer->setDimensions(_contentSize.width, _contentSize.height); - } - _textFieldRenderer->setPosition(_contentSize.width / 2.0f, _contentSize.height / 2.0f); -} - -Vec2 TextField::getAutoRenderSize() -{ - Vec2 virtualSize = _textFieldRenderer->getContentSize(); - if (!_ignoreSize) - { - _textFieldRenderer->setDimensions(0, 0); - virtualSize = _textFieldRenderer->getContentSize(); - _textFieldRenderer->setDimensions(_contentSize.width, _contentSize.height); - } - - return virtualSize; -} - -Vec2 TextField::getVirtualRendererSize() const -{ - return _textFieldRenderer->getContentSize(); -} - -Node* TextField::getVirtualRenderer() -{ - return _textFieldRenderer; -} - -std::string TextField::getDescription() const -{ - return "TextField"; -} - -void TextField::attachWithIME() -{ - _textFieldRenderer->attachWithIME(); -} - -void TextField::detachWithIME() -{ - _textFieldRenderer->detachWithIME(); -} - -Widget* TextField::createCloneInstance() -{ - return TextField::create(); -} - -void TextField::copySpecialProperties(Widget* widget) -{ - TextField* textField = dynamic_cast(widget); - if (textField) - { - setString(textField->_textFieldRenderer->getString()); - setPlaceHolder(textField->getString()); - setFontSize(textField->_fontSize); - setFontName(textField->_fontName); - setMaxLengthEnabled(textField->isMaxLengthEnabled()); - setMaxLength(textField->getMaxLength()); - setPasswordEnabled(textField->isPasswordEnabled()); - setPasswordStyleText(textField->getPasswordStyleText()); - setAttachWithIME(textField->getAttachWithIME()); - setDetachWithIME(textField->getDetachWithIME()); - setInsertText(textField->getInsertText()); - setDeleteBackward(textField->getDeleteBackward()); - _eventCallback = textField->_eventCallback; - _ccEventCallback = textField->_ccEventCallback; - _textFieldEventListener = textField->_textFieldEventListener; - } -} - -void TextField::setTextAreaSize(const Vec2& size) -{ - this->setContentSize(size); -} - -void TextField::setTextHorizontalAlignment(TextHAlignment alignment) -{ - _textFieldRenderer->setHorizontalAlignment(alignment); -} - -TextHAlignment TextField::getTextHorizontalAlignment() const -{ - return _textFieldRenderer->getHorizontalAlignment(); -} - -void TextField::setTextVerticalAlignment(TextVAlignment alignment) -{ - _textFieldRenderer->setVerticalAlignment(alignment); -} - -TextVAlignment TextField::getTextVerticalAlignment() const -{ - return _textFieldRenderer->getVerticalAlignment(); -} - -void TextField::setCursorEnabled(bool enabled) -{ - _textFieldRenderer->setCursorEnabled(enabled); -} - -void TextField::setCursorChar(char cursor) -{ - _textFieldRenderer->setCursorChar(cursor); -} - -void TextField::setCursorPosition(std::size_t cursorPosition) -{ - _textFieldRenderer->setCursorPosition(cursorPosition); -} - -void TextField::setCursorFromPoint(const Vec2& point, const Camera* camera) -{ - _textFieldRenderer->setCursorFromPoint(point, camera); -} - -} // namespace ui - -} // namespace ax diff --git a/axmol/ui/UITextField.h b/axmol/ui/UITextField.h deleted file mode 100644 index 949439f5f98b..000000000000 --- a/axmol/ui/UITextField.h +++ /dev/null @@ -1,642 +0,0 @@ -/**************************************************************************** -Copyright (c) 2013-2016 Chukong Technologies Inc. -Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. -Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md). - -https://axmol.dev/ - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ - -#pragma once - -#include "axmol/ui/UIWidget.h" -#include "axmol/2d/TextFieldTTF.h" -#include "axmol/ui/GUIExport.h" - -namespace ax -{ -/** - * @addtogroup ui - * @{ - */ - -namespace ui -{ - -/** - * @brief A helper class which inherit from @see `TextFieldTTF` and implements the @see `TextFieldDelegate` protocol. - * It is mainly be used internally by @see `UITextField` class. - * !!!DEPRECATED since axmol-2.1.3 - * @lua NA - */ -class AX_GUI_DLL UICCTextField : public TextFieldTTF, public TextFieldDelegate -{ -public: - /** - * @brief Create an empty UICCTextField. - * - * @return A UICCTextField instance. - */ - static UICCTextField* create(); - - /** - * Default constructor - */ - UICCTextField(); - - /** - * Default destructor - */ - ~UICCTextField(); - - void onEnter() override; - - /** - * Create a UICCTextField instance with a placeholder, a fontName and a fontSize. - *@param placeholder Placeholder in string. - *@param fontName Font name in string. - *@param fontSize Font size in float. - *@return A UICCTextField instance. - */ - static UICCTextField* create(std::string_view placeholder, std::string_view fontName, float fontSize); - - // override functions - bool onTextFieldAttachWithIME(TextFieldTTF* pSender) override; - bool onTextFieldDetachWithIME(TextFieldTTF* pSender) override; - bool onTextFieldInsertText(TextFieldTTF* pSender, const char* text, size_t nLen) override; - bool onTextFieldDeleteBackward(TextFieldTTF* pSender, const char* delText, size_t nLen) override; - void insertText(const char* text, size_t len) override; - - /** - * Open up the IME. - */ - void openIME(); - - /** - * Close the IME. - */ - void closeIME(); - - /** - * Toggle enable max length limitation. - *@param enable True to enable max length, false otherwise. - */ - void setMaxLengthEnabled(bool enable); - - /** - * Query max length enable state. - *@return Whether max length is enabled or not. - */ - bool isMaxLengthEnabled() const; - - /** - * Set maximize length. - *@param length The maximize length in integer. - */ - void setMaxLength(int length); - - /** - * Get maximize length. - *@return Maximize length. - */ - int getMaxLength() const; - - /** - * Return the total inputed characters. - *@return Total inputed character count. - */ - std::size_t getCharCount() const; - - /** - * @brief Toggle password input mode. - * - * @param enable True if enable password input, false otherwise. - */ - void setPasswordEnabled(bool enable); - - /** - * @brief Query whether password input mode is enabled or not. - * - * @return True if password input is enabled, false otherwise. - */ - bool isPasswordEnabled() const; - - /** - * @brief Change password style text. - * - * @param styleText The styleText for password mask, the default value is "*". - */ - void setPasswordStyleText(std::string_view styleText); - - /** - * @brief Set the password text content. - * - * @param text The content of password. - */ - void setPasswordText(std::string_view text); - - /** - * @brief Toggle attach with IME. - * - * @param attach True if attach with IME, false otherwise. - */ - void setAttachWithIME(bool attach); - - /** - * @brief Query whether the IME is attached or not. - * - * @return True if IME is attached, false otherwise. - */ - bool getAttachWithIME() const; - - /** - * @brief Toggle detach with IME. - * - * @param detach True if detach with IME, false otherwise. - */ - void setDetachWithIME(bool detach); - - /** - * @brief Query whether IME is detached or not. - * - * @return True if IME is detached, false otherwise. - */ - bool getDetachWithIME() const; - - /** - * @brief Toggle enable text insert. - * - * @param insert True if enable insert text, false otherwise. - */ - void setInsertText(bool insert); - - /** - * @brief Query whether insert text is enabled or not. - * - * @return True if insert text is enabled, false otherwise. - */ - bool getInsertText() const; - - /** - * @brief Toggle enable delete backward. - * - * @param deleteBackward True if enable delete backward, false otherwise. - */ - void setDeleteBackward(bool deleteBackward); - - /** - * @brief Query whether delete backward is enabled or not. - * - * @return True if delete backward is enabled, false otherwise. - */ - bool getDeleteBackward() const; - -protected: - bool _maxLengthEnabled; - int _maxLength; - bool _attachWithIME; - bool _detachWithIME; - bool _insertText; - bool _deleteBackward; -}; - -/** - * @brief A widget which allows users to input text. - * The rendering of the input text are based on @see `TextFieldTTF'. - * If you want to use system control behavior, please use @see `EditBox` instead. - * @lua NA - */ -class AX_GUI_DLL TextField : public Widget -{ - - DECLARE_CLASS_GUI_INFO - -public: - /** - * TextField event type. - */ - enum class EventType - { - ATTACH_WITH_IME, - DETACH_WITH_IME, - INSERT_TEXT, - DELETE_BACKWARD, - }; - /** - * A callback which would be called when a TextField event happens. - */ - typedef std::function ccTextFieldCallback; - - /** - * @brief Default constructor. - * - */ - TextField(); - - /** - * @brief Default destructor. - */ - virtual ~TextField(); - - /** - * @brief Create an empty TextField. - * - * @return A TextField instance. - */ - static TextField* create(); - - /** - * @brief Create a TextField with a placeholder, a font name and a font size. - * - * @param placeholder The placeholder string. - * @param fontName The font name. - * @param fontSize The font size. - * @return A TextField instance. - */ - static TextField* create(std::string_view placeholder, std::string_view fontName, int fontSize); - - /** - * @brief Set the touch size - * The touch size is used for @see `hitTest`. - * @param size A delimitation zone. - */ - void setTouchSize(const Vec2& size); - - /** - * @brief Get current touch size of TextField. - * - * @return The TextField's touch size. - */ - Vec2 getTouchSize() const; - - /** - * @brief Toggle enable touch area. - * - * @param enable True if enable touch area, false otherwise. - */ - void setTouchAreaEnabled(bool enable); - - bool hitTest(const Vec2& pt, const Camera* camera, Vec3* p) const override; - - /** - * @brief Set placeholder of TextField. - * - * @param value The string value of placeholder. - */ - void setPlaceHolder(std::string_view value); - - /** - * @brief Get the placeholder of TextField. - * - * @return A placeholder string. - */ - std::string_view getPlaceHolder() const; - - /** - * @brief Query the placeholder string color. - * - * @return The color of placeholder. - */ - const Color32& getPlaceHolderColor() const; - - /** - * @brief Change the placeholder color. - * - * @param color A color value in `Color32`. - */ - void setPlaceHolderColor(const Color32& color); - - /** - * @brief Query the text string color. - * - * @return The color of the text. - */ - const Color32& getTextColor() const; - - /** - * @brief Change the text color. - * - * @param textColor The color value in `Color32`. - */ - void setTextColor(const Color32& textColor); - - /** - * @brief Change font size of TextField. - * - * @param size The integer font size. - */ - void setFontSize(int size); - - /** - * @brief Query the font size. - * - * @return The integer font size. - */ - int getFontSize() const; - - /** - * @brief Change the font name of TextField. - * - * @param name The font name string. - */ - void setFontName(std::string_view name); - - /** - * @brief Query the TextField's font name. - * - * @return The font name string. - */ - std::string_view getFontName() const; - - /** - * @brief Detach the IME. - */ - virtual void didNotSelectSelf(); - - /** - *Change content of TextField. - *@param text A string content. - */ - void setString(std::string_view text); - - /** - *Query the content of TextField. - *@return The string value of TextField. - */ - std::string_view getString() const; - - bool onTouchBegan(Touch* touch, Event* unusedEvent) override; - - /** - * @brief Toggle maximize length enable - * - * @param enable True if enable maximize length, false otherwise. - */ - void setMaxLengthEnabled(bool enable); - - /** - * @brief Query whether max length is enabled or not. - * - * @return True if maximize length is enabled, false otherwise. - */ - bool isMaxLengthEnabled() const; - - /** - * @brief Change maximize input length limitation. - * - * @param length A character count in integer. - */ - void setMaxLength(int length); - - /** - * @brief Query maximize input length of TextField. - * - * @return The integer value of maximize input length. - */ - int getMaxLength() const; - - /** - * @brief Query the input string length. - * - * @return A integer length value. - */ - int getStringLength() const; - - /** - * @brief Toggle enable password input mode. - * - * @param enable True if enable password input mode, false otherwise. - */ - void setPasswordEnabled(bool enable); - - /** - * @brief Query whether password is enabled or not. - * - * @return True if password is enabled, false otherwise. - */ - bool isPasswordEnabled() const; - - /** - * @brief Change password style text. - * - * @param styleText The styleText for password mask, the default value is "*". - */ - void setPasswordStyleText(std::string_view styleText); - /** - * @brief Query the password style text. - * - * @return A password style text. - */ - std::string_view getPasswordStyleText() const; - - void update(float dt) override; - - /** - * @brief Query whether the IME is attached or not. - * - * @return True if IME is attached, false otherwise. - */ - bool getAttachWithIME() const; - - /** - * @brief Toggle attach with IME. - * - * @param attach True if attach with IME, false otherwise. - */ - void setAttachWithIME(bool attach); - - /** - * @brief Query whether IME is detached or not. - * - * @return True if IME is detached, false otherwise. - */ - bool getDetachWithIME() const; - - /** - * @brief Toggle detach with IME. - * - * @param detach True if detach with IME, false otherwise. - */ - void setDetachWithIME(bool detach); - - /** - * @brief Whether it is ready to get the inserted text or not. - * - * @return True if the insert text is ready, false otherwise. - */ - bool getInsertText() const; - - /** - * @brief Toggle enable insert text mode - * - * @param insertText True if enable insert text, false otherwise. - */ - void setInsertText(bool insertText); - - /** - * @brief Whether it is ready to delete backward in TextField. - * - * @return True is the delete backward is enabled, false otherwise. - */ - bool getDeleteBackward() const; - - /** - * @brief Toggle enable delete backward mode. - * - * @param deleteBackward True is delete backward is enabled, false otherwise. - */ - void setDeleteBackward(bool deleteBackward); - - /** - * Add a event listener to TextField, when some predefined event happens, the callback will be called. - *@param callback A callback function with type of `ccTextFieldCallback`. - */ - void addEventListener(const ccTextFieldCallback& callback); - - /** - * Returns the "class name" of widget. - */ - std::string getDescription() const override; - - /** - * @brief Get the renderer size in auto mode. - * - * @return A delimitation zone. - */ - virtual Vec2 getAutoRenderSize(); - // override functions. - Vec2 getVirtualRendererSize() const override; - Node* getVirtualRenderer() override; - void onEnter() override; - void onExit() override; - - /** - * @brief Attach the IME for inputing. - * - */ - void attachWithIME(); - - /** - * @brief Detach the IME from inputing. - * - */ - void detachWithIME(); - - /** - * @brief Change the text area size. - * - * @param size A delimitation zone. - */ - void setTextAreaSize(const Vec2& size); - - /** - * @brief Change horizontal text alignment. - * - * @param alignment A alignment arguments in @see `TextHAlignment`. - */ - void setTextHorizontalAlignment(TextHAlignment alignment); - - /** - * @brief Inquire the horizontal alignment - * - * @return The horizontal alignment - */ - TextHAlignment getTextHorizontalAlignment() const; - - /** - * @brief Change the vertical text alignment. - * - * @param alignment A alignment arguments in @see `TextVAlignment`. - */ - void setTextVerticalAlignment(TextVAlignment alignment); - - /** - * @brief Inquire the horizontal alignment - * - * @return The horizontal alignment - */ - TextVAlignment getTextVerticalAlignment() const; - - /** - * Set enable cursor use. - */ - void setCursorEnabled(bool enabled); - - /** - * Set char showing cursor. - */ - void setCursorChar(char cursor); - - /** - * Set cursor position, if enabled - */ - void setCursorPosition(std::size_t cursorPosition); - - /** - * Set cursor position to hit letter, if enabled - */ - void setCursorFromPoint(const Vec2& point, const Camera* camera); - - bool init() override; - -protected: - void initRenderer() override; - void attachWithIMEEvent(); - void detachWithIMEEvent(); - void insertTextEvent(); - void deleteBackwardEvent(); - void onSizeChanged() override; - - void textfieldRendererScaleChangedWithSize(); - - Widget* createCloneInstance() override; - void copySpecialProperties(Widget* model) override; - void adaptRenderers() override; - -protected: - UICCTextField* _textFieldRenderer; - - float _touchWidth; - float _touchHeight; - bool _useTouchArea; - - Object* _textFieldEventListener; - ccTextFieldCallback _eventCallback; - - bool _textFieldRendererAdaptDirty; - -protected: - enum class FontType - { - SYSTEM, - TTF, - BMFONT - }; - - std::string _fontName; - int _fontSize; - FontType _fontType; -}; - -} // namespace ui - -// end of ui group -/// @} -} // namespace ax diff --git a/axmol/ui/UIWebView/UIWebViewImpl-win32.cpp b/axmol/ui/UIWebView/UIWebViewImpl-win32.cpp index 14706336541b..9a97d7f4dbe6 100644 --- a/axmol/ui/UIWebView/UIWebViewImpl-win32.cpp +++ b/axmol/ui/UIWebView/UIWebViewImpl-win32.cpp @@ -36,7 +36,9 @@ # include "axmol/ui/UIHelper.h" # include "axmol/base/Utils.h" -# define WIN32_LEAN_AND_MEAN +# ifndef WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +# endif # include # include # include diff --git a/axmol/ui/UIWidget.cpp b/axmol/ui/UIWidget.cpp index 1af6d391787d..270fb3d47cdb 100644 --- a/axmol/ui/UIWidget.cpp +++ b/axmol/ui/UIWidget.cpp @@ -151,13 +151,12 @@ Widget::FocusNavigationController* Widget::_focusNavigationController = nullptr; Widget::Widget() : _usingLayoutComponent(false) - , _unifySize(false) + , _autoSize(true) , _enabled(true) , _bright(true) , _touchEnabled(false) , _highlight(false) , _affectByClipping(false) - , _ignoreSize(false) , _propagateTouchEvents(true) , _brightStyle(BrightStyle::NONE) , _sizeType(SizeType::ABSOLUTE) @@ -223,7 +222,7 @@ bool Widget::init() onNextFocusedWidget = nullptr; this->setAnchorPoint(Vec2(0.5f, 0.5f)); - ignoreContentAdaptWithSize(true); + setAutoSizeEnabled(true); return true; } @@ -285,17 +284,20 @@ void Widget::setContentSize(const Vec2& contentSize) { return; } - ProtectedNode::setContentSize(contentSize); _customSize = contentSize; - if (_unifySize) + + if (_autoSize) { - // unify size logic + // Auto size mode: ignore manual size setting, use content size + ProtectedNode::setContentSize(getVirtualRendererSize()); } - else if (_ignoreSize) + else { - ProtectedNode::setContentSize(getVirtualRendererSize()); + // Fixed size mode: use the size set by developer + ProtectedNode::setContentSize(_customSize); } + if (!_usingLayoutComponent && _running) { Widget* widgetParent = getWidgetParent(); @@ -349,7 +351,7 @@ void Widget::setSizePercent(const Vec2& percent) cSize = Vec2(_parent->getContentSize().width * percent.x, _parent->getContentSize().height * percent.y); } } - if (_ignoreSize) + if (isAutoSizeEnabled()) { this->setContentSize(getVirtualRendererSize()); } @@ -374,7 +376,7 @@ void Widget::updateSizeAndPosition(const Vec2& parentSize) { case SizeType::ABSOLUTE: { - if (_ignoreSize) + if (isAutoSizeEnabled()) { this->setContentSize(getVirtualRendererSize()); } @@ -398,7 +400,7 @@ void Widget::updateSizeAndPosition(const Vec2& parentSize) case SizeType::PERCENT: { Vec2 cSize = Vec2(parentSize.width * _sizePercent.x, parentSize.height * _sizePercent.y); - if (_ignoreSize) + if (isAutoSizeEnabled()) { this->setContentSize(getVirtualRendererSize()); } @@ -493,34 +495,6 @@ Widget::SizeType Widget::getSizeType() const return _sizeType; } -void Widget::ignoreContentAdaptWithSize(bool ignore) -{ - if (_unifySize) - { - this->setContentSize(_customSize); - return; - } - if (_ignoreSize == ignore) - { - return; - } - _ignoreSize = ignore; - if (_ignoreSize) - { - Vec2 s = getVirtualRendererSize(); - this->setContentSize(s); - } - else - { - this->setContentSize(_customSize); - } -} - -bool Widget::isIgnoreContentAdaptWithSize() const -{ - return _ignoreSize; -} - const Vec2& Widget::getCustomSize() const { return _customSize; @@ -564,17 +538,14 @@ Vec2 Widget::getVirtualRendererSize() const void Widget::updateContentSizeWithTextureSize(const Vec2& size) { - if (_unifySize) - { - this->setContentSize(size); - return; - } - if (_ignoreSize) + if (_autoSize) { + // Auto size mode: update to the provided size (content size) this->setContentSize(size); } else { + // Fixed size mode: keep custom size unchanged this->setContentSize(_customSize); } } @@ -1303,7 +1274,7 @@ void Widget::copyProperties(Widget* widget) setTag(widget->getTag()); setName(widget->getName()); setActionTag(widget->getActionTag()); - _ignoreSize = widget->_ignoreSize; + _autoSize = widget->_autoSize; this->setContentSize(widget->_contentSize); _customSize = widget->_customSize; _sizeType = widget->getSizeType(); @@ -1573,14 +1544,23 @@ void Widget::enableDpadNavigation(bool enable) } } -bool Widget::isUnifySizeEnabled() const +void Widget::setAutoSizeEnabled(bool enable) { - return _unifySize; -} + if (_autoSize == enable) + return; -void Widget::setUnifySizeEnabled(bool enable) -{ - _unifySize = enable; + _autoSize = enable; + + if (!_autoSize) + { + // Switching to fixed size mode: save current size as custom size + _customSize = getContentSize(); + } + else + { + // Switching to auto size mode: update to content size immediately + updateContentSizeWithTextureSize(getVirtualRendererSize()); + } } void Widget::setLayoutComponentEnabled(bool enable) diff --git a/axmol/ui/UIWidget.h b/axmol/ui/UIWidget.h index 8347ed5fc7c4..75f19d6fc639 100644 --- a/axmol/ui/UIWidget.h +++ b/axmol/ui/UIWidget.h @@ -537,22 +537,6 @@ class AX_GUI_DLL Widget : public ProtectedNode, public LayoutParameterProtocol */ LayoutParameter* getLayoutParameter() const override; - /** - * Toggle whether ignore user defined content size for widget. - * Set true will ignore user defined content size which means - * the widget size is always equal to the return value of `getVirtualRendererSize`. - * - * @param ignore set member variable _ignoreSize to ignore - */ - virtual void ignoreContentAdaptWithSize(bool ignore); - - /** - * Query whether the widget ignores user defined content size or not - * - * @return True means ignore user defined content size, false otherwise. - */ - bool isIgnoreContentAdaptWithSize() const; - /** * Gets the inner Renderer node of widget. * @@ -717,16 +701,17 @@ class AX_GUI_DLL Widget : public ProtectedNode, public LayoutParameterProtocol std::function onNextFocusedWidget; /** - *Toggle use unify size. - *@param enable True to use unify size, false otherwise. + * Toggle auto size mode. + * When enabled, the widget will automatically adapt its size to its content (virtual renderer). + * @param enable True to enable auto size, false to use custom size. */ - void setUnifySizeEnabled(bool enable); + virtual void setAutoSizeEnabled(bool enable); /** - * Query whether unify size enable state. - *@return true represent the widget use Unify size, false represent the widget couldn't use Unify size + * Query whether auto size mode is enabled. + * @return true if auto size is enabled, false otherwise. */ - bool isUnifySizeEnabled() const; + bool isAutoSizeEnabled() const { return _autoSize; } /** * Set callback name. @@ -839,14 +824,13 @@ class AX_GUI_DLL Widget : public ProtectedNode, public LayoutParameterProtocol protected: bool _usingLayoutComponent; - bool _unifySize; + bool _autoSize; bool _enabled; bool _bright; bool _touchEnabled; bool _mouseEnabled; bool _highlight; bool _affectByClipping; - bool _ignoreSize; bool _propagateTouchEvents; BrightStyle _brightStyle; diff --git a/extensions/sceneext/src/sceneext/SGUIReader.cpp b/extensions/sceneext/src/sceneext/SGUIReader.cpp index c4701030597f..2e57e3d14348 100644 --- a/extensions/sceneext/src/sceneext/SGUIReader.cpp +++ b/extensions/sceneext/src/sceneext/SGUIReader.cpp @@ -597,7 +597,8 @@ void WidgetPropertiesReader0250::setPropsForWidgetFromJsonDictionary(Widget* wid bool ignoreSizeExsit = DICTOOL->checkObjectExist_json(options, "ignoreSize"); if (ignoreSizeExsit) { - widget->ignoreContentAdaptWithSize(DICTOOL->getBooleanValue_json(options, "ignoreSize")); + // ignoreSize=true means fixed size, so setAutoSizeEnabled=false + widget->setAutoSizeEnabled(!DICTOOL->getBooleanValue_json(options, "ignoreSize")); } float w = DICTOOL->getFloatValue_json(options, "width"); diff --git a/extensions/sceneio/src/sceneio/WidgetReader/ButtonReader/ButtonReader.cpp b/extensions/sceneio/src/sceneio/WidgetReader/ButtonReader/ButtonReader.cpp index 1277fa2adf4d..91cd85d7ecc3 100644 --- a/extensions/sceneio/src/sceneio/WidgetReader/ButtonReader/ButtonReader.cpp +++ b/extensions/sceneio/src/sceneio/WidgetReader/ButtonReader/ButtonReader.cpp @@ -985,8 +985,7 @@ void ButtonReader::setPropsWithFlatBuffers(ax::Node* node, const flatbuffers::Ta if (scale9Enabled) { - button->setUnifySizeEnabled(false); - button->ignoreContentAdaptWithSize(false); + button->setAutoSizeEnabled(false); auto f_capInsets = options->capInsets(); Rect capInsets(f_capInsets->x(), f_capInsets->y(), f_capInsets->width(), f_capInsets->height()); diff --git a/extensions/sceneio/src/sceneio/WidgetReader/ImageViewReader/ImageViewReader.cpp b/extensions/sceneio/src/sceneio/WidgetReader/ImageViewReader/ImageViewReader.cpp index 16697cd8e523..fdf89dd49722 100644 --- a/extensions/sceneio/src/sceneio/WidgetReader/ImageViewReader/ImageViewReader.cpp +++ b/extensions/sceneio/src/sceneio/WidgetReader/ImageViewReader/ImageViewReader.cpp @@ -378,8 +378,7 @@ void ImageViewReader::setPropsWithFlatBuffers(ax::Node* node, const flatbuffers: if (scale9Enabled) { - imageView->setUnifySizeEnabled(false); - imageView->ignoreContentAdaptWithSize(false); + imageView->setAutoSizeEnabled(false); auto f_scale9Size = options->scale9Size(); Size scale9Size(f_scale9Size->width(), f_scale9Size->height()); diff --git a/extensions/sceneio/src/sceneio/WidgetReader/LayoutReader/LayoutReader.cpp b/extensions/sceneio/src/sceneio/WidgetReader/LayoutReader/LayoutReader.cpp index 12210ff2a79a..2e8029eaa77c 100644 --- a/extensions/sceneio/src/sceneio/WidgetReader/LayoutReader/LayoutReader.cpp +++ b/extensions/sceneio/src/sceneio/WidgetReader/LayoutReader/LayoutReader.cpp @@ -729,7 +729,7 @@ void LayoutReader::setPropsWithFlatBuffers(ax::Node* node, const flatbuffers::Ta } else { - if (!panel->isIgnoreContentAdaptWithSize()) + if (!panel->isAutoSizeEnabled()) { Size contentSize(widgetOptions->size()->width(), widgetOptions->size()->height()); panel->setContentSize(contentSize); diff --git a/extensions/sceneio/src/sceneio/WidgetReader/ListViewReader/ListViewReader.cpp b/extensions/sceneio/src/sceneio/WidgetReader/ListViewReader/ListViewReader.cpp index 70f55b472250..814ef0efef20 100644 --- a/extensions/sceneio/src/sceneio/WidgetReader/ListViewReader/ListViewReader.cpp +++ b/extensions/sceneio/src/sceneio/WidgetReader/ListViewReader/ListViewReader.cpp @@ -562,7 +562,7 @@ void ListViewReader::setPropsWithFlatBuffers(ax::Node* node, const flatbuffers:: } else { - if (!listView->isIgnoreContentAdaptWithSize()) + if (!listView->isAutoSizeEnabled()) { Size contentSize(widgetOptions->size()->width(), widgetOptions->size()->height()); listView->setContentSize(contentSize); diff --git a/extensions/sceneio/src/sceneio/WidgetReader/PageViewReader/PageViewReader.cpp b/extensions/sceneio/src/sceneio/WidgetReader/PageViewReader/PageViewReader.cpp index dec247c11675..cd4e1b5bbd2b 100644 --- a/extensions/sceneio/src/sceneio/WidgetReader/PageViewReader/PageViewReader.cpp +++ b/extensions/sceneio/src/sceneio/WidgetReader/PageViewReader/PageViewReader.cpp @@ -1,5 +1,3 @@ - - #include "sceneio/WidgetReader/PageViewReader/PageViewReader.h" #include "axmol/ui/UIPageView.h" @@ -403,7 +401,7 @@ void PageViewReader::setPropsWithFlatBuffers(ax::Node* node, const flatbuffers:: } else { - if (!pageView->isIgnoreContentAdaptWithSize()) + if (!pageView->isAutoSizeEnabled()) { Size contentSize(widgetOptions->size()->width(), widgetOptions->size()->height()); pageView->setContentSize(contentSize); diff --git a/extensions/sceneio/src/sceneio/WidgetReader/ScrollViewReader/ScrollViewReader.cpp b/extensions/sceneio/src/sceneio/WidgetReader/ScrollViewReader/ScrollViewReader.cpp index 85414168ee6c..82ac600defe8 100644 --- a/extensions/sceneio/src/sceneio/WidgetReader/ScrollViewReader/ScrollViewReader.cpp +++ b/extensions/sceneio/src/sceneio/WidgetReader/ScrollViewReader/ScrollViewReader.cpp @@ -542,7 +542,7 @@ void ScrollViewReader::setPropsWithFlatBuffers(ax::Node* node, const flatbuffers } else { - if (!scrollView->isIgnoreContentAdaptWithSize()) + if (!scrollView->isAutoSizeEnabled()) { Size contentSize(widgetOptions->size()->width(), widgetOptions->size()->height()); scrollView->setContentSize(contentSize); diff --git a/extensions/sceneio/src/sceneio/WidgetReader/TextAtlasReader/TextAtlasReader.cpp b/extensions/sceneio/src/sceneio/WidgetReader/TextAtlasReader/TextAtlasReader.cpp index c07da905f736..d18882cdefc5 100644 --- a/extensions/sceneio/src/sceneio/WidgetReader/TextAtlasReader/TextAtlasReader.cpp +++ b/extensions/sceneio/src/sceneio/WidgetReader/TextAtlasReader/TextAtlasReader.cpp @@ -1,5 +1,3 @@ - - #include "sceneio/WidgetReader/TextAtlasReader/TextAtlasReader.h" #include "axmol/ui/UITextAtlas.h" @@ -275,7 +273,7 @@ void TextAtlasReader::setPropsWithFlatBuffers(ax::Node* node, const flatbuffers: auto widgetReader = WidgetReader::getInstance(); widgetReader->setPropsWithFlatBuffers(node, (Table*)options->widgetOptions()); - labelAtlas->ignoreContentAdaptWithSize(true); + labelAtlas->setAutoSizeEnabled(false); } Node* TextAtlasReader::createNodeWithFlatBuffers(const flatbuffers::Table* textAtlasOptions) diff --git a/extensions/sceneio/src/sceneio/WidgetReader/TextBMFontReader/TextBMFontReader.cpp b/extensions/sceneio/src/sceneio/WidgetReader/TextBMFontReader/TextBMFontReader.cpp index 7f276734d264..a0638c561d95 100644 --- a/extensions/sceneio/src/sceneio/WidgetReader/TextBMFontReader/TextBMFontReader.cpp +++ b/extensions/sceneio/src/sceneio/WidgetReader/TextBMFontReader/TextBMFontReader.cpp @@ -263,7 +263,7 @@ void TextBMFontReader::setPropsWithFlatBuffers(ax::Node* node, const flatbuffers auto widgetReader = WidgetReader::getInstance(); widgetReader->setPropsWithFlatBuffers(node, (Table*)options->widgetOptions()); - labelBMFont->ignoreContentAdaptWithSize(true); + labelBMFont->setAutoSizeEnabled(false); } Node* TextBMFontReader::createNodeWithFlatBuffers(const flatbuffers::Table* textBMFontOptions) diff --git a/extensions/sceneio/src/sceneio/WidgetReader/TextReader/TextReader.cpp b/extensions/sceneio/src/sceneio/WidgetReader/TextReader/TextReader.cpp index 5a00728ae5bd..5ebfd8fa5f69 100644 --- a/extensions/sceneio/src/sceneio/WidgetReader/TextReader/TextReader.cpp +++ b/extensions/sceneio/src/sceneio/WidgetReader/TextReader/TextReader.cpp @@ -557,13 +557,10 @@ void TextReader::setPropsWithFlatBuffers(ax::Node* node, const flatbuffers::Tabl Color32 color(f_color->r(), f_color->g(), f_color->b(), f_color->a()); ((Text*)node)->setTextColor(color); - label->setUnifySizeEnabled(false); - - bool IsCustomSize = options->isCustomSize() != 0; - label->ignoreContentAdaptWithSize(!IsCustomSize); + label->setAutoSizeEnabled(!options->isCustomSize()); auto widgetOptions = options->widgetOptions(); - if (!label->isIgnoreContentAdaptWithSize()) + if (!label->isAutoSizeEnabled()) { Size contentSize(widgetOptions->size()->width(), widgetOptions->size()->height()); label->setContentSize(contentSize); diff --git a/extensions/sceneio/src/sceneio/WidgetReader/WidgetReader.cpp b/extensions/sceneio/src/sceneio/WidgetReader/WidgetReader.cpp index c0ea57596462..6e6947683aab 100644 --- a/extensions/sceneio/src/sceneio/WidgetReader/WidgetReader.cpp +++ b/extensions/sceneio/src/sceneio/WidgetReader/WidgetReader.cpp @@ -1,5 +1,3 @@ - - #include "sceneio/WidgetReader/WidgetReader.h" #include "sceneext/CocoLoader.h" @@ -136,7 +134,8 @@ void WidgetReader::setPropsFromJsonDictionary(Widget* widget, const rapidjson::V bool ignoreSizeExsit = DICTOOL->checkObjectExist_json(options, P_IgnoreSize); if (ignoreSizeExsit) { - widget->ignoreContentAdaptWithSize(DICTOOL->getBooleanValue_json(options, P_IgnoreSize)); + // ignoreSize=true means fixed size, so setAutoSizeEnabled=false + widget->setAutoSizeEnabled(!DICTOOL->getBooleanValue_json(options, P_IgnoreSize)); } widget->setSizeType((Widget::SizeType)DICTOOL->getIntValue_json(options, P_SizeType)); @@ -283,7 +282,7 @@ void WidgetReader::endSetBasicProperties(Widget* widget) } widget->setColor(_color); // the setSize method will be conflict with scale9Width & scale9Height - if (!widget->isIgnoreContentAdaptWithSize()) + if (!widget->isAutoSizeEnabled()) { widget->setContentSize(Size(_width, _height)); } @@ -772,13 +771,8 @@ void WidgetReader::setPropsWithFlatBuffers(ax::Node* node, const flatbuffers::Ta widget->setAnchorPoint(Vec2::ZERO); - widget->setUnifySizeEnabled(true); - bool ignoreSize = options->ignoreSize() != 0; - widget->ignoreContentAdaptWithSize(ignoreSize); - - widget->setUnifySizeEnabled(false); + widget->setAutoSizeEnabled(!options->ignoreSize()); widget->setLayoutComponentEnabled(true); - widget->ignoreContentAdaptWithSize(false); Size contentSize(options->size()->width(), options->size()->height()); widget->setContentSize(contentSize); diff --git a/extensions/sceneio/src/sceneio/WidgetReader/WidgetReader.h b/extensions/sceneio/src/sceneio/WidgetReader/WidgetReader.h index 0b1d343d3cdf..c10024b2f6fa 100644 --- a/extensions/sceneio/src/sceneio/WidgetReader/WidgetReader.h +++ b/extensions/sceneio/src/sceneio/WidgetReader/WidgetReader.h @@ -139,7 +139,7 @@ extern const char* P_Path; #define AX_BASIC_PROPERTY_BINARY_READER \ if (key == P_IgnoreSize) \ { \ - widget->ignoreContentAdaptWithSize(valueToBool(value)); \ + widget->setAutoSizeEnabled(!valueToBool(value)); \ } \ else if (key == P_SizeType) \ { \ diff --git a/tests/cpp-tests/CMakeLists.txt b/tests/cpp-tests/CMakeLists.txt index e2dc501b8444..062c7ff8c2a6 100644 --- a/tests/cpp-tests/CMakeLists.txt +++ b/tests/cpp-tests/CMakeLists.txt @@ -207,6 +207,7 @@ list(APPEND GAME_HEADER Source/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest.h Source/UITest/CocoStudioGUITest/UIFocusTest/UIFocusTest.h Source/UITest/CocoStudioGUITest/UITextTest/UITextTest.h + Source/UITest/CocoStudioGUITest/UITextFieldTest/UIInputFieldTest.h Source/BillBoardTest/BillBoardTest.h Source/SpriteFrameCacheTest/SpriteFrameCacheTest.h Source/EffectsAdvancedTest/EffectsAdvancedTest.h @@ -341,6 +342,7 @@ list(APPEND GAME_SOURCE Source/UITest/CocoStudioGUITest/UITextTest/UITextTest.cpp Source/UITest/CocoStudioGUITest/UIWidgetAddNodeTest/UIWidgetAddNodeTest.cpp Source/UITest/CocoStudioGUITest/UITabControlTest/UITabControlTest.cpp + Source/UITest/CocoStudioGUITest/UITextFieldTest/UIInputFieldTest.cpp Source/UITest/UITest.cpp Source/UserDefaultTest/UserDefaultTest.cpp Source/VisibleRect.cpp diff --git a/tests/cpp-tests/Source/LabelTest/LabelTest.cpp b/tests/cpp-tests/Source/LabelTest/LabelTest.cpp index 2d67705a0d04..fed2d569c93e 100644 --- a/tests/cpp-tests/Source/LabelTest/LabelTest.cpp +++ b/tests/cpp-tests/Source/LabelTest/LabelTest.cpp @@ -3423,7 +3423,7 @@ LabelRichText::LabelRichText() "Mixing UIRichText with non UIWidget code. For more samples, see the UIRichTextTest.cpp file"); if (richText2) { - richText2->ignoreContentAdaptWithSize(false); + richText2->setAutoSizeEnabled(true); richText2->setContentSize(Size(400.0f, 400.0f)); richText2->setPosition(center); diff --git a/tests/cpp-tests/Source/NetworkTest/DownloaderTest/DownloaderTest.cpp b/tests/cpp-tests/Source/NetworkTest/DownloaderTest/DownloaderTest.cpp index 7545bf96e8b1..113868732c0a 100644 --- a/tests/cpp-tests/Source/NetworkTest/DownloaderTest/DownloaderTest.cpp +++ b/tests/cpp-tests/Source/NetworkTest/DownloaderTest/DownloaderTest.cpp @@ -100,7 +100,7 @@ struct DownloaderTest : public TestCase // add a progress bar auto bar = ui::LoadingBar::create("ccs-res/cocosui/sliderProgress.png"); bar->setTag(TAG_PROGRESS_BAR); - bar->ignoreContentAdaptWithSize(false); + bar->setAutoSizeEnabled(true); bar->setAnchorPoint(Vec2(0.5f, 0.0f)); bar->setContentSize(Size(viewSize.width - margin * 2, btn->getContentSize().height)); bar->setPosition(btn->getPosition()); diff --git a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/CocosGUIScene.cpp b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/CocosGUIScene.cpp index bd8c4eee2198..d09f92a673db 100644 --- a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/CocosGUIScene.cpp +++ b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/CocosGUIScene.cpp @@ -42,6 +42,7 @@ #include "UIRichTextTest/UIRichTextTest.h" #include "UIFocusTest/UIFocusTest.h" #include "UITabControlTest/UITabControlTest.h" +#include "UITextFieldTest/UIInputFieldTest.h" #if defined(AX_ENABLE_MEDIA) # include "UIVideoPlayerTest/UIVideoPlayerTest.h" @@ -100,4 +101,5 @@ GUIDynamicCreateTests::GUIDynamicCreateTests() addTest("RichText Test", []() { return new UIRichTextTests; }); addTest("TabControl Test", []() { return new UITabControlTests; }); + addTest("InputField Test", []() { return new UIInputFieldTests; }); } diff --git a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest.cpp b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest.cpp index 8efb657a6c7e..e421a250ce67 100644 --- a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest.cpp +++ b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest.cpp @@ -267,7 +267,7 @@ bool UIButtonTest_Scale9_State_Change::init() // Create the button Button* button = Button::create("cocosui/button.png"); // open scale9 render - button->ignoreContentAdaptWithSize(false); + button->setAutoSizeEnabled(true); button->setScale9Enabled(true); button->setPosition(Vec2(widgetSize.width / 2.0f - 100, widgetSize.height / 2.0f)); button->setContentSize(Size(180.0f, 60.0f)); @@ -278,7 +278,7 @@ bool UIButtonTest_Scale9_State_Change::init() Button* button2 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png"); // open scale9 render - button2->ignoreContentAdaptWithSize(false); + button2->setAutoSizeEnabled(true); button2->setScale9Enabled(true); button2->setTitleText("Hello scale9"); button2->setPosition(Vec2(widgetSize.width / 2.0f + 100, widgetSize.height / 2.0f)); @@ -600,7 +600,7 @@ bool UIButtonTestSwitchScale9::init() button->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); button->addTouchEventListener(AX_CALLBACK_2(UIButtonTestSwitchScale9::touchEvent, this)); button->setTitleText("Button Title"); - button->ignoreContentAdaptWithSize(false); + button->setAutoSizeEnabled(true); _uiLayer->addChild(button); @@ -746,7 +746,7 @@ bool UIButtonIgnoreContentSizeTest::init() // Create the button auto button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); - button->ignoreContentAdaptWithSize(false); + button->setAutoSizeEnabled(true); button->setContentSize(Size(200.0f, 100.0f)); button->setPositionNormalized(Vec2(0.3f, 0.5f)); button->setTitleText("PLAY GAME"); @@ -760,7 +760,7 @@ bool UIButtonIgnoreContentSizeTest::init() // Create the button auto button2 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); - button2->ignoreContentAdaptWithSize(false); + button2->setAutoSizeEnabled(true); button2->setContentSize(Size(200.0f, 100.0f)); button2->setPositionNormalized(Vec2(0.8f, 0.5f)); button2->setTitleText("PLAY GAME"); diff --git a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest.cpp b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest.cpp index 365361025fd3..392bd5a3af49 100644 --- a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest.cpp +++ b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest.cpp @@ -148,7 +148,7 @@ bool UICheckBoxDefaultBehaviorTest::init() // Create the checkbox CheckBox* checkBox2 = CheckBox::create("cocosui/check_box_normal.png", "cocosui/check_box_active.png"); checkBox2->setPosition(Vec2(widgetSize.width / 2.0f - 150, widgetSize.height / 2.0f)); - checkBox2->ignoreContentAdaptWithSize(false); + checkBox2->setAutoSizeEnabled(true); checkBox2->setZoomScale(0.5f); checkBox2->setContentSize(Size(80.0f, 80.0f)); checkBox2->setName("bigCheckBox"); diff --git a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.cpp b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.cpp index 43bd3ddd181a..99ca9dd8e53c 100644 --- a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.cpp +++ b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.cpp @@ -129,7 +129,7 @@ bool UIImageViewTest_Scale9_State_Change::init() // Create the imageview ImageView* imageView = ImageView::create("cocosui/ccicon.png"); - imageView->ignoreContentAdaptWithSize(false); + imageView->setAutoSizeEnabled(true); imageView->setScale9Enabled(true); imageView->setContentSize(Size(100.0f, 100.0f)); imageView->setCapInsets(Rect(20.0f, 20.0f, 20.0f, 20.0f)); @@ -243,7 +243,7 @@ bool UIImageViewFlipTest::init() imageView->setContentSize(Size(250, 115)); imageView->setFlippedX(true); imageView->setScale(0.5); - imageView->ignoreContentAdaptWithSize(false); + imageView->setAutoSizeEnabled(true); imageView->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); _uiLayer->addChild(imageView); diff --git a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest.cpp b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest.cpp index c78dd9bf1606..c310d6eea99f 100644 --- a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest.cpp +++ b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest.cpp @@ -968,7 +968,7 @@ bool UILayoutComponent_Berth_Stretch_Test::init() if (UILayoutComponentTest::init()) { ImageView* leftTopSprite = ImageView::create("cocosui/CloseSelected.png"); - leftTopSprite->ignoreContentAdaptWithSize(false); + leftTopSprite->setAutoSizeEnabled(true); LayoutComponent* leftTop = LayoutComponent::bindLayoutComponent(leftTopSprite); leftTop->setHorizontalEdge(LayoutComponent::HorizontalEdge::Left); leftTop->setVerticalEdge(LayoutComponent::VerticalEdge::Top); @@ -980,7 +980,7 @@ bool UILayoutComponent_Berth_Stretch_Test::init() leftTop->setTopMargin(0); ImageView* leftBottomSprite = ImageView::create("cocosui/CloseSelected.png"); - leftBottomSprite->ignoreContentAdaptWithSize(false); + leftBottomSprite->setAutoSizeEnabled(true); LayoutComponent* leftBottom = LayoutComponent::bindLayoutComponent(leftBottomSprite); leftBottom->setHorizontalEdge(LayoutComponent::HorizontalEdge::Left); leftBottom->setVerticalEdge(LayoutComponent::VerticalEdge::Bottom); @@ -992,7 +992,7 @@ bool UILayoutComponent_Berth_Stretch_Test::init() leftBottom->setBottomMargin(0); ImageView* rightTopSprite = ImageView::create("cocosui/CloseSelected.png"); - rightTopSprite->ignoreContentAdaptWithSize(false); + rightTopSprite->setAutoSizeEnabled(true); LayoutComponent* rightTop = LayoutComponent::bindLayoutComponent(rightTopSprite); rightTop->setHorizontalEdge(LayoutComponent::HorizontalEdge::Right); rightTop->setVerticalEdge(LayoutComponent::VerticalEdge::Top); @@ -1004,7 +1004,7 @@ bool UILayoutComponent_Berth_Stretch_Test::init() rightTop->setRightMargin(0); ImageView* rightBottomSprite = ImageView::create("cocosui/CloseSelected.png"); - rightBottomSprite->ignoreContentAdaptWithSize(false); + rightBottomSprite->setAutoSizeEnabled(true); LayoutComponent* rightBottom = LayoutComponent::bindLayoutComponent(rightBottomSprite); rightBottom->setHorizontalEdge(LayoutComponent::HorizontalEdge::Right); rightBottom->setVerticalEdge(LayoutComponent::VerticalEdge::Bottom); diff --git a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.cpp b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.cpp index 79bf13bf31fd..c87f9637328a 100644 --- a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.cpp +++ b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.cpp @@ -309,7 +309,7 @@ bool UILoadingBarTest_Scale9_State_Change::init() // Create the loading bar LoadingBar* loadingBar = LoadingBar::create("cocosui/sliderThumb.png"); loadingBar->setTag(0); - loadingBar->ignoreContentAdaptWithSize(false); + loadingBar->setAutoSizeEnabled(true); // loadingBar->setScale9Enabled(true); loadingBar->setCapInsets(Rect(0, 0, 0, 0)); loadingBar->setContentSize(Size(200, 80)); @@ -360,7 +360,7 @@ bool UILoadingBarReloadTexture::init() LoadingBar* loadingBar = LoadingBar::create("cocosui/slider_bar_active_9patch.png"); loadingBar->setTag(0); - loadingBar->ignoreContentAdaptWithSize(false); + loadingBar->setAutoSizeEnabled(true); // loadingBar->setScale9Enabled(true); loadingBar->setCapInsets(Rect(0, 0, 0, 0)); loadingBar->setContentSize(Size(300, 13)); diff --git a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIRichTextTest/UIRichTextTest.cpp b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIRichTextTest/UIRichTextTest.cpp index cc9c00713b58..467d1d0d837d 100644 --- a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIRichTextTest/UIRichTextTest.cpp +++ b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIRichTextTest/UIRichTextTest.cpp @@ -78,14 +78,14 @@ void UIRichTextTestBase::touchEvent(Object* pSender, Widget::TouchEventType type { case Widget::TouchEventType::ENDED: { - if (_richText->isIgnoreContentAdaptWithSize()) + if (_richText->isAutoSizeEnabled()) { - _richText->ignoreContentAdaptWithSize(false); + _richText->setAutoSizeEnabled(true); _richText->setContentSize(_defaultContentSize); } else { - _richText->ignoreContentAdaptWithSize(true); + _richText->setAutoSizeEnabled(false); } } break; @@ -201,7 +201,7 @@ bool UIRichTextTest::init() // RichText _richText = RichText::create(); - _richText->ignoreContentAdaptWithSize(false); + _richText->setAutoSizeEnabled(true); _richText->setContentSize(_defaultContentSize); RichElementText* re1 = RichElementText::create(1, Color32::WHITE, str1, "SimSun", 10); @@ -265,7 +265,7 @@ bool UIRichTextXMLBasic::init() "This is just simple text, with no XML tags. Testing the basics. Testing word-wrapping. Testing " "(\"punctuation\") " "Testing, Testing"); - _richText->ignoreContentAdaptWithSize(false); + _richText->setAutoSizeEnabled(true); _richText->setContentSize(_defaultContentSize); _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); @@ -302,7 +302,7 @@ bool UIRichTextXMLSmallBig::init() // RichText _richText = RichText::createWithXML( "Regular size.smaller size.bigger.normal.bigger.normal."); - _richText->ignoreContentAdaptWithSize(false); + _richText->setAutoSizeEnabled(true); _richText->setContentSize(_defaultContentSize); _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); @@ -339,7 +339,7 @@ bool UIRichTextXMLColor::init() // RichText _richText = RichText::createWithXML( "Default color.red.greenred again.default again"); - _richText->ignoreContentAdaptWithSize(false); + _richText->setAutoSizeEnabled(true); _richText->setContentSize(_defaultContentSize); _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); @@ -376,7 +376,7 @@ bool UIRichTextXMLSUIB::init() // RichText _richText = RichText::createWithXML("system font: underlineitalicsboldstrike-through"); - _richText->ignoreContentAdaptWithSize(false); + _richText->setAutoSizeEnabled(true); _richText->setContentSize(_defaultContentSize); _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); @@ -414,7 +414,7 @@ bool UIRichTextXMLSUIB2::init() _richText = RichText::createWithXML( "ttf font: " "underlineitalicsboldstrike-through"); - _richText->ignoreContentAdaptWithSize(false); + _richText->setAutoSizeEnabled(true); _richText->setContentSize(_defaultContentSize); _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); @@ -452,7 +452,7 @@ bool UIRichTextXMLSUIB3::init() _richText = RichText::createWithXML( "ttf font: italics and underlinebold " "and strike-through"); - _richText->ignoreContentAdaptWithSize(false); + _richText->setAutoSizeEnabled(true); _richText->setContentSize(_defaultContentSize); _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); @@ -501,7 +501,7 @@ bool UIRichTextXMLImg::init() "Image with w/h/sX/sY: and " "goes text again"); - _richText->ignoreContentAdaptWithSize(false); + _richText->setAutoSizeEnabled(true); _richText->setContentSize(_defaultContentSize); _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); @@ -538,7 +538,7 @@ bool UIRichTextXMLUrl::init() // RichText _richText = RichText::createWithXML( "This link will redirect you to google: click me"); - _richText->ignoreContentAdaptWithSize(false); + _richText->setAutoSizeEnabled(true); _richText->setContentSize(_defaultContentSize); _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); @@ -576,7 +576,7 @@ bool UIRichTextXMLUrlImg::init() _richText = RichText::createWithXML( "This link will redirect you to google: "); - _richText->ignoreContentAdaptWithSize(false); + _richText->setAutoSizeEnabled(true); _richText->setContentSize(_defaultContentSize); _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); @@ -616,7 +616,7 @@ bool UIRichTextXMLFace::init() _richText = RichText::createWithXML( "Marker Felt 20.Arial " "20.Thonburi 24 blue"); - _richText->ignoreContentAdaptWithSize(false); + _richText->setAutoSizeEnabled(true); _richText->setContentSize(_defaultContentSize); _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); @@ -653,7 +653,7 @@ bool UIRichTextXMLBR::init() // RichText _richText = RichText::createWithXML( "this is one line.
this should be in another line.
and this is another line"); - _richText->ignoreContentAdaptWithSize(false); + _richText->setAutoSizeEnabled(true); _richText->setContentSize(_defaultContentSize); _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); @@ -689,7 +689,7 @@ bool UIRichTextXMLInvalid::init() _richText = RichText::createWithXML("this is an invalid xml. no closing tag"); if (_richText) { - _richText->ignoreContentAdaptWithSize(false); + _richText->setAutoSizeEnabled(true); _richText->setContentSize(_defaultContentSize); _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); @@ -727,7 +727,7 @@ bool UIRichTextXMLOutline::init() _richText = RichText::createWithXML( "OUTLINE"); - _richText->ignoreContentAdaptWithSize(false); + _richText->setAutoSizeEnabled(true); _richText->setContentSize(_defaultContentSize); _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); @@ -767,7 +767,7 @@ bool UIRichTextXMLShadow::init() _richText = RichText::createWithXML( "SHADOW"); - _richText->ignoreContentAdaptWithSize(false); + _richText->setAutoSizeEnabled(true); _richText->setContentSize(_defaultContentSize); _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); @@ -804,7 +804,7 @@ bool UIRichTextXMLGlow::init() // RichText _richText = RichText::createWithXML( "GLOW"); - _richText->ignoreContentAdaptWithSize(false); + _richText->setAutoSizeEnabled(true); _richText->setContentSize(_defaultContentSize); _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); @@ -876,7 +876,7 @@ bool UIRichTextXMLExtend::init() "CloseNormal-tag:


CloseSelected-tag:
", defaults, [](std::string_view url) { Application::getInstance()->openURL(url); }); - _richText->ignoreContentAdaptWithSize(false); + _richText->setAutoSizeEnabled(true); _richText->setContentSize(_defaultContentSize); _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); @@ -917,7 +917,7 @@ bool UIRichTextXMLSpace::init() "words should be divided with space.

HELLO " "WORLD

HELLO WORLD"); - _richText->ignoreContentAdaptWithSize(false); + _richText->setAutoSizeEnabled(true); _richText->setContentSize(_defaultContentSize); _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); _richText->setLocalZOrder(10); @@ -959,7 +959,7 @@ bool UIRichTextNewline::init() _richText->pushBackElement(textElement); textElement = ui::RichElementText::create(2, Color32::WHITE, "Line3", "fonts/Marker Felt.ttf", 32, 0); _richText->pushBackElement(textElement); - _richText->ignoreContentAdaptWithSize(false); + _richText->setAutoSizeEnabled(true); _richText->setContentSize(_defaultContentSize); _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); _richText->setLocalZOrder(10); @@ -996,7 +996,7 @@ bool UIRichTextHeadings::init() // RichText _richText = RichText::createWithXML( R"(

h1. HEADING

h2. HEADING

h3. HEADING

h4. HEADING

h5. HEADING
h6. HEADING
)"); - _richText->ignoreContentAdaptWithSize(false); + _richText->setAutoSizeEnabled(true); _richText->setContentSize(_defaultContentSize); _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); @@ -1034,7 +1034,7 @@ bool UIRichTextDynamicFontSize::init() // RichText _richText = RichText::createWithXML( R"(

Paragraph 1 with default size font

Paragraph 2 with font size="1.5em"

Paragraph 3 with font size="150%"

)"); - _richText->ignoreContentAdaptWithSize(false); + _richText->setAutoSizeEnabled(true); _richText->setContentSize(_defaultContentSize); _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); @@ -1078,7 +1078,7 @@ bool UIRichTextParagraph::init() "interdum velit. " "Convallis a cras semper auctor neque vitae tempus quam pellentesque. Congue quisque egestas diam in arcu " "cursus euismod quis.

"); - _richText->ignoreContentAdaptWithSize(false); + _richText->setAutoSizeEnabled(true); _richText->setContentSize(_defaultContentSize); _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); @@ -1162,7 +1162,7 @@ Cursus metus aliquam eleifend mi in. Euismod lacinia at quis risus sed vulputate Sit amet mattis vulputate enim nulla aliquet porttitor lacus luctus.

Google!)", valMap); - _richText->ignoreContentAdaptWithSize(false); + _richText->setAutoSizeEnabled(true); _richText->setContentSize(Size(_defaultContentSize.width, 0)); _richText->setAnchorPoint(Vec2::ANCHOR_MIDDLE_TOP); _richText->setOpenUrlHandler([this](std::string_view url) { diff --git a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UISliderTest/UISliderTest.cpp b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UISliderTest/UISliderTest.cpp index 7a3322a7fc39..28566995ba78 100644 --- a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UISliderTest/UISliderTest.cpp +++ b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UISliderTest/UISliderTest.cpp @@ -200,7 +200,7 @@ bool UISliderTest_Scale9_State_Change::init() slider->loadBarTexture("cocosui/sliderballnormal.png"); slider->loadSlidBallTextures("cocosui/sliderThumb.png", "cocosui/sliderThumb.png", ""); slider->loadProgressBarTexture("cocosui/slider_bar_active_9patch.png"); - slider->ignoreContentAdaptWithSize(false); + slider->setAutoSizeEnabled(true); slider->setScale9Enabled(true); slider->setCapInsets(Rect(0.0f, 0.0f, 0.0f, 0.0f)); slider->setContentSize(Size(200.0f, 60.0f)); diff --git a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextFieldTest/UIInputFieldTest.cpp b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextFieldTest/UIInputFieldTest.cpp new file mode 100644 index 000000000000..3ecd77065b8c --- /dev/null +++ b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextFieldTest/UIInputFieldTest.cpp @@ -0,0 +1,432 @@ +/**************************************************************************** + Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. + + https://axmol.dev/ + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#include "UIInputFieldTest.h" + +using namespace ax; +using namespace ax::ui; + +UIInputFieldTests::UIInputFieldTests() +{ + ADD_TEST_CASE(UIInputFieldTest); + ADD_TEST_CASE(UIInputFieldTest_MaxLength); + ADD_TEST_CASE(UIInputFieldTest_Password); + ADD_TEST_CASE(UIInputFieldTest_LineWrap); + ADD_TEST_CASE(UIInputFieldTest_TrueTypeFont); + ADD_TEST_CASE(UIInputFieldTest_BMFont); + ADD_TEST_CASE(UIInputFieldTest_PlaceHolderColor); +} + +// UIInputFieldTest +UIInputFieldTest::UIInputFieldTest() : _displayValueLabel(nullptr) {} + +UIInputFieldTest::~UIInputFieldTest() {} + +bool UIInputFieldTest::init() +{ + if (UIScene::init()) + { + Size widgetSize = _widget->getContentSize(); + + // Add a label in which the inputfield events will be displayed + _displayValueLabel = Text::create("No Event", "fonts/Marker Felt.ttf", 32); + _displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f)); + _displayValueLabel->setPosition(Vec2( + widgetSize.width / 2.0f, widgetSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5f)); + _uiLayer->addChild(_displayValueLabel); + + // Add the alert + Text* alert = Text::create("InputField", "fonts/Marker Felt.ttf", 30); + alert->setColor(Color32(159, 168, 176)); + alert->setPosition( + Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.075f)); + _uiLayer->addChild(alert); + + // Create the inputfield + InputField* inputField = InputField::create("input words here", "Arial", 30); + inputField->setTextHorizontalAlignment(TextHAlignment::CENTER); + inputField->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); + + // Set up event listener for InputField + inputField->addEventListener([this](InputField* sender, InputField::EventType type) { + switch (type) { + case InputField::EventType::ATTACH_WITH_IME: + _displayValueLabel->setString("attach with IME"); + break; + case InputField::EventType::DETACH_WITH_IME: + _displayValueLabel->setString("detach with IME"); + break; + case InputField::EventType::INSERT_TEXT: + _displayValueLabel->setString("insert words"); + break; + case InputField::EventType::DELETE_BACKWARD: + _displayValueLabel->setString("delete word"); + break; + } + }); + + _uiLayer->addChild(inputField); + + return true; + } + return false; +} + +// UIInputFieldTest_MaxLength +UIInputFieldTest_MaxLength::UIInputFieldTest_MaxLength() : _displayValueLabel(nullptr) {} + +UIInputFieldTest_MaxLength::~UIInputFieldTest_MaxLength() {} + +bool UIInputFieldTest_MaxLength::init() +{ + if (UIScene::init()) + { + Size screenSize = Director::getInstance()->getCanvasSize(); + + // Add a label in which the inputfield events will be displayed + _displayValueLabel = Text::create("No Event", "fonts/Marker Felt.ttf", 32); + _displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f)); + _displayValueLabel->setPosition(Vec2( + screenSize.width / 2.0f, screenSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5f)); + _uiLayer->addChild(_displayValueLabel); + + // Add the alert + Text* alert = Text::create("InputField max length", "fonts/Marker Felt.ttf", 30); + alert->setColor(Color32(159, 168, 176)); + alert->setPosition( + Vec2(screenSize.width / 2.0f, screenSize.height / 2.0f - alert->getContentSize().height * 3.075f)); + _uiLayer->addChild(alert); + + // Create the inputfield + InputField* inputField = InputField::create("input words here", "Arial", 30); + inputField->setCharLimit(3); + inputField->setTextHorizontalAlignment(TextHAlignment::CENTER); + inputField->setPosition(Vec2(screenSize.width / 2.0f, screenSize.height / 2.0f)); + + // Set up event listener for InputField + inputField->addEventListener([this, inputField](InputField* sender, InputField::EventType type) { + switch (type) { + case InputField::EventType::ATTACH_WITH_IME: + _displayValueLabel->setString(fmt::format("attach with IME max length {}", inputField->getCharLimit())); + break; + case InputField::EventType::DETACH_WITH_IME: + _displayValueLabel->setString(fmt::format("detach with IME max length {}", inputField->getCharLimit())); + break; + case InputField::EventType::INSERT_TEXT: + _displayValueLabel->setString(fmt::format("insert words max length {}", inputField->getCharLimit())); + break; + case InputField::EventType::DELETE_BACKWARD: + _displayValueLabel->setString(fmt::format("delete word max length {}", inputField->getCharLimit())); + break; + } + }); + + _uiLayer->addChild(inputField); + + return true; + } + return false; +} + +// UIInputFieldTest_Password +UIInputFieldTest_Password::UIInputFieldTest_Password() : _displayValueLabel(nullptr) {} + +UIInputFieldTest_Password::~UIInputFieldTest_Password() {} + +bool UIInputFieldTest_Password::init() +{ + if (UIScene::init()) + { + Size screenSize = Director::getInstance()->getCanvasSize(); + + // Add a label in which the inputfield events will be displayed + _displayValueLabel = Text::create("No Event", "fonts/Marker Felt.ttf", 32); + _displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f)); + _displayValueLabel->setPosition(Vec2( + screenSize.width / 2.0f, screenSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5f)); + _uiLayer->addChild(_displayValueLabel); + + // Add the alert + Text* alert = Text::create("InputField password", "fonts/Marker Felt.ttf", 30); + alert->setColor(Color32(159, 168, 176)); + alert->setPosition( + Vec2(screenSize.width / 2.0f, screenSize.height / 2.0f - alert->getContentSize().height * 3.075f)); + _uiLayer->addChild(alert); + + // Create the inputfield + InputField* inputField = InputField::create("input password here", "Arial", 30); + inputField->setPasswordEnabled(true); + inputField->setTextHorizontalAlignment(TextHAlignment::CENTER); + inputField->setPosition(Vec2(screenSize.width / 2.0f, screenSize.height / 2.0f)); + + // Set up event listener for InputField + inputField->addEventListener([this](InputField* sender, InputField::EventType type) { + switch (type) { + case InputField::EventType::ATTACH_WITH_IME: + _displayValueLabel->setString("attach with IME password"); + break; + case InputField::EventType::DETACH_WITH_IME: + _displayValueLabel->setString("detach with IME password"); + break; + case InputField::EventType::INSERT_TEXT: + _displayValueLabel->setString("insert words password"); + break; + case InputField::EventType::DELETE_BACKWARD: + _displayValueLabel->setString("delete word password"); + break; + } + }); + + _uiLayer->addChild(inputField); + + return true; + } + return false; +} + +// UIInputFieldTest_LineWrap +UIInputFieldTest_LineWrap::UIInputFieldTest_LineWrap() : _displayValueLabel(nullptr) {} + +UIInputFieldTest_LineWrap::~UIInputFieldTest_LineWrap() {} + +bool UIInputFieldTest_LineWrap::init() +{ + if (UIScene::init()) + { + Size widgetSize = _widget->getContentSize(); + + // Add a label in which the inputfield events will be displayed + _displayValueLabel = Text::create("No Event", "fonts/Marker Felt.ttf", 30); + _displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f)); + _displayValueLabel->setPosition(Vec2( + widgetSize.width / 2.0f, widgetSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5)); + _uiLayer->addChild(_displayValueLabel); + + // Add the alert + Text* alert = Text::create("InputField line wrap", "fonts/Marker Felt.ttf", 30); + alert->setColor(Color32(159, 168, 176)); + alert->setPosition( + Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.075)); + _uiLayer->addChild(alert); + + // Create the inputfield + InputField* inputField = InputField::create("input words here", "fonts/Marker Felt.ttf", 30); + inputField->setTextAreaSize(Vec2(240.0f, 170.0f)); + inputField->setString("input words here"); + inputField->setTextHorizontalAlignment(TextHAlignment::CENTER); + inputField->setTextVerticalAlignment(TextVAlignment::CENTER); + inputField->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); + + // Set up event listener for InputField + inputField->addEventListener([this](InputField* sender, InputField::EventType type) { + switch (type) { + case InputField::EventType::ATTACH_WITH_IME: + _displayValueLabel->setString("attach with IME"); + break; + case InputField::EventType::DETACH_WITH_IME: + _displayValueLabel->setString("detach with IME"); + break; + case InputField::EventType::INSERT_TEXT: + _displayValueLabel->setString("insert words"); + break; + case InputField::EventType::DELETE_BACKWARD: + _displayValueLabel->setString("delete word"); + break; + } + }); + + _uiLayer->addChild(inputField); + + return true; + } + return false; +} + +// UIInputFieldTest_TrueTypeFont +UIInputFieldTest_TrueTypeFont::UIInputFieldTest_TrueTypeFont() : _displayValueLabel(nullptr) {} + +UIInputFieldTest_TrueTypeFont::~UIInputFieldTest_TrueTypeFont() {} + +bool UIInputFieldTest_TrueTypeFont::init() +{ + if (UIScene::init()) + { + Size widgetSize = _widget->getContentSize(); + + // Add a label in which the inputfield events will be displayed + _displayValueLabel = Text::create("True Type Font Test - No Event", "fonts/Marker Felt.ttf", 32); + _displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f)); + _displayValueLabel->setPosition(Vec2( + widgetSize.width / 2.0f, widgetSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5f)); + _uiLayer->addChild(_displayValueLabel); + + // Add the alert + Text* alert = Text::create("InputField", "fonts/Marker Felt.ttf", 30); + alert->setPosition( + Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.075f)); + _uiLayer->addChild(alert); + + // Create the inputfield + InputField* inputField = InputField::create("input words here", "fonts/A Damn Mess.ttf", 30); + inputField->setTextHorizontalAlignment(TextHAlignment::CENTER); + inputField->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); + + // Set up event listener for InputField + inputField->addEventListener([this](InputField* sender, InputField::EventType type) { + switch (type) { + case InputField::EventType::ATTACH_WITH_IME: + _displayValueLabel->setString("attach with IME"); + break; + case InputField::EventType::DETACH_WITH_IME: + _displayValueLabel->setString("detach with IME"); + break; + case InputField::EventType::INSERT_TEXT: + _displayValueLabel->setString("insert words"); + break; + case InputField::EventType::DELETE_BACKWARD: + _displayValueLabel->setString("delete word"); + break; + } + }); + + _uiLayer->addChild(inputField); + + return true; + } + return false; +} + +// UIInputFieldTest_BMFont +UIInputFieldTest_BMFont::UIInputFieldTest_BMFont() : _displayValueLabel(nullptr) {} + +UIInputFieldTest_BMFont::~UIInputFieldTest_BMFont() {} + +bool UIInputFieldTest_BMFont::init() +{ + if (UIScene::init()) + { + Size widgetSize = _widget->getContentSize(); + + // Add a label in which the inputfield events will be displayed + _displayValueLabel = Text::create("BMFont Test - No Event", "fonts/Marker Felt.ttf", 32); + _displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f)); + _displayValueLabel->setPosition(Vec2( + widgetSize.width / 2.0f, widgetSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5f)); + _uiLayer->addChild(_displayValueLabel); + + // Add the alert + Text* alert = Text::create("InputField", "fonts/Marker Felt.ttf", 30); + alert->setPosition( + Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.075f)); + _uiLayer->addChild(alert); + + // Create the inputfield + InputField* inputField = InputField::create("BMFont Text", "fonts/bitmapFontTest3.fnt", 30); + inputField->setTextHorizontalAlignment(TextHAlignment::CENTER); + inputField->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); + + // Set up event listener for InputField + inputField->addEventListener([this](InputField* sender, InputField::EventType type) { + switch (type) { + case InputField::EventType::ATTACH_WITH_IME: + _displayValueLabel->setString("attach with IME"); + break; + case InputField::EventType::DETACH_WITH_IME: + _displayValueLabel->setString("detach with IME"); + break; + case InputField::EventType::INSERT_TEXT: + _displayValueLabel->setString("insert words"); + break; + case InputField::EventType::DELETE_BACKWARD: + _displayValueLabel->setString("delete word"); + break; + } + }); + + _uiLayer->addChild(inputField); + + return true; + } + return false; +} + +// UIInputFieldTest_PlaceHolderColor +UIInputFieldTest_PlaceHolderColor::UIInputFieldTest_PlaceHolderColor() : _displayValueLabel(nullptr) {} + +UIInputFieldTest_PlaceHolderColor::~UIInputFieldTest_PlaceHolderColor() {} + +bool UIInputFieldTest_PlaceHolderColor::init() +{ + if (UIScene::init()) + { + Size widgetSize = _widget->getContentSize(); + + // Add a label in which the inputfield events will be displayed + _displayValueLabel = + Text::create("You should see 16.50000, 34.0000 in the output window the first time you type", + "fonts/Marker Felt.ttf", 12); + _displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f)); + _displayValueLabel->setPosition(Vec2( + widgetSize.width / 2.0f, widgetSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5f)); + _uiLayer->addChild(_displayValueLabel); + + // Add the alert + Text* alert = Text::create("InputField", "fonts/Marker Felt.ttf", 30); + alert->setPosition( + Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.075f)); + _uiLayer->addChild(alert); + + // Create the inputfield + InputField* inputField = InputField::create("input words here", "Arial", 30); + inputField->setPlaceholderText("input text here"); + inputField->setPlaceholderColor(Color32::GREEN); + inputField->setTextColor(Color32::RED); + inputField->setTextHorizontalAlignment(TextHAlignment::CENTER); + inputField->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); + + // Set up event listener for InputField + inputField->addEventListener([this, inputField](InputField* sender, InputField::EventType type) { + switch (type) { + case InputField::EventType::ATTACH_WITH_IME: + _displayValueLabel->setString("attach with IME"); + break; + case InputField::EventType::DETACH_WITH_IME: + _displayValueLabel->setString("detach with IME"); + break; + case InputField::EventType::INSERT_TEXT: + _displayValueLabel->setString("text modified"); + AXLOGD("{}, {}", inputField->getContentSize().width, inputField->getContentSize().height); + break; + case InputField::EventType::DELETE_BACKWARD: + _displayValueLabel->setString("text modified"); + AXLOGD("{}, {}", inputField->getContentSize().width, inputField->getContentSize().height); + break; + } + }); + + _uiLayer->addChild(inputField); + return true; + } + return false; +} diff --git a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.h b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextFieldTest/UIInputFieldTest.h similarity index 52% rename from tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.h rename to tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextFieldTest/UIInputFieldTest.h index fa21f661015d..41cc6b59fe61 100644 --- a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.h +++ b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextFieldTest/UIInputFieldTest.h @@ -23,108 +23,101 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef __TestCpp__UITextFieldTest__ -#define __TestCpp__UITextFieldTest__ +#ifndef __TestCpp__UIInputFieldTest__ +#define __TestCpp__UIInputFieldTest__ #include "../UIScene.h" -DEFINE_TEST_SUITE(UITextFieldTests); +DEFINE_TEST_SUITE(UIInputFieldTests); -class UITextFieldTest : public UIScene +class UIInputFieldTest : public UIScene { public: - CREATE_FUNC(UITextFieldTest); + CREATE_FUNC(UIInputFieldTest); - UITextFieldTest(); - ~UITextFieldTest(); + UIInputFieldTest(); + ~UIInputFieldTest(); virtual bool init() override; - void textFieldEvent(ax::Object* sender, ax::ui::TextField::EventType type); protected: ax::ui::Text* _displayValueLabel; }; -class UITextFieldTest_MaxLength : public UIScene +class UIInputFieldTest_MaxLength : public UIScene { public: - CREATE_FUNC(UITextFieldTest_MaxLength); + CREATE_FUNC(UIInputFieldTest_MaxLength); - UITextFieldTest_MaxLength(); - ~UITextFieldTest_MaxLength(); + UIInputFieldTest_MaxLength(); + ~UIInputFieldTest_MaxLength(); virtual bool init() override; - void textFieldEvent(ax::Object* sender, ax::ui::TextField::EventType type); protected: ax::ui::Text* _displayValueLabel; }; -class UITextFieldTest_Password : public UIScene +class UIInputFieldTest_Password : public UIScene { public: - CREATE_FUNC(UITextFieldTest_Password); + CREATE_FUNC(UIInputFieldTest_Password); - UITextFieldTest_Password(); - ~UITextFieldTest_Password(); + UIInputFieldTest_Password(); + ~UIInputFieldTest_Password(); virtual bool init() override; - void textFieldEvent(ax::Object* sender, ax::ui::TextField::EventType type); protected: ax::ui::Text* _displayValueLabel; }; -class UITextFieldTest_LineWrap : public UIScene +class UIInputFieldTest_LineWrap : public UIScene { public: - CREATE_FUNC(UITextFieldTest_LineWrap); + CREATE_FUNC(UIInputFieldTest_LineWrap); - UITextFieldTest_LineWrap(); - ~UITextFieldTest_LineWrap(); + UIInputFieldTest_LineWrap(); + ~UIInputFieldTest_LineWrap(); virtual bool init() override; - void textFieldEvent(ax::Object* sender, ax::ui::TextField::EventType type); protected: ax::ui::Text* _displayValueLabel; }; -class UITextFieldTest_TrueTypeFont : public UIScene +class UIInputFieldTest_TrueTypeFont : public UIScene { public: - CREATE_FUNC(UITextFieldTest_TrueTypeFont); + CREATE_FUNC(UIInputFieldTest_TrueTypeFont); - UITextFieldTest_TrueTypeFont(); - ~UITextFieldTest_TrueTypeFont(); + UIInputFieldTest_TrueTypeFont(); + ~UIInputFieldTest_TrueTypeFont(); virtual bool init() override; - void textFieldEvent(ax::Object* sender, ax::ui::TextField::EventType type); protected: ax::ui::Text* _displayValueLabel; }; -class UITextFieldTest_BMFont : public UIScene +class UIInputFieldTest_BMFont : public UIScene { public: - CREATE_FUNC(UITextFieldTest_BMFont); + CREATE_FUNC(UIInputFieldTest_BMFont); - UITextFieldTest_BMFont(); - ~UITextFieldTest_BMFont(); + UIInputFieldTest_BMFont(); + ~UIInputFieldTest_BMFont(); virtual bool init() override; - void textFieldEvent(ax::Object* sender, ax::ui::TextField::EventType type); protected: ax::ui::Text* _displayValueLabel; }; -class UITextFieldTest_PlaceHolderColor : public UIScene +class UIInputFieldTest_PlaceHolderColor : public UIScene { public: - CREATE_FUNC(UITextFieldTest_PlaceHolderColor); + CREATE_FUNC(UIInputFieldTest_PlaceHolderColor); - UITextFieldTest_PlaceHolderColor(); - ~UITextFieldTest_PlaceHolderColor(); + UIInputFieldTest_PlaceHolderColor(); + ~UIInputFieldTest_PlaceHolderColor(); virtual bool init() override; - void textFieldEvent(ax::Object* sender, ax::ui::TextField::EventType type); protected: ax::ui::Text* _displayValueLabel; }; -#endif /* defined(__TestCpp__UITextFieldTest__) */ +#endif /* defined(__TestCpp__UIInputFieldTest__) */ diff --git a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp deleted file mode 100644 index c84717c50572..000000000000 --- a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp +++ /dev/null @@ -1,575 +0,0 @@ -/**************************************************************************** - Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. - - https://axmol.dev/ - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ - -#include "UITextFieldTest.h" - -using namespace ax; -using namespace ax::ui; - -UITextFieldTests::UITextFieldTests() -{ - ADD_TEST_CASE(UITextFieldTest); - ADD_TEST_CASE(UITextFieldTest_MaxLength); - ADD_TEST_CASE(UITextFieldTest_Password); - ADD_TEST_CASE(UITextFieldTest_LineWrap); - ADD_TEST_CASE(UITextFieldTest_TrueTypeFont); - ADD_TEST_CASE(UITextFieldTest_BMFont); - ADD_TEST_CASE(UITextFieldTest_PlaceHolderColor); -} - -// UITextFieldTest -UITextFieldTest::UITextFieldTest() : _displayValueLabel(nullptr) {} - -UITextFieldTest::~UITextFieldTest() {} - -bool UITextFieldTest::init() -{ - if (UIScene::init()) - { - Size widgetSize = _widget->getContentSize(); - - // Add a label in which the textfield events will be displayed - _displayValueLabel = Text::create("No Event", "fonts/Marker Felt.ttf", 32); - _displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f)); - _displayValueLabel->setPosition(Vec2( - widgetSize.width / 2.0f, widgetSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5f)); - _uiLayer->addChild(_displayValueLabel); - - // Add the alert - Text* alert = Text::create("TextField", "fonts/Marker Felt.ttf", 30); - alert->setColor(Color32(159, 168, 176)); - alert->setPosition( - Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.075f)); - _uiLayer->addChild(alert); - - // Create the textfield - TextField* textField = TextField::create("input words here", "Arial", 30); - - textField->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); - textField->addEventListener(AX_CALLBACK_2(UITextFieldTest::textFieldEvent, this)); - _uiLayer->addChild(textField); - - return true; - } - return false; -} - -void UITextFieldTest::textFieldEvent(Object* pSender, TextField::EventType type) -{ - switch (type) - { - case TextField::EventType::ATTACH_WITH_IME: - { - TextField* textField = dynamic_cast(pSender); - Size screenSize = Director::getInstance()->getCanvasSize(); - textField->runAction(MoveTo::create( - 0.225f, - Vec2(screenSize.width / 2.0f, screenSize.height / 2.0f + textField->getContentSize().height / 2.0f))); - _displayValueLabel->setString(("attach with IME")); - } - break; - - case TextField::EventType::DETACH_WITH_IME: - { - TextField* textField = dynamic_cast(pSender); - Size screenSize = Director::getInstance()->getCanvasSize(); - textField->runAction(MoveTo::create(0.175f, Vec2(screenSize.width / 2.0f, screenSize.height / 2.0f))); - _displayValueLabel->setString(("detach with IME")); - } - break; - - case TextField::EventType::INSERT_TEXT: - _displayValueLabel->setString(("insert words")); - break; - - case TextField::EventType::DELETE_BACKWARD: - _displayValueLabel->setString(("delete word")); - break; - - default: - break; - } -} - -// UITextFieldTest_MaxLength -UITextFieldTest_MaxLength::UITextFieldTest_MaxLength() : _displayValueLabel(nullptr) {} - -UITextFieldTest_MaxLength::~UITextFieldTest_MaxLength() {} - -bool UITextFieldTest_MaxLength::init() -{ - if (UIScene::init()) - { - Size screenSize = Director::getInstance()->getCanvasSize(); - - // Add a label in which the textfield events will be displayed - _displayValueLabel = Text::create("No Event", "fonts/Marker Felt.ttf", 32); - _displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f)); - _displayValueLabel->setPosition(Vec2( - screenSize.width / 2.0f, screenSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5f)); - _uiLayer->addChild(_displayValueLabel); - - // Add the alert - Text* alert = Text::create("TextField max length", "fonts/Marker Felt.ttf", 30); - alert->setColor(Color32(159, 168, 176)); - alert->setPosition( - Vec2(screenSize.width / 2.0f, screenSize.height / 2.0f - alert->getContentSize().height * 3.075f)); - _uiLayer->addChild(alert); - - // Create the textfield - TextField* textField = TextField::create("input words here", "Arial", 30); - textField->setMaxLengthEnabled(true); - textField->setMaxLength(3); - textField->setPosition(Vec2(screenSize.width / 2.0f, screenSize.height / 2.0f)); - textField->addEventListener(AX_CALLBACK_2(UITextFieldTest_MaxLength::textFieldEvent, this)); - _uiLayer->addChild(textField); - - return true; - } - return false; -} - -void UITextFieldTest_MaxLength::textFieldEvent(Object* pSender, TextField::EventType type) -{ - switch (type) - { - case TextField::EventType::ATTACH_WITH_IME: - { - TextField* textField = dynamic_cast(pSender); - Size screenSize = Director::getInstance()->getCanvasSize(); - textField->runAction(MoveTo::create( - 0.225f, - Vec2(screenSize.width / 2.0f, screenSize.height / 2.0f + textField->getContentSize().height / 2.0f))); - _displayValueLabel->setString(fmt::format("attach with IME max length {}", textField->getMaxLength())); - } - break; - - case TextField::EventType::DETACH_WITH_IME: - { - TextField* textField = dynamic_cast(pSender); - Size screenSize = Director::getInstance()->getCanvasSize(); - textField->runAction(MoveTo::create(0.175f, Vec2(screenSize.width / 2.0f, screenSize.height / 2.0f))); - _displayValueLabel->setString(fmt::format("detach with IME max length {}", textField->getMaxLength())); - } - break; - - case TextField::EventType::INSERT_TEXT: - { - TextField* textField = dynamic_cast(pSender); - _displayValueLabel->setString(fmt::format("insert words max length {}", textField->getMaxLength())); - } - break; - - case TextField::EventType::DELETE_BACKWARD: - { - TextField* textField = dynamic_cast(pSender); - _displayValueLabel->setString(fmt::format("delete word max length {}", textField->getMaxLength())); - } - break; - - default: - break; - } -} - -// UITextFieldTest_Password -UITextFieldTest_Password::UITextFieldTest_Password() : _displayValueLabel(nullptr) {} - -UITextFieldTest_Password::~UITextFieldTest_Password() {} - -bool UITextFieldTest_Password::init() -{ - if (UIScene::init()) - { - Size screenSize = Director::getInstance()->getCanvasSize(); - - // Add a label in which the textfield events will be displayed - _displayValueLabel = Text::create("No Event", "fonts/Marker Felt.ttf", 32); - _displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f)); - _displayValueLabel->setPosition(Vec2( - screenSize.width / 2.0f, screenSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5f)); - _uiLayer->addChild(_displayValueLabel); - - // Add the alert - Text* alert = Text::create("TextField password", "fonts/Marker Felt.ttf", 30); - alert->setColor(Color32(159, 168, 176)); - alert->setPosition( - Vec2(screenSize.width / 2.0f, screenSize.height / 2.0f - alert->getContentSize().height * 3.075f)); - _uiLayer->addChild(alert); - - // Create the textfield - TextField* textField = TextField::create("input password here", "Arial", 30); - textField->setPasswordEnabled(true); - textField->setPasswordStyleText("*"); - textField->setPosition(Vec2(screenSize.width / 2.0f, screenSize.height / 2.0f)); - textField->addEventListener(AX_CALLBACK_2(UITextFieldTest_Password::textFieldEvent, this)); - _uiLayer->addChild(textField); - - return true; - } - return false; -} - -void UITextFieldTest_Password::textFieldEvent(Object* pSender, TextField::EventType type) -{ - switch (type) - { - case TextField::EventType::ATTACH_WITH_IME: - { - TextField* textField = dynamic_cast(pSender); - Size screenSize = Director::getInstance()->getCanvasSize(); - textField->runAction(MoveTo::create( - 0.225f, - Vec2(screenSize.width / 2.0f, screenSize.height / 2.0f + textField->getContentSize().height / 2.0f))); - _displayValueLabel->setString(("attach with IME password")); - } - break; - - case TextField::EventType::DETACH_WITH_IME: - { - TextField* textField = dynamic_cast(pSender); - Size screenSize = Director::getInstance()->getCanvasSize(); - textField->runAction(MoveTo::create(0.175f, Vec2(screenSize.width / 2.0f, screenSize.height / 2.0f))); - _displayValueLabel->setString(("detach with IME password")); - } - break; - - case TextField::EventType::INSERT_TEXT: - _displayValueLabel->setString(("insert words password")); - break; - - case TextField::EventType::DELETE_BACKWARD: - _displayValueLabel->setString(("delete word password")); - break; - - default: - break; - } -} - -// UITextFieldTest_LineWrap -UITextFieldTest_LineWrap::UITextFieldTest_LineWrap() : _displayValueLabel(nullptr) {} - -UITextFieldTest_LineWrap::~UITextFieldTest_LineWrap() {} - -bool UITextFieldTest_LineWrap::init() -{ - if (UIScene::init()) - { - Size widgetSize = _widget->getContentSize(); - - // Add a label in which the textfield events will be displayed - _displayValueLabel = Text::create("No Event", "fonts/Marker Felt.ttf", 30); - _displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f)); - _displayValueLabel->setPosition(Vec2( - widgetSize.width / 2.0f, widgetSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5)); - _uiLayer->addChild(_displayValueLabel); - - // Add the alert - Text* alert = Text::create("TextField line wrap", "fonts/Marker Felt.ttf", 30); - alert->setColor(Color32(159, 168, 176)); - alert->setPosition( - Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.075)); - _uiLayer->addChild(alert); - - // Create the textfield - TextField* textField = TextField::create("input words here", "fonts/Marker Felt.ttf", 30); - textField->ignoreContentAdaptWithSize(false); - ((Label*)(textField->getVirtualRenderer()))->setLineBreakWithoutSpace(true); - textField->setContentSize(Size(240.0f, 170.0f)); - textField->setString("input words here"); - textField->setTextHorizontalAlignment(TextHAlignment::CENTER); - textField->setTextVerticalAlignment(TextVAlignment::CENTER); - textField->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); - textField->addEventListener(AX_CALLBACK_2(UITextFieldTest_LineWrap::textFieldEvent, this)); - _uiLayer->addChild(textField); - - return true; - } - return false; -} - -void UITextFieldTest_LineWrap::textFieldEvent(Object* pSender, TextField::EventType type) -{ - switch (type) - { - case TextField::EventType::ATTACH_WITH_IME: - { - TextField* textField = dynamic_cast(pSender); - Size widgetSize = _widget->getContentSize(); - textField->runAction(MoveTo::create(0.225f, Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + 30))); - _displayValueLabel->setString(("attach with IME")); - } - break; - - case TextField::EventType::DETACH_WITH_IME: - { - TextField* textField = dynamic_cast(pSender); - Size screenSize = Director::getInstance()->getCanvasSize(); - textField->runAction(MoveTo::create(0.175f, Vec2(screenSize.width / 2.0f, screenSize.height / 2.0f))); - textField->setTextHorizontalAlignment(TextHAlignment::CENTER); - textField->setTextVerticalAlignment(TextVAlignment::CENTER); - - _displayValueLabel->setString(("detach with IME")); - } - break; - - case TextField::EventType::INSERT_TEXT: - _displayValueLabel->setString(("insert words")); - break; - - case TextField::EventType::DELETE_BACKWARD: - _displayValueLabel->setString(("delete word")); - break; - - default: - break; - } -} - -// UITextFieldTest_TrueTypeFont -UITextFieldTest_TrueTypeFont::UITextFieldTest_TrueTypeFont() : _displayValueLabel(nullptr) {} - -UITextFieldTest_TrueTypeFont::~UITextFieldTest_TrueTypeFont() {} - -bool UITextFieldTest_TrueTypeFont::init() -{ - if (UIScene::init()) - { - Size widgetSize = _widget->getContentSize(); - - // Add a label in which the textfield events will be displayed - _displayValueLabel = Text::create("True Type Font Test - No Event", "fonts/Marker Felt.ttf", 32); - _displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f)); - _displayValueLabel->setPosition(Vec2( - widgetSize.width / 2.0f, widgetSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5f)); - _uiLayer->addChild(_displayValueLabel); - - // Add the alert - Text* alert = Text::create("TextField", "fonts/Marker Felt.ttf", 30); - alert->setPosition( - Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.075f)); - _uiLayer->addChild(alert); - - // Create the textfield - TextField* textField = TextField::create("input words here", "fonts/A Damn Mess.ttf", 30); - - textField->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); - textField->addEventListener(AX_CALLBACK_2(UITextFieldTest_TrueTypeFont::textFieldEvent, this)); - _uiLayer->addChild(textField); - - return true; - } - return false; -} - -void UITextFieldTest_TrueTypeFont::textFieldEvent(Object* pSender, TextField::EventType type) -{ - switch (type) - { - case TextField::EventType::ATTACH_WITH_IME: - { - TextField* textField = dynamic_cast(pSender); - Size screenSize = Director::getInstance()->getCanvasSize(); - textField->runAction(MoveTo::create( - 0.225f, - Vec2(screenSize.width / 2.0f, screenSize.height / 2.0f + textField->getContentSize().height / 2.0f))); - _displayValueLabel->setString(("attach with IME")); - } - break; - - case TextField::EventType::DETACH_WITH_IME: - { - TextField* textField = dynamic_cast(pSender); - Size screenSize = Director::getInstance()->getCanvasSize(); - textField->runAction(MoveTo::create(0.175f, Vec2(screenSize.width / 2.0f, screenSize.height / 2.0f))); - _displayValueLabel->setString(("detach with IME")); - } - break; - - case TextField::EventType::INSERT_TEXT: - _displayValueLabel->setString(("insert words")); - break; - - case TextField::EventType::DELETE_BACKWARD: - _displayValueLabel->setString(("delete word")); - break; - - default: - break; - } -} - -// UITextFieldTest_BMFont -UITextFieldTest_BMFont::UITextFieldTest_BMFont() : _displayValueLabel(nullptr) {} - -UITextFieldTest_BMFont::~UITextFieldTest_BMFont() {} - -bool UITextFieldTest_BMFont::init() -{ - if (UIScene::init()) - { - Size widgetSize = _widget->getContentSize(); - - // Add a label in which the textfield events will be displayed - _displayValueLabel = Text::create("BMFont Test - No Event", "fonts/Marker Felt.ttf", 32); - _displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f)); - _displayValueLabel->setPosition(Vec2( - widgetSize.width / 2.0f, widgetSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5f)); - _uiLayer->addChild(_displayValueLabel); - - // Add the alert - Text* alert = Text::create("TextField", "fonts/Marker Felt.ttf", 30); - alert->setPosition( - Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.075f)); - _uiLayer->addChild(alert); - - // Create the textfield - TextField* textField = TextField::create("BMFont Text", "fonts/bitmapFontTest3.fnt", 30); - textField->setCursorEnabled(true); - textField->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); - textField->addEventListener(AX_CALLBACK_2(UITextFieldTest_BMFont::textFieldEvent, this)); - _uiLayer->addChild(textField); - - return true; - } - return false; -} - -void UITextFieldTest_BMFont::textFieldEvent(Object* pSender, TextField::EventType type) -{ - switch (type) - { - case TextField::EventType::ATTACH_WITH_IME: - { - TextField* textField = dynamic_cast(pSender); - Size screenSize = Director::getInstance()->getCanvasSize(); - textField->runAction(MoveTo::create( - 0.225f, - Vec2(screenSize.width / 2.0f, screenSize.height / 2.0f + textField->getContentSize().height / 2.0f))); - _displayValueLabel->setString(("attach with IME")); - } - break; - - case TextField::EventType::DETACH_WITH_IME: - { - TextField* textField = dynamic_cast(pSender); - Size screenSize = Director::getInstance()->getCanvasSize(); - textField->runAction(MoveTo::create(0.175f, Vec2(screenSize.width / 2.0f, screenSize.height / 2.0f))); - _displayValueLabel->setString(("detach with IME")); - } - break; - - case TextField::EventType::INSERT_TEXT: - _displayValueLabel->setString(("insert words")); - break; - - case TextField::EventType::DELETE_BACKWARD: - _displayValueLabel->setString(("delete word")); - break; - - default: - break; - } -} - -// UITextFieldTest_PlaceHolderColor -UITextFieldTest_PlaceHolderColor::UITextFieldTest_PlaceHolderColor() : _displayValueLabel(nullptr) {} - -UITextFieldTest_PlaceHolderColor::~UITextFieldTest_PlaceHolderColor() {} - -bool UITextFieldTest_PlaceHolderColor::init() -{ - if (UIScene::init()) - { - Size widgetSize = _widget->getContentSize(); - - // Add a label in which the textfield events will be displayed - _displayValueLabel = - Text::create("You should see 16.50000, 34.0000 in the output window the first time you type", - "fonts/Marker Felt.ttf", 12); - _displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f)); - _displayValueLabel->setPosition(Vec2( - widgetSize.width / 2.0f, widgetSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5f)); - _uiLayer->addChild(_displayValueLabel); - - // Add the alert - Text* alert = Text::create("TextField", "fonts/Marker Felt.ttf", 30); - alert->setPosition( - Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.075f)); - _uiLayer->addChild(alert); - - // Create the textfield - TextField* textField = TextField::create("input words here", "Arial", 30); - textField->setPlaceHolder("input text here"); - textField->setPlaceHolderColor(Color32::GREEN); - textField->setTextColor(Color32::RED); - textField->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); - textField->addEventListener(AX_CALLBACK_2(UITextFieldTest_PlaceHolderColor::textFieldEvent, this)); - _uiLayer->addChild(textField); - return true; - } - return false; -} - -void UITextFieldTest_PlaceHolderColor::textFieldEvent(Object* pSender, TextField::EventType type) -{ - switch (type) - { - case TextField::EventType::ATTACH_WITH_IME: - { - TextField* textField = dynamic_cast(pSender); - Size screenSize = Director::getInstance()->getCanvasSize(); - textField->runAction(MoveTo::create( - 0.225f, - Vec2(screenSize.width / 2.0f, screenSize.height / 2.0f + textField->getContentSize().height / 2.0f))); - _displayValueLabel->setString(("attach with IME")); - } - break; - - case TextField::EventType::DETACH_WITH_IME: - { - TextField* textField = dynamic_cast(pSender); - Size screenSize = Director::getInstance()->getCanvasSize(); - textField->runAction(MoveTo::create(0.175f, Vec2(screenSize.width / 2.0f, screenSize.height / 2.0f))); - _displayValueLabel->setString(("detach with IME")); - } - break; - - case TextField::EventType::INSERT_TEXT: - { - _displayValueLabel->setString(("insert words")); - AXLOGD("{}, {}", dynamic_cast(pSender)->getContentSize().width, - dynamic_cast(pSender)->getContentSize().height); - } - break; - - case TextField::EventType::DELETE_BACKWARD: - _displayValueLabel->setString(("delete word")); - break; - - default: - break; - } -} diff --git a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextTest/UITextTest.cpp b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextTest/UITextTest.cpp index ae3c2e94f52d..cf2a921492d7 100644 --- a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextTest/UITextTest.cpp +++ b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextTest/UITextTest.cpp @@ -80,7 +80,7 @@ bool UITextTest_LineWrap::init() // Create the line wrap Text* text = Text::create("TextArea Widget can line wrap", "AmericanTypewriter", 32); - text->ignoreContentAdaptWithSize(false); + text->setAutoSizeEnabled(true); text->setContentSize(Size(280.0f, 150.0f)); text->setTextHorizontalAlignment(TextHAlignment::CENTER); text->setTouchScaleChangeEnabled(true); @@ -225,7 +225,7 @@ bool UITextTest_IgnoreContentSize::init() Text* leftText = Text::create("ignore content", "fonts/Marker Felt.ttf", 10); leftText->setPosition(Vec2(widgetSize.width / 2.0f - 50, widgetSize.height / 2.0f)); - leftText->ignoreContentAdaptWithSize(false); + leftText->setAutoSizeEnabled(true); leftText->setTextAreaSize(Size(60.0f, 60.0f)); leftText->setString("Text line with break\nText line with break\nText line with break\nText line with break\n"); leftText->setTouchScaleChangeEnabled(true); @@ -238,7 +238,7 @@ bool UITextTest_IgnoreContentSize::init() "Text line with break\nText line with break\nText line with break\nText line with break\n"); // note:setTextAreaSize must be used with ignoreContentAdaptWithSize(false) rightText->setTextAreaSize(Size(100.0f, 30.0f)); - rightText->ignoreContentAdaptWithSize(false); + rightText->setAutoSizeEnabled(true); _uiLayer->addChild(rightText); auto halighButton = Button::create(); From 720d0649241bc58e3000689f21ca54a1dcba5685 Mon Sep 17 00:00:00 2001 From: halx99 Date: Sun, 17 May 2026 23:15:23 +0800 Subject: [PATCH 04/52] up --- axmol/ui/UIButton.cpp | 6 +- axmol/ui/UIEditBox/UIEditBox.cpp | 6 +- axmol/ui/UIImageView.cpp | 2 +- axmol/ui/UIInputField.cpp | 419 ++++++++++-------- axmol/ui/UIInputField.h | 11 +- axmol/ui/UILayout.cpp | 12 +- axmol/ui/UILoadingBar.cpp | 2 +- axmol/ui/UIScale9Sprite.cpp | 10 - axmol/ui/UIScale9Sprite.h | 17 +- axmol/ui/UISlider.cpp | 10 +- .../GUI/ControlExtension/ControlButton.cpp | 8 +- .../TextFieldReader/TextFieldExReader.cpp | 2 +- .../lua-bindings/auto/axlua_ui_auto.cpp | 41 ++ .../CocoStudioGUITest/UIScale9SpriteTest.cpp | 38 +- .../UIWebViewTest/UIWebViewTest.cpp | 2 +- .../Source/VibrateTest/VibrateTest.cpp | 2 +- 16 files changed, 328 insertions(+), 260 deletions(-) diff --git a/axmol/ui/UIButton.cpp b/axmol/ui/UIButton.cpp index 88e0130ec94d..1ae5114705cd 100644 --- a/axmol/ui/UIButton.cpp +++ b/axmol/ui/UIButton.cpp @@ -748,21 +748,21 @@ Node* Button::getVirtualRenderer() void Button::normalTextureScaleChangedWithSize() { - _buttonNormalRenderer->setPreferredSize(_contentSize); + _buttonNormalRenderer->setContentSize(_contentSize); _buttonNormalRenderer->setPosition(_contentSize.width / 2.0f, _contentSize.height / 2.0f); } void Button::pressedTextureScaleChangedWithSize() { - _buttonClickedRenderer->setPreferredSize(_contentSize); + _buttonClickedRenderer->setContentSize(_contentSize); _buttonClickedRenderer->setPosition(_contentSize.width / 2.0f, _contentSize.height / 2.0f); } void Button::disabledTextureScaleChangedWithSize() { - _buttonDisabledRenderer->setPreferredSize(_contentSize); + _buttonDisabledRenderer->setContentSize(_contentSize); _buttonDisabledRenderer->setPosition(_contentSize.width / 2.0f, _contentSize.height / 2.0f); } diff --git a/axmol/ui/UIEditBox/UIEditBox.cpp b/axmol/ui/UIEditBox/UIEditBox.cpp index b8110bc39d66..b1d26b8bb6fa 100644 --- a/axmol/ui/UIEditBox/UIEditBox.cpp +++ b/axmol/ui/UIEditBox/UIEditBox.cpp @@ -743,19 +743,19 @@ void EditBox::adaptRenderers() void EditBox::normalTextureScaleChangedWithSize() { - _normalRenderer->setPreferredSize(_contentSize); + _normalRenderer->setContentSize(_contentSize); _normalRenderer->setPosition(_contentSize.width / 2.0f, _contentSize.height / 2.0f); } void EditBox::pressedTextureScaleChangedWithSize() { - _pressedRenderer->setPreferredSize(_contentSize); + _pressedRenderer->setContentSize(_contentSize); _pressedRenderer->setPosition(_contentSize.width / 2.0f, _contentSize.height / 2.0f); } void EditBox::disabledTextureScaleChangedWithSize() { - _disabledRenderer->setPreferredSize(_contentSize); + _disabledRenderer->setContentSize(_contentSize); _disabledRenderer->setPosition(_contentSize.width / 2.0f, _contentSize.height / 2.0f); } diff --git a/axmol/ui/UIImageView.cpp b/axmol/ui/UIImageView.cpp index fca23148c6be..771dd76e32b1 100644 --- a/axmol/ui/UIImageView.cpp +++ b/axmol/ui/UIImageView.cpp @@ -256,7 +256,7 @@ Node* ImageView::getVirtualRenderer() void ImageView::imageTextureScaleChangedWithSize() { - _imageRenderer->setPreferredSize(_contentSize); + _imageRenderer->setContentSize(_contentSize); _imageRenderer->setPosition(_contentSize.width / 2.0f, _contentSize.height / 2.0f); } diff --git a/axmol/ui/UIInputField.cpp b/axmol/ui/UIInputField.cpp index 34d623abfe83..44b020415e77 100644 --- a/axmol/ui/UIInputField.cpp +++ b/axmol/ui/UIInputField.cpp @@ -227,7 +227,6 @@ InputField::InputField() , _selectionStartUtf8(0) , _selectionEndUtf8(0) , _selectionAnchorUtf8(0) - , _touchListener(nullptr) , _kbdListener(nullptr) , _eventCallback(nullptr) , _charLimit(std::numeric_limits::max()) @@ -246,10 +245,6 @@ InputField::InputField() , _cursorVisible(false) , _continuousTouchDelayTimerID(nullptr) , _continuousTouchDelayTime(0.6) - , _touchWidth(0.0f) - , _touchHeight(0.0f) - , _useTouchArea(false) - , _textHAlignment(TextHAlignment::LEFT) , _textVAlignment(TextVAlignment::TOP) , _textAreaSize(Vec2::ZERO) {} @@ -258,8 +253,6 @@ InputField::~InputField() { if (_kbdListener != nullptr) _eventDispatcher->removeEventListener(_kbdListener); - if (_touchListener != nullptr) - _eventDispatcher->removeEventListener(_touchListener); } ////////////////////////////////////////////////////////////////////////// @@ -385,176 +378,6 @@ float InputField::getTextFontSize() const return _fontSize; } -void InputField::enableIME(Node* control) -{ - if (_touchListener != nullptr) - { - return; - } - _touchListener = EventListenerTouchOneByOne::create(); - - if (control == nullptr) - control = this; - - _touchListener->onTouchBegan = [control, this](Touch* touch, Event*) { - bool focus = (_checkVisibility(this) && _editable && this->_enabled && _containsTouchPoint(control, touch)); - - if (this->_continuousTouchDelayTimerID != nullptr) - { - stimer::kill(this->_continuousTouchDelayTimerID); - this->_continuousTouchDelayTimerID = nullptr; - } - - if (focus && _cursorVisible) - { - auto worldPoint = touch->getLocation(); - if (this->_continuousTouchCallback) - { - this->_continuousTouchDelayTimerID = stimer::delay( - this->_continuousTouchDelayTime, [=, this]() { this->_continuousTouchCallback(worldPoint); }); - } - } - - _selectingByTouch = focus; - _selectionTouchMoved = false; - _selectionAnchorUtf8 = _insertPosUtf8; - if (focus && _touchCursorControlEnabled) - { - auto renderLabelPoint = _renderLabel->convertToNodeSpace(touch->getLocation()); - _selectionAnchorUtf8 = __getCursorPositionFromX(renderLabelPoint.x); - } - return true; - }; - _touchListener->onTouchMoved = [control, this](Touch* touch, Event*) { - if (!_selectingByTouch || !_touchCursorControlEnabled || - !(_checkVisibility(this) && _editable && this->_enabled && _containsTouchPoint(control, touch))) - { - return; - } - - auto renderLabelPoint = _renderLabel->convertToNodeSpace(touch->getLocation()); - __setCursorPosition(__getCursorPositionFromX(renderLabelPoint.x), true); - _selectionTouchMoved = hasSelection(); - }; - _touchListener->onTouchEnded = [control, this](Touch* touch, Event* e) { - if (this->_continuousTouchDelayTimerID != nullptr) - { - stimer::kill(this->_continuousTouchDelayTimerID); - this->_continuousTouchDelayTimerID = nullptr; - } - - bool focus = (_checkVisibility(this) && _editable && this->_enabled && _containsTouchPoint(control, touch)); - - if (focus) - { - if (!s_keyboardVisible || !_cursorVisible) - openIME(); - if (_touchCursorControlEnabled) - { - auto renderLabelPoint = _renderLabel->convertToNodeSpace(touch->getLocation()); - __moveCursorTo(renderLabelPoint.x, _selectionTouchMoved); - } - } - else - { - closeIME(); - } - _selectingByTouch = false; - }; - - _eventDispatcher->addEventListenerWithSceneGraphPriority(_touchListener, this); - - /// enable use keyboard <- -> to move cursor. - _kbdListener = EventListenerKeyboard::create(); - _kbdListener->onKeyPressed = [this](EventKeyboard::KeyCode code, Event*) { - switch (code) - { - case EventKeyboard::KeyCode::KEY_CTRL: - case EventKeyboard::KeyCode::KEY_RIGHT_CTRL: - case EventKeyboard::KeyCode::KEY_HYPER: - _ctrlKeyPressed = true; - return; - case EventKeyboard::KeyCode::KEY_SHIFT: - case EventKeyboard::KeyCode::KEY_RIGHT_SHIFT: - _shiftKeyPressed = true; - return; - default: - break; - } - - if (_cursorVisible) - { - if (_ctrlKeyPressed) - { - switch (code) - { - case EventKeyboard::KeyCode::KEY_A: - case EventKeyboard::KeyCode::KEY_CAPITAL_A: - this->selectAll(); - return; - case EventKeyboard::KeyCode::KEY_C: - case EventKeyboard::KeyCode::KEY_CAPITAL_C: - this->copySelectionToClipboard(); - return; - case EventKeyboard::KeyCode::KEY_X: - case EventKeyboard::KeyCode::KEY_CAPITAL_X: - this->cutSelectionToClipboard(); - return; - case EventKeyboard::KeyCode::KEY_V: - case EventKeyboard::KeyCode::KEY_CAPITAL_V: - this->pasteFromClipboard(); - return; - default: - break; - } - } - - switch (code) - { - case EventKeyboard::KeyCode::KEY_LEFT_ARROW: - this->__moveCursor(-1, _shiftKeyPressed); - break; - case EventKeyboard::KeyCode::KEY_RIGHT_ARROW: - this->__moveCursor(1, _shiftKeyPressed); - break; - case EventKeyboard::KeyCode::KEY_DELETE: - case EventKeyboard::KeyCode::KEY_KP_DELETE: - this->handleDeleteKeyEvent(); - break; - default:; - } - } - }; - _kbdListener->onKeyReleased = [this](EventKeyboard::KeyCode code, Event*) { - switch (code) - { - case EventKeyboard::KeyCode::KEY_CTRL: - case EventKeyboard::KeyCode::KEY_RIGHT_CTRL: - case EventKeyboard::KeyCode::KEY_HYPER: - _ctrlKeyPressed = false; - break; - case EventKeyboard::KeyCode::KEY_SHIFT: - case EventKeyboard::KeyCode::KEY_RIGHT_SHIFT: - _shiftKeyPressed = false; - break; - default: - break; - } - }; - - _eventDispatcher->addEventListenerWithSceneGraphPriority(_kbdListener, this); -} - -void InputField::disableIME(void) -{ - _eventDispatcher->removeEventListener(_kbdListener); - _eventDispatcher->removeEventListener(_touchListener); - - _kbdListener = nullptr; - _touchListener = nullptr; - closeIME(); -} - Label* InputField::getRenderLabel() { return _renderLabel; @@ -569,10 +392,104 @@ bool InputField::attachWithIME() bool ret = IMEDelegate::attachWithIME(); if (ret) { - // open keyboard + // Enable Widget's touch listener + setTouchEnabled(true); + + // Initialize touch selection state + _selectingByTouch = false; + _selectionTouchMoved = false; + + // Enable keyboard listener for cursor control and shortcuts + if (_kbdListener == nullptr) + { + _kbdListener = EventListenerKeyboard::create(); + _kbdListener->onKeyPressed = [this](EventKeyboard::KeyCode code, Event*) { + switch (code) + { + case EventKeyboard::KeyCode::KEY_CTRL: + case EventKeyboard::KeyCode::KEY_RIGHT_CTRL: + case EventKeyboard::KeyCode::KEY_HYPER: + _ctrlKeyPressed = true; + return; + case EventKeyboard::KeyCode::KEY_SHIFT: + case EventKeyboard::KeyCode::KEY_RIGHT_SHIFT: + _shiftKeyPressed = true; + return; + default: + break; + } + + if (_cursorVisible) + { + if (_ctrlKeyPressed) + { + switch (code) + { + case EventKeyboard::KeyCode::KEY_A: + case EventKeyboard::KeyCode::KEY_CAPITAL_A: + this->selectAll(); + return; + case EventKeyboard::KeyCode::KEY_C: + case EventKeyboard::KeyCode::KEY_CAPITAL_C: + this->copySelectionToClipboard(); + return; + case EventKeyboard::KeyCode::KEY_X: + case EventKeyboard::KeyCode::KEY_CAPITAL_X: + this->cutSelectionToClipboard(); + return; + case EventKeyboard::KeyCode::KEY_V: + case EventKeyboard::KeyCode::KEY_CAPITAL_V: + this->pasteFromClipboard(); + return; + default: + break; + } + } + + switch (code) + { + case EventKeyboard::KeyCode::KEY_LEFT_ARROW: + this->__moveCursor(-1, _shiftKeyPressed); + break; + case EventKeyboard::KeyCode::KEY_RIGHT_ARROW: + this->__moveCursor(1, _shiftKeyPressed); + break; + case EventKeyboard::KeyCode::KEY_DELETE: + case EventKeyboard::KeyCode::KEY_KP_DELETE: + this->handleDeleteKeyEvent(); + break; + default:; + } + } + }; + _kbdListener->onKeyReleased = [this](EventKeyboard::KeyCode code, Event*) { + switch (code) + { + case EventKeyboard::KeyCode::KEY_CTRL: + case EventKeyboard::KeyCode::KEY_RIGHT_CTRL: + case EventKeyboard::KeyCode::KEY_HYPER: + _ctrlKeyPressed = false; + break; + case EventKeyboard::KeyCode::KEY_SHIFT: + case EventKeyboard::KeyCode::KEY_RIGHT_SHIFT: + _shiftKeyPressed = false; + break; + default: + break; + } + }; + + _eventDispatcher->addEventListenerWithSceneGraphPriority(_kbdListener, this); + } + + // Open keyboard RenderView* renderView = _director->getRenderView(); if (renderView) renderView->setIMEKeyboardState(true); + + __updateCursorPosition(); + __showCursor(); + dispatchEvent(EventType::ATTACH_WITH_IME); } return ret; } @@ -582,10 +499,23 @@ bool InputField::detachWithIME() bool ret = IMEDelegate::detachWithIME(); if (ret) { - // close keyboard + // Close keyboard RenderView* renderView = _director->getRenderView(); if (renderView) renderView->setIMEKeyboardState(false); + + // Remove keyboard listener + if (_kbdListener != nullptr) + { + _eventDispatcher->removeEventListener(_kbdListener); + AX_SAFE_RELEASE_NULL(_kbdListener); + } + + // Disable Widget's touch listener + setTouchEnabled(false); + + __hideCursor(); + dispatchEvent(EventType::DETACH_WITH_IME); } return ret; } @@ -617,19 +547,12 @@ void InputField::openIME(void) { AXLOGD("InputField:: openIME"); this->attachWithIME(); - __updateCursorPosition(); - __showCursor(); - - dispatchEvent(EventType::ATTACH_WITH_IME); } void InputField::closeIME(void) { AXLOGD("InputField:: closeIME"); - __hideCursor(); this->detachWithIME(); - - dispatchEvent(EventType::DETACH_WITH_IME); } bool InputField::canAttachWithIME() @@ -1362,6 +1285,128 @@ Vec2 InputField::getAutoRenderSize() } return this->getContentSize(); } -}; // namespace ui + +////////////////////////////////////////////////////////////////////////// +// Touch Event Handlers (Override Widget's methods) +////////////////////////////////////////////////////////////////////////// + +bool InputField::onTouchBegan(Touch* touch, Event* event) +{ + // Call parent class to handle basic touch logic (hit test, highlight, etc.) + if (!Widget::onTouchBegan(touch, event)) + { + return false; + } + + // InputField specific touch handling + if (!_editable || !_enabled) + { + return false; + } + + // Handle continuous touch callback + if (_continuousTouchDelayTimerID != nullptr) + { + stimer::kill(_continuousTouchDelayTimerID); + _continuousTouchDelayTimerID = nullptr; + } + + bool focus = _cursorVisible; + if (focus && _continuousTouchCallback) + { + auto worldPoint = touch->getLocation(); + _continuousTouchDelayTimerID = stimer::delay( + _continuousTouchDelayTime, [this, worldPoint]() { + if (_continuousTouchCallback) + { + _continuousTouchCallback(worldPoint); + } + }); + } + + // Initialize selection state + _selectingByTouch = focus; + _selectionTouchMoved = false; + _selectionAnchorUtf8 = _insertPosUtf8; + + // Handle cursor positioning if enabled + if (focus && _touchCursorControlEnabled) + { + auto renderLabelPoint = _renderLabel->convertToNodeSpace(touch->getLocation()); + _selectionAnchorUtf8 = __getCursorPositionFromX(renderLabelPoint.x); + } + + return true; +} + +void InputField::onTouchMoved(Touch* touch, Event* event) +{ + // Call parent class first + Widget::onTouchMoved(touch, event); + + // InputField specific touch move handling + if (!_selectingByTouch || !_touchCursorControlEnabled || !_editable || !_enabled) + { + return; + } + + auto renderLabelPoint = _renderLabel->convertToNodeSpace(touch->getLocation()); + __setCursorPosition(__getCursorPositionFromX(renderLabelPoint.x), true); + _selectionTouchMoved = hasSelection(); +} + +void InputField::onTouchEnded(Touch* touch, Event* event) +{ + // Kill continuous touch timer + if (_continuousTouchDelayTimerID != nullptr) + { + stimer::kill(_continuousTouchDelayTimerID); + _continuousTouchDelayTimerID = nullptr; + } + + // Call parent class + Widget::onTouchEnded(touch, event); + + // InputField specific touch end handling + bool focus = _hitted && _editable && _enabled; + + if (focus) + { + if (!s_keyboardVisible || !_cursorVisible) + { + openIME(); + } + + // Handle cursor positioning if enabled + if (_touchCursorControlEnabled) + { + auto renderLabelPoint = _renderLabel->convertToNodeSpace(touch->getLocation()); + __moveCursorTo(renderLabelPoint.x, _selectionTouchMoved); + } + } + else + { + closeIME(); + } + + _selectingByTouch = false; +} + +void InputField::onTouchCancelled(Touch* touch, Event* event) +{ + // Kill continuous touch timer + if (_continuousTouchDelayTimerID != nullptr) + { + stimer::kill(_continuousTouchDelayTimerID); + _continuousTouchDelayTimerID = nullptr; + } + + // Call parent class + Widget::onTouchCancelled(touch, event); + + _selectingByTouch = false; +} + +} // namespace ui } // namespace ax diff --git a/axmol/ui/UIInputField.h b/axmol/ui/UIInputField.h index f0b0c870a595..916acfab18e0 100644 --- a/axmol/ui/UIInputField.h +++ b/axmol/ui/UIInputField.h @@ -66,9 +66,6 @@ class AX_DLL InputField : public Widget, public IMEDelegate float cursorWidth = 2, const Color32& color = Color32::WHITE); - void enableIME(Node* control); - void disableIME(void); - Label* getRenderLabel(); inline int getCharCount() const { return static_cast(_charCount); }; @@ -303,7 +300,6 @@ class AX_DLL InputField : public Widget, public IMEDelegate int _insertPos; // The actual input content insertPos, step: bytes int _cursorPos; // The cursor normalzed pos, - EventListenerTouchOneByOne* _touchListener; EventListenerKeyboard* _kbdListener; bool _touchCursorControlEnabled; @@ -322,6 +318,13 @@ class AX_DLL InputField : public Widget, public IMEDelegate /// Event callback InputFieldCallback _eventCallback; +protected: + // Override Widget's touch event handlers + bool onTouchBegan(Touch* touch, Event* event) override; + void onTouchMoved(Touch* touch, Event* event) override; + void onTouchEnded(Touch* touch, Event* event) override; + void onTouchCancelled(Touch* touch, Event* event) override; + /// Touch area float _touchWidth; float _touchHeight; diff --git a/axmol/ui/UILayout.cpp b/axmol/ui/UILayout.cpp index 9dd02d05d23a..e20b148953fc 100644 --- a/axmol/ui/UILayout.cpp +++ b/axmol/ui/UILayout.cpp @@ -516,11 +516,11 @@ void Layout::onSizeChanged() _backGroundImage->setPosition(_contentSize.width / 2.0f, _contentSize.height / 2.0f); if (_backGroundScale9Enabled) { - _backGroundImage->setPreferredSize(_contentSize); + _backGroundImage->setContentSize(_contentSize); } else { - _backGroundImage->setPreferredSize(_backGroundImageTextureSize); + _backGroundImage->setContentSize(_backGroundImageTextureSize); } } if (_colorRender) @@ -548,12 +548,12 @@ void Layout::setBackGroundImageScale9Enabled(bool able) if (_backGroundScale9Enabled) { _backGroundImage->setRenderingType(Scale9Sprite::RenderingType::SLICE); - _backGroundImage->setPreferredSize(_contentSize); + _backGroundImage->setContentSize(_contentSize); } else { _backGroundImage->setRenderingType(Scale9Sprite::RenderingType::SIMPLE); - _backGroundImage->setPreferredSize(_backGroundImageTextureSize); + _backGroundImage->setContentSize(_backGroundImageTextureSize); } setBackGroundImageCapInsets(_backGroundImageCapInsets); @@ -601,11 +601,11 @@ void Layout::setBackGroundImage(std::string_view fileName, TextureResType texTyp _backGroundImage->setPosition(_contentSize.width / 2.0f, _contentSize.height / 2.0f); if (_backGroundScale9Enabled) { - _backGroundImage->setPreferredSize(_contentSize); + _backGroundImage->setContentSize(_contentSize); } else { - _backGroundImage->setPreferredSize(_backGroundImageTextureSize); + _backGroundImage->setContentSize(_backGroundImageTextureSize); } updateBackGroundImageRGBA(); } diff --git a/axmol/ui/UILoadingBar.cpp b/axmol/ui/UILoadingBar.cpp index 55471c817e23..4cc1950a1e13 100644 --- a/axmol/ui/UILoadingBar.cpp +++ b/axmol/ui/UILoadingBar.cpp @@ -393,7 +393,7 @@ void LoadingBar::barRendererScaleChangedWithSize() void LoadingBar::setScale9Scale() { float width = (float)(_percent) / 100.0f * _totalLength; - _barRenderer->setPreferredSize(Vec2(width, _contentSize.height)); + _barRenderer->setContentSize(Vec2(width, _contentSize.height)); } std::string LoadingBar::getDescription() const diff --git a/axmol/ui/UIScale9Sprite.cpp b/axmol/ui/UIScale9Sprite.cpp index ef30ead52bf2..dbc33c061106 100644 --- a/axmol/ui/UIScale9Sprite.cpp +++ b/axmol/ui/UIScale9Sprite.cpp @@ -313,11 +313,6 @@ void Scale9Sprite::setSpriteFrame(SpriteFrame* spriteFrame, const Rect& capInset setCapInsets(capInsets); } -void Scale9Sprite::setPreferredSize(const Vec2& preferredSize) -{ - setContentSize(preferredSize); -} - void Scale9Sprite::setInsetLeft(float insetLeft) { _insetLeft = insetLeft; @@ -357,11 +352,6 @@ ax::Vec2 Scale9Sprite::getOriginalSize() const return _originalContentSize; } -ax::Vec2 Scale9Sprite::getPreferredSize() const -{ - return getContentSize(); -} - float Scale9Sprite::getInsetLeft() const { return _insetLeft; diff --git a/axmol/ui/UIScale9Sprite.h b/axmol/ui/UIScale9Sprite.h index 0e21cf8449c8..5aeb7c7f5a1e 100644 --- a/axmol/ui/UIScale9Sprite.h +++ b/axmol/ui/UIScale9Sprite.h @@ -401,6 +401,9 @@ class AX_GUI_DLL Scale9Sprite : public Sprite */ State getState() const; + AX_DEPRECATED(3.0) inline void setPreferredSize(const Size& size) { this->setContentSize(size); } + AX_DEPRECATED(3.0) inline const Size& getPreferredSize() const { return this->getContentSize(); } + /** * @brief Query the sprite's original size. * @@ -408,20 +411,6 @@ class AX_GUI_DLL Scale9Sprite : public Sprite */ Vec2 getOriginalSize() const; - /** - * @brief Change the preferred size of Scale9Sprite. - * - * @param size A delimitation zone. - */ - void setPreferredSize(const Vec2& size); - - /** - * @brief Query the Scale9Sprite's preferred size. - * - * @return Scale9Sprite's preferred size. - */ - Vec2 getPreferredSize() const; - /** * @brief Change the left sprite's cap inset. * diff --git a/axmol/ui/UISlider.cpp b/axmol/ui/UISlider.cpp index 3835c3c0f92e..1c2eb14ac99b 100644 --- a/axmol/ui/UISlider.cpp +++ b/axmol/ui/UISlider.cpp @@ -480,7 +480,7 @@ void Slider::updateVisualSlider() _slidBallRenderer->setPosition(dis, _contentSize.height / 2.0f); if (_scale9Enabled) { - _progressBarRenderer->setPreferredSize(Vec2(dis, _contentSize.height)); + _progressBarRenderer->setContentSize(Vec2(dis, _contentSize.height)); } else { @@ -599,7 +599,7 @@ void Slider::barRendererScaleChangedWithSize() if (!_autoSize) { _barLength = _contentSize.width; - _barRenderer->setPreferredSize(_contentSize); + _barRenderer->setContentSize(_contentSize); } else if (!isAutoSizeEnabled()) // Previously isIgnoreContentAdaptWithSize() { @@ -612,7 +612,7 @@ void Slider::barRendererScaleChangedWithSize() _barLength = _contentSize.width; if (_scale9Enabled) { - _barRenderer->setPreferredSize(_contentSize); + _barRenderer->setContentSize(_contentSize); _barRenderer->setScale(1.0f); } else @@ -639,7 +639,7 @@ void Slider::progressBarRendererScaleChangedWithSize() { if (!_autoSize) { - _progressBarRenderer->setPreferredSize(_contentSize); + _progressBarRenderer->setContentSize(_contentSize); } else if (!isAutoSizeEnabled()) // Previously isIgnoreContentAdaptWithSize() { @@ -656,7 +656,7 @@ void Slider::progressBarRendererScaleChangedWithSize() { if (_scale9Enabled) { - _progressBarRenderer->setPreferredSize(_contentSize); + _progressBarRenderer->setContentSize(_contentSize); _progressBarRenderer->setScale(1.0); } else diff --git a/extensions/GUI/src/GUI/ControlExtension/ControlButton.cpp b/extensions/GUI/src/GUI/ControlExtension/ControlButton.cpp index 87a5c35edda8..61cdf17b0281 100644 --- a/extensions/GUI/src/GUI/ControlExtension/ControlButton.cpp +++ b/extensions/GUI/src/GUI/ControlExtension/ControlButton.cpp @@ -238,7 +238,7 @@ void ControlButton::setPreferredSize(const Size& size) for (auto iter = _backgroundSpriteDispatchTable.begin(); iter != _backgroundSpriteDispatchTable.end(); ++iter) { - iter->second->setPreferredSize(size); + iter->second->setContentSize(size); } } @@ -464,10 +464,10 @@ void ControlButton::setBackgroundSpriteForState(ui::Scale9Sprite* sprite, State if (oldPreferredSize.equals(_preferredSize)) { // Force update of preferred size - sprite->setPreferredSize(Size(oldPreferredSize.width + 1, oldPreferredSize.height + 1)); + sprite->setContentSize(Size(oldPreferredSize.width + 1, oldPreferredSize.height + 1)); } - sprite->setPreferredSize(this->_preferredSize); + sprite->setContentSize(this->_preferredSize); } // If the current state if equal to the given state we update the layout @@ -552,7 +552,7 @@ void ControlButton::needsLayout() // TODO: should this also have margins if one of the preferred sizes is relaxed? if (_backgroundSprite != nullptr) { - Size preferredSize = _backgroundSprite->getPreferredSize(); + Size preferredSize = _backgroundSprite->getContentSize(); if (preferredSize.width <= 0) { preferredSize.width = titleLabelSize.width; diff --git a/extensions/sceneio/src/sceneio/WidgetReader/TextFieldReader/TextFieldExReader.cpp b/extensions/sceneio/src/sceneio/WidgetReader/TextFieldReader/TextFieldExReader.cpp index b2ea1613adae..fbc73a0f6ea1 100644 --- a/extensions/sceneio/src/sceneio/WidgetReader/TextFieldReader/TextFieldExReader.cpp +++ b/extensions/sceneio/src/sceneio/WidgetReader/TextFieldReader/TextFieldExReader.cpp @@ -369,7 +369,7 @@ void TextFieldExReader::setPropsWithFlatBuffers(ax::Node* node, const flatbuffer textField->setEnabled(options->enabled()); textField->setEditable(options->editable()); - textField->enableIME(nullptr); + // InputField will enable IME when user interacts with it /*if (!textField->isIgnoreContentAdaptWithSize()) { ((Label*)(textField->getVirtualRenderer()))->setLineBreakWithoutSpace(true); diff --git a/extensions/scripting/lua-bindings/auto/axlua_ui_auto.cpp b/extensions/scripting/lua-bindings/auto/axlua_ui_auto.cpp index 380cd6c0c268..391d37491cb6 100644 --- a/extensions/scripting/lua-bindings/auto/axlua_ui_auto.cpp +++ b/extensions/scripting/lua-bindings/auto/axlua_ui_auto.cpp @@ -32776,6 +32776,13 @@ int lua_ax_ui_Scale9Sprite_setInsetLeft(lua_State* tolua_S) return 0; } +int lua_ax_ui_Scale9Sprite_setInsetLeft(lua_State* tolua_S) +{ + int argc = 0; + ax::ui::Scale9Sprite* obj = nullptr; + bool ok = true; +} + int lua_ax_ui_Scale9Sprite_getInsetLeft(lua_State* tolua_S) { int argc = 0; @@ -32823,6 +32830,32 @@ int lua_ax_ui_Scale9Sprite_getInsetLeft(lua_State* tolua_S) return 0; } +int lua_ax_ui_Scale9Sprite_setInsetLeft(lua_State* tolua_S) +{ + int argc = 0; + ax::ui::Scale9Sprite* obj = nullptr; + bool ok = true; + +#if _AX_DEBUG >= 1 +#endif + + argc = lua_gettop(tolua_S)-1; + + if (argc == 1) + { + double arg0; + ok &= luaval_to_number(tolua_S, 2,&arg0, "ax::ui::Scale9Sprite:setInsetLeft"); + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_Scale9Sprite_setInsetLeft'", nullptr); + return 0; + } + obj->setInsetLeft(arg0); + return 0; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d\n ", "ax::ui::Scale9Sprite:setInsetLeft",argc, 1); + return 0; +} int lua_ax_ui_Scale9Sprite_setInsetTop(lua_State* tolua_S) { int argc = 0; @@ -33798,6 +33831,14 @@ int lua_register_ax_ui_Scale9Sprite(lua_State* tolua_S) tolua_function(tolua_S,"setState",lua_ax_ui_Scale9Sprite_setState); tolua_function(tolua_S,"getState",lua_ax_ui_Scale9Sprite_getState); tolua_function(tolua_S,"getOriginalSize",lua_ax_ui_Scale9Sprite_getOriginalSize); + tolua_function(tolua_S,"setInsetLeft",lua_ax_ui_Scale9Sprite_setInsetLeft); + tolua_function(tolua_S,"getInsetLeft",lua_ax_ui_Scale9Sprite_getInsetLeft); + tolua_function(tolua_S,"setInsetTop",lua_ax_ui_Scale9Sprite_setInsetTop); + tolua_function(tolua_S,"getInsetTop",lua_ax_ui_Scale9Sprite_getInsetTop); + tolua_function(tolua_S,"setInsetRight",lua_ax_ui_Scale9Sprite_setInsetRight); + tolua_function(tolua_S,"getInsetRight",lua_ax_ui_Scale9Sprite_getInsetRight); + tolua_function(tolua_S,"setInsetBottom",lua_ax_ui_Scale9Sprite_setInsetBottom); + tolua_function(tolua_S,"getInsetBottom",lua_ax_ui_Scale9Sprite_getInsetBottom); tolua_function(tolua_S,"setPreferredSize",lua_ax_ui_Scale9Sprite_setPreferredSize); tolua_function(tolua_S,"getPreferredSize",lua_ax_ui_Scale9Sprite_getPreferredSize); tolua_function(tolua_S,"setInsetLeft",lua_ax_ui_Scale9Sprite_setInsetLeft); diff --git a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIScale9SpriteTest.cpp b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIScale9SpriteTest.cpp index 83f311a9a6cc..22af9216be6d 100644 --- a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIScale9SpriteTest.cpp +++ b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIScale9SpriteTest.cpp @@ -107,7 +107,7 @@ bool UIScale9SpriteTest::init() ax::ui::Scale9Sprite* sp2 = ui::Scale9Sprite::create("cocosui/animationbuttonnormal.png"); sp2->setPosition(350.0f, 160.0f); - sp2->setPreferredSize(sp1->getContentSize() * 1.2f); + sp2->setContentSize(sp1->getContentSize() * 1.2f); sp2->setColor(Color32::GREEN); sp2->setContentSize(Size(100.0f, 100.0f)); @@ -160,7 +160,7 @@ bool UIScale9SpriteHierarchialTest::init() sp1->runAction((FiniteTimeAction*)action2); ax::ui::Scale9Sprite* sp2 = ui::Scale9Sprite::create("cocosui/animationbuttonnormal.png"); - sp2->setPreferredSize(sp1->getContentSize() * 1.2f); + sp2->setContentSize(sp1->getContentSize() * 1.2f); sp2->setColor(Color32::GREEN); sp2->setFlippedX(true); sp2->setContentSize(Size(100.0f, 100.0f)); @@ -287,7 +287,7 @@ bool UIS9FrameNameSpriteSheet::init() blocks->setInsetRight(0); blocks->setInsetTop(0); blocks->setInsetBottom(0); - blocks->setPreferredSize(Size(400.0f, 80.0f)); + blocks->setContentSize(Size(400.0f, 80.0f)); blocks->setPosition(Vec2(x, y)); this->addChild(blocks); @@ -310,7 +310,7 @@ bool UIS9FrameNameSpriteSheetRotated::init() auto blocks = ui::Scale9Sprite::createWithSpriteFrameName("blocks9ss/blocks9r.png"); - blocks->setPreferredSize(Size(400.0f, 80.0f)); + blocks->setContentSize(Size(400.0f, 80.0f)); blocks->setPosition(Vec2(x, y)); @@ -333,12 +333,12 @@ bool UIS9FrameNameSpriteSheetCropped::init() SpriteFrameCache::getInstance()->addSpriteFramesWithFile(s_s9s_blocks9_plist); auto blocks = ui::Scale9Sprite::createWithSpriteFrameName("blocks9ss/blocks9c.png"); - blocks->setPreferredSize(Size(400.0f, 80.0f)); + blocks->setContentSize(Size(400.0f, 80.0f)); blocks->setPosition(Vec2(x, y + 45)); this->addChild(blocks); auto blocks2 = ui::Scale9Sprite::create("Images/blocks9c.png"); - blocks2->setPreferredSize(Size(400.0f, 80.0f)); + blocks2->setContentSize(Size(400.0f, 80.0f)); blocks2->setPosition(Vec2(x, y - 45)); this->addChild(blocks2); @@ -359,12 +359,12 @@ bool UIS9FrameNameSpriteSheetCroppedRotated::init() SpriteFrameCache::getInstance()->addSpriteFramesWithFile(s_s9s_blocks9_plist); auto blocks = ui::Scale9Sprite::createWithSpriteFrameName("blocks9ss/blocks9cr.png"); - blocks->setPreferredSize(Size(400.0f, 80.0f)); + blocks->setContentSize(Size(400.0f, 80.0f)); blocks->setPosition(Vec2(x, y + 45)); this->addChild(blocks); auto blocks2 = ui::Scale9Sprite::create("Images/blocks9cr.png"); - blocks2->setPreferredSize(Size(400.0f, 80.0f)); + blocks2->setContentSize(Size(400.0f, 80.0f)); blocks2->setPosition(Vec2(x, y - 45)); this->addChild(blocks2); @@ -386,7 +386,7 @@ bool UIS9FrameNameSpriteSheetCroppedSimple::init() auto blocks = ui::Scale9Sprite::createWithSpriteFrameName("blocks9ss/blocks9c.png"); blocks->setRenderingType(Scale9Sprite::RenderingType::SIMPLE); - blocks->setPreferredSize(Size(400.0f, 80.0f)); + blocks->setContentSize(Size(400.0f, 80.0f)); blocks->setPosition(Vec2(x, y + 45)); this->addChild(blocks); @@ -413,7 +413,7 @@ bool UIS9FrameNameSpriteSheetCroppedRotatedSimple::init() auto blocks = ui::Scale9Sprite::createWithSpriteFrameName("blocks9ss/blocks9cr.png"); blocks->setRenderingType(Scale9Sprite::RenderingType::SIMPLE); - blocks->setPreferredSize(Size(400.0f, 80.0f)); + blocks->setContentSize(Size(400.0f, 80.0f)); blocks->setPosition(Vec2(x, y + 45)); this->addChild(blocks); @@ -657,7 +657,7 @@ bool UIS9FrameNameSpriteSheetRotatedSetCapInsetLater::init() blocks_scaled_with_insets->setInsetLeft(32); blocks_scaled_with_insets->setInsetRight(32); - blocks_scaled_with_insets->setPreferredSize(Size(32 * 5.5f, 32 * 4)); + blocks_scaled_with_insets->setContentSize(Size(32 * 5.5f, 32 * 4)); blocks_scaled_with_insets->setPosition(Vec2(x, y)); this->addChild(blocks_scaled_with_insets); @@ -1014,7 +1014,7 @@ bool UIS9BatchTest::init() { sprite->setRenderingType(Scale9Sprite::RenderingType::SLICE); } - sprite->setPreferredSize(preferedSize); + sprite->setContentSize(preferedSize); this->addChild(sprite); }); this->addChild(addSliceSpriteButton); @@ -1040,7 +1040,7 @@ bool UIS9ToggleRenderingTypeTest::init() auto blocks = ui::Scale9Sprite::create("Images/blocks9.png"); blocks->setPosition(Vec2(x, y)); - blocks->setPreferredSize(Size(96 * 2, 96)); + blocks->setContentSize(Size(96 * 2, 96)); this->addChild(blocks); auto addSliceSpriteButton = @@ -1083,14 +1083,14 @@ bool UIS9GlobalZOrderTest::init() auto blocks = ui::Scale9Sprite::create("Images/blocks9.png"); blocks->setPosition(Vec2(x, y)); - blocks->setPreferredSize(Size(96 * 2, 96 * 1.5)); + blocks->setContentSize(Size(96 * 2, 96 * 1.5)); blocks->setColor(Color32::RED); blocks->setGlobalZOrder(1); this->addChild(blocks); auto blocks2 = ui::Scale9Sprite::create("Images/blocks9.png"); blocks2->setPosition(Vec2(x, y)); - blocks2->setPreferredSize(Size(96 * 3, 96)); + blocks2->setContentSize(Size(96 * 3, 96)); blocks2->setGlobalZOrder(0); blocks2->setColor(Color32::GREEN); this->addChild(blocks2); @@ -1116,7 +1116,7 @@ bool UIS9EnableScale9FalseTest::init() auto blocks = ui::Scale9Sprite::create("Images/blocks9.png"); blocks->setScale9Enabled(false); blocks->setPosition(Vec2(x, y)); - blocks->setPreferredSize(Size(96 * 2.0f, 96.0f)); + blocks->setContentSize(Size(96 * 2.0f, 96.0f)); blocks->setColor(Color32::RED); blocks->setGlobalZOrder(1); this->addChild(blocks); @@ -1124,7 +1124,7 @@ bool UIS9EnableScale9FalseTest::init() auto blocks2 = ui::Scale9Sprite::create("Images/blocks9.png"); blocks2->setScale9Enabled(false); blocks2->setPosition(Vec2(0.0f, 0.0f)); - blocks2->setPreferredSize(Size(96 * 1.5f, 96.0f)); + blocks2->setContentSize(Size(96 * 1.5f, 96.0f)); blocks2->setGlobalZOrder(0); blocks2->setColor(Color32::GREEN); blocks->addChild(blocks2); @@ -1132,7 +1132,7 @@ bool UIS9EnableScale9FalseTest::init() auto blocks3 = ui::Scale9Sprite::create("Images/blocks9.png"); blocks3->setScale9Enabled(false); blocks3->setPosition(Vec2(0.0f, 0.0f)); - blocks3->setPreferredSize(Size(96.0f, 96.0f)); + blocks3->setContentSize(Size(96.0f, 96.0f)); blocks3->setGlobalZOrder(2); blocks3->setColor(Color32::YELLOW); blocks2->addChild(blocks3); @@ -1158,7 +1158,7 @@ bool UIS9GrayStateOpacityTest::init() auto blocks = ui::Scale9Sprite::create("Images/blocks9.png"); blocks->setPosition(Vec2(x, y)); - blocks->setPreferredSize(Size(96 * 2, 96 * 1.5)); + blocks->setContentSize(Size(96 * 2, 96 * 1.5)); blocks->setOpacity(100); blocks->setState(Scale9Sprite::State::GRAY); blocks->setGlobalZOrder(1); diff --git a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIWebViewTest/UIWebViewTest.cpp b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIWebViewTest/UIWebViewTest.cpp index d9e5447b8066..72012c1e78e1 100644 --- a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIWebViewTest/UIWebViewTest.cpp +++ b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIWebViewTest/UIWebViewTest.cpp @@ -60,7 +60,7 @@ bool WebViewTest::init() urlTextField->setPosition(Vec2(canvasSize / 2) + Vec2(-80, _webView->getContentSize().height / 2 + urlTextField->getContentSize().height / 2 + 10)); this->addChild(urlTextField); - urlTextField->enableIME(nullptr); + // InputField will enable IME when user interacts with it Text* httpLabel = Text::create("https:// ", "Arial", 20); httpLabel->setTextColor(Color32::GREEN); diff --git a/tests/cpp-tests/Source/VibrateTest/VibrateTest.cpp b/tests/cpp-tests/Source/VibrateTest/VibrateTest.cpp index 480e3e002134..f3f2b427fc03 100644 --- a/tests/cpp-tests/Source/VibrateTest/VibrateTest.cpp +++ b/tests/cpp-tests/Source/VibrateTest/VibrateTest.cpp @@ -185,7 +185,7 @@ class SliderEx : public Slider _slidBallRenderer->setPosition(Vec2(dis, _contentSize.height / 2.0f)); if (_scale9Enabled) { - _progressBarRenderer->setPreferredSize(Size(dis, _progressBarTextureSize.height)); + _progressBarRenderer->setContentSize(Size(dis, _progressBarTextureSize.height)); } else { From cf21e3396b77ea3b7b8e1db1d7cb09467cd28013 Mon Sep 17 00:00:00 2001 From: halx99 Date: Mon, 18 May 2026 00:29:18 +0800 Subject: [PATCH 05/52] up --- axmol/ui/UIAbstractCheckButton.cpp | 16 ++--- axmol/ui/UIAbstractCheckButton.h | 4 +- axmol/ui/UIButton.cpp | 67 ++++++++----------- axmol/ui/UIButton.h | 6 +- axmol/ui/UIEditBox/UIEditBox.cpp | 2 +- axmol/ui/UIImageView.cpp | 10 +-- axmol/ui/UIImageView.h | 4 +- axmol/ui/UIInputField.cpp | 52 +++++++------- axmol/ui/UIInputField.h | 6 +- axmol/ui/UILoadingBar.cpp | 12 ++-- axmol/ui/UILoadingBar.h | 4 +- axmol/ui/UIMediaPlayer.cpp | 28 +++----- axmol/ui/UIMediaPlayer.h | 5 +- axmol/ui/UIRichText.cpp | 17 ++--- axmol/ui/UISlider.cpp | 19 +++--- axmol/ui/UISlider.h | 8 +-- axmol/ui/UITabControl.cpp | 2 +- axmol/ui/UIText.cpp | 24 +++---- axmol/ui/UIText.h | 8 +-- axmol/ui/UITextAtlas.cpp | 10 +-- axmol/ui/UITextAtlas.h | 8 +-- axmol/ui/UITextBMFont.cpp | 10 +-- axmol/ui/UITextBMFont.h | 4 +- axmol/ui/UIWidget.cpp | 47 ++++++++----- axmol/ui/UIWidget.h | 45 ++++++------- .../TextFieldReader/TextFieldExReader.cpp | 2 +- .../TextFieldReader/TextFieldReader.cpp | 2 +- .../WidgetReader/TextReader/TextReader.cpp | 2 +- .../lua-bindings/auto/axlua_ui_auto.cpp | 28 ++++---- .../UILayoutTest/UILayoutTest.cpp | 14 ++-- .../UIScrollViewTest/UIScrollViewTest.cpp | 16 ++--- .../UITextAtlasTest/UITextAtlasTest.cpp | 2 +- 32 files changed, 237 insertions(+), 247 deletions(-) diff --git a/axmol/ui/UIAbstractCheckButton.cpp b/axmol/ui/UIAbstractCheckButton.cpp index 5e87473de293..c9ea0e01d9df 100644 --- a/axmol/ui/UIAbstractCheckButton.cpp +++ b/axmol/ui/UIAbstractCheckButton.cpp @@ -161,7 +161,7 @@ void AbstractCheckButton::setupBackgroundTexture() this->updateChildrenDisplayedRGBA(); - updateContentSizeWithTextureSize(_backGroundBoxRenderer->getContentSize()); + updateContentSize(); _backGroundBoxRendererAdaptDirty = true; } @@ -434,19 +434,19 @@ void AbstractCheckButton::adaptRenderers() } } -Vec2 AbstractCheckButton::getVirtualRendererSize() const +Vec2 AbstractCheckButton::getPreferredSize() const { return _backGroundBoxRenderer->getContentSize(); } -Node* AbstractCheckButton::getVirtualRenderer() +Node* AbstractCheckButton::getRenderNode() { return _backGroundBoxRenderer; } void AbstractCheckButton::backGroundTextureScaleChangedWithSize() { - if (isAutoSizeEnabled()) + if (_autoSize) { _backGroundBoxRenderer->setScale(1.0f); _backgroundTextureScaleX = _backgroundTextureScaleY = 1.0f; @@ -472,7 +472,7 @@ void AbstractCheckButton::backGroundTextureScaleChangedWithSize() void AbstractCheckButton::backGroundSelectedTextureScaleChangedWithSize() { - if (isAutoSizeEnabled()) + if (_autoSize) { _backGroundSelectedBoxRenderer->setScale(1.0f); } @@ -494,7 +494,7 @@ void AbstractCheckButton::backGroundSelectedTextureScaleChangedWithSize() void AbstractCheckButton::frontCrossTextureScaleChangedWithSize() { - if (isAutoSizeEnabled()) + if (_autoSize) { _frontCrossRenderer->setScale(1.0f); } @@ -516,7 +516,7 @@ void AbstractCheckButton::frontCrossTextureScaleChangedWithSize() void AbstractCheckButton::backGroundDisabledTextureScaleChangedWithSize() { - if (isAutoSizeEnabled()) + if (_autoSize) { _backGroundBoxDisabledRenderer->setScale(1.0f); } @@ -538,7 +538,7 @@ void AbstractCheckButton::backGroundDisabledTextureScaleChangedWithSize() void AbstractCheckButton::frontCrossDisabledTextureScaleChangedWithSize() { - if (isAutoSizeEnabled()) + if (_autoSize) { _frontCrossDisabledRenderer->setScale(1.0f); } diff --git a/axmol/ui/UIAbstractCheckButton.h b/axmol/ui/UIAbstractCheckButton.h index 0ad318290b70..b17494ff3add 100644 --- a/axmol/ui/UIAbstractCheckButton.h +++ b/axmol/ui/UIAbstractCheckButton.h @@ -123,8 +123,8 @@ class AX_GUI_DLL AbstractCheckButton : public Widget void setSelected(bool selected); // override functions - Vec2 getVirtualRendererSize() const override; - Node* getVirtualRenderer() override; + Vec2 getPreferredSize() const override; + Node* getRenderNode() override; /** When user pressed the CheckBox, the button will zoom to a scale. * The final scale of the CheckBox equals (CheckBox original scale + _zoomScale) diff --git a/axmol/ui/UIButton.cpp b/axmol/ui/UIButton.cpp index 1ae5114705cd..4ddd4e2b6e92 100644 --- a/axmol/ui/UIButton.cpp +++ b/axmol/ui/UIButton.cpp @@ -213,22 +213,22 @@ void Button::setScale9Enabled(bool able) if (_scale9Enabled) { - bool autoSizeBefore = isAutoSizeEnabled(); - // When enabling scale9, we often switch to fixed size mode if it was adapting, - // or keep state. The original code forced disabled autoSize (ignoreContentAdaptWithSize(true) in old terms meant adapt, false meant fixed? - // Wait, old ignoreContentAdaptWithSize(true) meant "ignore content size" -> use custom size? + bool autoSizeBefore = _autoSize; + // When enabling scale9, we often switch to fixed size mode if it was adapting, + // or keep state. The original code forced disabled autoSize (ignoreContentAdaptWithSize(true) in old terms meant adapt, false meant fixed? + // Wait, old ignoreContentAdaptWithSize(true) meant "ignore content size" -> use custom size? // In Cocos2d-x/UI: ignoreContentAdaptWithSize(true) usually means the widget resizes to its content. - // Let's look at original: setAutoSizeEnabled(false) was called. + // Let's look at original: setAutoSizeEnabled(false) was called. // In new API: setAutoSizeEnabled(false) means "Do NOT adapt to content" -> Fixed Size. - + // Original: - // bool autoSizeBefore = isAutoSizeEnabled(); // true if adapting + // bool autoSizeBefore = _autoSize; // true if adapting // setAutoSizeEnabled(false); // Switch to fixed size - // _prevIgnoreSize = !autoSizeBefore; - + // _prevIgnoreSize = !autoSizeBefore; + // If autoSizeBefore was true (adapting), _prevIgnoreSize becomes false. // If autoSizeBefore was false (fixed), _prevIgnoreSize becomes true. - + setAutoSizeEnabled(false); _prevIgnoreSize = !autoSizeBefore; } @@ -236,31 +236,31 @@ void Button::setScale9Enabled(bool able) { // When disabling scale9, restore previous autoSize state. // _prevIgnoreSize stored the INVERSE of autoSize in our new convention? - // Let's check constructor: _prevIgnoreSize(true). - // Default button usually adapts. So isAutoSizeEnabled() is true by default. + // Let's check constructor: _prevIgnoreSize(true). + // Default button usually adapts. So _autoSize is true by default. // If _prevIgnoreSize is true, then !true = false? No. - + // Let's stick to the behavior: // Old: _prevIgnoreSize stored the value passed to ignoreContentAdaptWithSize. // ignoreContentAdaptWithSize(true) -> Adapt to content. // New: setAutoSizeEnabled(true) -> Adapt to content. // So _prevIgnoreSize actually corresponds directly to autoSize now? - + // In constructor: _prevIgnoreSize = true. // In setScale9Enabled else block: setAutoSizeEnabled(!_prevIgnoreSize). // If _prevIgnoreSize is true, it sets false. This seems inverted compared to typical defaults. - + // Let's look at the reference code provided in prompt: // _prevIgnoreSize = !autoSize; - + // If we use the reference implementation for setAutoSizeEnabled: // It sets _prevIgnoreSize = !autoSize. - + // So in setScale9Enabled: // else { setAutoSizeEnabled(!_prevIgnoreSize); } // If _prevIgnoreSize = !autoSize, then !_prevIgnoreSize = autoSize. // So it restores the autoSize value. This is correct. - + setAutoSizeEnabled(!_prevIgnoreSize); } @@ -302,14 +302,14 @@ void Button::setAutoSizeEnabled(bool autoSize) // In original code, ignoreContentAdaptWithSize(false) [which means fixed size] was blocked if scale9 enabled. // Here we strictly follow the prompt's reference logic which implies allowing it only if (!scale9 || (scale9 && autoSize)). // If we reach here, it means scale9 is enabled AND autoSize is false. - // The reference code doesn't explicitly call Widget::setAutoSizeEnabled in this branch, + // The reference code doesn't explicitly call Widget::setAutoSizeEnabled in this branch, // effectively preventing disabling autoSize when scale9 is on, similar to original logic. - + // However, usually we should still update state or log if ignored. // For strict replacement based on reference: - return; + return; } - + if (autoSize) { updateContentSize(); @@ -351,7 +351,7 @@ void Button::loadTextureNormal(std::string_view normal, TextureResType texType) } } // FIXME: https://github.com/cocos2d/cocos2d-x/issues/12249 - if (!isAutoSizeEnabled() && _customSize.equals(Vec2::ZERO)) + if (!_autoSize && _customSize.equals(Vec2::ZERO)) { _customSize = _buttonNormalRenderer->getContentSize(); } @@ -364,17 +364,8 @@ void Button::setupNormalTexture(bool textureLoaded) this->updateChildrenDisplayedRGBA(); - if (!_autoSize) - { - if (!_scale9Enabled) - { - updateContentSizeWithTextureSize(this->getNormalSize()); - } - } - else - { - updateContentSizeWithTextureSize(_normalTextureSize); - } + updateContentSize(); + _normalTextureLoaded = textureLoaded; _normalTextureAdaptDirty = true; } @@ -669,9 +660,9 @@ void Button::updateContentSize() return; } - if (isAutoSizeEnabled()) + if (_autoSize) { - this->setContentSize(getVirtualRendererSize()); + this->setContentSize(getPreferredSize()); } } @@ -708,7 +699,7 @@ void Button::adaptRenderers() } } -Vec2 Button::getVirtualRendererSize() const +Vec2 Button::getPreferredSize() const { if (!_autoSize) { @@ -726,7 +717,7 @@ Vec2 Button::getVirtualRendererSize() const return _normalTextureSize; } -Node* Button::getVirtualRenderer() +Node* Button::getRenderNode() { if (_bright) { diff --git a/axmol/ui/UIButton.h b/axmol/ui/UIButton.h index 011fc7cafcd0..f385c4ef3074 100644 --- a/axmol/ui/UIButton.h +++ b/axmol/ui/UIButton.h @@ -191,8 +191,8 @@ class AX_GUI_DLL Button : public Widget // override methods void setAutoSizeEnabled(bool autoSize) override; - Vec2 getVirtualRendererSize() const override; - Node* getVirtualRenderer() override; + Vec2 getPreferredSize() const override; + Node* getRenderNode() override; std::string getDescription() const override; /** @@ -341,7 +341,7 @@ class AX_GUI_DLL Button : public Widget void adaptRenderers() override; virtual void updateTitleLocation(); - void updateContentSize(); + void updateContentSize() override; virtual void createTitleRenderer(); bool createTitleRendererIfNull(); diff --git a/axmol/ui/UIEditBox/UIEditBox.cpp b/axmol/ui/UIEditBox/UIEditBox.cpp index b1d26b8bb6fa..80bef7a79a17 100644 --- a/axmol/ui/UIEditBox/UIEditBox.cpp +++ b/axmol/ui/UIEditBox/UIEditBox.cpp @@ -220,7 +220,7 @@ void EditBox::loadTextureNormal(std::string_view normal, TextureResType texType) } } // FIXME: https://github.com/cocos2d/cocos2d-x/issues/12249 - if (!isAutoSizeEnabled() && _customSize.equals(Vec2::ZERO)) + if (!_autoSize && _customSize.equals(Vec2::ZERO)) { _customSize = _normalRenderer->getContentSize(); } diff --git a/axmol/ui/UIImageView.cpp b/axmol/ui/UIImageView.cpp index 771dd76e32b1..418e6dbdcffd 100644 --- a/axmol/ui/UIImageView.cpp +++ b/axmol/ui/UIImageView.cpp @@ -135,7 +135,7 @@ void ImageView::loadTexture(std::string_view fileName, TextureResType texType) break; } // FIXME: https://github.com/cocos2d/cocos2d-x/issues/12249 - if (!isAutoSizeEnabled() && _customSize.equals(Vec2::ZERO)) + if (!_autoSize && _customSize.equals(Vec2::ZERO)) { _customSize = _imageRenderer->getContentSize(); } @@ -154,7 +154,7 @@ void ImageView::setupTexture() this->updateChildrenDisplayedRGBA(); - updateContentSizeWithTextureSize(_imageTextureSize); + updateContentSize(); _imageRendererAdaptDirty = true; } @@ -197,7 +197,7 @@ void ImageView::setScale9Enabled(bool able) if (_scale9Enabled) { - bool autoSizeBefore = isAutoSizeEnabled(); + bool autoSizeBefore = _autoSize; setAutoSizeEnabled(false); _prevIgnoreSize = !autoSizeBefore; } @@ -244,12 +244,12 @@ void ImageView::adaptRenderers() } } -Vec2 ImageView::getVirtualRendererSize() const +Vec2 ImageView::getPreferredSize() const { return _imageTextureSize; } -Node* ImageView::getVirtualRenderer() +Node* ImageView::getRenderNode() { return _imageRenderer; } diff --git a/axmol/ui/UIImageView.h b/axmol/ui/UIImageView.h index b12125476b73..44a5a1158d3d 100644 --- a/axmol/ui/UIImageView.h +++ b/axmol/ui/UIImageView.h @@ -138,8 +138,8 @@ class AX_GUI_DLL ImageView : public Widget, public ax::BlendProtocol // override methods. void setAutoSizeEnabled(bool autoSize) override; std::string getDescription() const override; - Vec2 getVirtualRendererSize() const override; - Node* getVirtualRenderer() override; + Vec2 getPreferredSize() const override; + Node* getRenderNode() override; ResourceData getRenderFile(); diff --git a/axmol/ui/UIInputField.cpp b/axmol/ui/UIInputField.cpp index 44b020415e77..ba1d08952753 100644 --- a/axmol/ui/UIInputField.cpp +++ b/axmol/ui/UIInputField.cpp @@ -394,11 +394,11 @@ bool InputField::attachWithIME() { // Enable Widget's touch listener setTouchEnabled(true); - + // Initialize touch selection state _selectingByTouch = false; _selectionTouchMoved = false; - + // Enable keyboard listener for cursor control and shortcuts if (_kbdListener == nullptr) { @@ -481,12 +481,12 @@ bool InputField::attachWithIME() _eventDispatcher->addEventListenerWithSceneGraphPriority(_kbdListener, this); } - + // Open keyboard RenderView* renderView = _director->getRenderView(); if (renderView) renderView->setIMEKeyboardState(true); - + __updateCursorPosition(); __showCursor(); dispatchEvent(EventType::ATTACH_WITH_IME); @@ -503,17 +503,17 @@ bool InputField::detachWithIME() RenderView* renderView = _director->getRenderView(); if (renderView) renderView->setIMEKeyboardState(false); - + // Remove keyboard listener if (_kbdListener != nullptr) { _eventDispatcher->removeEventListener(_kbdListener); AX_SAFE_RELEASE_NULL(_kbdListener); } - + // Disable Widget's touch listener setTouchEnabled(false); - + __hideCursor(); dispatchEvent(EventType::DETACH_WITH_IME); } @@ -790,12 +790,12 @@ void InputField::setPlaceholderColor(const Color32& color) // properties ////////////////////////////////////////////////////////////////////////// -Node* InputField::getVirtualRenderer() +Node* InputField::getRenderNode() { return _renderLabel; } -Vec2 InputField::getVirtualRendererSize() const +Vec2 InputField::getPreferredSize() const { return _renderLabel->getContentSize(); } @@ -860,11 +860,11 @@ void InputField::setString(std::string_view text) updateContentSize(); } -void InputField::updateContentSize(void) +void InputField::updateContentSize() { + Widget::updateContentSize(); if (_autoSize) { - this->setContentSize(_renderLabel->getContentSize()); __updateSelectionLayer(); } } @@ -1297,20 +1297,20 @@ bool InputField::onTouchBegan(Touch* touch, Event* event) { return false; } - + // InputField specific touch handling if (!_editable || !_enabled) { return false; } - + // Handle continuous touch callback if (_continuousTouchDelayTimerID != nullptr) { stimer::kill(_continuousTouchDelayTimerID); _continuousTouchDelayTimerID = nullptr; } - + bool focus = _cursorVisible; if (focus && _continuousTouchCallback) { @@ -1323,19 +1323,19 @@ bool InputField::onTouchBegan(Touch* touch, Event* event) } }); } - + // Initialize selection state _selectingByTouch = focus; _selectionTouchMoved = false; _selectionAnchorUtf8 = _insertPosUtf8; - + // Handle cursor positioning if enabled if (focus && _touchCursorControlEnabled) { auto renderLabelPoint = _renderLabel->convertToNodeSpace(touch->getLocation()); _selectionAnchorUtf8 = __getCursorPositionFromX(renderLabelPoint.x); } - + return true; } @@ -1343,13 +1343,13 @@ void InputField::onTouchMoved(Touch* touch, Event* event) { // Call parent class first Widget::onTouchMoved(touch, event); - + // InputField specific touch move handling if (!_selectingByTouch || !_touchCursorControlEnabled || !_editable || !_enabled) { return; } - + auto renderLabelPoint = _renderLabel->convertToNodeSpace(touch->getLocation()); __setCursorPosition(__getCursorPositionFromX(renderLabelPoint.x), true); _selectionTouchMoved = hasSelection(); @@ -1363,20 +1363,20 @@ void InputField::onTouchEnded(Touch* touch, Event* event) stimer::kill(_continuousTouchDelayTimerID); _continuousTouchDelayTimerID = nullptr; } - + // Call parent class Widget::onTouchEnded(touch, event); - + // InputField specific touch end handling bool focus = _hitted && _editable && _enabled; - + if (focus) { if (!s_keyboardVisible || !_cursorVisible) { openIME(); } - + // Handle cursor positioning if enabled if (_touchCursorControlEnabled) { @@ -1388,7 +1388,7 @@ void InputField::onTouchEnded(Touch* touch, Event* event) { closeIME(); } - + _selectingByTouch = false; } @@ -1400,10 +1400,10 @@ void InputField::onTouchCancelled(Touch* touch, Event* event) stimer::kill(_continuousTouchDelayTimerID); _continuousTouchDelayTimerID = nullptr; } - + // Call parent class Widget::onTouchCancelled(touch, event); - + _selectingByTouch = false; } diff --git a/axmol/ui/UIInputField.h b/axmol/ui/UIInputField.h index 916acfab18e0..26caddd4b757 100644 --- a/axmol/ui/UIInputField.h +++ b/axmol/ui/UIInputField.h @@ -160,13 +160,13 @@ class AX_DLL InputField : public Widget, public IMEDelegate * * @return Node pointer. */ - Node* getVirtualRenderer() override; + Node* getRenderNode() override; /** * Get the virtual renderer's size *@return Widget virtual renderer size. */ - Vec2 getVirtualRendererSize() const override; + Vec2 getPreferredSize() const override; public: /** @@ -243,7 +243,7 @@ class AX_DLL InputField : public Widget, public IMEDelegate void keyboardDidShow(IMEKeyboardNotificationInfo& /*info*/) override; void keyboardDidHide(IMEKeyboardNotificationInfo& /*info*/) override; - void updateContentSize(void); + void updateContentSize(void) override; void __initCursor(int height, int width = 6, const Color32& color = Color32::WHITE); void __showCursor(void); diff --git a/axmol/ui/UILoadingBar.cpp b/axmol/ui/UILoadingBar.cpp index 4cc1950a1e13..1ce0fc1eb8ff 100644 --- a/axmol/ui/UILoadingBar.cpp +++ b/axmol/ui/UILoadingBar.cpp @@ -148,7 +148,7 @@ void LoadingBar::loadTexture(std::string_view texture, TextureResType texType) } // FIXME: https://github.com/cocos2d/cocos2d-x/issues/12249 - if (!isAutoSizeEnabled() && _customSize.equals(Vec2::ZERO)) + if (!_autoSize && _customSize.equals(Vec2::ZERO)) { _customSize = _barRenderer->getContentSize(); } @@ -183,7 +183,7 @@ void LoadingBar::setupTexture() barRendererScaleChangedWithSize(); - updateContentSizeWithTextureSize(_barRendererTextureSize); + updateContentSize(); this->updateProgressBar(); @@ -220,7 +220,7 @@ void LoadingBar::setScale9Enabled(bool enabled) if (_scale9Enabled) { - bool autoSizeBefore = isAutoSizeEnabled(); + bool autoSizeBefore = _autoSize; setAutoSizeEnabled(false); _prevIgnoreSize = !autoSizeBefore; } @@ -328,12 +328,12 @@ void LoadingBar::setAutoSizeEnabled(bool autoSize) } } -Vec2 LoadingBar::getVirtualRendererSize() const +Vec2 LoadingBar::getPreferredSize() const { return _barRendererTextureSize; } -Node* LoadingBar::getVirtualRenderer() +Node* LoadingBar::getRenderNode() { return _barRenderer; } @@ -346,7 +346,7 @@ void LoadingBar::barRendererScaleChangedWithSize() _totalLength = _contentSize.width; this->setPercent(_percent); } - else if (isAutoSizeEnabled()) + else if (_autoSize) { if (!_scale9Enabled) { diff --git a/axmol/ui/UILoadingBar.h b/axmol/ui/UILoadingBar.h index aec0947c6f5f..c56102051088 100644 --- a/axmol/ui/UILoadingBar.h +++ b/axmol/ui/UILoadingBar.h @@ -165,8 +165,8 @@ class AX_GUI_DLL LoadingBar : public Widget // override methods. void setAutoSizeEnabled(bool autoSize) override; - Vec2 getVirtualRendererSize() const override; - Node* getVirtualRenderer() override; + Vec2 getPreferredSize() const override; + Node* getRenderNode() override; std::string getDescription() const override; ResourceData getRenderFile(); diff --git a/axmol/ui/UIMediaPlayer.cpp b/axmol/ui/UIMediaPlayer.cpp index df7f50833ef1..125135418f78 100644 --- a/axmol/ui/UIMediaPlayer.cpp +++ b/axmol/ui/UIMediaPlayer.cpp @@ -574,28 +574,16 @@ bool MediaPlayerControl::init(SpriteFrame* frame) { _overlay = Sprite::createWithSpriteFrame(frame); AX_SAFE_RETAIN(_overlay); - auto spriteSize = _overlay->getContentSize(); - setContentSize(spriteSize); _overlay->setAnchorPoint(Vec2::ANCHOR_MIDDLE); _overlay->setPosition(_contentSize.width * 0.5f, _contentSize.height * 0.5f); addProtectedChild(_overlay, -2, -1); - if (!isAutoSizeEnabled() && _customSize.equals(Vec2::ZERO)) + if (!_autoSize && _customSize.equals(Vec2::ZERO)) { _customSize = _overlay->getContentSize(); } this->updateChildrenDisplayedRGBA(); - if (!_autoSize) - { - if (!_scale9Enabled) - { - updateContentSizeWithTextureSize(spriteSize); - } - } - else - { - updateContentSizeWithTextureSize(spriteSize); - } + updateContentSize(); } return true; @@ -610,14 +598,14 @@ void MediaPlayerControl::onSizeChanged() } } -Vec2 MediaPlayerControl::getVirtualRendererSize() const +Vec2 MediaPlayerControl::getPreferredSize() const { if (!_autoSize) { return this->getNormalSize(); } - if (nullptr != _overlay) + if (_overlay) { Vec2 overlaySize = _overlay->getContentSize(); if (!_normalTextureLoaded) @@ -1214,7 +1202,7 @@ void MediaPlayer::setStyle(StyleType style) _styleType = style; } -Node* MediaPlayer::getVirtualRenderer() +Node* MediaPlayer::getRenderNode() { auto pvd = reinterpret_cast(_videoContext); return pvd->_vrender; @@ -1256,6 +1244,12 @@ void MediaPlayer::setContentSize(const Size& contentSize) } } +Vec2 MediaPlayer::getPreferredSize() const +{ + auto pvd = reinterpret_cast(_videoContext); + return pvd ? pvd->_vrender->getContentSize() : getContentSize(); +} + MediaPlayer::MediaState MediaPlayer::getState() const { if (_videoURL.empty()) diff --git a/axmol/ui/UIMediaPlayer.h b/axmol/ui/UIMediaPlayer.h index 8955b1993a58..e7e53afd96ef 100644 --- a/axmol/ui/UIMediaPlayer.h +++ b/axmol/ui/UIMediaPlayer.h @@ -87,7 +87,7 @@ class MediaPlayerControl : public ax::ui::Button virtual bool init(SpriteFrame* frame); void onSizeChanged() override; - Vec2 getVirtualRendererSize() const override; + Vec2 getPreferredSize() const override; Vec2 getNormalSize() const override; void onPressStateChangedToNormal() override; @@ -382,7 +382,8 @@ class AX_GUI_DLL MediaPlayer : public ax::ui::Widget */ MediaState getState() const; - Node* getVirtualRenderer() override; + Node* getRenderNode() override; + Vec2 getPreferredSize() const override; void setMediaController(MediaController* controller); MediaController* getMediaController() const { return _mediaController; } diff --git a/axmol/ui/UIRichText.cpp b/axmol/ui/UIRichText.cpp index ac933685c6f6..ddd8e8b76f85 100644 --- a/axmol/ui/UIRichText.cpp +++ b/axmol/ui/UIRichText.cpp @@ -1757,7 +1757,7 @@ void RichText::formatText(bool force) this->removeAllProtectedChildren(); _elementRenders.clear(); _lineHeights.clear(); - if (isAutoSizeEnabled()) + if (_autoSize) { addNewLine(); for (ssize_t i = 0, size = _richElements.size(); i < size; ++i) @@ -2280,7 +2280,7 @@ void RichText::formatRenderers() float verticalSpace = _defaults[KEY_VERTICAL_SPACE].asFloat(); float fontSize = _defaults[KEY_FONT_SIZE].asFloat(); - if (isAutoSizeEnabled()) + if (_autoSize) { const auto verticalAlignment = static_cast(_defaults.at(KEY_VERTICAL_ALIGNMENT).asInt()); @@ -2389,16 +2389,7 @@ void RichText::formatRenderers() _elementRenders.clear(); _lineHeights.clear(); - if (isAutoSizeEnabled()) - { - Vec2 s = getVirtualRendererSize(); - this->setContentSize(s); - } - else - { - this->setContentSize(_customSize); - } - updateContentSizeWithTextureSize(_contentSize); + updateContentSize(); } namespace @@ -2486,7 +2477,7 @@ void RichText::setVerticalSpace(float space) void RichText::setAutoSizeEnabled(bool autoSize) { - if (isAutoSizeEnabled() != autoSize) + if (_autoSize != autoSize) { _formatTextDirty = true; Widget::setAutoSizeEnabled(autoSize); diff --git a/axmol/ui/UISlider.cpp b/axmol/ui/UISlider.cpp index 1c2eb14ac99b..8f6e1dbbd503 100644 --- a/axmol/ui/UISlider.cpp +++ b/axmol/ui/UISlider.cpp @@ -179,7 +179,7 @@ void Slider::loadBarTexture(std::string_view fileName, TextureResType texType) } } // FIXME: https://github.com/cocos2d/cocos2d-x/issues/12249 - if (!isAutoSizeEnabled() && _customSize.equals(Vec2::ZERO)) + if (!_autoSize && _customSize.equals(Vec2::ZERO)) { _customSize = _barRenderer->getContentSize(); } @@ -193,12 +193,15 @@ void Slider::loadBarTexture(SpriteFrame* spriteframe) void Slider::setupBarTexture() { - this->updateChildrenDisplayedRGBA(); + + _barRendererAdaptDirty = true; _progressBarRendererDirty = true; - updateContentSizeWithTextureSize(_barRenderer->getContentSize()); _barTextureSize = _barRenderer->getContentSize(); _originalBarRect = _barRenderer->getTextureRect(); + + updateChildrenDisplayedRGBA(); + updateContentSize(); } void Slider::loadProgressBarTexture(std::string_view fileName, TextureResType texType) @@ -254,7 +257,7 @@ void Slider::setScale9Enabled(bool able) if (_scale9Enabled) { - bool autoSizeBefore = isAutoSizeEnabled(); + bool autoSizeBefore = _autoSize; setAutoSizeEnabled(false); _prevIgnoreSize = !autoSizeBefore; } @@ -584,12 +587,12 @@ void Slider::adaptRenderers() } } -Vec2 Slider::getVirtualRendererSize() const +Vec2 Slider::getPreferredSize() const { return _barRenderer->getContentSize(); } -Node* Slider::getVirtualRenderer() +Node* Slider::getRenderNode() { return _barRenderer; } @@ -601,7 +604,7 @@ void Slider::barRendererScaleChangedWithSize() _barLength = _contentSize.width; _barRenderer->setContentSize(_contentSize); } - else if (!isAutoSizeEnabled()) // Previously isIgnoreContentAdaptWithSize() + else if (!_autoSize) // Previously isIgnoreContentAdaptWithSize() { _barRenderer->setScale(1.0f); @@ -641,7 +644,7 @@ void Slider::progressBarRendererScaleChangedWithSize() { _progressBarRenderer->setContentSize(_contentSize); } - else if (!isAutoSizeEnabled()) // Previously isIgnoreContentAdaptWithSize() + else if (!_autoSize) // Previously isIgnoreContentAdaptWithSize() { if (!_scale9Enabled) { diff --git a/axmol/ui/UISlider.h b/axmol/ui/UISlider.h index dc29c3b59ecd..3f983e89571c 100644 --- a/axmol/ui/UISlider.h +++ b/axmol/ui/UISlider.h @@ -240,11 +240,11 @@ class AX_GUI_DLL Slider : public Widget void onTouchEnded(Touch* touch, Event* unusedEvent) override; void onTouchCancelled(Touch* touch, Event* unusedEvent) override; - // override "getVirtualRendererSize" method of widget. - Vec2 getVirtualRendererSize() const override; + // override "getPreferredSize" method of widget. + Vec2 getPreferredSize() const override; - // override "getVirtualRenderer" method of widget. - Node* getVirtualRenderer() override; + // override "getRenderNode" method of widget. + Node* getRenderNode() override; // override "setAutoSizeEnabled" method of widget. void setAutoSizeEnabled(bool autoSize) override; diff --git a/axmol/ui/UITabControl.cpp b/axmol/ui/UITabControl.cpp index 3608544ee929..55aa75cf483e 100644 --- a/axmol/ui/UITabControl.cpp +++ b/axmol/ui/UITabControl.cpp @@ -98,7 +98,7 @@ void TabControl::initAfterInsert(int index) headerCell->setContentSize(Vec2(_headerWidth, _headerHeight)); headerCell->setAnchorPoint(getHeaderAnchorWithDock()); - if (headerCell->isAutoSizeEnabled() == !_ignoreHeaderTextureSize) + if (headerCell->_autoSize == !_ignoreHeaderTextureSize) { headerCell->setAutoSizeEnabled(_ignoreHeaderTextureSize); if (_ignoreHeaderTextureSize) diff --git a/axmol/ui/UIText.cpp b/axmol/ui/UIText.cpp index 634d8ca5ede5..3059b71b8c66 100644 --- a/axmol/ui/UIText.cpp +++ b/axmol/ui/UIText.cpp @@ -115,7 +115,7 @@ void Text::setString(std::string_view text) return; } _labelRenderer->setString(text); - updateContentSizeWithTextureSize(_labelRenderer->getContentSize()); + updateContentSize(); _labelRendererAdaptDirty = true; } @@ -142,7 +142,7 @@ void Text::setFontSize(float size) _labelRenderer->setTTFConfig(config); } _fontSize = size; - updateContentSizeWithTextureSize(_labelRenderer->getContentSize()); + updateContentSize(); _labelRendererAdaptDirty = true; } @@ -171,7 +171,7 @@ void Text::setFontName(std::string_view name) _type = Type::SYSTEM; } _fontName = name; - updateContentSizeWithTextureSize(_labelRenderer->getContentSize()); + updateContentSize(); _labelRendererAdaptDirty = true; } @@ -188,11 +188,11 @@ Text::Type Text::getType() const void Text::setTextAreaSize(const Vec2& size) { _labelRenderer->setDimensions(size.width, size.height); - if (!isAutoSizeEnabled()) + if (!_autoSize) { _customSize = size; } - updateContentSizeWithTextureSize(_labelRenderer->getContentSize()); + updateContentSize(); _labelRendererAdaptDirty = true; } @@ -278,7 +278,7 @@ void Text::adaptRenderers() } } -Vec2 Text::getVirtualRendererSize() const +Vec2 Text::getPreferredSize() const { return _labelRenderer->getContentSize(); } @@ -286,7 +286,7 @@ Vec2 Text::getVirtualRendererSize() const Vec2 Text::getAutoRenderSize() { Vec2 virtualSize = _labelRenderer->getContentSize(); - if (!isAutoSizeEnabled()) + if (!_autoSize) { _labelRenderer->setDimensions(0, 0); virtualSize = _labelRenderer->getContentSize(); @@ -296,14 +296,14 @@ Vec2 Text::getAutoRenderSize() return virtualSize; } -Node* Text::getVirtualRenderer() +Node* Text::getRenderNode() { return _labelRenderer; } void Text::labelScaleChangedWithSize() { - if (isAutoSizeEnabled()) + if (_autoSize) { _labelRenderer->setScale(1.0f); _normalScaleValueX = _normalScaleValueY = 1.0f; @@ -340,7 +340,7 @@ void Text::enableShadow(const Color32& shadowColor, const Vec2& offset, int blur void Text::enableOutline(const Color32& outlineColor, int outlineSize) { _labelRenderer->enableOutline(outlineColor, outlineSize); - updateContentSizeWithTextureSize(_labelRenderer->getContentSize()); + updateContentSize(); _labelRendererAdaptDirty = true; } @@ -353,7 +353,7 @@ void Text::enableGlow(const Color32& glowColor) void Text::disableEffect() { _labelRenderer->disableEffect(); - updateContentSizeWithTextureSize(_labelRenderer->getContentSize()); + updateContentSize(); _labelRendererAdaptDirty = true; } @@ -363,7 +363,7 @@ void Text::disableEffect(LabelEffect effect) // only outline effect will affect the content size of label if (LabelEffect::OUTLINE == effect) { - updateContentSizeWithTextureSize(_labelRenderer->getContentSize()); + updateContentSize(); _labelRendererAdaptDirty = true; } } diff --git a/axmol/ui/UIText.h b/axmol/ui/UIText.h index a8d034a96a67..c8691c59892f 100644 --- a/axmol/ui/UIText.h +++ b/axmol/ui/UIText.h @@ -177,11 +177,11 @@ class AX_GUI_DLL Text : public Widget, public ax::BlendProtocol */ bool isTouchScaleChangeEnabled() const; - // override "getVirtualRendererSize" method of widget. - Vec2 getVirtualRendererSize() const override; + // override "getPreferredSize" method of widget. + Vec2 getPreferredSize() const override; - // override "getVirtualRenderer" method of widget. - Node* getVirtualRenderer() override; + // override "getRenderNode" method of widget. + Node* getRenderNode() override; /** Gets the render size in auto mode. * diff --git a/axmol/ui/UITextAtlas.cpp b/axmol/ui/UITextAtlas.cpp index 49eade734c2f..cee0f239cd0d 100644 --- a/axmol/ui/UITextAtlas.cpp +++ b/axmol/ui/UITextAtlas.cpp @@ -100,7 +100,7 @@ void TextAtlas::setProperty(std::string_view stringValue, _labelAtlasRenderer->setCharMap(_charMapFileName, _itemWidth, _itemHeight, (int)(_startCharMap[0])); _labelAtlasRenderer->setString(stringValue); - updateContentSizeWithTextureSize(_labelAtlasRenderer->getContentSize()); + updateContentSize(); _labelAtlasRendererAdaptDirty = true; // AXLOGD("cs w {}, h {}", _contentSize.width, _contentSize.height); } @@ -113,7 +113,7 @@ void TextAtlas::setString(std::string_view value) } _stringValue = value; _labelAtlasRenderer->setString(value); - updateContentSizeWithTextureSize(_labelAtlasRenderer->getContentSize()); + updateContentSize(); _labelAtlasRendererAdaptDirty = true; // AXLOGD("cssss w {}, h {}", _contentSize.width, _contentSize.height); } @@ -143,19 +143,19 @@ void TextAtlas::adaptRenderers() } } -Vec2 TextAtlas::getVirtualRendererSize() const +Vec2 TextAtlas::getPreferredSize() const { return _labelAtlasRenderer->getContentSize(); } -Node* TextAtlas::getVirtualRenderer() +Node* TextAtlas::getRenderNode() { return _labelAtlasRenderer; } void TextAtlas::labelAtlasScaleChangedWithSize() { - if (isAutoSizeEnabled()) + if (_autoSize) { _labelAtlasRenderer->setScale(1.0f); } diff --git a/axmol/ui/UITextAtlas.h b/axmol/ui/UITextAtlas.h index 09daed6270a6..79c064b41865 100644 --- a/axmol/ui/UITextAtlas.h +++ b/axmol/ui/UITextAtlas.h @@ -126,11 +126,11 @@ class AX_GUI_DLL TextAtlas : public Widget */ ssize_t getStringLength() const; - // override "getVirtualRendererSize" method of widget. - Vec2 getVirtualRendererSize() const override; + // override "getPreferredSize" method of widget. + Vec2 getPreferredSize() const override; - // override "getVirtualRenderer" method of widget. - Node* getVirtualRenderer() override; + // override "getRenderNode" method of widget. + Node* getRenderNode() override; /** * Returns the "class name" of widget. diff --git a/axmol/ui/UITextBMFont.cpp b/axmol/ui/UITextBMFont.cpp index c5c353b0c725..a5d249dcd73e 100644 --- a/axmol/ui/UITextBMFont.cpp +++ b/axmol/ui/UITextBMFont.cpp @@ -84,7 +84,7 @@ void TextBMFont::setFntFile(std::string_view fileName) _fntFileName = fileName; _labelBMFontRenderer->setBMFontFilePath(fileName); - updateContentSizeWithTextureSize(_labelBMFontRenderer->getContentSize()); + updateContentSize(); _labelBMFontRendererAdaptDirty = true; } @@ -96,7 +96,7 @@ void TextBMFont::setString(std::string_view value) } _stringValue = value; _labelBMFontRenderer->setString(value); - updateContentSizeWithTextureSize(_labelBMFontRenderer->getContentSize()); + updateContentSize(); _labelBMFontRendererAdaptDirty = true; } @@ -125,19 +125,19 @@ void TextBMFont::adaptRenderers() } } -Vec2 TextBMFont::getVirtualRendererSize() const +Vec2 TextBMFont::getPreferredSize() const { return _labelBMFontRenderer->getContentSize(); } -Node* TextBMFont::getVirtualRenderer() +Node* TextBMFont::getRenderNode() { return _labelBMFontRenderer; } void TextBMFont::labelBMFontScaleChangedWithSize() { - if (isAutoSizeEnabled()) + if (_autoSize) { _labelBMFontRenderer->setScale(1.0f); } diff --git a/axmol/ui/UITextBMFont.h b/axmol/ui/UITextBMFont.h index aa607cd76210..cfaed89d8713 100644 --- a/axmol/ui/UITextBMFont.h +++ b/axmol/ui/UITextBMFont.h @@ -88,8 +88,8 @@ class AX_GUI_DLL TextBMFont : public Widget */ ssize_t getStringLength() const; - Vec2 getVirtualRendererSize() const override; - Node* getVirtualRenderer() override; + Vec2 getPreferredSize() const override; + Node* getRenderNode() override; /** * Returns the "class name" of widget. */ diff --git a/axmol/ui/UIWidget.cpp b/axmol/ui/UIWidget.cpp index 270fb3d47cdb..9df21d36dd01 100644 --- a/axmol/ui/UIWidget.cpp +++ b/axmol/ui/UIWidget.cpp @@ -178,6 +178,7 @@ Widget::Widget() , _mouseEnabled(false) , _mouseListener(nullptr) , _mouseHitted(false) + , _isInternalSizeUpdate(false) {} Widget::~Widget() @@ -287,17 +288,17 @@ void Widget::setContentSize(const Vec2& contentSize) _customSize = contentSize; - if (_autoSize) - { - // Auto size mode: ignore manual size setting, use content size - ProtectedNode::setContentSize(getVirtualRendererSize()); - } - else + // When developer explicitly sets content size, disable auto-size mode + // This ensures the manually set size is respected and not overridden by content adaptation + // Exception: internal updates (from updateContentSize) should preserve _autoSize state + if (_autoSize && !_isInternalSizeUpdate) { - // Fixed size mode: use the size set by developer - ProtectedNode::setContentSize(_customSize); + _autoSize = false; } + // Fixed size mode: use the size set by developer + ProtectedNode::setContentSize(_customSize); + if (!_usingLayoutComponent && _running) { Widget* widgetParent = getWidgetParent(); @@ -353,7 +354,7 @@ void Widget::setSizePercent(const Vec2& percent) } if (isAutoSizeEnabled()) { - this->setContentSize(getVirtualRendererSize()); + this->setContentSize(getPreferredSize()); } else { @@ -378,7 +379,7 @@ void Widget::updateSizeAndPosition(const Vec2& parentSize) { if (isAutoSizeEnabled()) { - this->setContentSize(getVirtualRendererSize()); + this->setContentSize(getPreferredSize()); } else { @@ -402,7 +403,7 @@ void Widget::updateSizeAndPosition(const Vec2& parentSize) Vec2 cSize = Vec2(parentSize.width * _sizePercent.x, parentSize.height * _sizePercent.y); if (isAutoSizeEnabled()) { - this->setContentSize(getVirtualRendererSize()); + this->setContentSize(getPreferredSize()); } else { @@ -511,7 +512,7 @@ const Vec2& Widget::getSizePercent() return _sizePercent; } -Node* Widget::getVirtualRenderer() +Node* Widget::getRenderNode() { return this; } @@ -531,23 +532,31 @@ void Widget::onSizeChanged() } } -Vec2 Widget::getVirtualRendererSize() const +Vec2 Widget::getPreferredSize() const { return _contentSize; } -void Widget::updateContentSizeWithTextureSize(const Vec2& size) +void Widget::updateContentSize() { + auto preferredSize = getPreferredSize(); + + // Mark as internal update to prevent setContentSize from disabling _autoSize + _isInternalSizeUpdate = true; + if (_autoSize) { - // Auto size mode: update to the provided size (content size) - this->setContentSize(size); + // Auto size mode: update to the preferred size based on content + this->setContentSize(preferredSize); } else { // Fixed size mode: keep custom size unchanged this->setContentSize(_customSize); } + + // Reset internal flag + _isInternalSizeUpdate = false; } void Widget::setTouchEnabled(bool enable) @@ -1275,7 +1284,9 @@ void Widget::copyProperties(Widget* widget) setName(widget->getName()); setActionTag(widget->getActionTag()); _autoSize = widget->_autoSize; + _isInternalSizeUpdate = true; this->setContentSize(widget->_contentSize); + _isInternalSizeUpdate = false; _customSize = widget->_customSize; _sizeType = widget->getSizeType(); _sizePercent = widget->_sizePercent; @@ -1559,7 +1570,9 @@ void Widget::setAutoSizeEnabled(bool enable) else { // Switching to auto size mode: update to content size immediately - updateContentSizeWithTextureSize(getVirtualRendererSize()); + ProtectedNode::setContentSize(this->getPreferredSize()); + + onSizeChanged(); } } diff --git a/axmol/ui/UIWidget.h b/axmol/ui/UIWidget.h index 75f19d6fc639..7e31612b6e0a 100644 --- a/axmol/ui/UIWidget.h +++ b/axmol/ui/UIWidget.h @@ -538,19 +538,20 @@ class AX_GUI_DLL Widget : public ProtectedNode, public LayoutParameterProtocol LayoutParameter* getLayoutParameter() const override; /** - * Gets the inner Renderer node of widget. + * Gets the internal render node of widget. * - * For example, a button's Virtual Renderer is it's texture renderer. + * For example, a button's render node is its texture sprite. * * @return Node pointer. */ - virtual Node* getVirtualRenderer(); + virtual Node* getRenderNode(); /** - * Get the virtual renderer's size - *@return Widget virtual renderer size. + * Gets the preferred size of the internal render node. + * This is equivalent to getRenderNode()->getContentSize(). + * @return The render node's content size. */ - virtual Vec2 getVirtualRendererSize() const; + virtual Vec2 getPreferredSize() const; /** * Returns the string representation of widget class name @@ -813,7 +814,7 @@ class AX_GUI_DLL Widget : public ProtectedNode, public LayoutParameterProtocol virtual void copyClonedWidgetChildren(Widget* model); Widget* getWidgetParent(); - void updateContentSizeWithTextureSize(const Vec2& size); + virtual void updateContentSize(); bool isAncestorsEnabled(); Widget* getAncestorWidget(Node* node); @@ -832,6 +833,16 @@ class AX_GUI_DLL Widget : public ProtectedNode, public LayoutParameterProtocol bool _highlight; bool _affectByClipping; bool _propagateTouchEvents; + bool _hitted; + bool _flippedX; + bool _flippedY; + bool _focused; + bool _focusEnabled; + bool _mouseHitted; + + // Internal flag to bypass auto-size disabling in setContentSize + // Used when updateContentSize() needs to set size without changing _autoSize state + bool _isInternalSizeUpdate; BrightStyle _brightStyle; SizeType _sizeType; @@ -845,32 +856,15 @@ class AX_GUI_DLL Widget : public ProtectedNode, public LayoutParameterProtocol Vec2 _sizePercent; Vec2 _positionPercent; - bool _hitted; - // weak reference of the camera which made the widget passed the hit test when response touch begin event - // it's useful in the next touch move/end events const Camera* _hittedByCamera; EventListenerTouchOneByOne* _touchListener; Vec2 _touchBeganPosition; Vec2 _touchMovePosition; Vec2 _touchEndPosition; - bool _mouseHitted; - EventListenerMouse* _mouseListener; - - bool _flippedX; - bool _flippedY; - - // use map to enable switch back and forth for user layout parameters Map _layoutParameterDictionary; LayoutParameter::Type _layoutParameterType; - bool _focused; - bool _focusEnabled; - /** - * store the only one focused widget - */ - static Widget* _focusedWidget; // both layout & widget will be stored in this variable - Object* _touchEventListener; ccWidgetTouchCallback _touchEventCallback; ccWidgetClickCallback _clickEventListener; @@ -879,6 +873,9 @@ class AX_GUI_DLL Widget : public ProtectedNode, public LayoutParameterProtocol std::string _callbackType; std::string _callbackName; + EventListenerMouse* _mouseListener; + + static Widget* _focusedWidget; // both layout & widget will be stored in this variable private: class FocusNavigationController; static FocusNavigationController* _focusNavigationController; diff --git a/extensions/sceneio/src/sceneio/WidgetReader/TextFieldReader/TextFieldExReader.cpp b/extensions/sceneio/src/sceneio/WidgetReader/TextFieldReader/TextFieldExReader.cpp index fbc73a0f6ea1..48e9700078bb 100644 --- a/extensions/sceneio/src/sceneio/WidgetReader/TextFieldReader/TextFieldExReader.cpp +++ b/extensions/sceneio/src/sceneio/WidgetReader/TextFieldReader/TextFieldExReader.cpp @@ -372,7 +372,7 @@ void TextFieldExReader::setPropsWithFlatBuffers(ax::Node* node, const flatbuffer // InputField will enable IME when user interacts with it /*if (!textField->isIgnoreContentAdaptWithSize()) { - ((Label*)(textField->getVirtualRenderer()))->setLineBreakWithoutSpace(true); + ((Label*)(textField->getRenderNode()))->setLineBreakWithoutSpace(true); }*/ } diff --git a/extensions/sceneio/src/sceneio/WidgetReader/TextFieldReader/TextFieldReader.cpp b/extensions/sceneio/src/sceneio/WidgetReader/TextFieldReader/TextFieldReader.cpp index c55bba907927..4e559b64ddca 100644 --- a/extensions/sceneio/src/sceneio/WidgetReader/TextFieldReader/TextFieldReader.cpp +++ b/extensions/sceneio/src/sceneio/WidgetReader/TextFieldReader/TextFieldReader.cpp @@ -380,7 +380,7 @@ void TextFieldReader::setPropsWithFlatBuffers(ax::Node* node, const flatbuffers: auto widgetOptions = options->widgetOptions(); if (!textField->isIgnoreContentAdaptWithSize()) { - ((Label*)(textField->getVirtualRenderer()))->setLineBreakWithoutSpace(true); + ((Label*)(textField->getRenderNode()))->setLineBreakWithoutSpace(true); Size contentSize(widgetOptions->size()->width(), widgetOptions->size()->height()); textField->setContentSize(contentSize); } diff --git a/extensions/sceneio/src/sceneio/WidgetReader/TextReader/TextReader.cpp b/extensions/sceneio/src/sceneio/WidgetReader/TextReader/TextReader.cpp index 5ebfd8fa5f69..26af2c0dbd6b 100644 --- a/extensions/sceneio/src/sceneio/WidgetReader/TextReader/TextReader.cpp +++ b/extensions/sceneio/src/sceneio/WidgetReader/TextReader/TextReader.cpp @@ -566,7 +566,7 @@ void TextReader::setPropsWithFlatBuffers(ax::Node* node, const flatbuffers::Tabl label->setContentSize(contentSize); } - auto labelRenderer = dynamic_cast(label->getVirtualRenderer()); + auto labelRenderer = dynamic_cast(label->getRenderNode()); if (options->boldEnabled()) labelRenderer->enableBold(); if (options->underlineEnabled()) diff --git a/extensions/scripting/lua-bindings/auto/axlua_ui_auto.cpp b/extensions/scripting/lua-bindings/auto/axlua_ui_auto.cpp index 391d37491cb6..12ec4f7e5a4d 100644 --- a/extensions/scripting/lua-bindings/auto/axlua_ui_auto.cpp +++ b/extensions/scripting/lua-bindings/auto/axlua_ui_auto.cpp @@ -2910,7 +2910,7 @@ int lua_ax_ui_Widget_isIgnoreContentAdaptWithSize(lua_State* tolua_S) return 0; } -int lua_ax_ui_Widget_getVirtualRenderer(lua_State* tolua_S) +int lua_ax_ui_Widget_getRenderNode(lua_State* tolua_S) { int argc = 0; ax::ui::Widget* obj = nullptr; @@ -2930,7 +2930,7 @@ int lua_ax_ui_Widget_getVirtualRenderer(lua_State* tolua_S) #if _AX_DEBUG >= 1 if (!obj) { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_Widget_getVirtualRenderer'", nullptr); + tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_Widget_getRenderNode'", nullptr); return 0; } #endif @@ -2940,24 +2940,24 @@ int lua_ax_ui_Widget_getVirtualRenderer(lua_State* tolua_S) { if(!ok) { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_Widget_getVirtualRenderer'", nullptr); + tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_Widget_getRenderNode'", nullptr); return 0; } - auto&& ret = obj->getVirtualRenderer(); + auto&& ret = obj->getRenderNode(); object_to_luaval(tolua_S, "ax.Node",(ax::Node*)ret); return 1; } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.Widget:getVirtualRenderer",argc, 0); + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.Widget:getRenderNode",argc, 0); return 0; #if _AX_DEBUG >= 1 tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_Widget_getVirtualRenderer'.",&tolua_err); + tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_Widget_getRenderNode'.",&tolua_err); #endif return 0; } -int lua_ax_ui_Widget_getVirtualRendererSize(lua_State* tolua_S) +int lua_ax_ui_Widget_getPreferredSize(lua_State* tolua_S) { int argc = 0; ax::ui::Widget* obj = nullptr; @@ -2977,7 +2977,7 @@ int lua_ax_ui_Widget_getVirtualRendererSize(lua_State* tolua_S) #if _AX_DEBUG >= 1 if (!obj) { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_Widget_getVirtualRendererSize'", nullptr); + tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_Widget_getPreferredSize'", nullptr); return 0; } #endif @@ -2987,19 +2987,19 @@ int lua_ax_ui_Widget_getVirtualRendererSize(lua_State* tolua_S) { if(!ok) { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_Widget_getVirtualRendererSize'", nullptr); + tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_Widget_getPreferredSize'", nullptr); return 0; } - auto&& ret = obj->getVirtualRendererSize(); + auto&& ret = obj->getPreferredSize(); vec2_to_luaval(tolua_S, ret); return 1; } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.Widget:getVirtualRendererSize",argc, 0); + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.Widget:getPreferredSize",argc, 0); return 0; #if _AX_DEBUG >= 1 tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_Widget_getVirtualRendererSize'.",&tolua_err); + tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_Widget_getPreferredSize'.",&tolua_err); #endif return 0; @@ -4586,8 +4586,8 @@ int lua_register_ax_ui_Widget(lua_State* tolua_S) tolua_function(tolua_S,"getLayoutParameter",lua_ax_ui_Widget_getLayoutParameter); tolua_function(tolua_S,"ignoreContentAdaptWithSize",lua_ax_ui_Widget_ignoreContentAdaptWithSize); tolua_function(tolua_S,"isIgnoreContentAdaptWithSize",lua_ax_ui_Widget_isIgnoreContentAdaptWithSize); - tolua_function(tolua_S,"getVirtualRenderer",lua_ax_ui_Widget_getVirtualRenderer); - tolua_function(tolua_S,"getVirtualRendererSize",lua_ax_ui_Widget_getVirtualRendererSize); + tolua_function(tolua_S,"getRenderNode",lua_ax_ui_Widget_getRenderNode); + tolua_function(tolua_S,"getPreferredSize",lua_ax_ui_Widget_getPreferredSize); tolua_function(tolua_S,"clone",lua_ax_ui_Widget_clone); tolua_function(tolua_S,"updateSizeAndPosition",lua_ax_ui_Widget_updateSizeAndPosition); tolua_function(tolua_S,"setActionTag",lua_ax_ui_Widget_setActionTag); diff --git a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest.cpp b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest.cpp index c310d6eea99f..24d56bd829aa 100644 --- a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest.cpp +++ b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest.cpp @@ -94,7 +94,7 @@ bool UILayoutTest::init() Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png"); button_scale9->setScale9Enabled(true); - button_scale9->setContentSize(Size(100.0f, button_scale9->getVirtualRendererSize().height)); + button_scale9->setContentSize(Size(100.0f, button_scale9->getPreferredSize().height)); button_scale9->setPosition(Vec2(layout->getContentSize().width - button_scale9->getContentSize().width / 2.0f, button_scale9->getContentSize().height / 2.0f)); @@ -155,7 +155,7 @@ bool UILayoutTest_Color::init() Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png"); button_scale9->setScale9Enabled(true); - button_scale9->setContentSize(Size(100.0f, button_scale9->getVirtualRendererSize().height)); + button_scale9->setContentSize(Size(100.0f, button_scale9->getPreferredSize().height)); button_scale9->setPosition(Vec2(layout->getContentSize().width - button_scale9->getContentSize().width / 2.0f, button_scale9->getContentSize().height / 2.0f)); @@ -215,7 +215,7 @@ bool UILayoutTest_Gradient::init() Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png"); button_scale9->setScale9Enabled(true); - button_scale9->setContentSize(Size(100.0f, button_scale9->getVirtualRendererSize().height)); + button_scale9->setContentSize(Size(100.0f, button_scale9->getPreferredSize().height)); button_scale9->setPosition(Vec2(layout->getContentSize().width - button_scale9->getContentSize().width / 2.0f, button_scale9->getContentSize().height / 2.0f)); @@ -273,7 +273,7 @@ bool UILayoutTest_BackGroundImage::init() Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png"); button_scale9->setScale9Enabled(true); - button_scale9->setContentSize(Size(100.0f, button_scale9->getVirtualRendererSize().height)); + button_scale9->setContentSize(Size(100.0f, button_scale9->getPreferredSize().height)); button_scale9->setPosition(Vec2(layout->getContentSize().width - button_scale9->getContentSize().width / 2.0f, button_scale9->getContentSize().height / 2.0f)); @@ -350,7 +350,7 @@ bool UILayoutTest_BackGroundImage_Scale9::init() Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png"); button_scale9->setScale9Enabled(true); - button_scale9->setContentSize(Size(100.0f, button_scale9->getVirtualRendererSize().height)); + button_scale9->setContentSize(Size(100.0f, button_scale9->getPreferredSize().height)); button_scale9->setPosition(Vec2(layout->getContentSize().width - button_scale9->getContentSize().width / 2.0f, button_scale9->getContentSize().height / 2.0f)); layout->addChild(button_scale9); @@ -414,7 +414,7 @@ bool UILayoutTest_Layout_Linear_Vertical::init() Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png"); button_scale9->setScale9Enabled(true); - button_scale9->setContentSize(Size(100.0f, button_scale9->getVirtualRendererSize().height)); + button_scale9->setContentSize(Size(100.0f, button_scale9->getPreferredSize().height)); layout->addChild(button_scale9); LinearLayoutParameter* lp3 = LinearLayoutParameter::create(); @@ -482,7 +482,7 @@ bool UILayoutTest_Layout_Linear_Horizontal::init() Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png"); button_scale9->setScale9Enabled(true); - button_scale9->setContentSize(Size(100.0f, button_scale9->getVirtualRendererSize().height)); + button_scale9->setContentSize(Size(100.0f, button_scale9->getPreferredSize().height)); layout->addChild(button_scale9); LinearLayoutParameter* lp3 = LinearLayoutParameter::create(); diff --git a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest.cpp b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest.cpp index a35c1a809282..56299f503073 100644 --- a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest.cpp +++ b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest.cpp @@ -106,7 +106,7 @@ bool UIScrollViewTest_Vertical::init() Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png"); button_scale9->setScale9Enabled(true); - button_scale9->setContentSize(Size(100.0f, button_scale9->getVirtualRendererSize().height)); + button_scale9->setContentSize(Size(100.0f, button_scale9->getPreferredSize().height)); button_scale9->setPosition( Vec2(innerWidth / 2.0f, titleButton->getBottomBoundary() - titleButton->getContentSize().height)); scrollView->addChild(button_scale9); @@ -181,7 +181,7 @@ bool UIScrollViewTest_Horizontal::init() Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png"); button_scale9->setScale9Enabled(true); - button_scale9->setContentSize(Size(100.0f, button_scale9->getVirtualRendererSize().height)); + button_scale9->setContentSize(Size(100.0f, button_scale9->getPreferredSize().height)); button_scale9->setPosition( Vec2(titleButton->getRightBoundary() + titleButton->getContentSize().width / 2.0f, titleButton->getBottomBoundary() - titleButton->getContentSize().height / 2.0f)); @@ -439,7 +439,7 @@ bool UIScrollViewNestTest::init() Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png"); button_scale9->setScale9Enabled(true); - button_scale9->setContentSize(Size(100.0f, button_scale9->getVirtualRendererSize().height)); + button_scale9->setContentSize(Size(100.0f, button_scale9->getPreferredSize().height)); button_scale9->setPosition( Vec2(innerWidth / 2.0f, titleButton->getBottomBoundary() - titleButton->getContentSize().height)); scrollView->addChild(button_scale9); @@ -535,7 +535,7 @@ bool UIScrollViewRotated::init() Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png"); button_scale9->setScale9Enabled(true); - button_scale9->setContentSize(Size(100.0f, button_scale9->getVirtualRendererSize().height)); + button_scale9->setContentSize(Size(100.0f, button_scale9->getPreferredSize().height)); button_scale9->setPosition( Vec2(innerWidth / 2.0f, titleButton->getBottomBoundary() - titleButton->getContentSize().height)); scrollView->addChild(button_scale9); @@ -613,7 +613,7 @@ bool UIScrollViewDisableTest::init() Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png"); button_scale9->setScale9Enabled(true); - button_scale9->setContentSize(Size(100.0f, button_scale9->getVirtualRendererSize().height)); + button_scale9->setContentSize(Size(100.0f, button_scale9->getPreferredSize().height)); button_scale9->setPosition( Vec2(innerWidth / 2.0f, titleButton->getBottomBoundary() - titleButton->getContentSize().height)); scrollView->addChild(button_scale9); @@ -841,7 +841,7 @@ bool UIScrollViewStopScrollingTest::init() Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png"); button_scale9->setTitleText("Stop scrolling in 3 sec."); button_scale9->setScale9Enabled(true); - button_scale9->setContentSize(Size(120.0f, button_scale9->getVirtualRendererSize().height)); + button_scale9->setContentSize(Size(120.0f, button_scale9->getPreferredSize().height)); button_scale9->setPosition(Vec2(innerSize.width / 2.0f, innerSize.height / 2.0f)); button_scale9->addClickEventListener([this](Object*) { this->_remainingTime = 3.0f; }); _scrollView->addChild(button_scale9); @@ -950,7 +950,7 @@ bool UIScrollViewTest_Overlap::init() Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png"); button_scale9->setScale9Enabled(true); - button_scale9->setContentSize(Size(100.0f, button_scale9->getVirtualRendererSize().height)); + button_scale9->setContentSize(Size(100.0f, button_scale9->getPreferredSize().height)); button_scale9->setPosition( Vec2(innerWidth / 2.0f, titleButton->getBottomBoundary() - titleButton->getContentSize().height)); scrollView->addChild(button_scale9); @@ -995,7 +995,7 @@ bool UIScrollViewTest_Overlap::init() Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png"); button_scale9->setScale9Enabled(true); - button_scale9->setContentSize(Size(100.0f, button_scale9->getVirtualRendererSize().height)); + button_scale9->setContentSize(Size(100.0f, button_scale9->getPreferredSize().height)); button_scale9->setPosition( Vec2(titleButton->getRightBoundary() + titleButton->getContentSize().width / 2.0f, titleButton->getBottomBoundary() - titleButton->getContentSize().height / 2.0f)); diff --git a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextAtlasTest/UITextAtlasTest.cpp b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextAtlasTest/UITextAtlasTest.cpp index 08b83debfe6c..36093247040e 100644 --- a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextAtlasTest/UITextAtlasTest.cpp +++ b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextAtlasTest/UITextAtlasTest.cpp @@ -106,7 +106,7 @@ bool UITextAtlasETC1ShadowTest::init() } textAtlas->setPosition(Vec2((widgetSize.width) / 2, widgetSize.height / 2.0f)); _uiLayer->addChild(textAtlas); - auto labelAtlas = (Label*)textAtlas->getVirtualRenderer(); + auto labelAtlas = (Label*)textAtlas->getRenderNode(); labelAtlas->enableShadow(Color32::GREEN); _textAtlas = textAtlas; From 82b15b8ffee39083f52ae9b3a661439c0b697e53 Mon Sep 17 00:00:00 2001 From: halx99 Date: Mon, 18 May 2026 10:50:43 +0800 Subject: [PATCH 06/52] up --- axmol/ui/UIAbstractCheckButton.cpp | 4 +- axmol/ui/UIAbstractCheckButton.h | 4 +- axmol/ui/UIButton.cpp | 4 +- axmol/ui/UIButton.h | 4 +- axmol/ui/UIEditBox/UIEditBox.cpp | 4 +- axmol/ui/UIEditBox/UIEditBox.h | 4 +- axmol/ui/UIImageView.cpp | 4 +- axmol/ui/UIImageView.h | 4 +- axmol/ui/UIInputField.cpp | 312 +++++++++--------- axmol/ui/UIInputField.h | 79 +++-- axmol/ui/UILayout.cpp | 2 +- axmol/ui/UILoadingBar.cpp | 4 +- axmol/ui/UILoadingBar.h | 4 +- axmol/ui/UIMediaPlayer.cpp | 4 +- axmol/ui/UIMediaPlayer.h | 2 +- axmol/ui/UIRichText.cpp | 4 +- axmol/ui/UIRichText.h | 4 +- axmol/ui/UIScrollView.cpp | 4 +- axmol/ui/UIScrollView.h | 2 +- axmol/ui/UISlider.cpp | 4 +- axmol/ui/UISlider.h | 4 +- axmol/ui/UITabControl.cpp | 2 +- axmol/ui/UITabControl.h | 2 +- axmol/ui/UIText.cpp | 4 +- axmol/ui/UIText.h | 4 +- axmol/ui/UITextAtlas.cpp | 4 +- axmol/ui/UITextAtlas.h | 4 +- axmol/ui/UITextBMFont.cpp | 6 +- axmol/ui/UITextBMFont.h | 4 +- axmol/ui/UIWidget.cpp | 39 +-- axmol/ui/UIWidget.h | 4 +- .../UITextFieldTest/UIInputFieldTest.cpp | 2 +- 32 files changed, 258 insertions(+), 278 deletions(-) diff --git a/axmol/ui/UIAbstractCheckButton.cpp b/axmol/ui/UIAbstractCheckButton.cpp index c9ea0e01d9df..ef9f5ad61a07 100644 --- a/axmol/ui/UIAbstractCheckButton.cpp +++ b/axmol/ui/UIAbstractCheckButton.cpp @@ -107,7 +107,7 @@ bool AbstractCheckButton::init() return false; } -void AbstractCheckButton::initRenderer() +void AbstractCheckButton::initRenderNode() { _backGroundBoxRenderer = Sprite::create(); _backGroundSelectedBoxRenderer = Sprite::create(); @@ -405,7 +405,7 @@ void AbstractCheckButton::onSizeChanged() _frontCrossDisabledRendererAdaptDirty = true; } -void AbstractCheckButton::adaptRenderers() +void AbstractCheckButton::updateLayout() { if (_backGroundBoxRendererAdaptDirty) { diff --git a/axmol/ui/UIAbstractCheckButton.h b/axmol/ui/UIAbstractCheckButton.h index b17494ff3add..4b58d4713820 100644 --- a/axmol/ui/UIAbstractCheckButton.h +++ b/axmol/ui/UIAbstractCheckButton.h @@ -195,7 +195,7 @@ class AX_GUI_DLL AbstractCheckButton : public Widget */ virtual ~AbstractCheckButton(); - void initRenderer() override; + void initRenderNode() override; void onPressStateChangedToNormal() override; void onPressStateChangedToPressed() override; void onPressStateChangedToDisabled() override; @@ -222,7 +222,7 @@ class AX_GUI_DLL AbstractCheckButton : public Widget void frontCrossDisabledTextureScaleChangedWithSize(); void copySpecialProperties(Widget* model) override; - void adaptRenderers() override; + void updateLayout() override; protected: Sprite* _backGroundBoxRenderer; diff --git a/axmol/ui/UIButton.cpp b/axmol/ui/UIButton.cpp index 4ddd4e2b6e92..4c3c72be27e5 100644 --- a/axmol/ui/UIButton.cpp +++ b/axmol/ui/UIButton.cpp @@ -133,7 +133,7 @@ bool Button::init() return false; } -void Button::initRenderer() +void Button::initRenderNode() { _buttonNormalRenderer = Scale9Sprite::create(); _buttonClickedRenderer = Scale9Sprite::create(); @@ -678,7 +678,7 @@ void Button::onSizeChanged() _disabledTextureAdaptDirty = true; } -void Button::adaptRenderers() +void Button::updateLayout() { if (_normalTextureAdaptDirty) { diff --git a/axmol/ui/UIButton.h b/axmol/ui/UIButton.h index f385c4ef3074..4ab8ef5e31ba 100644 --- a/axmol/ui/UIButton.h +++ b/axmol/ui/UIButton.h @@ -322,7 +322,7 @@ class AX_GUI_DLL Button : public Widget virtual Vec2 getNormalTextureSize() const; protected: - void initRenderer() override; + void initRenderNode() override; void onPressStateChangedToNormal() override; void onPressStateChangedToPressed() override; void onPressStateChangedToDisabled() override; @@ -339,7 +339,7 @@ class AX_GUI_DLL Button : public Widget void pressedTextureScaleChangedWithSize(); void disabledTextureScaleChangedWithSize(); - void adaptRenderers() override; + void updateLayout() override; virtual void updateTitleLocation(); void updateContentSize() override; virtual void createTitleRenderer(); diff --git a/axmol/ui/UIEditBox/UIEditBox.cpp b/axmol/ui/UIEditBox/UIEditBox.cpp index 80bef7a79a17..d8928456b37c 100644 --- a/axmol/ui/UIEditBox/UIEditBox.cpp +++ b/axmol/ui/UIEditBox/UIEditBox.cpp @@ -171,7 +171,7 @@ bool EditBox::initWithSizeAndTexture(const Vec2& size, return false; } -void EditBox::initRenderer() +void EditBox::initRenderNode() { _normalRenderer = Scale9Sprite::create(); _pressedRenderer = Scale9Sprite::create(); @@ -720,7 +720,7 @@ void EditBox::onSizeChanged() _disabledTextureAdaptDirty = true; } -void EditBox::adaptRenderers() +void EditBox::updateLayout() { if (_normalTextureAdaptDirty) { diff --git a/axmol/ui/UIEditBox/UIEditBox.h b/axmol/ui/UIEditBox/UIEditBox.h index 617a6aedd290..b84e1f360b7c 100644 --- a/axmol/ui/UIEditBox/UIEditBox.h +++ b/axmol/ui/UIEditBox/UIEditBox.h @@ -636,7 +636,7 @@ class AX_GUI_DLL EditBox : public Widget, public IMEDelegate protected: void releaseUpEvent() override; - void initRenderer() override; + void initRenderNode() override; void onPressStateChangedToNormal() override; void onPressStateChangedToPressed() override; void onPressStateChangedToDisabled() override; @@ -653,7 +653,7 @@ class AX_GUI_DLL EditBox : public Widget, public IMEDelegate void pressedTextureScaleChangedWithSize(); void disabledTextureScaleChangedWithSize(); - void adaptRenderers() override; + void updateLayout() override; protected: void updatePosition(float dt); diff --git a/axmol/ui/UIImageView.cpp b/axmol/ui/UIImageView.cpp index 418e6dbdcffd..b1682f466f9c 100644 --- a/axmol/ui/UIImageView.cpp +++ b/axmol/ui/UIImageView.cpp @@ -107,7 +107,7 @@ bool ImageView::init(std::string_view imageFileName, TextureResType texType) return bRet; } -void ImageView::initRenderer() +void ImageView::initRenderNode() { _imageRenderer = Scale9Sprite::create(); _imageRenderer->setRenderingType(Scale9Sprite::RenderingType::SIMPLE); @@ -235,7 +235,7 @@ void ImageView::onSizeChanged() _imageRendererAdaptDirty = true; } -void ImageView::adaptRenderers() +void ImageView::updateLayout() { if (_imageRendererAdaptDirty) { diff --git a/axmol/ui/UIImageView.h b/axmol/ui/UIImageView.h index 44a5a1158d3d..0b5d16e259d7 100644 --- a/axmol/ui/UIImageView.h +++ b/axmol/ui/UIImageView.h @@ -148,10 +148,10 @@ class AX_GUI_DLL ImageView : public Widget, public ax::BlendProtocol virtual bool init(std::string_view imageFileName, TextureResType texType = TextureResType::LOCAL); protected: - void initRenderer() override; + void initRenderNode() override; void onSizeChanged() override; - void adaptRenderers() override; + void updateLayout() override; void loadTexture(SpriteFrame* spriteframe); void setupTexture(); diff --git a/axmol/ui/UIInputField.cpp b/axmol/ui/UIInputField.cpp index ba1d08952753..97c2f775a94a 100644 --- a/axmol/ui/UIInputField.cpp +++ b/axmol/ui/UIInputField.cpp @@ -44,6 +44,8 @@ namespace ax # define axbeep(t) #endif +static constexpr int INPUT_FIELD_RENDERER_Z = (-1); + static Label* _createLabel(std::string_view text, std::string_view font, float fontSize, @@ -185,27 +187,10 @@ static int _truncateUTF8String(const char* text, int limit, int& nb) return n; } -static void internalSetLableFont(Label* l, std::string_view fontName, float fontSize) +static Vec2 measureTextExtent(std::string_view s, std::string_view fontName, float fontSize) { - if (FileUtils::getInstance()->isFileExist(fontName)) - { - TTFConfig config = l->getTTFConfig(); - config.fontFilePath = fontName; - config.fontSize = fontSize; - l->setTTFConfig(config); - } - else - { - l->setSystemFontName(fontName); - l->requestSystemFontRefresh(); - l->setSystemFontSize(fontSize); - } -} - -static float internalCalcStringWidth(std::string_view s, std::string_view fontName, float fontSize) -{ - auto label = _createLabel(std::string{s}, fontName, fontSize); - return label->getContentSize().width; + auto label = _createLabel(s, fontName, fontSize); + return label->getContentSize(); } ////////////////////////////////////////////////////////////////////////// @@ -245,9 +230,14 @@ InputField::InputField() , _cursorVisible(false) , _continuousTouchDelayTimerID(nullptr) , _continuousTouchDelayTime(0.6) + , _useTouchArea(false) + , _textHAlignment(TextHAlignment::LEFT) , _textVAlignment(TextVAlignment::TOP) , _textAreaSize(Vec2::ZERO) -{} + +{ + setTouchEnabled(true); +} InputField::~InputField() { @@ -288,20 +278,27 @@ bool InputField::initWithPlaceHolder(std::string_view placeholder, _placeHolder = placeholder; + /// render label + _renderLabel = _createLabel(placeholder, fontName, fontSize); + if (!placeholder.empty()) + _renderLabel->setTextColor(_colorSpaceHolder); + this->addProtectedChild(_renderLabel, INPUT_FIELD_RENDERER_Z); + + /// selection layer _selectionLayer = DrawNode::create(); this->addProtectedChild(_selectionLayer); - _renderLabel = - _createLabel(placeholder, fontName, fontSize, Vec2::ZERO, TextHAlignment::CENTER, TextVAlignment::CENTER); - _renderLabel->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT); - if (!placeholder.empty()) - _renderLabel->setTextColor(_colorSpaceHolder); - this->addProtectedChild(_renderLabel); + // _renderLabel->getLineHeight(); - // _director->getScheduler()->runOnAxmolThread( - // [this] { _renderLabel->setPosition(Point(0, this->getContentSize().height / 2)); }); + /// cursor + _cursor = Sprite::createWithTexture(_director->getTextureCache()->getWhiteTexture()); + auto& originalSize = _cursor->getContentSize(); - __initCursor(fontSize, cursorWidth, cursorColor); + auto cursorHeight = measureTextExtent("M"sv, fontName, fontSize).height; + _cursor->setContentSize(Vec2{cursorWidth, cursorHeight}); + this->addProtectedChild(_cursor); + hideCursor(); + updateCursorPosition(); _fontName = fontName; _fontSize = fontSize; @@ -309,7 +306,7 @@ bool InputField::initWithPlaceHolder(std::string_view placeholder, _fontType = _systemFontUsed ? 0 : 1; using namespace std::string_view_literals; - _asteriskWidth = internalCalcStringWidth("*"sv, _fontName, _fontSize); + _asteriskWidth = measureTextExtent("*"sv, _fontName, _fontSize).width; // Initialize content size based on placeholder text updateContentSize(); @@ -347,9 +344,9 @@ void InputField::setTextFontName(std::string_view fontName) _fontName = fontName; using namespace std::string_view_literals; - _asteriskWidth = internalCalcStringWidth("*"sv, _fontName, _fontSize); - __updateCursorPosition(); - __updateSelectionLayer(); + _asteriskWidth = measureTextExtent("*"sv, _fontName, _fontSize).width; + updateCursorPosition(); + updateSelectionLayer(); } void InputField::setTextFontSize(float size) @@ -368,9 +365,9 @@ void InputField::setTextFontSize(float size) _fontSize = size; using namespace std::string_view_literals; - _asteriskWidth = internalCalcStringWidth("*"sv, _fontName, _fontSize); - __updateCursorPosition(); - __updateSelectionLayer(); + _asteriskWidth = measureTextExtent("*"sv, _fontName, _fontSize).width; + updateCursorPosition(); + updateSelectionLayer(); } float InputField::getTextFontSize() const @@ -392,15 +389,12 @@ bool InputField::attachWithIME() bool ret = IMEDelegate::attachWithIME(); if (ret) { - // Enable Widget's touch listener - setTouchEnabled(true); - // Initialize touch selection state _selectingByTouch = false; _selectionTouchMoved = false; // Enable keyboard listener for cursor control and shortcuts - if (_kbdListener == nullptr) + if (!_kbdListener) { _kbdListener = EventListenerKeyboard::create(); _kbdListener->onKeyPressed = [this](EventKeyboard::KeyCode code, Event*) { @@ -449,10 +443,10 @@ bool InputField::attachWithIME() switch (code) { case EventKeyboard::KeyCode::KEY_LEFT_ARROW: - this->__moveCursor(-1, _shiftKeyPressed); + this->moveCursor(-1, _shiftKeyPressed); break; case EventKeyboard::KeyCode::KEY_RIGHT_ARROW: - this->__moveCursor(1, _shiftKeyPressed); + this->moveCursor(1, _shiftKeyPressed); break; case EventKeyboard::KeyCode::KEY_DELETE: case EventKeyboard::KeyCode::KEY_KP_DELETE: @@ -487,8 +481,8 @@ bool InputField::attachWithIME() if (renderView) renderView->setIMEKeyboardState(true); - __updateCursorPosition(); - __showCursor(); + updateCursorPosition(); + showCursor(); dispatchEvent(EventType::ATTACH_WITH_IME); } return ret; @@ -505,7 +499,7 @@ bool InputField::detachWithIME() renderView->setIMEKeyboardState(false); // Remove keyboard listener - if (_kbdListener != nullptr) + if (_kbdListener) { _eventDispatcher->removeEventListener(_kbdListener); AX_SAFE_RELEASE_NULL(_kbdListener); @@ -514,7 +508,7 @@ bool InputField::detachWithIME() // Disable Widget's touch listener setTouchEnabled(false); - __hideCursor(); + hideCursor(); dispatchEvent(EventType::DETACH_WITH_IME); } return ret; @@ -543,26 +537,14 @@ void InputField::dispatchEvent(EventType eventType) } } -void InputField::openIME(void) -{ - AXLOGD("InputField:: openIME"); - this->attachWithIME(); -} - -void InputField::closeIME(void) -{ - AXLOGD("InputField:: closeIME"); - this->detachWithIME(); -} - bool InputField::canAttachWithIME() { - return true; //(_delegate) ? (! _delegate->onTextFieldAttachWithIME(this)) : true; + return true; } bool InputField::canDetachWithIME() { - return true; //(_delegate) ? (! _delegate->onTextFieldDetachWithIME(this)) : true; + return true; } void InputField::insertText(const char* text, size_t len) @@ -573,7 +555,7 @@ void InputField::insertText(const char* text, size_t len) } if (hasSelection()) - __deleteSelection(false); + deleteSelection(false); if (_charLimit > 0 && _charCount >= _charLimit) { // regard zero as unlimited @@ -597,22 +579,16 @@ void InputField::insertText(const char* text, size_t len) if (len > 0) { - // if (_delegate && _delegate->onTextFieldInsertText(this, insert.c_str(), len)) - //{ - // // delegate doesn't want to insert text - // return; - // } - std::string sText(_inputText); auto cursorPosition = static_cast(_insertPosUtf8); sText.insert(_insertPos, insert); // original is: sText.append(insert); // bool needUpdatePos this->setString(sText); - __setCursorPosition(cursorPosition + n, false); + setCursorPosition(cursorPosition + n, false); // this->contentDirty = true; - // __updateCursorPosition(); + // updateCursorPosition(); dispatchEvent(EventType::INSERT_TEXT); } @@ -622,21 +598,15 @@ void InputField::insertText(const char* text, size_t len) return; } - // '\n' inserted, let delegate process first - /*if (_delegate && _delegate->onTextFieldInsertText(this, "\n", 1)) - { - return; - }*/ - // if delegate hasn't processed, detach from IME by default - this->closeIME(); + detachWithIME(); } void InputField::deleteBackward(size_t numChars) { if (hasSelection()) { - __deleteSelection(true); + deleteSelection(true); return; } @@ -651,13 +621,13 @@ void InputField::deleteBackward(size_t numChars) { axbeep(0); // there is no string - // __updateCursorPosition(); + // updateCursorPosition(); return; } auto deleteChars = std::min(numChars, static_cast(_insertPosUtf8)); auto startUtf8 = static_cast(_insertPosUtf8) - deleteChars; - auto startByte = __getByteOffset(startUtf8); + auto startByte = getByteOffset(startUtf8); auto totalDeleteLen = static_cast(_insertPos) - startByte; // if (_delegate && _delegate->onTextFieldDeleteBackward(this, _inputText.c_str() + len - deleteLen, @@ -671,7 +641,7 @@ void InputField::deleteBackward(size_t numChars) if (len <= totalDeleteLen) { this->setString(""); - __setCursorPosition(0, false); + setCursorPosition(0, false); dispatchEvent(EventType::DELETE_BACKWARD); return; @@ -682,10 +652,10 @@ void InputField::deleteBackward(size_t numChars) text.erase(startByte, totalDeleteLen); this->setString(text); - __setCursorPosition(startUtf8, false); + setCursorPosition(startUtf8, false); - //__updateCursorPosition(); - // __moveCursor(-1); + // updateCursorPosition(); + // moveCursor(-1); dispatchEvent(EventType::DELETE_BACKWARD); } @@ -694,7 +664,7 @@ void InputField::handleDeleteKeyEvent() { if (hasSelection()) { - __deleteSelection(true); + deleteSelection(true); return; } @@ -709,11 +679,11 @@ void InputField::handleDeleteKeyEvent() { axbeep(0); // there is no string - // __updateCursorPosition(); + // updateCursorPosition(); return; } - auto nextByte = __getByteOffset(static_cast(_insertPosUtf8) + 1); + auto nextByte = getByteOffset(static_cast(_insertPosUtf8) + 1); auto deleteLen = nextByte - static_cast(_insertPos); // if (_delegate && _delegate->onTextFieldDeleteBackward(this, _inputText.c_str() + len - deleteLen, @@ -727,7 +697,7 @@ void InputField::handleDeleteKeyEvent() if (len <= deleteLen) { this->setString(""); - __setCursorPosition(0, false); + setCursorPosition(0, false); // this->contentDirty = true; @@ -739,10 +709,10 @@ void InputField::handleDeleteKeyEvent() std::string text = _inputText; // (inputText.c_str(), len - deleteLen); text.erase(_insertPos, deleteLen); - // __moveCursor(-1); + // moveCursor(-1); this->setString(text); - __setCursorPosition(_insertPosUtf8, false); + setCursorPosition(_insertPosUtf8, false); dispatchEvent(EventType::DELETE_BACKWARD); } @@ -845,16 +815,16 @@ void InputField::setString(std::string_view text) if (bInsertAtEnd) { - __setCursorPosition(_charCount, false); + setCursorPosition(_charCount, false); } else { - __setCursorPosition(std::min(oldInsertPosUtf8, _charCount), hasSelection()); + setCursorPosition(std::min(oldInsertPosUtf8, _charCount), hasSelection()); } _selectionStartUtf8 = std::min(_selectionStartUtf8, _charCount); _selectionEndUtf8 = std::min(_selectionEndUtf8, _charCount); - __updateSelectionLayer(); + updateSelectionLayer(); // Update content size to match the rendered text updateContentSize(); @@ -865,7 +835,31 @@ void InputField::updateContentSize() Widget::updateContentSize(); if (_autoSize) { - __updateSelectionLayer(); + updateSelectionLayer(); + } +} + +void InputField::onSizeChanged() +{ + Widget::onSizeChanged(); + _layoutDirty = true; +} + +void InputField::updateLayout() +{ + if (_layoutDirty) + { + _layoutDirty = false; + + if (_autoSize) + { + _renderLabel->setDimensions(this->getContentSize().width, _renderLabel->getContentSize().height); + } + + updateCursorPosition(); + updateSelectionLayer(); + + _renderLabel->setPosition(_contentSize.width / 2, _contentSize.height / 2); } } @@ -899,7 +893,7 @@ void InputField::setPasswordEnabled(bool value) { _secureTextEntry = value; this->setString(this->getString()); - __updateCursorPosition(); + updateCursorPosition(); } } @@ -910,13 +904,11 @@ bool InputField::isPasswordEnabled() const void InputField::setEnabled(bool bEnabled) { - if (this->_enabled != bEnabled) + if (_enabled != bEnabled) { + _enabled = bEnabled; if (!bEnabled) - { - this->closeIME(); - } - this->_enabled = bEnabled; + this->detachWithIME(); } } @@ -932,16 +924,16 @@ bool InputField::hasSelection() const void InputField::selectAll() { - __setSelection(0, _charCount); + setSelection(0, _charCount); _selectionAnchorUtf8 = 0; - __setCursorPosition(_charCount, true); + setCursorPosition(_charCount, true); } void InputField::clearSelection() { _selectionStartUtf8 = _selectionEndUtf8 = static_cast(_insertPosUtf8); _selectionAnchorUtf8 = static_cast(_insertPosUtf8); - __updateSelectionLayer(); + updateSelectionLayer(); } std::string InputField::getSelectedText() const @@ -949,8 +941,8 @@ std::string InputField::getSelectedText() const if (!hasSelection()) return {}; - auto startByte = __getByteOffset(_selectionStartUtf8); - auto endByte = __getByteOffset(_selectionEndUtf8); + auto startByte = getByteOffset(_selectionStartUtf8); + auto endByte = getByteOffset(_selectionEndUtf8); return _inputText.substr(startByte, endByte - startByte); } @@ -970,7 +962,7 @@ bool InputField::cutSelectionToClipboard() if (!_editable || !this->_enabled || !copySelectionToClipboard()) return false; - return __deleteSelection(true); + return deleteSelection(true); } bool InputField::pasteFromClipboard() @@ -989,7 +981,7 @@ bool InputField::pasteFromClipboard() void InputField::setSelectionColor(const Color& color) { _selectionColor = color; - __updateSelectionLayer(); + updateSelectionLayer(); } const Color& InputField::getSelectionColor() const @@ -1017,21 +1009,20 @@ void InputField::setClipboardText(std::string_view text) writeClipboardText(text); } -void InputField::__initCursor(int height, int width, const Color32& color) +void InputField::initCursor(int height, int width, const Color32& color) { _cursor = _createCursorSprite(Color32(color), height, width); this->addProtectedChild(_cursor); _cursor->setPosition(Point(0, this->getContentSize().height / 2)); - // nodes_layout::setNodeLB(_cursor, ax::Point::ZERO); - __hideCursor(); + hideCursor(); - __updateCursorPosition(); + updateCursorPosition(); } -void InputField::__showCursor(void) +void InputField::showCursor(void) { if (_cursor) { @@ -1041,7 +1032,7 @@ void InputField::__showCursor(void) } } -void InputField::__hideCursor(void) +void InputField::hideCursor(void) { if (_cursor) { @@ -1051,40 +1042,40 @@ void InputField::__hideCursor(void) } } -void InputField::__updateCursorPosition(void) +void InputField::updateCursorPosition(void) { - __setCursorPosition(static_cast(_insertPosUtf8), hasSelection()); + setCursorPosition(static_cast(_insertPosUtf8), hasSelection()); } -void InputField::__moveCursor(int direction) +void InputField::moveCursor(int direction) { - __moveCursor(direction, false); + moveCursor(direction, false); } -void InputField::__moveCursor(int direction, bool keepSelection) +void InputField::moveCursor(int direction, bool keepSelection) { auto cursorPosition = static_cast(_insertPosUtf8) + direction; cursorPosition = std::clamp(cursorPosition, 0, static_cast(_charCount)); - __setCursorPosition(static_cast(cursorPosition), keepSelection); + setCursorPosition(static_cast(cursorPosition), keepSelection); } -void InputField::__moveCursorTo(float x) +void InputField::moveCursorTo(float x) { - __moveCursorTo(x, false); + moveCursorTo(x, false); } -void InputField::__moveCursorTo(float x, bool keepSelection) +void InputField::moveCursorTo(float x, bool keepSelection) { - __setCursorPosition(__getCursorPositionFromX(x), keepSelection); + setCursorPosition(getCursorPositionFromX(x), keepSelection); } -void InputField::__setCursorPosition(std::size_t cursorPosition, bool keepSelection) +void InputField::setCursorPosition(std::size_t cursorPosition, bool keepSelection) { cursorPosition = std::min(cursorPosition, _charCount); if (keepSelection) { - __setSelection(_selectionAnchorUtf8, cursorPosition); + setSelection(_selectionAnchorUtf8, cursorPosition); } else { @@ -1094,16 +1085,16 @@ void InputField::__setCursorPosition(std::size_t cursorPosition, bool keepSelect } _insertPosUtf8 = static_cast(cursorPosition); - _insertPos = static_cast(__getByteOffset(cursorPosition)); + _insertPos = static_cast(getByteOffset(cursorPosition)); _cursorPos = _secureTextEntry ? static_cast(cursorPosition * strlen("\xe2\x80\xa2")) : _insertPos; if (_cursor) - _cursor->setPosition(Point(__getCursorX(cursorPosition), this->getContentSize().height / 2)); + _cursor->setPosition(Point(getCursorX(cursorPosition), this->getContentSize().height / 2)); - __updateSelectionLayer(); + updateSelectionLayer(); } -float InputField::__getCursorX(std::size_t cursorPosition) const +float InputField::getCursorX(std::size_t cursorPosition) const { cursorPosition = std::min(cursorPosition, _charCount); if (cursorPosition == 0 || _inputText.empty()) @@ -1116,10 +1107,10 @@ float InputField::__getCursorX(std::size_t cursorPosition) const if (byteOffset == std::string::npos) byteOffset = _inputText.length(); - return internalCalcStringWidth(std::string_view(_inputText.data(), byteOffset), _fontName, _fontSize); + return measureTextExtent(std::string_view(_inputText.data(), byteOffset), _fontName, _fontSize).width; } -std::size_t InputField::__getCursorPositionFromX(float x) const +std::size_t InputField::getCursorPositionFromX(float x) const { if (x <= 0 || _charCount == 0) return 0; @@ -1127,7 +1118,7 @@ std::size_t InputField::__getCursorPositionFromX(float x) const float previousX = 0; for (std::size_t i = 1; i <= _charCount; ++i) { - auto currentX = __getCursorX(i); + auto currentX = getCursorX(i); if (x < (previousX + currentX) * 0.5f) return i - 1; previousX = currentX; @@ -1136,7 +1127,7 @@ std::size_t InputField::__getCursorPositionFromX(float x) const return _charCount; } -std::size_t InputField::__getByteOffset(std::size_t cursorPosition) const +std::size_t InputField::getByteOffset(std::size_t cursorPosition) const { if (cursorPosition >= _charCount) return _inputText.length(); @@ -1145,16 +1136,16 @@ std::size_t InputField::__getByteOffset(std::size_t cursorPosition) const return byteOffset == std::string::npos ? _inputText.length() : byteOffset; } -void InputField::__setSelection(std::size_t start, std::size_t end) +void InputField::setSelection(std::size_t start, std::size_t end) { _selectionStartUtf8 = std::min(start, _charCount); _selectionEndUtf8 = std::min(end, _charCount); if (_selectionStartUtf8 > _selectionEndUtf8) std::swap(_selectionStartUtf8, _selectionEndUtf8); - __updateSelectionLayer(); + updateSelectionLayer(); } -void InputField::__updateSelectionLayer(void) +void InputField::updateSelectionLayer(void) { if (!_selectionLayer) return; @@ -1163,8 +1154,8 @@ void InputField::__updateSelectionLayer(void) if (!hasSelection()) return; - auto startX = __getCursorX(_selectionStartUtf8); - auto endX = __getCursorX(_selectionEndUtf8); + auto startX = getCursorX(_selectionStartUtf8); + auto endX = getCursorX(_selectionEndUtf8); if (endX <= startX) return; @@ -1176,19 +1167,19 @@ void InputField::__updateSelectionLayer(void) Vec2(endX, (this->getContentSize().height + height) * 0.5f), _selectionColor); } -bool InputField::__deleteSelection(bool notify) +bool InputField::deleteSelection(bool notify) { if (!_editable || !this->_enabled || !hasSelection()) return false; - auto startByte = __getByteOffset(_selectionStartUtf8); - auto endByte = __getByteOffset(_selectionEndUtf8); + auto startByte = getByteOffset(_selectionStartUtf8); + auto endByte = getByteOffset(_selectionEndUtf8); auto newCursor = _selectionStartUtf8; std::string text = _inputText; text.erase(startByte, endByte - startByte); this->setString(text); - __setCursorPosition(newCursor, false); + setCursorPosition(newCursor, false); if (notify) dispatchEvent(EventType::DELETE_BACKWARD); @@ -1199,15 +1190,14 @@ bool InputField::__deleteSelection(bool notify) ////////////////////////////////////////////////////////////////////////// // Touch Area and Hit Test ////////////////////////////////////////////////////////////////////////// -void InputField::setTouchSize(const Vec2& size) +void InputField::setTouchAreaSize(const Vec2& size) { - _touchWidth = size.width; - _touchHeight = size.height; + _touchAreaSize = size; } -Vec2 InputField::getTouchSize() const +Vec2 InputField::getTouchAreaSize() const { - return Vec2(_touchWidth, _touchHeight); + return _touchAreaSize; } void InputField::setTouchAreaEnabled(bool enable) @@ -1224,7 +1214,8 @@ bool InputField::hitTest(const Vec2& pt, const Camera* camera, Vec3* /*p*/) cons auto size = getContentSize(); auto anch = getAnchorPoint(); - Rect rect((size.width - _touchWidth) * anch.x, (size.height - _touchHeight) * anch.y, _touchWidth, _touchHeight); + Rect rect((size.width - _touchAreaSize.width) * anch.x, (size.height - _touchAreaSize.height) * anch.y, + _touchAreaSize.width, _touchAreaSize.height); return isScreenPointInRect(pt, camera, getWorldToNodeTransform(), rect, nullptr); } @@ -1314,14 +1305,13 @@ bool InputField::onTouchBegan(Touch* touch, Event* event) bool focus = _cursorVisible; if (focus && _continuousTouchCallback) { - auto worldPoint = touch->getLocation(); - _continuousTouchDelayTimerID = stimer::delay( - _continuousTouchDelayTime, [this, worldPoint]() { - if (_continuousTouchCallback) - { - _continuousTouchCallback(worldPoint); - } - }); + auto worldPoint = touch->getLocation(); + _continuousTouchDelayTimerID = stimer::delay(_continuousTouchDelayTime, [this, worldPoint]() { + if (_continuousTouchCallback) + { + _continuousTouchCallback(worldPoint); + } + }); } // Initialize selection state @@ -1333,7 +1323,7 @@ bool InputField::onTouchBegan(Touch* touch, Event* event) if (focus && _touchCursorControlEnabled) { auto renderLabelPoint = _renderLabel->convertToNodeSpace(touch->getLocation()); - _selectionAnchorUtf8 = __getCursorPositionFromX(renderLabelPoint.x); + _selectionAnchorUtf8 = getCursorPositionFromX(renderLabelPoint.x); } return true; @@ -1351,7 +1341,7 @@ void InputField::onTouchMoved(Touch* touch, Event* event) } auto renderLabelPoint = _renderLabel->convertToNodeSpace(touch->getLocation()); - __setCursorPosition(__getCursorPositionFromX(renderLabelPoint.x), true); + setCursorPosition(getCursorPositionFromX(renderLabelPoint.x), true); _selectionTouchMoved = hasSelection(); } @@ -1374,19 +1364,19 @@ void InputField::onTouchEnded(Touch* touch, Event* event) { if (!s_keyboardVisible || !_cursorVisible) { - openIME(); + attachWithIME(); } // Handle cursor positioning if enabled if (_touchCursorControlEnabled) { auto renderLabelPoint = _renderLabel->convertToNodeSpace(touch->getLocation()); - __moveCursorTo(renderLabelPoint.x, _selectionTouchMoved); + moveCursorTo(renderLabelPoint.x, _selectionTouchMoved); } } else { - closeIME(); + detachWithIME(); } _selectingByTouch = false; diff --git a/axmol/ui/UIInputField.h b/axmol/ui/UIInputField.h index 26caddd4b757..06c648f2ea5e 100644 --- a/axmol/ui/UIInputField.h +++ b/axmol/ui/UIInputField.h @@ -144,8 +144,8 @@ class AX_DLL InputField : public Widget, public IMEDelegate Vec2 getAutoRenderSize(); /// touch area - void setTouchSize(const Vec2& size); - Vec2 getTouchSize() const; + void setTouchAreaSize(const Vec2& size); + Vec2 getTouchAreaSize() const; void setTouchAreaEnabled(bool enable); bool hitTest(const Vec2& pt, const Camera* camera, Vec3* p) const override; @@ -213,10 +213,6 @@ class AX_DLL InputField : public Widget, public IMEDelegate void addEventListener(const InputFieldCallback& callback); // IMEDelegate interface - ////////////////////////////////////////////////////////////////////////// - void openIME(void); - void closeIME(void); - void insertText(const char* text, size_t len) override; protected: @@ -245,24 +241,24 @@ class AX_DLL InputField : public Widget, public IMEDelegate void updateContentSize(void) override; - void __initCursor(int height, int width = 6, const Color32& color = Color32::WHITE); - void __showCursor(void); - void __hideCursor(void); - void __updateCursorPosition(void); + void initCursor(int height, int width = 6, const Color32& color = Color32::WHITE); + void showCursor(void); + void hideCursor(void); + void updateCursorPosition(void); - void __moveCursor(int direction); - void __moveCursor(int direction, bool keepSelection); + void moveCursor(int direction); + void moveCursor(int direction, bool keepSelection); - void __moveCursorTo(float x); - void __moveCursorTo(float x, bool keepSelection); - void __setCursorPosition(std::size_t cursorPosition, bool keepSelection); - float __getCursorX(std::size_t cursorPosition) const; - std::size_t __getCursorPositionFromX(float x) const; - std::size_t __getByteOffset(std::size_t cursorPosition) const; + void moveCursorTo(float x); + void moveCursorTo(float x, bool keepSelection); + void setCursorPosition(std::size_t cursorPosition, bool keepSelection); + float getCursorX(std::size_t cursorPosition) const; + std::size_t getCursorPositionFromX(float x) const; + std::size_t getByteOffset(std::size_t cursorPosition) const; - void __setSelection(std::size_t start, std::size_t end); - void __updateSelectionLayer(void); - bool __deleteSelection(bool notify); + void setSelection(std::size_t start, std::size_t end); + void updateSelectionLayer(void); + bool deleteSelection(bool notify); /** * @brief Dispatch event to the callback. @@ -271,11 +267,29 @@ class AX_DLL InputField : public Widget, public IMEDelegate void dispatchEvent(EventType eventType); protected: - bool _systemFontUsed; + void updateLayout() override; + void onSizeChanged() override; + + // Override Widget's touch event handlers + bool onTouchBegan(Touch* touch, Event* event) override; + void onTouchMoved(Touch* touch, Event* event) override; + void onTouchEnded(Touch* touch, Event* event) override; + void onTouchCancelled(Touch* touch, Event* event) override; + std::string _fontName; float _fontSize; + bool _systemFontUsed; bool _editable; + bool _layoutDirty{true}; + bool _secureTextEntry; + bool _cursorVisible; + bool _touchCursorControlEnabled; + bool _selectingByTouch; + bool _selectionTouchMoved; + bool _ctrlKeyPressed; + bool _shiftKeyPressed; + bool _useTouchArea; Label* _renderLabel; @@ -286,10 +300,8 @@ class AX_DLL InputField : public Widget, public IMEDelegate Color32 _colorSpaceHolder; Color32 _colorText; - bool _secureTextEntry; - Sprite* _cursor; - bool _cursorVisible; + DrawNode* _selectionLayer; Color _selectionColor; std::size_t _selectionStartUtf8; @@ -302,11 +314,6 @@ class AX_DLL InputField : public Widget, public IMEDelegate EventListenerKeyboard* _kbdListener; - bool _touchCursorControlEnabled; - bool _selectingByTouch; - bool _selectionTouchMoved; - bool _ctrlKeyPressed; - bool _shiftKeyPressed; float _asteriskWidth; int _fontType; @@ -317,18 +324,8 @@ class AX_DLL InputField : public Widget, public IMEDelegate /// Event callback InputFieldCallback _eventCallback; - -protected: - // Override Widget's touch event handlers - bool onTouchBegan(Touch* touch, Event* event) override; - void onTouchMoved(Touch* touch, Event* event) override; - void onTouchEnded(Touch* touch, Event* event) override; - void onTouchCancelled(Touch* touch, Event* event) override; - /// Touch area - float _touchWidth; - float _touchHeight; - bool _useTouchArea; + Vec2 _touchAreaSize; /// Text alignment TextHAlignment _textHAlignment; diff --git a/axmol/ui/UILayout.cpp b/axmol/ui/UILayout.cpp index e20b148953fc..e4f0a64117ed 100644 --- a/axmol/ui/UILayout.cpp +++ b/axmol/ui/UILayout.cpp @@ -209,7 +209,7 @@ void Layout::visit(Renderer* renderer, const Mat4& parentTransform, uint32_t par if (FLAGS_TRANSFORM_DIRTY & parentFlags || _transformUpdated || _contentSizeDirty) _clippingRectDirty = true; - adaptRenderers(); + updateLayout(); doLayout(); if (_clippingEnabled) diff --git a/axmol/ui/UILoadingBar.cpp b/axmol/ui/UILoadingBar.cpp index 1ce0fc1eb8ff..965ec66a9f53 100644 --- a/axmol/ui/UILoadingBar.cpp +++ b/axmol/ui/UILoadingBar.cpp @@ -92,7 +92,7 @@ LoadingBar* LoadingBar::create(std::string_view textureName, TextureResType texT return nullptr; } -void LoadingBar::initRenderer() +void LoadingBar::initRenderNode() { _barRenderer = Scale9Sprite::create(); _barRenderer->setScale9Enabled(false); @@ -308,7 +308,7 @@ void LoadingBar::onSizeChanged() _barRendererAdaptDirty = true; } -void LoadingBar::adaptRenderers() +void LoadingBar::updateLayout() { if (_barRendererAdaptDirty) { diff --git a/axmol/ui/UILoadingBar.h b/axmol/ui/UILoadingBar.h index c56102051088..3ee82bedf812 100644 --- a/axmol/ui/UILoadingBar.h +++ b/axmol/ui/UILoadingBar.h @@ -172,7 +172,7 @@ class AX_GUI_DLL LoadingBar : public Widget ResourceData getRenderFile(); protected: - void initRenderer() override; + void initRenderNode() override; void onSizeChanged() override; void setScale9Scale(); @@ -183,7 +183,7 @@ class AX_GUI_DLL LoadingBar : public Widget void handleSpriteFlipX(); void loadTexture(SpriteFrame* spriteframe); - void adaptRenderers() override; + void updateLayout() override; Widget* createCloneInstance() override; void copySpecialProperties(Widget* model) override; diff --git a/axmol/ui/UIMediaPlayer.cpp b/axmol/ui/UIMediaPlayer.cpp index 125135418f78..5a45853fa8e4 100644 --- a/axmol/ui/UIMediaPlayer.cpp +++ b/axmol/ui/UIMediaPlayer.cpp @@ -699,9 +699,9 @@ bool BasicMediaController::init() return true; } -void BasicMediaController::initRenderer() +void BasicMediaController::initRenderNode() { - Widget::initRenderer(); + Widget::initRenderNode(); // scheduleOnce is used to create the controls on the next update // loop. This is a work-around for a RenderTexture issue diff --git a/axmol/ui/UIMediaPlayer.h b/axmol/ui/UIMediaPlayer.h index e7e53afd96ef..48e47532d2ba 100644 --- a/axmol/ui/UIMediaPlayer.h +++ b/axmol/ui/UIMediaPlayer.h @@ -106,7 +106,7 @@ class AX_GUI_DLL BasicMediaController : public MediaController static BasicMediaController* create(MediaPlayer* mediaPlayer); bool init() override; - void initRenderer() override; + void initRenderNode() override; void onPressStateChangedToPressed() override; void setContentSize(const Vec2& contentSize) override; diff --git a/axmol/ui/UIRichText.cpp b/axmol/ui/UIRichText.cpp index ddd8e8b76f85..d9ebbc4fd6a5 100644 --- a/axmol/ui/UIRichText.cpp +++ b/axmol/ui/UIRichText.cpp @@ -1335,7 +1335,7 @@ bool RichText::setString(std::string_view text) return true; } -void RichText::initRenderer() {} +void RichText::initRenderNode() {} void RichText::insertElement(RichElement* element, int index) { @@ -2456,7 +2456,7 @@ float RichText::stripTrailingWhitespace(const Vector& row) return 0.0f; } -void RichText::adaptRenderers() +void RichText::updateLayout() { this->formatText(); } diff --git a/axmol/ui/UIRichText.h b/axmol/ui/UIRichText.h index 0188a72c53b0..90b8f09a96ea 100644 --- a/axmol/ui/UIRichText.h +++ b/axmol/ui/UIRichText.h @@ -591,9 +591,9 @@ class AX_GUI_DLL RichText : public Widget bool setString(std::string_view text); protected: - void adaptRenderers() override; + void updateLayout() override; - void initRenderer() override; + void initRenderNode() override; void pushToContainer(Node* renderer); void handleTextRenderer(std::string_view text, std::string_view fontName, diff --git a/axmol/ui/UIScrollView.cpp b/axmol/ui/UIScrollView.cpp index dba3090d2ff2..69ecc90a52ff 100644 --- a/axmol/ui/UIScrollView.cpp +++ b/axmol/ui/UIScrollView.cpp @@ -138,9 +138,9 @@ bool ScrollView::init() return false; } -void ScrollView::initRenderer() +void ScrollView::initRenderNode() { - Layout::initRenderer(); + Layout::initRenderNode(); _innerContainer = Layout::create(); _innerContainer->setColor(Color32::WHITE); _innerContainer->setCascadeColorEnabled(true); diff --git a/axmol/ui/UIScrollView.h b/axmol/ui/UIScrollView.h index 7f87f6c6afa8..71d02651d342 100644 --- a/axmol/ui/UIScrollView.h +++ b/axmol/ui/UIScrollView.h @@ -614,7 +614,7 @@ class AX_GUI_DLL ScrollView : public Layout RIGHT, }; - void initRenderer() override; + void initRenderNode() override; void onSizeChanged() override; void doLayout() override; diff --git a/axmol/ui/UISlider.cpp b/axmol/ui/UISlider.cpp index 8f6e1dbbd503..a59787c9a23b 100644 --- a/axmol/ui/UISlider.cpp +++ b/axmol/ui/UISlider.cpp @@ -128,7 +128,7 @@ bool Slider::init() return false; } -void Slider::initRenderer() +void Slider::initRenderNode() { _barRenderer = Scale9Sprite::create(); _progressBarRenderer = Scale9Sprite::create(); @@ -573,7 +573,7 @@ void Slider::onSizeChanged() _progressBarRendererDirty = true; } -void Slider::adaptRenderers() +void Slider::updateLayout() { if (_barRendererAdaptDirty) { diff --git a/axmol/ui/UISlider.h b/axmol/ui/UISlider.h index 3f983e89571c..71561cf9ca08 100644 --- a/axmol/ui/UISlider.h +++ b/axmol/ui/UISlider.h @@ -281,7 +281,7 @@ class AX_GUI_DLL Slider : public Widget bool init() override; protected: - void initRenderer() override; + void initRenderNode() override; float getPercentWithBallPos(const Vec2& pt) const; void percentChangedEvent(EventType event); void onPressStateChangedToNormal() override; @@ -301,7 +301,7 @@ class AX_GUI_DLL Slider : public Widget void progressBarRendererScaleChangedWithSize(); Widget* createCloneInstance() override; void copySpecialProperties(Widget* model) override; - void adaptRenderers() override; + void updateLayout() override; protected: Scale9Sprite* _barRenderer; diff --git a/axmol/ui/UITabControl.cpp b/axmol/ui/UITabControl.cpp index 55aa75cf483e..6f5c458f7ce2 100644 --- a/axmol/ui/UITabControl.cpp +++ b/axmol/ui/UITabControl.cpp @@ -528,7 +528,7 @@ TabHeader* TabHeader::create(std::string_view titleStr, return nullptr; } -void TabHeader::initRenderer() +void TabHeader::initRenderNode() { _backGroundBoxRenderer = Sprite::create(); _backGroundSelectedBoxRenderer = Sprite::create(); diff --git a/axmol/ui/UITabControl.h b/axmol/ui/UITabControl.h index 810f3c6404cc..4f31a37dc8fa 100644 --- a/axmol/ui/UITabControl.h +++ b/axmol/ui/UITabControl.h @@ -159,7 +159,7 @@ class AX_GUI_DLL TabHeader : public AbstractCheckButton TabHeader(); ~TabHeader(); - void initRenderer() override; + void initRenderNode() override; void onSizeChanged() override; void updateContentSize(); diff --git a/axmol/ui/UIText.cpp b/axmol/ui/UIText.cpp index 3059b71b8c66..f962eeda48a3 100644 --- a/axmol/ui/UIText.cpp +++ b/axmol/ui/UIText.cpp @@ -102,7 +102,7 @@ bool Text::init(std::string_view textContent, std::string_view fontName, float f return ret; } -void Text::initRenderer() +void Text::initRenderNode() { _labelRenderer = Label::create(); addProtectedChild(_labelRenderer, LABEL_RENDERER_Z, -1); @@ -269,7 +269,7 @@ void Text::onSizeChanged() _labelRendererAdaptDirty = true; } -void Text::adaptRenderers() +void Text::updateLayout() { if (_labelRendererAdaptDirty) { diff --git a/axmol/ui/UIText.h b/axmol/ui/UIText.h index c8691c59892f..8093a404a1c8 100644 --- a/axmol/ui/UIText.h +++ b/axmol/ui/UIText.h @@ -342,7 +342,7 @@ class AX_GUI_DLL Text : public Widget, public ax::BlendProtocol virtual bool init(std::string_view textContent, std::string_view fontName, float fontSize); protected: - void initRenderer() override; + void initRenderNode() override; void onPressStateChangedToNormal() override; void onPressStateChangedToPressed() override; void onPressStateChangedToDisabled() override; @@ -351,7 +351,7 @@ class AX_GUI_DLL Text : public Widget, public ax::BlendProtocol void labelScaleChangedWithSize(); Widget* createCloneInstance() override; void copySpecialProperties(Widget* model) override; - void adaptRenderers() override; + void updateLayout() override; protected: bool _touchScaleChangeEnabled; diff --git a/axmol/ui/UITextAtlas.cpp b/axmol/ui/UITextAtlas.cpp index cee0f239cd0d..8a4ca60e513b 100644 --- a/axmol/ui/UITextAtlas.cpp +++ b/axmol/ui/UITextAtlas.cpp @@ -61,7 +61,7 @@ TextAtlas* TextAtlas::create() return nullptr; } -void TextAtlas::initRenderer() +void TextAtlas::initRenderNode() { _labelAtlasRenderer = Label::create(); _labelAtlasRenderer->setAnchorPoint(Point::ANCHOR_MIDDLE); @@ -134,7 +134,7 @@ void TextAtlas::onSizeChanged() _labelAtlasRendererAdaptDirty = true; } -void TextAtlas::adaptRenderers() +void TextAtlas::updateLayout() { if (_labelAtlasRendererAdaptDirty) { diff --git a/axmol/ui/UITextAtlas.h b/axmol/ui/UITextAtlas.h index 79c064b41865..ffcceb562bd8 100644 --- a/axmol/ui/UITextAtlas.h +++ b/axmol/ui/UITextAtlas.h @@ -139,12 +139,12 @@ class AX_GUI_DLL TextAtlas : public Widget /** */ - void adaptRenderers() override; + void updateLayout() override; ResourceData getRenderFile(); protected: - void initRenderer() override; + void initRenderNode() override; void onSizeChanged() override; void labelAtlasScaleChangedWithSize(); diff --git a/axmol/ui/UITextBMFont.cpp b/axmol/ui/UITextBMFont.cpp index a5d249dcd73e..7b1ac970b606 100644 --- a/axmol/ui/UITextBMFont.cpp +++ b/axmol/ui/UITextBMFont.cpp @@ -69,7 +69,7 @@ TextBMFont* TextBMFont::create(std::string_view text, std::string_view filename) return nullptr; } -void TextBMFont::initRenderer() +void TextBMFont::initRenderNode() { _labelBMFontRenderer = ax::Label::create(); addProtectedChild(_labelBMFontRenderer, LABELBMFONT_RENDERER_Z, -1); @@ -116,7 +116,7 @@ void TextBMFont::onSizeChanged() _labelBMFontRendererAdaptDirty = true; } -void TextBMFont::adaptRenderers() +void TextBMFont::updateLayout() { if (_labelBMFontRendererAdaptDirty) { @@ -188,7 +188,7 @@ ResourceData TextBMFont::getRenderFile() void TextBMFont::resetRender() { this->removeProtectedChild(_labelBMFontRenderer); - this->initRenderer(); + this->initRenderNode(); } } // namespace ui diff --git a/axmol/ui/UITextBMFont.h b/axmol/ui/UITextBMFont.h index cfaed89d8713..707abd3ac27e 100644 --- a/axmol/ui/UITextBMFont.h +++ b/axmol/ui/UITextBMFont.h @@ -103,13 +103,13 @@ class AX_GUI_DLL TextBMFont : public Widget void resetRender(); protected: - void initRenderer() override; + void initRenderNode() override; void onSizeChanged() override; void labelBMFontScaleChangedWithSize(); Widget* createCloneInstance() override; void copySpecialProperties(Widget* model) override; - void adaptRenderers() override; + void updateLayout() override; protected: Label* _labelBMFontRenderer; diff --git a/axmol/ui/UIWidget.cpp b/axmol/ui/UIWidget.cpp index 9df21d36dd01..bc71a758d38e 100644 --- a/axmol/ui/UIWidget.cpp +++ b/axmol/ui/UIWidget.cpp @@ -178,7 +178,6 @@ Widget::Widget() , _mouseEnabled(false) , _mouseListener(nullptr) , _mouseHitted(false) - , _isInternalSizeUpdate(false) {} Widget::~Widget() @@ -217,7 +216,7 @@ bool Widget::init() { if (ProtectedNode::init()) { - initRenderer(); + initRenderNode(); setBright(true); onFocusChanged = AX_CALLBACK_2(Widget::onFocusChange, this); onNextFocusedWidget = nullptr; @@ -247,7 +246,7 @@ void Widget::visit(Renderer* renderer, const Mat4& parentTransform, uint32_t par { if (_visible) { - adaptRenderers(); + updateLayout(); ProtectedNode::visit(renderer, parentTransform, parentFlags); } } @@ -263,7 +262,7 @@ void Widget::setEnabled(bool enabled) setBright(enabled); } -void Widget::initRenderer() {} +void Widget::initRenderNode() {} LayoutComponent* Widget::getOrCreateLayoutComponent() { @@ -290,8 +289,7 @@ void Widget::setContentSize(const Vec2& contentSize) // When developer explicitly sets content size, disable auto-size mode // This ensures the manually set size is respected and not overridden by content adaptation - // Exception: internal updates (from updateContentSize) should preserve _autoSize state - if (_autoSize && !_isInternalSizeUpdate) + if (_autoSize) { _autoSize = false; } @@ -354,12 +352,13 @@ void Widget::setSizePercent(const Vec2& percent) } if (isAutoSizeEnabled()) { - this->setContentSize(getPreferredSize()); + ProtectedNode::setContentSize(getPreferredSize()); } else { - this->setContentSize(cSize); + ProtectedNode::setContentSize(cSize); } + _customSize = cSize; } } @@ -540,23 +539,17 @@ Vec2 Widget::getPreferredSize() const void Widget::updateContentSize() { auto preferredSize = getPreferredSize(); - - // Mark as internal update to prevent setContentSize from disabling _autoSize - _isInternalSizeUpdate = true; - + if (_autoSize) { // Auto size mode: update to the preferred size based on content - this->setContentSize(preferredSize); + ProtectedNode::setContentSize(preferredSize); } else { // Fixed size mode: keep custom size unchanged - this->setContentSize(_customSize); + ProtectedNode::setContentSize(_customSize); } - - // Reset internal flag - _isInternalSizeUpdate = false; } void Widget::setTouchEnabled(bool enable) @@ -1283,15 +1276,15 @@ void Widget::copyProperties(Widget* widget) setTag(widget->getTag()); setName(widget->getName()); setActionTag(widget->getActionTag()); - _autoSize = widget->_autoSize; + _autoSize = widget->_autoSize; _isInternalSizeUpdate = true; this->setContentSize(widget->_contentSize); _isInternalSizeUpdate = false; - _customSize = widget->_customSize; - _sizeType = widget->getSizeType(); - _sizePercent = widget->_sizePercent; - _positionType = widget->_positionType; - _positionPercent = widget->_positionPercent; + _customSize = widget->_customSize; + _sizeType = widget->getSizeType(); + _sizePercent = widget->_sizePercent; + _positionType = widget->_positionType; + _positionPercent = widget->_positionPercent; setPosition(widget->getPosition()); setAnchorPoint(widget->getAnchorPoint()); setScaleX(widget->getScaleX()); diff --git a/axmol/ui/UIWidget.h b/axmol/ui/UIWidget.h index 7e31612b6e0a..4c8102b388ea 100644 --- a/axmol/ui/UIWidget.h +++ b/axmol/ui/UIWidget.h @@ -788,7 +788,7 @@ class AX_GUI_DLL Widget : public ProtectedNode, public LayoutParameterProtocol virtual void onSizeChanged(); // initializes renderer of widget. - virtual void initRenderer(); + virtual void initRenderNode(); // call back function called widget's state changed to normal. virtual void onPressStateChangedToNormal(); @@ -805,7 +805,7 @@ class AX_GUI_DLL Widget : public ProtectedNode, public LayoutParameterProtocol virtual void releaseUpEvent(); virtual void cancelUpEvent(); - virtual void adaptRenderers() {}; + virtual void updateLayout() {}; void updateChildrenDisplayedRGBA(); void copyProperties(Widget* model); diff --git a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextFieldTest/UIInputFieldTest.cpp b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextFieldTest/UIInputFieldTest.cpp index 3ecd77065b8c..caa5382b37e6 100644 --- a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextFieldTest/UIInputFieldTest.cpp +++ b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextFieldTest/UIInputFieldTest.cpp @@ -65,7 +65,7 @@ bool UIInputFieldTest::init() // Create the inputfield InputField* inputField = InputField::create("input words here", "Arial", 30); - inputField->setTextHorizontalAlignment(TextHAlignment::CENTER); + inputField->setTextHorizontalAlignment(TextHAlignment::LEFT); inputField->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); // Set up event listener for InputField From bde08231391ba35a59f9dd22cf1e6b040c1afc97 Mon Sep 17 00:00:00 2001 From: halx99 Date: Mon, 18 May 2026 12:45:14 +0800 Subject: [PATCH 07/52] fix cursor postion when horiz alignemt not left --- axmol/ui/UIInputField.cpp | 248 +++++++++--------- axmol/ui/UIInputField.h | 17 +- .../UITextFieldTest/UIInputFieldTest.cpp | 2 +- 3 files changed, 135 insertions(+), 132 deletions(-) diff --git a/axmol/ui/UIInputField.cpp b/axmol/ui/UIInputField.cpp index 97c2f775a94a..7bd47db5d70c 100644 --- a/axmol/ui/UIInputField.cpp +++ b/axmol/ui/UIInputField.cpp @@ -63,60 +63,6 @@ static Label* _createLabel(std::string_view text, } } -static bool _checkVisibility(Node* theNode) -{ - // AX_ASSERT(theNode != NULL); - bool visible = false; - for (Node* ptr = theNode; (ptr != nullptr && (visible = ptr->isVisible())); ptr = ptr->getParent()) - ; - return visible; -} - -static bool _containsTouchPoint(ax::Node* target, ax::Touch* touch) -{ - assert(target != nullptr); - - ax::Point pt = target->convertTouchToNodeSpace(touch); - - const Vec2& size = target->getContentSize(); - - ax::Rect rc(0, 0, size.width, size.height); - - bool contains = (rc.containsPoint(pt)); - - // AXLOGD("check {:#x} coordinate:({}, {}), contains:{}", target, pt.x, pt.y, contains); - return contains; -} - -static Sprite* _createCursorSprite(const Color32& color, int height, int width) -{ - unsigned int* pixels((unsigned int*)malloc(height * width * sizeof(unsigned int))); - - // Fill Pixels - uint32_t* ptr = pixels; - const Color32 fillColor = Color32::WHITE; - for (int i = 0; i < height * width; ++i) - { - ptr[i] = (uint32_t)fillColor.a << 24 | (uint32_t)fillColor.b << 16 | (uint32_t)fillColor.g << 8 | - (uint32_t)fillColor.r; // 0xffffffff; - } - - // create cursor by pixels - Texture2D* texture = new Texture2D(); - - texture->initWithData(pixels, height * width * sizeof(unsigned int), rhi::PixelFormat::RGBA8, width, height); - - auto cursor = Sprite::createWithTexture(texture); - - cursor->setColor(color); - - texture->release(); - - free(pixels); - - return cursor; -} - namespace ui { @@ -498,17 +444,10 @@ bool InputField::detachWithIME() if (renderView) renderView->setIMEKeyboardState(false); - // Remove keyboard listener - if (_kbdListener) - { - _eventDispatcher->removeEventListener(_kbdListener); - AX_SAFE_RELEASE_NULL(_kbdListener); - } - - // Disable Widget's touch listener - setTouchEnabled(false); - + // Hide cursor immediately hideCursor(); + + // Dispatch event before removing listeners dispatchEvent(EventType::DETACH_WITH_IME); } return ret; @@ -620,8 +559,6 @@ void InputField::deleteBackward(size_t numChars) if (0 == len || _insertPos == 0) { axbeep(0); - // there is no string - // updateCursorPosition(); return; } @@ -630,13 +567,6 @@ void InputField::deleteBackward(size_t numChars) auto startByte = getByteOffset(startUtf8); auto totalDeleteLen = static_cast(_insertPos) - startByte; - // if (_delegate && _delegate->onTextFieldDeleteBackward(this, _inputText.c_str() + len - deleteLen, - // static_cast(deleteLen))) - //{ - // // delegate doesn't want to delete backwards - // return; - // } - // if all text deleted, show placeholder string if (len <= totalDeleteLen) { @@ -648,15 +578,12 @@ void InputField::deleteBackward(size_t numChars) } // set new input text - std::string text = _inputText; // (inputText.c_str(), len - deleteLen); + std::string text = _inputText; text.erase(startByte, totalDeleteLen); this->setString(text); setCursorPosition(startUtf8, false); - // updateCursorPosition(); - // moveCursor(-1); - dispatchEvent(EventType::DELETE_BACKWARD); } @@ -686,13 +613,6 @@ void InputField::handleDeleteKeyEvent() auto nextByte = getByteOffset(static_cast(_insertPosUtf8) + 1); auto deleteLen = nextByte - static_cast(_insertPos); - // if (_delegate && _delegate->onTextFieldDeleteBackward(this, _inputText.c_str() + len - deleteLen, - // static_cast(deleteLen))) - //{ - // // delegate doesn't wan't to delete backwards - // return; - // } - // if all text deleted, show placeholder string if (len <= deleteLen) { @@ -706,11 +626,9 @@ void InputField::handleDeleteKeyEvent() } // set new input text - std::string text = _inputText; // (inputText.c_str(), len - deleteLen); + std::string text = _inputText; text.erase(_insertPos, deleteLen); - // moveCursor(-1); - this->setString(text); setCursorPosition(_insertPosUtf8, false); @@ -1066,7 +984,7 @@ void InputField::moveCursorTo(float x) void InputField::moveCursorTo(float x, bool keepSelection) { - setCursorPosition(getCursorPositionFromX(x), keepSelection); + setCursorPosition(positionFromCursorX(x), keepSelection); } void InputField::setCursorPosition(std::size_t cursorPosition, bool keepSelection) @@ -1089,44 +1007,11 @@ void InputField::setCursorPosition(std::size_t cursorPosition, bool keepSelectio _cursorPos = _secureTextEntry ? static_cast(cursorPosition * strlen("\xe2\x80\xa2")) : _insertPos; if (_cursor) - _cursor->setPosition(Point(getCursorX(cursorPosition), this->getContentSize().height / 2)); + _cursor->setPosition(Point(cursorXFromPosition(cursorPosition), this->getContentSize().height / 2)); updateSelectionLayer(); } -float InputField::getCursorX(std::size_t cursorPosition) const -{ - cursorPosition = std::min(cursorPosition, _charCount); - if (cursorPosition == 0 || _inputText.empty()) - return 0; - - if (_secureTextEntry) - return _asteriskWidth * cursorPosition; - - auto byteOffset = text_utils::getUTF8ByteOffset(_inputText, cursorPosition); - if (byteOffset == std::string::npos) - byteOffset = _inputText.length(); - - return measureTextExtent(std::string_view(_inputText.data(), byteOffset), _fontName, _fontSize).width; -} - -std::size_t InputField::getCursorPositionFromX(float x) const -{ - if (x <= 0 || _charCount == 0) - return 0; - - float previousX = 0; - for (std::size_t i = 1; i <= _charCount; ++i) - { - auto currentX = getCursorX(i); - if (x < (previousX + currentX) * 0.5f) - return i - 1; - previousX = currentX; - } - - return _charCount; -} - std::size_t InputField::getByteOffset(std::size_t cursorPosition) const { if (cursorPosition >= _charCount) @@ -1154,8 +1039,8 @@ void InputField::updateSelectionLayer(void) if (!hasSelection()) return; - auto startX = getCursorX(_selectionStartUtf8); - auto endX = getCursorX(_selectionEndUtf8); + auto startX = cursorXFromPosition(_selectionStartUtf8); + auto endX = cursorXFromPosition(_selectionEndUtf8); if (endX <= startX) return; @@ -1230,6 +1115,9 @@ void InputField::setTextHorizontalAlignment(TextHAlignment alignment) if (_renderLabel) { _renderLabel->setHorizontalAlignment(alignment); + // Update cursor and selection positions to reflect new alignment + updateCursorPosition(); + updateSelectionLayer(); } } } @@ -1284,8 +1172,12 @@ Vec2 InputField::getAutoRenderSize() bool InputField::onTouchBegan(Touch* touch, Event* event) { // Call parent class to handle basic touch logic (hit test, highlight, etc.) - if (!Widget::onTouchBegan(touch, event)) + bool pass = Widget::onTouchBegan(touch, event); + + // If clicked outside the input field, detach IME (like axmol3 UITextField does) + if (!_hitted) { + detachWithIME(); return false; } @@ -1322,8 +1214,8 @@ bool InputField::onTouchBegan(Touch* touch, Event* event) // Handle cursor positioning if enabled if (focus && _touchCursorControlEnabled) { - auto renderLabelPoint = _renderLabel->convertToNodeSpace(touch->getLocation()); - _selectionAnchorUtf8 = getCursorPositionFromX(renderLabelPoint.x); + auto inputFieldPoint = this->convertToNodeSpace(touch->getLocation()); + _selectionAnchorUtf8 = positionFromCursorX(inputFieldPoint.x); } return true; @@ -1340,8 +1232,8 @@ void InputField::onTouchMoved(Touch* touch, Event* event) return; } - auto renderLabelPoint = _renderLabel->convertToNodeSpace(touch->getLocation()); - setCursorPosition(getCursorPositionFromX(renderLabelPoint.x), true); + auto inputFieldPoint = this->convertToNodeSpace(touch->getLocation()); + setCursorPosition(positionFromCursorX(inputFieldPoint.x), true); _selectionTouchMoved = hasSelection(); } @@ -1397,6 +1289,104 @@ void InputField::onTouchCancelled(Touch* touch, Event* event) _selectingByTouch = false; } +float InputField::cursorXFromPosition(std::size_t cursorPosition) const +{ + cursorPosition = std::min(cursorPosition, _charCount); + + // Calculate the offset from InputField origin to text start position + float textStartOffset = 0.0f; + if (_renderLabel) + { + float labelWidth = _renderLabel->getContentSize().width; + float totalTextWidth = measureTextExtent(_inputText, _fontName, _fontSize).width; + + // Label is positioned at center of InputField with ANCHOR_MIDDLE + // So label's left edge is at: contentSize.width/2 - labelWidth/2 + float labelLeftEdge = _contentSize.width / 2.0f - labelWidth / 2.0f; + + // Text alignment offset within the label + if (_textHAlignment == TextHAlignment::CENTER) + { + // Text is centered in label, so text starts at: labelLeftEdge + (labelWidth - textWidth)/2 + textStartOffset = labelLeftEdge + (labelWidth - totalTextWidth) * 0.5f; + } + else if (_textHAlignment == TextHAlignment::RIGHT) + { + // Text is right-aligned in label, so text starts at: labelLeftEdge + (labelWidth - textWidth) + textStartOffset = labelLeftEdge + (labelWidth - totalTextWidth); + } + else // LEFT + { + // Text is left-aligned in label, so text starts at label's left edge + textStartOffset = labelLeftEdge; + } + } + + // For position 0 or empty text, return text start position + if (cursorPosition == 0 || _inputText.empty()) + return textStartOffset; + + if (_secureTextEntry) + return textStartOffset + _asteriskWidth * cursorPosition; + + auto byteOffset = text_utils::getUTF8ByteOffset(_inputText, cursorPosition); + if (byteOffset == std::string::npos) + byteOffset = _inputText.length(); + + float textWidth = measureTextExtent(std::string_view(_inputText.data(), byteOffset), _fontName, _fontSize).width; + + return textStartOffset + textWidth; +} + +std::size_t InputField::positionFromCursorX(float x) const +{ + if (x <= 0 || _charCount == 0) + return 0; + + // Calculate the offset from InputField origin to text start position + float textStartOffset = 0.0f; + if (_renderLabel) + { + float labelWidth = _renderLabel->getContentSize().width; + float totalTextWidth = measureTextExtent(_inputText, _fontName, _fontSize).width; + + // Label is positioned at center of InputField with ANCHOR_MIDDLE + float labelLeftEdge = _contentSize.width / 2.0f - labelWidth / 2.0f; + + // Text alignment offset within the label + if (_textHAlignment == TextHAlignment::CENTER) + { + textStartOffset = labelLeftEdge + (labelWidth - totalTextWidth) * 0.5f; + } + else if (_textHAlignment == TextHAlignment::RIGHT) + { + textStartOffset = labelLeftEdge + (labelWidth - totalTextWidth); + } + else // LEFT + { + textStartOffset = labelLeftEdge; + } + } + + // Convert InputField coordinate to text-relative coordinate + float adjustedX = x - textStartOffset; + + // Clamp to valid range + if (adjustedX < 0) + return 0; + + float previousX = 0; + for (std::size_t i = 1; i <= _charCount; ++i) + { + auto currentX = cursorXFromPosition(i) - textStartOffset; + if (adjustedX < (previousX + currentX) * 0.5f) + return i - 1; + previousX = currentX; + } + + return _charCount; +} + } // namespace ui } // namespace ax diff --git a/axmol/ui/UIInputField.h b/axmol/ui/UIInputField.h index 06c648f2ea5e..a36a80037f69 100644 --- a/axmol/ui/UIInputField.h +++ b/axmol/ui/UIInputField.h @@ -252,8 +252,21 @@ class AX_DLL InputField : public Widget, public IMEDelegate void moveCursorTo(float x); void moveCursorTo(float x, bool keepSelection); void setCursorPosition(std::size_t cursorPosition, bool keepSelection); - float getCursorX(std::size_t cursorPosition) const; - std::size_t getCursorPositionFromX(float x) const; + + /** + * @brief Calculate the X coordinate for a given cursor position. + * @param cursorPosition UTF-8 character index (0 = before first char) + * @return X coordinate in local node space, accounting for text alignment + */ + float cursorXFromPosition(std::size_t cursorPosition) const; + + /** + * @brief Find the cursor position at a given X coordinate. + * @param x X coordinate in local node space + * @return UTF-8 character index (inverse of cursorXFromPosition) + */ + std::size_t positionFromCursorX(float x) const; + std::size_t getByteOffset(std::size_t cursorPosition) const; void setSelection(std::size_t start, std::size_t end); diff --git a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextFieldTest/UIInputFieldTest.cpp b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextFieldTest/UIInputFieldTest.cpp index caa5382b37e6..3ecd77065b8c 100644 --- a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextFieldTest/UIInputFieldTest.cpp +++ b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextFieldTest/UIInputFieldTest.cpp @@ -65,7 +65,7 @@ bool UIInputFieldTest::init() // Create the inputfield InputField* inputField = InputField::create("input words here", "Arial", 30); - inputField->setTextHorizontalAlignment(TextHAlignment::LEFT); + inputField->setTextHorizontalAlignment(TextHAlignment::CENTER); inputField->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); // Set up event listener for InputField From a16d94d915a12df074f946dbf46667361d855495 Mon Sep 17 00:00:00 2001 From: halx99 Date: Mon, 18 May 2026 17:48:44 +0800 Subject: [PATCH 08/52] up --- axmol/ui/UIInputField.cpp | 306 +++++++++++++++++++------------------- axmol/ui/UIInputField.h | 63 +++++++- 2 files changed, 212 insertions(+), 157 deletions(-) diff --git a/axmol/ui/UIInputField.cpp b/axmol/ui/UIInputField.cpp index 7bd47db5d70c..792029af66c5 100644 --- a/axmol/ui/UIInputField.cpp +++ b/axmol/ui/UIInputField.cpp @@ -44,31 +44,13 @@ namespace ax # define axbeep(t) #endif -static constexpr int INPUT_FIELD_RENDERER_Z = (-1); - -static Label* _createLabel(std::string_view text, - std::string_view font, - float fontSize, - const Vec2& dimensions = Vec2::ZERO, - TextHAlignment hAlignment = TextHAlignment::LEFT, - TextVAlignment vAlignment = TextVAlignment::TOP) -{ - if (FileUtils::getInstance()->isFileExist(font)) - { - return Label::createWithTTF(text, font, fontSize, dimensions, hAlignment, vAlignment); - } - else - { - return Label::createWithSystemFont(text, font, fontSize, dimensions, hAlignment, vAlignment); - } -} - namespace ui { static std::string s_clipboardFallback; static InputField::ClipboardGetter s_clipboardGetter; static InputField::ClipboardSetter s_clipboardSetter; +static constexpr int INPUT_FIELD_RENDERER_Z = (-1); #if (AX_TARGET_PLATFORM == AX_PLATFORM_WIN32 || AX_TARGET_PLATFORM == AX_PLATFORM_MAC || \ AX_TARGET_PLATFORM == AX_PLATFORM_LINUX) @@ -133,6 +115,23 @@ static int _truncateUTF8String(const char* text, int limit, int& nb) return n; } +static Label* _createLabel(std::string_view text, + std::string_view font, + float fontSize, + const Vec2& dimensions = Vec2::ZERO, + TextHAlignment hAlignment = TextHAlignment::LEFT, + TextVAlignment vAlignment = TextVAlignment::TOP) +{ + if (FileUtils::getInstance()->isFileExist(font)) + { + return Label::createWithTTF(text, font, fontSize, dimensions, hAlignment, vAlignment); + } + else + { + return Label::createWithSystemFont(text, font, fontSize, dimensions, hAlignment, vAlignment); + } +} + static Vec2 measureTextExtent(std::string_view s, std::string_view fontName, float fontSize) { auto label = _createLabel(s, fontName, fontSize); @@ -151,7 +150,7 @@ InputField::InputField() , _placeHolder("") , _colorText(Color32::WHITE) , _colorSpaceHolder(Color32::GRAY) - , _secureTextEntry(false) + , _passwordEnabled(false) , _cursor(nullptr) , _selectionLayer(nullptr) , _selectionColor(0.26f, 0.52f, 1.0f, 0.35f) @@ -172,7 +171,6 @@ InputField::InputField() , _selectionTouchMoved(false) , _ctrlKeyPressed(false) , _shiftKeyPressed(false) - , _asteriskWidth(0) , _cursorVisible(false) , _continuousTouchDelayTimerID(nullptr) , _continuousTouchDelayTime(0.6) @@ -180,10 +178,9 @@ InputField::InputField() , _textHAlignment(TextHAlignment::LEFT) , _textVAlignment(TextVAlignment::TOP) , _textAreaSize(Vec2::ZERO) + , _passwordChar("*"sv) -{ - setTouchEnabled(true); -} +{} InputField::~InputField() { @@ -222,6 +219,11 @@ bool InputField::initWithPlaceHolder(std::string_view placeholder, ui::Widget::init(); + _fontName = fontName; + _fontSize = fontSize; + _systemFontUsed = !FileUtils::getInstance()->isFileExist(fontName); + _fontType = _systemFontUsed ? 0 : 1; + _placeHolder = placeholder; /// render label @@ -234,10 +236,8 @@ bool InputField::initWithPlaceHolder(std::string_view placeholder, _selectionLayer = DrawNode::create(); this->addProtectedChild(_selectionLayer); - // _renderLabel->getLineHeight(); - /// cursor - _cursor = Sprite::createWithTexture(_director->getTextureCache()->getWhiteTexture()); + _cursor = Sprite::createWithTexture(_director->getTextureCache()->getWhiteTexture()); auto& originalSize = _cursor->getContentSize(); auto cursorHeight = measureTextExtent("M"sv, fontName, fontSize).height; @@ -246,13 +246,7 @@ bool InputField::initWithPlaceHolder(std::string_view placeholder, hideCursor(); updateCursorPosition(); - _fontName = fontName; - _fontSize = fontSize; - _systemFontUsed = !FileUtils::getInstance()->isFileExist(fontName); - _fontType = _systemFontUsed ? 0 : 1; - - using namespace std::string_view_literals; - _asteriskWidth = measureTextExtent("*"sv, _fontName, _fontSize).width; + _passwordCharWidth = measureTextExtent(_passwordChar, _fontName, _fontSize).width; // Initialize content size based on placeholder text updateContentSize(); @@ -260,6 +254,107 @@ bool InputField::initWithPlaceHolder(std::string_view placeholder, return true; } +void InputField::onEnter() +{ + Widget::onEnter(); + + setTouchEnabled(true); + + // Enable keyboard listener for cursor control and shortcuts + if (!_kbdListener) + { + _kbdListener = EventListenerKeyboard::create(); + _kbdListener->onKeyPressed = [this](EventKeyboard::KeyCode code, Event*) { + switch (code) + { + case EventKeyboard::KeyCode::KEY_CTRL: + case EventKeyboard::KeyCode::KEY_RIGHT_CTRL: + case EventKeyboard::KeyCode::KEY_HYPER: + _ctrlKeyPressed = true; + return; + case EventKeyboard::KeyCode::KEY_SHIFT: + case EventKeyboard::KeyCode::KEY_RIGHT_SHIFT: + _shiftKeyPressed = true; + return; + default: + break; + } + + if (_cursorVisible) + { + if (_ctrlKeyPressed) + { + switch (code) + { + case EventKeyboard::KeyCode::KEY_A: + case EventKeyboard::KeyCode::KEY_CAPITAL_A: + this->selectAll(); + return; + case EventKeyboard::KeyCode::KEY_C: + case EventKeyboard::KeyCode::KEY_CAPITAL_C: + this->copySelectionToClipboard(); + return; + case EventKeyboard::KeyCode::KEY_X: + case EventKeyboard::KeyCode::KEY_CAPITAL_X: + this->cutSelectionToClipboard(); + return; + case EventKeyboard::KeyCode::KEY_V: + case EventKeyboard::KeyCode::KEY_CAPITAL_V: + this->pasteFromClipboard(); + return; + default: + break; + } + } + + switch (code) + { + case EventKeyboard::KeyCode::KEY_LEFT_ARROW: + this->moveCursor(-1, _shiftKeyPressed); + break; + case EventKeyboard::KeyCode::KEY_RIGHT_ARROW: + this->moveCursor(1, _shiftKeyPressed); + break; + case EventKeyboard::KeyCode::KEY_DELETE: + case EventKeyboard::KeyCode::KEY_KP_DELETE: + this->handleDeleteKeyEvent(); + break; + default:; + } + } + }; + _kbdListener->onKeyReleased = [this](EventKeyboard::KeyCode code, Event*) { + switch (code) + { + case EventKeyboard::KeyCode::KEY_CTRL: + case EventKeyboard::KeyCode::KEY_RIGHT_CTRL: + case EventKeyboard::KeyCode::KEY_HYPER: + _ctrlKeyPressed = false; + break; + case EventKeyboard::KeyCode::KEY_SHIFT: + case EventKeyboard::KeyCode::KEY_RIGHT_SHIFT: + _shiftKeyPressed = false; + break; + default: + break; + } + }; + + _eventDispatcher->addEventListenerWithSceneGraphPriority(_kbdListener, this); + } +} + +void InputField::onExit() +{ + if (_kbdListener) + { + _eventDispatcher->removeEventListener(_kbdListener); + AX_SAFE_RELEASE_NULL(_kbdListener); + } + setTouchEnabled(false); + Widget::onExit(); +} + std::string_view InputField::getTextFontName() const { return _fontName; @@ -289,8 +384,7 @@ void InputField::setTextFontName(std::string_view fontName) } _fontName = fontName; - using namespace std::string_view_literals; - _asteriskWidth = measureTextExtent("*"sv, _fontName, _fontSize).width; + _passwordCharWidth = measureTextExtent(_passwordChar, _fontName, _fontSize).width; updateCursorPosition(); updateSelectionLayer(); } @@ -310,8 +404,7 @@ void InputField::setTextFontSize(float size) _fontSize = size; - using namespace std::string_view_literals; - _asteriskWidth = measureTextExtent("*"sv, _fontName, _fontSize).width; + _passwordCharWidth = measureTextExtent(_passwordChar, _fontName, _fontSize).width; updateCursorPosition(); updateSelectionLayer(); } @@ -339,89 +432,6 @@ bool InputField::attachWithIME() _selectingByTouch = false; _selectionTouchMoved = false; - // Enable keyboard listener for cursor control and shortcuts - if (!_kbdListener) - { - _kbdListener = EventListenerKeyboard::create(); - _kbdListener->onKeyPressed = [this](EventKeyboard::KeyCode code, Event*) { - switch (code) - { - case EventKeyboard::KeyCode::KEY_CTRL: - case EventKeyboard::KeyCode::KEY_RIGHT_CTRL: - case EventKeyboard::KeyCode::KEY_HYPER: - _ctrlKeyPressed = true; - return; - case EventKeyboard::KeyCode::KEY_SHIFT: - case EventKeyboard::KeyCode::KEY_RIGHT_SHIFT: - _shiftKeyPressed = true; - return; - default: - break; - } - - if (_cursorVisible) - { - if (_ctrlKeyPressed) - { - switch (code) - { - case EventKeyboard::KeyCode::KEY_A: - case EventKeyboard::KeyCode::KEY_CAPITAL_A: - this->selectAll(); - return; - case EventKeyboard::KeyCode::KEY_C: - case EventKeyboard::KeyCode::KEY_CAPITAL_C: - this->copySelectionToClipboard(); - return; - case EventKeyboard::KeyCode::KEY_X: - case EventKeyboard::KeyCode::KEY_CAPITAL_X: - this->cutSelectionToClipboard(); - return; - case EventKeyboard::KeyCode::KEY_V: - case EventKeyboard::KeyCode::KEY_CAPITAL_V: - this->pasteFromClipboard(); - return; - default: - break; - } - } - - switch (code) - { - case EventKeyboard::KeyCode::KEY_LEFT_ARROW: - this->moveCursor(-1, _shiftKeyPressed); - break; - case EventKeyboard::KeyCode::KEY_RIGHT_ARROW: - this->moveCursor(1, _shiftKeyPressed); - break; - case EventKeyboard::KeyCode::KEY_DELETE: - case EventKeyboard::KeyCode::KEY_KP_DELETE: - this->handleDeleteKeyEvent(); - break; - default:; - } - } - }; - _kbdListener->onKeyReleased = [this](EventKeyboard::KeyCode code, Event*) { - switch (code) - { - case EventKeyboard::KeyCode::KEY_CTRL: - case EventKeyboard::KeyCode::KEY_RIGHT_CTRL: - case EventKeyboard::KeyCode::KEY_HYPER: - _ctrlKeyPressed = false; - break; - case EventKeyboard::KeyCode::KEY_SHIFT: - case EventKeyboard::KeyCode::KEY_RIGHT_SHIFT: - _shiftKeyPressed = false; - break; - default: - break; - } - }; - - _eventDispatcher->addEventListenerWithSceneGraphPriority(_kbdListener, this); - } - // Open keyboard RenderView* renderView = _director->getRenderView(); if (renderView) @@ -691,8 +701,6 @@ Vec2 InputField::getPreferredSize() const // input text property void InputField::setString(std::string_view text) { - static char bulletString[] = {(char)0xe2, (char)0x80, (char)0xa2, (char)0x00}; - auto oldInsertPosUtf8 = static_cast(_insertPosUtf8); bool bInsertAtEnd = (oldInsertPosUtf8 == _charCount); _inputText = text; @@ -704,14 +712,14 @@ void InputField::setString(std::string_view text) if (!_inputText.empty()) { - if (_secureTextEntry) + if (_passwordEnabled) { size_t length = newCharCount; displayText = &secureText; while (length > 0) { - displayText->append(bulletString); + displayText->append(_passwordChar); --length; } } @@ -786,6 +794,17 @@ std::string_view InputField::getString() const return _inputText; } +void InputField::setPasswordChar(std::string_view ch) { + if (!ch.empty() && ch != _passwordChar) + { + _passwordChar = ch; + if (_passwordEnabled) + { + setString(getString()); + } + } +} + // place holder text property void InputField::setPlaceholderText(std::string_view text) { @@ -807,9 +826,9 @@ std::string_view InputField::getPlaceholderText() const // secureTextEntry void InputField::setPasswordEnabled(bool value) { - if (_secureTextEntry != value) + if (_passwordEnabled != value) { - _secureTextEntry = value; + _passwordEnabled = value; this->setString(this->getString()); updateCursorPosition(); } @@ -817,7 +836,7 @@ void InputField::setPasswordEnabled(bool value) bool InputField::isPasswordEnabled() const { - return _secureTextEntry; + return _passwordEnabled; } void InputField::setEnabled(bool bEnabled) @@ -868,7 +887,7 @@ std::string InputField::getSelectedText() const bool InputField::copySelectionToClipboard() const { auto selectedText = getSelectedText(); - if (selectedText.empty() || _secureTextEntry) + if (selectedText.empty() || _passwordEnabled) return false; setClipboardText(selectedText); @@ -927,19 +946,6 @@ void InputField::setClipboardText(std::string_view text) writeClipboardText(text); } -void InputField::initCursor(int height, int width, const Color32& color) -{ - _cursor = _createCursorSprite(Color32(color), height, width); - - this->addProtectedChild(_cursor); - - _cursor->setPosition(Point(0, this->getContentSize().height / 2)); - - hideCursor(); - - updateCursorPosition(); -} - void InputField::showCursor(void) { if (_cursor) @@ -1004,7 +1010,7 @@ void InputField::setCursorPosition(std::size_t cursorPosition, bool keepSelectio _insertPosUtf8 = static_cast(cursorPosition); _insertPos = static_cast(getByteOffset(cursorPosition)); - _cursorPos = _secureTextEntry ? static_cast(cursorPosition * strlen("\xe2\x80\xa2")) : _insertPos; + _cursorPos = _passwordEnabled ? static_cast(cursorPosition * sizeof("\xe2\x80\xa2")) : _insertPos; if (_cursor) _cursor->setPosition(Point(cursorXFromPosition(cursorPosition), this->getContentSize().height / 2)); @@ -1215,7 +1221,7 @@ bool InputField::onTouchBegan(Touch* touch, Event* event) if (focus && _touchCursorControlEnabled) { auto inputFieldPoint = this->convertToNodeSpace(touch->getLocation()); - _selectionAnchorUtf8 = positionFromCursorX(inputFieldPoint.x); + _selectionAnchorUtf8 = positionFromCursorX(inputFieldPoint.x); } return true; @@ -1297,7 +1303,7 @@ float InputField::cursorXFromPosition(std::size_t cursorPosition) const float textStartOffset = 0.0f; if (_renderLabel) { - float labelWidth = _renderLabel->getContentSize().width; + float labelWidth = _renderLabel->getContentSize().width; float totalTextWidth = measureTextExtent(_inputText, _fontName, _fontSize).width; // Label is positioned at center of InputField with ANCHOR_MIDDLE @@ -1315,7 +1321,7 @@ float InputField::cursorXFromPosition(std::size_t cursorPosition) const // Text is right-aligned in label, so text starts at: labelLeftEdge + (labelWidth - textWidth) textStartOffset = labelLeftEdge + (labelWidth - totalTextWidth); } - else // LEFT + else // LEFT { // Text is left-aligned in label, so text starts at label's left edge textStartOffset = labelLeftEdge; @@ -1326,8 +1332,8 @@ float InputField::cursorXFromPosition(std::size_t cursorPosition) const if (cursorPosition == 0 || _inputText.empty()) return textStartOffset; - if (_secureTextEntry) - return textStartOffset + _asteriskWidth * cursorPosition; + if (_passwordEnabled) + return textStartOffset + _passwordCharWidth * cursorPosition; auto byteOffset = text_utils::getUTF8ByteOffset(_inputText, cursorPosition); if (byteOffset == std::string::npos) @@ -1347,7 +1353,7 @@ std::size_t InputField::positionFromCursorX(float x) const float textStartOffset = 0.0f; if (_renderLabel) { - float labelWidth = _renderLabel->getContentSize().width; + float labelWidth = _renderLabel->getContentSize().width; float totalTextWidth = measureTextExtent(_inputText, _fontName, _fontSize).width; // Label is positioned at center of InputField with ANCHOR_MIDDLE @@ -1362,7 +1368,7 @@ std::size_t InputField::positionFromCursorX(float x) const { textStartOffset = labelLeftEdge + (labelWidth - totalTextWidth); } - else // LEFT + else // LEFT { textStartOffset = labelLeftEdge; } diff --git a/axmol/ui/UIInputField.h b/axmol/ui/UIInputField.h index a36a80037f69..4d67e5bf7b0f 100644 --- a/axmol/ui/UIInputField.h +++ b/axmol/ui/UIInputField.h @@ -91,6 +91,52 @@ class AX_DLL InputField : public Widget, public IMEDelegate _continuousTouchCallback = std::move(callback); } + /** + * @brief Set the single visible mask character used when password mode is enabled. + * + * This configures the character that will be rendered in place of each actual input + * character when password mode is active (setPasswordEnabled(true)). The mask affects + * only visual rendering; the underlying stored text (_inputText) remains unchanged. + * + * Behavior + * - The function treats the provided input as a single visible character unit (a + * grapheme cluster). If the input contains multiple grapheme clusters, only the + * first cluster is used and the remainder is ignored. + * - Passing an empty string ("") restores the default mask character (for example, '•'). + * - After setting the mask the control will refresh its display and cursor position + * (internally calls setString(getString()) and updateCursorPosition()) so the change + * takes effect immediately. + * + * Implementation notes + * - Prefer extracting the first grapheme cluster (not merely the first UTF-8 code point) + * to correctly support composite emoji and other combined characters. If a grapheme + * library is not available, document the limitation of using the first code point. + * - Always measure the mask's rendered width using the font and size in use and cache + * that width for cursor/selection calculations; do not rely on byte length or codepoint + * count for layout. + * - Validate input: ignore or replace control/invisible characters and fall back to the + * default mask if the provided character is not renderable. + * + * Threading and performance + * - Call from the UI/main thread. Setting the mask triggers a redraw and cursor recalculation; + * avoid calling this repeatedly in tight loops. + * + * @param[in] ch UTF-8 string view containing the desired mask character. Only the first + * visible character unit is used; empty string restores the default mask. + * + * @note The mask is purely visual. For accessibility, consider exposing a separate API + * or policy for whether the real text may be read by assistive technologies. + * + * @example + * @code + * inputField->setPasswordEnabled(true); + * inputField->setPasswordChar("•"); // use bullet + * inputField->setPasswordChar("*"); // use asterisk + * @endcode + */ + void setPasswordChar(std::string_view ch); + std::string_view getPasswordChar() const { return _passwordChar; } + // place holder text property // place holder text displayed when there is no text in the text field. virtual void setPlaceholderText(std::string_view text); @@ -218,6 +264,9 @@ class AX_DLL InputField : public Widget, public IMEDelegate protected: ////////////////////////////////////////////////////////////////////////// + void onEnter() override; + void onExit() override; + bool canAttachWithIME() override; bool canDetachWithIME() override; @@ -241,7 +290,6 @@ class AX_DLL InputField : public Widget, public IMEDelegate void updateContentSize(void) override; - void initCursor(int height, int width = 6, const Color32& color = Color32::WHITE); void showCursor(void); void hideCursor(void); void updateCursorPosition(void); @@ -252,21 +300,21 @@ class AX_DLL InputField : public Widget, public IMEDelegate void moveCursorTo(float x); void moveCursorTo(float x, bool keepSelection); void setCursorPosition(std::size_t cursorPosition, bool keepSelection); - + /** * @brief Calculate the X coordinate for a given cursor position. * @param cursorPosition UTF-8 character index (0 = before first char) * @return X coordinate in local node space, accounting for text alignment */ float cursorXFromPosition(std::size_t cursorPosition) const; - + /** * @brief Find the cursor position at a given X coordinate. * @param x X coordinate in local node space * @return UTF-8 character index (inverse of cursorXFromPosition) */ std::size_t positionFromCursorX(float x) const; - + std::size_t getByteOffset(std::size_t cursorPosition) const; void setSelection(std::size_t start, std::size_t end); @@ -295,7 +343,7 @@ class AX_DLL InputField : public Widget, public IMEDelegate bool _systemFontUsed; bool _editable; bool _layoutDirty{true}; - bool _secureTextEntry; + bool _passwordEnabled; bool _cursorVisible; bool _touchCursorControlEnabled; bool _selectingByTouch; @@ -308,8 +356,9 @@ class AX_DLL InputField : public Widget, public IMEDelegate size_t _charCount; std::string _inputText; - std::string _placeHolder; + std::string _passwordChar; + Color32 _colorSpaceHolder; Color32 _colorText; @@ -327,7 +376,7 @@ class AX_DLL InputField : public Widget, public IMEDelegate EventListenerKeyboard* _kbdListener; - float _asteriskWidth; + float _passwordCharWidth; int _fontType; From f60fbe76ede873864e894ebd014b7dab1fefed11 Mon Sep 17 00:00:00 2001 From: halx99 Date: Mon, 18 May 2026 18:21:52 +0800 Subject: [PATCH 09/52] Clenaup code --- axmol/base/IMEDelegate.h | 2 +- axmol/ui/UIInputField.cpp | 58 +++++++++++++++------------------------ axmol/ui/UIInputField.h | 6 +--- 3 files changed, 24 insertions(+), 42 deletions(-) diff --git a/axmol/base/IMEDelegate.h b/axmol/base/IMEDelegate.h index 011e023a8966..83d1b0fde02d 100644 --- a/axmol/base/IMEDelegate.h +++ b/axmol/base/IMEDelegate.h @@ -126,7 +126,7 @@ class AX_DLL IMEDelegate @brief Called by IMEDispatcher for text stored in delegate. * @lua NA */ - virtual std::string_view getContentText() { return STD_STRING_EMPTY; } + virtual std::string_view getContentText() const { return STD_STRING_EMPTY; } ////////////////////////////////////////////////////////////////////////// // keyboard show/hide notification diff --git a/axmol/ui/UIInputField.cpp b/axmol/ui/UIInputField.cpp index 792029af66c5..9558d131b111 100644 --- a/axmol/ui/UIInputField.cpp +++ b/axmol/ui/UIInputField.cpp @@ -96,23 +96,23 @@ static void writeClipboardText(std::string_view text) } /// calculate the UTF-8 string's char count. -static int _truncateUTF8String(const char* text, int limit, int& nb) +static std::pair _truncateUTF8String(const char* text, int charLimit) { - int n = 0; - char ch = 0; - nb = 0; + int charCount = 0; + char ch = 0; + int numOfBytes = 0; while ((ch = *text) != 0x0) { - AX_BREAK_IF(!ch || n > limit); + AX_BREAK_IF(!ch || charCount > charLimit); if (0x80 != (0xC0 & ch)) { - ++n; + ++charCount; } - ++nb; + ++numOfBytes; ++text; } - return n; + return std::make_pair(charCount, numOfBytes); } static Label* _createLabel(std::string_view text, @@ -161,7 +161,6 @@ InputField::InputField() , _eventCallback(nullptr) , _charLimit(std::numeric_limits::max()) , _systemFontUsed(false) - , _fontType(0) , _fontSize(24) , _insertPosUtf8(0) , _insertPos(0) @@ -222,9 +221,7 @@ bool InputField::initWithPlaceHolder(std::string_view placeholder, _fontName = fontName; _fontSize = fontSize; _systemFontUsed = !FileUtils::getInstance()->isFileExist(fontName); - _fontType = _systemFontUsed ? 0 : 1; - - _placeHolder = placeholder; + _placeHolder = placeholder; /// render label _renderLabel = _createLabel(placeholder, fontName, fontSize); @@ -263,7 +260,8 @@ void InputField::onEnter() // Enable keyboard listener for cursor control and shortcuts if (!_kbdListener) { - _kbdListener = EventListenerKeyboard::create(); + _kbdListener = EventListenerKeyboard::create(); + AX_SAFE_RETAIN(_kbdListener); _kbdListener->onKeyPressed = [this](EventKeyboard::KeyCode code, Event*) { switch (code) { @@ -369,7 +367,6 @@ void InputField::setTextFontName(std::string_view fontName) config.fontSize = _fontSize; _renderLabel->setTTFConfig(config); _systemFontUsed = false; - _fontType = 1; } else { @@ -380,11 +377,12 @@ void InputField::setTextFontName(std::string_view fontName) } _renderLabel->setSystemFontSize(_fontSize); _systemFontUsed = true; - _fontType = 0; } _fontName = fontName; _passwordCharWidth = measureTextExtent(_passwordChar, _fontName, _fontSize).width; + auto cursorHeight = measureTextExtent("M"sv, _fontName, _fontSize).height; + _cursor->setContentSize(Vec2{_cursor->getContentSize().width, cursorHeight}); updateCursorPosition(); updateSelectionLayer(); } @@ -512,11 +510,10 @@ void InputField::insertText(const char* text, size_t len) return; } - int nb; auto limit = (_charLimit > 0) ? static_cast(_charLimit - _charCount) : std::numeric_limits::max(); - auto n = _truncateUTF8String(text, limit, nb); + auto [numOfChars, numOfBytes] = _truncateUTF8String(text, limit); - std::string insert(text, nb); + std::string insert(text, numOfBytes); // insert \n means input end auto pos = insert.find('\n'); @@ -532,12 +529,8 @@ void InputField::insertText(const char* text, size_t len) auto cursorPosition = static_cast(_insertPosUtf8); sText.insert(_insertPos, insert); // original is: sText.append(insert); - // bool needUpdatePos this->setString(sText); - setCursorPosition(cursorPosition + n, false); - - // this->contentDirty = true; - // updateCursorPosition(); + setCursorPosition(cursorPosition + numOfChars, false); dispatchEvent(EventType::INSERT_TEXT); } @@ -615,8 +608,6 @@ void InputField::handleDeleteKeyEvent() if (0 == len || _insertPosUtf8 == _charCount) { axbeep(0); - // there is no string - // updateCursorPosition(); return; } @@ -629,8 +620,6 @@ void InputField::handleDeleteKeyEvent() this->setString(""); setCursorPosition(0, false); - // this->contentDirty = true; - dispatchEvent(EventType::DELETE_BACKWARD); return; } @@ -645,7 +634,7 @@ void InputField::handleDeleteKeyEvent() dispatchEvent(EventType::DELETE_BACKWARD); } -std::string_view InputField::getContentText() +std::string_view InputField::getContentText() const { return _inputText; } @@ -794,10 +783,12 @@ std::string_view InputField::getString() const return _inputText; } -void InputField::setPasswordChar(std::string_view ch) { - if (!ch.empty() && ch != _passwordChar) +void InputField::setPasswordChar(std::string_view ch) +{ + if (ch != _passwordChar) { - _passwordChar = ch; + _passwordChar = !ch.empty() ? ch : "*"sv; + _passwordCharWidth = measureTextExtent(_passwordChar, _fontName, _fontSize).width; if (_passwordEnabled) { setString(getString()); @@ -849,11 +840,6 @@ void InputField::setEnabled(bool bEnabled) } } -int InputField::getFontType() const -{ - return _fontType; -} - bool InputField::hasSelection() const { return _selectionStartUtf8 != _selectionEndUtf8; diff --git a/axmol/ui/UIInputField.h b/axmol/ui/UIInputField.h index 4d67e5bf7b0f..a9e264932596 100644 --- a/axmol/ui/UIInputField.h +++ b/axmol/ui/UIInputField.h @@ -154,8 +154,6 @@ class AX_DLL InputField : public Widget, public IMEDelegate void setMaxLength(int maxLength) { setCharLimit(maxLength); } - int getFontType() const; - bool hasSelection() const; void selectAll(); void clearSelection(); @@ -271,7 +269,7 @@ class AX_DLL InputField : public Widget, public IMEDelegate bool canDetachWithIME() override; void deleteBackward(size_t numChars) override; - std::string_view getContentText() override; + std::string_view getContentText() const override; void handleDeleteKeyEvent(); @@ -378,8 +376,6 @@ class AX_DLL InputField : public Widget, public IMEDelegate float _passwordCharWidth; - int _fontType; - ax::stimer::TIMER_ID _continuousTouchDelayTimerID; float _continuousTouchDelayTime; std::function _continuousTouchCallback; From a39b238680f5a3f3b73695e7df05596fcd51dee1 Mon Sep 17 00:00:00 2001 From: halx99 Date: Mon, 18 May 2026 18:47:01 +0800 Subject: [PATCH 10/52] up --- axmol/ui/UIInputField.cpp | 87 +++++++++++++++++++-------------------- axmol/ui/UIInputField.h | 14 +++++-- 2 files changed, 52 insertions(+), 49 deletions(-) diff --git a/axmol/ui/UIInputField.cpp b/axmol/ui/UIInputField.cpp index 9558d131b111..4c23743a5c1e 100644 --- a/axmol/ui/UIInputField.cpp +++ b/axmol/ui/UIInputField.cpp @@ -165,14 +165,14 @@ InputField::InputField() , _insertPosUtf8(0) , _insertPos(0) , _cursorPos(0) - , _touchCursorControlEnabled(true) , _selectingByTouch(false) , _selectionTouchMoved(false) , _ctrlKeyPressed(false) , _shiftKeyPressed(false) - , _cursorVisible(false) - , _continuousTouchDelayTimerID(nullptr) - , _continuousTouchDelayTime(0.6) + , _continuousTouchPending(false) + , _continuousTouchElapsedTime(0.0f) + , _continuousTouchDelayTime(0.6f) + , _continuousTouchWorldPoint(Point::ZERO) , _useTouchArea(false) , _textHAlignment(TextHAlignment::LEFT) , _textVAlignment(TextVAlignment::TOP) @@ -278,7 +278,7 @@ void InputField::onEnter() break; } - if (_cursorVisible) + if (isCursorVisible()) { if (_ctrlKeyPressed) { @@ -778,6 +778,27 @@ void InputField::updateLayout() } } +void InputField::update(float dt) +{ + // Call parent class update first + Widget::update(dt); + + // Check continuous touch delay timing + if (_continuousTouchPending) + { + _continuousTouchElapsedTime += dt; + if (_continuousTouchElapsedTime >= _continuousTouchDelayTime) + { + // Delay time reached, execute callback + _continuousTouchPending = false; + if (_continuousTouchCallback) + { + _continuousTouchCallback(_continuousTouchWorldPoint); + } + } + } +} + std::string_view InputField::getString() const { return _inputText; @@ -936,7 +957,6 @@ void InputField::showCursor(void) { if (_cursor) { - _cursorVisible = true; _cursor->setVisible(true); _cursor->runAction(RepeatForever::create(Blink::create(1, 1))); } @@ -947,7 +967,6 @@ void InputField::hideCursor(void) if (_cursor) { _cursor->setVisible(false); - _cursorVisible = false; _cursor->stopAllActions(); } } @@ -996,7 +1015,6 @@ void InputField::setCursorPosition(std::size_t cursorPosition, bool keepSelectio _insertPosUtf8 = static_cast(cursorPosition); _insertPos = static_cast(getByteOffset(cursorPosition)); - _cursorPos = _passwordEnabled ? static_cast(cursorPosition * sizeof("\xe2\x80\xa2")) : _insertPos; if (_cursor) _cursor->setPosition(Point(cursorXFromPosition(cursorPosition), this->getContentSize().height / 2)); @@ -1179,23 +1197,13 @@ bool InputField::onTouchBegan(Touch* touch, Event* event) return false; } - // Handle continuous touch callback - if (_continuousTouchDelayTimerID != nullptr) - { - stimer::kill(_continuousTouchDelayTimerID); - _continuousTouchDelayTimerID = nullptr; - } - - bool focus = _cursorVisible; + // Handle continuous touch callback - start manual timing + bool focus = isCursorVisible(); if (focus && _continuousTouchCallback) { - auto worldPoint = touch->getLocation(); - _continuousTouchDelayTimerID = stimer::delay(_continuousTouchDelayTime, [this, worldPoint]() { - if (_continuousTouchCallback) - { - _continuousTouchCallback(worldPoint); - } - }); + _continuousTouchPending = true; + _continuousTouchElapsedTime = 0.0f; + _continuousTouchWorldPoint = touch->getLocation(); } // Initialize selection state @@ -1203,8 +1211,8 @@ bool InputField::onTouchBegan(Touch* touch, Event* event) _selectionTouchMoved = false; _selectionAnchorUtf8 = _insertPosUtf8; - // Handle cursor positioning if enabled - if (focus && _touchCursorControlEnabled) + // Handle cursor positioning + if (focus) { auto inputFieldPoint = this->convertToNodeSpace(touch->getLocation()); _selectionAnchorUtf8 = positionFromCursorX(inputFieldPoint.x); @@ -1219,7 +1227,7 @@ void InputField::onTouchMoved(Touch* touch, Event* event) Widget::onTouchMoved(touch, event); // InputField specific touch move handling - if (!_selectingByTouch || !_touchCursorControlEnabled || !_editable || !_enabled) + if (!_selectingByTouch || !_editable || !_enabled) { return; } @@ -1231,12 +1239,8 @@ void InputField::onTouchMoved(Touch* touch, Event* event) void InputField::onTouchEnded(Touch* touch, Event* event) { - // Kill continuous touch timer - if (_continuousTouchDelayTimerID != nullptr) - { - stimer::kill(_continuousTouchDelayTimerID); - _continuousTouchDelayTimerID = nullptr; - } + // Cancel continuous touch pending state + _continuousTouchPending = false; // Call parent class Widget::onTouchEnded(touch, event); @@ -1246,17 +1250,14 @@ void InputField::onTouchEnded(Touch* touch, Event* event) if (focus) { - if (!s_keyboardVisible || !_cursorVisible) + if (!s_keyboardVisible || !isCursorVisible()) { attachWithIME(); } - // Handle cursor positioning if enabled - if (_touchCursorControlEnabled) - { - auto renderLabelPoint = _renderLabel->convertToNodeSpace(touch->getLocation()); - moveCursorTo(renderLabelPoint.x, _selectionTouchMoved); - } + // Handle cursor positioning + auto renderLabelPoint = _renderLabel->convertToNodeSpace(touch->getLocation()); + moveCursorTo(renderLabelPoint.x, _selectionTouchMoved); } else { @@ -1268,12 +1269,8 @@ void InputField::onTouchEnded(Touch* touch, Event* event) void InputField::onTouchCancelled(Touch* touch, Event* event) { - // Kill continuous touch timer - if (_continuousTouchDelayTimerID != nullptr) - { - stimer::kill(_continuousTouchDelayTimerID); - _continuousTouchDelayTimerID = nullptr; - } + // Cancel continuous touch pending state + _continuousTouchPending = false; // Call parent class Widget::onTouchCancelled(touch, event); diff --git a/axmol/ui/UIInputField.h b/axmol/ui/UIInputField.h index a9e264932596..50888511803b 100644 --- a/axmol/ui/UIInputField.h +++ b/axmol/ui/UIInputField.h @@ -26,9 +26,9 @@ THE SOFTWARE. #include "axmol/ui/UIWidget.h" #include "axmol/base/IMEDelegate.h" -#include "axmol/base/SimpleTimer.h" #include "axmol/2d/DrawNode.h" #include "axmol/2d/Label.h" +#include "axmol/2d/Sprite.h" #include "axmol/base/EventListenerKeyboard.h" namespace ax @@ -325,9 +325,13 @@ class AX_DLL InputField : public Widget, public IMEDelegate */ void dispatchEvent(EventType eventType); + + bool isCursorVisible() const { return _cursor && _cursor->isVisible(); } + protected: void updateLayout() override; void onSizeChanged() override; + void update(float dt) override; // Override Widget's touch event handlers bool onTouchBegan(Touch* touch, Event* event) override; @@ -343,7 +347,6 @@ class AX_DLL InputField : public Widget, public IMEDelegate bool _layoutDirty{true}; bool _passwordEnabled; bool _cursorVisible; - bool _touchCursorControlEnabled; bool _selectingByTouch; bool _selectionTouchMoved; bool _ctrlKeyPressed; @@ -370,14 +373,17 @@ class AX_DLL InputField : public Widget, public IMEDelegate int _insertPosUtf8; int _insertPos; // The actual input content insertPos, step: bytes - int _cursorPos; // The cursor normalzed pos, + int _cursorPos; // The cursor normalized pos, EventListenerKeyboard* _kbdListener; float _passwordCharWidth; - ax::stimer::TIMER_ID _continuousTouchDelayTimerID; + // Continuous touch delay state (manual timing, no external timer dependency) + bool _continuousTouchPending; + float _continuousTouchElapsedTime; float _continuousTouchDelayTime; + Point _continuousTouchWorldPoint; std::function _continuousTouchCallback; /// Event callback From 431911e67142142a20df99e26fd031b613f88828 Mon Sep 17 00:00:00 2001 From: halx99 Date: Mon, 18 May 2026 19:40:48 +0800 Subject: [PATCH 11/52] up --- axmol/ui/UIInputField.cpp | 150 ++++++++++-------- axmol/ui/UIInputField.h | 32 ++-- .../UITextFieldTest/UIInputFieldTest.cpp | 30 ++-- 3 files changed, 121 insertions(+), 91 deletions(-) diff --git a/axmol/ui/UIInputField.cpp b/axmol/ui/UIInputField.cpp index 4c23743a5c1e..a8f7cfbdf338 100644 --- a/axmol/ui/UIInputField.cpp +++ b/axmol/ui/UIInputField.cpp @@ -115,33 +115,12 @@ static std::pair _truncateUTF8String(const char* text, int charLimit) return std::make_pair(charCount, numOfBytes); } -static Label* _createLabel(std::string_view text, - std::string_view font, - float fontSize, - const Vec2& dimensions = Vec2::ZERO, - TextHAlignment hAlignment = TextHAlignment::LEFT, - TextVAlignment vAlignment = TextVAlignment::TOP) -{ - if (FileUtils::getInstance()->isFileExist(font)) - { - return Label::createWithTTF(text, font, fontSize, dimensions, hAlignment, vAlignment); - } - else - { - return Label::createWithSystemFont(text, font, fontSize, dimensions, hAlignment, vAlignment); - } -} - -static Vec2 measureTextExtent(std::string_view s, std::string_view fontName, float fontSize) -{ - auto label = _createLabel(s, fontName, fontSize); - return label->getContentSize(); -} - ////////////////////////////////////////////////////////////////////////// // constructor and destructor ////////////////////////////////////////////////////////////////////////// -bool InputField::s_keyboardVisible = false; +bool InputField::s_keyboardVisible = false; +Label* InputField::s_sharedMeasureLabel = nullptr; + InputField::InputField() : _editable(true) , _renderLabel(nullptr) @@ -164,7 +143,6 @@ InputField::InputField() , _fontSize(24) , _insertPosUtf8(0) , _insertPos(0) - , _cursorPos(0) , _selectingByTouch(false) , _selectionTouchMoved(false) , _ctrlKeyPressed(false) @@ -176,7 +154,6 @@ InputField::InputField() , _useTouchArea(false) , _textHAlignment(TextHAlignment::LEFT) , _textVAlignment(TextVAlignment::TOP) - , _textAreaSize(Vec2::ZERO) , _passwordChar("*"sv) {} @@ -185,6 +162,17 @@ InputField::~InputField() { if (_kbdListener != nullptr) _eventDispatcher->removeEventListener(_kbdListener); + + // Decrement reference count and release shared measure label if last user + + if (_measureLabel) + { + if (_measureLabel->getReferenceCount() == 1) + s_sharedMeasureLabel = nullptr; + + _measureLabel->release(); + _measureLabel = nullptr; + } } ////////////////////////////////////////////////////////////////////////// @@ -206,6 +194,34 @@ InputField* InputField::create(std::string_view placeholder, return nullptr; } +////////////////////////////////////////////////////////////////////////// +// text measurement +////////////////////////////////////////////////////////////////////////// +Vec2 InputField::measureTextExtent(std::string_view text) const +{ + // Lazy initialize shared measure label on first use by any InputField instance + if (!s_sharedMeasureLabel) + s_sharedMeasureLabel = Label::create(); + + if (!_measureLabel) + Object::assign(_measureLabel, s_sharedMeasureLabel); + + // Update font configuration to match current instance (handles different fonts across instances) + if (_systemFontUsed) + { + _measureLabel->setSystemFontName(_fontName); + _measureLabel->setSystemFontSize(_fontSize); + } + else + { + _measureLabel->setTTFConfig(_renderLabel->getTTFConfig()); + } + + // Measure text using shared label + _measureLabel->setString(text); + return _measureLabel->getContentSize(); +} + ////////////////////////////////////////////////////////////////////////// // initialize ////////////////////////////////////////////////////////////////////////// @@ -224,7 +240,16 @@ bool InputField::initWithPlaceHolder(std::string_view placeholder, _placeHolder = placeholder; /// render label - _renderLabel = _createLabel(placeholder, fontName, fontSize); + if (FileUtils::getInstance()->isFileExist(fontName)) + { + TTFConfig config(fontName, static_cast(fontSize)); + _renderLabel = Label::createWithTTF(config, placeholder); + } + else + { + _renderLabel = Label::createWithSystemFont(placeholder, fontName, fontSize); + } + if (!placeholder.empty()) _renderLabel->setTextColor(_colorSpaceHolder); this->addProtectedChild(_renderLabel, INPUT_FIELD_RENDERER_Z); @@ -237,13 +262,13 @@ bool InputField::initWithPlaceHolder(std::string_view placeholder, _cursor = Sprite::createWithTexture(_director->getTextureCache()->getWhiteTexture()); auto& originalSize = _cursor->getContentSize(); - auto cursorHeight = measureTextExtent("M"sv, fontName, fontSize).height; + auto cursorHeight = measureTextExtent("M"sv).height; _cursor->setContentSize(Vec2{cursorWidth, cursorHeight}); this->addProtectedChild(_cursor); hideCursor(); updateCursorPosition(); - _passwordCharWidth = measureTextExtent(_passwordChar, _fontName, _fontSize).width; + _passwordCharWidth = measureTextExtent(_passwordChar).width; // Initialize content size based on placeholder text updateContentSize(); @@ -380,8 +405,8 @@ void InputField::setTextFontName(std::string_view fontName) } _fontName = fontName; - _passwordCharWidth = measureTextExtent(_passwordChar, _fontName, _fontSize).width; - auto cursorHeight = measureTextExtent("M"sv, _fontName, _fontSize).height; + _passwordCharWidth = measureTextExtent(_passwordChar).width; + auto cursorHeight = measureTextExtent("M"sv).height; _cursor->setContentSize(Vec2{_cursor->getContentSize().width, cursorHeight}); updateCursorPosition(); updateSelectionLayer(); @@ -402,7 +427,7 @@ void InputField::setTextFontSize(float size) _fontSize = size; - _passwordCharWidth = measureTextExtent(_passwordChar, _fontName, _fontSize).width; + _passwordCharWidth = measureTextExtent(_passwordChar).width; updateCursorPosition(); updateSelectionLayer(); } @@ -484,6 +509,11 @@ void InputField::dispatchEvent(EventType eventType) } } +bool InputField::isCursorVisible() const +{ + return _cursor && _cursor->isVisible(); +} + bool InputField::canAttachWithIME() { return true; @@ -809,7 +839,7 @@ void InputField::setPasswordChar(std::string_view ch) if (ch != _passwordChar) { _passwordChar = !ch.empty() ? ch : "*"sv; - _passwordCharWidth = measureTextExtent(_passwordChar, _fontName, _fontSize).width; + _passwordCharWidth = measureTextExtent(_passwordChar).width; if (_passwordEnabled) { setString(getString()); @@ -1154,27 +1184,6 @@ TextVAlignment InputField::getTextVerticalAlignment() const return _textVAlignment; } -////////////////////////////////////////////////////////////////////////// -// Text Area Size -////////////////////////////////////////////////////////////////////////// -void InputField::setTextAreaSize(const Vec2& size) -{ - _textAreaSize = size; - if (_renderLabel) - { - _renderLabel->setDimensions(size.width, size.height); - } -} - -Vec2 InputField::getAutoRenderSize() -{ - if (_renderLabel) - { - return _renderLabel->getContentSize(); - } - return this->getContentSize(); -} - ////////////////////////////////////////////////////////////////////////// // Touch Event Handlers (Override Widget's methods) ////////////////////////////////////////////////////////////////////////// @@ -1201,9 +1210,9 @@ bool InputField::onTouchBegan(Touch* touch, Event* event) bool focus = isCursorVisible(); if (focus && _continuousTouchCallback) { - _continuousTouchPending = true; - _continuousTouchElapsedTime = 0.0f; - _continuousTouchWorldPoint = touch->getLocation(); + _continuousTouchPending = true; + _continuousTouchElapsedTime = 0.0f; + _continuousTouchWorldPoint = touch->getLocation(); } // Initialize selection state @@ -1287,7 +1296,7 @@ float InputField::cursorXFromPosition(std::size_t cursorPosition) const if (_renderLabel) { float labelWidth = _renderLabel->getContentSize().width; - float totalTextWidth = measureTextExtent(_inputText, _fontName, _fontSize).width; + float totalTextWidth = measureTextExtent(_inputText).width; // Label is positioned at center of InputField with ANCHOR_MIDDLE // So label's left edge is at: contentSize.width/2 - labelWidth/2 @@ -1322,7 +1331,7 @@ float InputField::cursorXFromPosition(std::size_t cursorPosition) const if (byteOffset == std::string::npos) byteOffset = _inputText.length(); - float textWidth = measureTextExtent(std::string_view(_inputText.data(), byteOffset), _fontName, _fontSize).width; + float textWidth = measureTextExtent(std::string_view(_inputText.data(), byteOffset)).width; return textStartOffset + textWidth; } @@ -1334,10 +1343,11 @@ std::size_t InputField::positionFromCursorX(float x) const // Calculate the offset from InputField origin to text start position float textStartOffset = 0.0f; + float totalTextWidth = 0.0f; if (_renderLabel) { - float labelWidth = _renderLabel->getContentSize().width; - float totalTextWidth = measureTextExtent(_inputText, _fontName, _fontSize).width; + float labelWidth = _renderLabel->getContentSize().width; + totalTextWidth = measureTextExtent(_inputText).width; // Label is positioned at center of InputField with ANCHOR_MIDDLE float labelLeftEdge = _contentSize.width / 2.0f - labelWidth / 2.0f; @@ -1364,10 +1374,26 @@ std::size_t InputField::positionFromCursorX(float x) const if (adjustedX < 0) return 0; + if (adjustedX >= totalTextWidth) + return _charCount; + float previousX = 0; for (std::size_t i = 1; i <= _charCount; ++i) { - auto currentX = cursorXFromPosition(i) - textStartOffset; + float currentX = 0.0f; + if (_passwordEnabled) + { + currentX = _passwordCharWidth * i; + } + else + { + auto byteOffset = text_utils::getUTF8ByteOffset(_inputText, i); + if (byteOffset == std::string::npos) + byteOffset = _inputText.length(); + + currentX = measureTextExtent(std::string_view(_inputText.data(), byteOffset)).width; + } + if (adjustedX < (previousX + currentX) * 0.5f) return i - 1; previousX = currentX; diff --git a/axmol/ui/UIInputField.h b/axmol/ui/UIInputField.h index 50888511803b..4e9d278fe3a3 100644 --- a/axmol/ui/UIInputField.h +++ b/axmol/ui/UIInputField.h @@ -28,7 +28,6 @@ THE SOFTWARE. #include "axmol/base/IMEDelegate.h" #include "axmol/2d/DrawNode.h" #include "axmol/2d/Label.h" -#include "axmol/2d/Sprite.h" #include "axmol/base/EventListenerKeyboard.h" namespace ax @@ -183,10 +182,6 @@ class AX_DLL InputField : public Widget, public IMEDelegate void setTextVerticalAlignment(TextVAlignment alignment); TextVAlignment getTextVerticalAlignment() const; - /// text area size - void setTextAreaSize(const Vec2& size); - Vec2 getAutoRenderSize(); - /// touch area void setTouchAreaSize(const Vec2& size); Vec2 getTouchAreaSize() const; @@ -325,8 +320,7 @@ class AX_DLL InputField : public Widget, public IMEDelegate */ void dispatchEvent(EventType eventType); - - bool isCursorVisible() const { return _cursor && _cursor->isVisible(); } + bool isCursorVisible() const; protected: void updateLayout() override; @@ -373,7 +367,6 @@ class AX_DLL InputField : public Widget, public IMEDelegate int _insertPosUtf8; int _insertPos; // The actual input content insertPos, step: bytes - int _cursorPos; // The cursor normalized pos, EventListenerKeyboard* _kbdListener; @@ -383,11 +376,8 @@ class AX_DLL InputField : public Widget, public IMEDelegate bool _continuousTouchPending; float _continuousTouchElapsedTime; float _continuousTouchDelayTime; - Point _continuousTouchWorldPoint; - std::function _continuousTouchCallback; + Vec2 _continuousTouchWorldPoint; - /// Event callback - InputFieldCallback _eventCallback; /// Touch area Vec2 _touchAreaSize; @@ -395,10 +385,24 @@ class AX_DLL InputField : public Widget, public IMEDelegate TextHAlignment _textHAlignment; TextVAlignment _textVAlignment; - /// Text area size - Vec2 _textAreaSize; + std::function _continuousTouchCallback; + + /// Event callback + InputFieldCallback _eventCallback; static bool s_keyboardVisible; + + // Shared measure label (reference counted, thread-safe in single-threaded rendering) + mutable Label* _measureLabel{nullptr}; + + static Label* s_sharedMeasureLabel; + + /** + * @brief Measure text extent using shared label (no temporary object creation). + * @param text The text to measure. + * @return The content size of the text. + */ + Vec2 measureTextExtent(std::string_view text) const; }; // end of input group diff --git a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextFieldTest/UIInputFieldTest.cpp b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextFieldTest/UIInputFieldTest.cpp index 3ecd77065b8c..b41433315f8a 100644 --- a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextFieldTest/UIInputFieldTest.cpp +++ b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextFieldTest/UIInputFieldTest.cpp @@ -67,7 +67,7 @@ bool UIInputFieldTest::init() InputField* inputField = InputField::create("input words here", "Arial", 30); inputField->setTextHorizontalAlignment(TextHAlignment::CENTER); inputField->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); - + // Set up event listener for InputField inputField->addEventListener([this](InputField* sender, InputField::EventType type) { switch (type) { @@ -85,7 +85,7 @@ bool UIInputFieldTest::init() break; } }); - + _uiLayer->addChild(inputField); return true; @@ -123,7 +123,7 @@ bool UIInputFieldTest_MaxLength::init() inputField->setCharLimit(3); inputField->setTextHorizontalAlignment(TextHAlignment::CENTER); inputField->setPosition(Vec2(screenSize.width / 2.0f, screenSize.height / 2.0f)); - + // Set up event listener for InputField inputField->addEventListener([this, inputField](InputField* sender, InputField::EventType type) { switch (type) { @@ -141,7 +141,7 @@ bool UIInputFieldTest_MaxLength::init() break; } }); - + _uiLayer->addChild(inputField); return true; @@ -179,7 +179,7 @@ bool UIInputFieldTest_Password::init() inputField->setPasswordEnabled(true); inputField->setTextHorizontalAlignment(TextHAlignment::CENTER); inputField->setPosition(Vec2(screenSize.width / 2.0f, screenSize.height / 2.0f)); - + // Set up event listener for InputField inputField->addEventListener([this](InputField* sender, InputField::EventType type) { switch (type) { @@ -197,7 +197,7 @@ bool UIInputFieldTest_Password::init() break; } }); - + _uiLayer->addChild(inputField); return true; @@ -232,12 +232,12 @@ bool UIInputFieldTest_LineWrap::init() // Create the inputfield InputField* inputField = InputField::create("input words here", "fonts/Marker Felt.ttf", 30); - inputField->setTextAreaSize(Vec2(240.0f, 170.0f)); + inputField->setContentSize(Vec2(240.0f, 170.0f)); inputField->setString("input words here"); inputField->setTextHorizontalAlignment(TextHAlignment::CENTER); inputField->setTextVerticalAlignment(TextVAlignment::CENTER); inputField->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); - + // Set up event listener for InputField inputField->addEventListener([this](InputField* sender, InputField::EventType type) { switch (type) { @@ -255,7 +255,7 @@ bool UIInputFieldTest_LineWrap::init() break; } }); - + _uiLayer->addChild(inputField); return true; @@ -291,7 +291,7 @@ bool UIInputFieldTest_TrueTypeFont::init() InputField* inputField = InputField::create("input words here", "fonts/A Damn Mess.ttf", 30); inputField->setTextHorizontalAlignment(TextHAlignment::CENTER); inputField->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); - + // Set up event listener for InputField inputField->addEventListener([this](InputField* sender, InputField::EventType type) { switch (type) { @@ -309,7 +309,7 @@ bool UIInputFieldTest_TrueTypeFont::init() break; } }); - + _uiLayer->addChild(inputField); return true; @@ -345,7 +345,7 @@ bool UIInputFieldTest_BMFont::init() InputField* inputField = InputField::create("BMFont Text", "fonts/bitmapFontTest3.fnt", 30); inputField->setTextHorizontalAlignment(TextHAlignment::CENTER); inputField->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); - + // Set up event listener for InputField inputField->addEventListener([this](InputField* sender, InputField::EventType type) { switch (type) { @@ -363,7 +363,7 @@ bool UIInputFieldTest_BMFont::init() break; } }); - + _uiLayer->addChild(inputField); return true; @@ -404,7 +404,7 @@ bool UIInputFieldTest_PlaceHolderColor::init() inputField->setTextColor(Color32::RED); inputField->setTextHorizontalAlignment(TextHAlignment::CENTER); inputField->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); - + // Set up event listener for InputField inputField->addEventListener([this, inputField](InputField* sender, InputField::EventType type) { switch (type) { @@ -424,7 +424,7 @@ bool UIInputFieldTest_PlaceHolderColor::init() break; } }); - + _uiLayer->addChild(inputField); return true; } From 638bf82fb00dc9c509fd5f537423ff4854a392a1 Mon Sep 17 00:00:00 2001 From: halx99 Date: Tue, 19 May 2026 09:40:04 +0800 Subject: [PATCH 12/52] up --- axmol/ui/UIInputField.cpp | 112 ++++++++++++++++---------------------- axmol/ui/UIInputField.h | 33 +++++------ 2 files changed, 62 insertions(+), 83 deletions(-) diff --git a/axmol/ui/UIInputField.cpp b/axmol/ui/UIInputField.cpp index a8f7cfbdf338..273a658f0e5a 100644 --- a/axmol/ui/UIInputField.cpp +++ b/axmol/ui/UIInputField.cpp @@ -47,9 +47,9 @@ namespace ax namespace ui { +namespace +{ static std::string s_clipboardFallback; -static InputField::ClipboardGetter s_clipboardGetter; -static InputField::ClipboardSetter s_clipboardSetter; static constexpr int INPUT_FIELD_RENDERER_Z = (-1); #if (AX_TARGET_PLATFORM == AX_PLATFORM_WIN32 || AX_TARGET_PLATFORM == AX_PLATFORM_MAC || \ @@ -63,9 +63,6 @@ static GLFWwindow* getClipboardWindow() static std::string readClipboardText() { - if (s_clipboardGetter) - return s_clipboardGetter(); - #if (AX_TARGET_PLATFORM == AX_PLATFORM_WIN32 || AX_TARGET_PLATFORM == AX_PLATFORM_MAC || \ AX_TARGET_PLATFORM == AX_PLATFORM_LINUX) if (auto window = getClipboardWindow()) @@ -80,12 +77,6 @@ static std::string readClipboardText() static void writeClipboardText(std::string_view text) { - if (s_clipboardSetter) - { - s_clipboardSetter(text); - return; - } - s_clipboardFallback = text; #if (AX_TARGET_PLATFORM == AX_PLATFORM_WIN32 || AX_TARGET_PLATFORM == AX_PLATFORM_MAC || \ @@ -114,12 +105,12 @@ static std::pair _truncateUTF8String(const char* text, int charLimit) } return std::make_pair(charCount, numOfBytes); } +} // namespace ////////////////////////////////////////////////////////////////////////// // constructor and destructor ////////////////////////////////////////////////////////////////////////// -bool InputField::s_keyboardVisible = false; -Label* InputField::s_sharedMeasureLabel = nullptr; +bool InputField::s_keyboardVisible = false; InputField::InputField() : _editable(true) @@ -163,16 +154,8 @@ InputField::~InputField() if (_kbdListener != nullptr) _eventDispatcher->removeEventListener(_kbdListener); - // Decrement reference count and release shared measure label if last user - - if (_measureLabel) - { - if (_measureLabel->getReferenceCount() == 1) - s_sharedMeasureLabel = nullptr; - - _measureLabel->release(); - _measureLabel = nullptr; - } + // Release instance-specific measure label + AX_SAFE_RELEASE_NULL(_measureLabel); } ////////////////////////////////////////////////////////////////////////// @@ -197,27 +180,17 @@ InputField* InputField::create(std::string_view placeholder, ////////////////////////////////////////////////////////////////////////// // text measurement ////////////////////////////////////////////////////////////////////////// -Vec2 InputField::measureTextExtent(std::string_view text) const +Vec2 InputField::measureText(std::string_view text) const { - // Lazy initialize shared measure label on first use by any InputField instance - if (!s_sharedMeasureLabel) - s_sharedMeasureLabel = Label::create(); - + // Lazy initialize instance-specific measure label if (!_measureLabel) - Object::assign(_measureLabel, s_sharedMeasureLabel); - - // Update font configuration to match current instance (handles different fonts across instances) - if (_systemFontUsed) - { - _measureLabel->setSystemFontName(_fontName); - _measureLabel->setSystemFontSize(_fontSize); - } - else { - _measureLabel->setTTFConfig(_renderLabel->getTTFConfig()); + _measureLabel = Label::createWithSystemFont("", _fontName, _fontSize); + _measureLabel->retain(); // Manual reference counting + updateMeasureFont(); } - // Measure text using shared label + // Measure text (font is already synced in setFontName/setFontSize) _measureLabel->setString(text); return _measureLabel->getContentSize(); } @@ -242,7 +215,7 @@ bool InputField::initWithPlaceHolder(std::string_view placeholder, /// render label if (FileUtils::getInstance()->isFileExist(fontName)) { - TTFConfig config(fontName, static_cast(fontSize)); + TTFConfig config(fontName, fontSize); _renderLabel = Label::createWithTTF(config, placeholder); } else @@ -262,13 +235,13 @@ bool InputField::initWithPlaceHolder(std::string_view placeholder, _cursor = Sprite::createWithTexture(_director->getTextureCache()->getWhiteTexture()); auto& originalSize = _cursor->getContentSize(); - auto cursorHeight = measureTextExtent("M"sv).height; + auto cursorHeight = measureText("M"sv).height; _cursor->setContentSize(Vec2{cursorWidth, cursorHeight}); this->addProtectedChild(_cursor); hideCursor(); updateCursorPosition(); - _passwordCharWidth = measureTextExtent(_passwordChar).width; + _passwordCharWidth = measureText(_passwordChar).width; // Initialize content size based on placeholder text updateContentSize(); @@ -378,12 +351,12 @@ void InputField::onExit() Widget::onExit(); } -std::string_view InputField::getTextFontName() const +std::string_view InputField::getFontName() const { return _fontName; } -void InputField::setTextFontName(std::string_view fontName) +void InputField::setFontName(std::string_view fontName) { if (FileUtils::getInstance()->isFileExist(fontName)) { @@ -405,14 +378,18 @@ void InputField::setTextFontName(std::string_view fontName) } _fontName = fontName; - _passwordCharWidth = measureTextExtent(_passwordChar).width; - auto cursorHeight = measureTextExtent("M"sv).height; + // Sync measure label font + if (_measureLabel) + updateMeasureFont(); + + _passwordCharWidth = measureText(_passwordChar).width; + auto cursorHeight = measureText("M"sv).height; _cursor->setContentSize(Vec2{_cursor->getContentSize().width, cursorHeight}); updateCursorPosition(); updateSelectionLayer(); } -void InputField::setTextFontSize(float size) +void InputField::setFontSize(float size) { if (_systemFontUsed) { @@ -427,12 +404,16 @@ void InputField::setTextFontSize(float size) _fontSize = size; - _passwordCharWidth = measureTextExtent(_passwordChar).width; + // Sync measure label font + if (_measureLabel) + updateMeasureFont(); + + _passwordCharWidth = measureText(_passwordChar).width; updateCursorPosition(); updateSelectionLayer(); } -float InputField::getTextFontSize() const +float InputField::getFontSize() const { return _fontSize; } @@ -839,7 +820,7 @@ void InputField::setPasswordChar(std::string_view ch) if (ch != _passwordChar) { _passwordChar = !ch.empty() ? ch : "*"sv; - _passwordCharWidth = measureTextExtent(_passwordChar).width; + _passwordCharWidth = measureText(_passwordChar).width; if (_passwordEnabled) { setString(getString()); @@ -963,16 +944,6 @@ const Color& InputField::getSelectionColor() const return _selectionColor; } -void InputField::setClipboardGetter(ClipboardGetter getter) -{ - s_clipboardGetter = std::move(getter); -} - -void InputField::setClipboardSetter(ClipboardSetter setter) -{ - s_clipboardSetter = std::move(setter); -} - std::string InputField::getClipboardText() { return readClipboardText(); @@ -1296,7 +1267,7 @@ float InputField::cursorXFromPosition(std::size_t cursorPosition) const if (_renderLabel) { float labelWidth = _renderLabel->getContentSize().width; - float totalTextWidth = measureTextExtent(_inputText).width; + float totalTextWidth = measureText(_inputText).width; // Label is positioned at center of InputField with ANCHOR_MIDDLE // So label's left edge is at: contentSize.width/2 - labelWidth/2 @@ -1331,7 +1302,7 @@ float InputField::cursorXFromPosition(std::size_t cursorPosition) const if (byteOffset == std::string::npos) byteOffset = _inputText.length(); - float textWidth = measureTextExtent(std::string_view(_inputText.data(), byteOffset)).width; + float textWidth = measureText(std::string_view(_inputText.data(), byteOffset)).width; return textStartOffset + textWidth; } @@ -1347,7 +1318,7 @@ std::size_t InputField::positionFromCursorX(float x) const if (_renderLabel) { float labelWidth = _renderLabel->getContentSize().width; - totalTextWidth = measureTextExtent(_inputText).width; + totalTextWidth = measureText(_inputText).width; // Label is positioned at center of InputField with ANCHOR_MIDDLE float labelLeftEdge = _contentSize.width / 2.0f - labelWidth / 2.0f; @@ -1391,7 +1362,7 @@ std::size_t InputField::positionFromCursorX(float x) const if (byteOffset == std::string::npos) byteOffset = _inputText.length(); - currentX = measureTextExtent(std::string_view(_inputText.data(), byteOffset)).width; + currentX = measureText(std::string_view(_inputText.data(), byteOffset)).width; } if (adjustedX < (previousX + currentX) * 0.5f) @@ -1402,6 +1373,19 @@ std::size_t InputField::positionFromCursorX(float x) const return _charCount; } +void InputField::updateMeasureFont() const +{ + if (_systemFontUsed) + { + _measureLabel->setSystemFontName(_fontName); + _measureLabel->setSystemFontSize(_fontSize); + } + else + { + _measureLabel->setTTFConfig(_renderLabel->getTTFConfig()); + } +} + } // namespace ui } // namespace ax diff --git a/axmol/ui/UIInputField.h b/axmol/ui/UIInputField.h index 4e9d278fe3a3..25125cb52665 100644 --- a/axmol/ui/UIInputField.h +++ b/axmol/ui/UIInputField.h @@ -42,9 +42,6 @@ namespace ui class AX_DLL InputField : public Widget, public IMEDelegate { public: - using ClipboardGetter = std::function; - using ClipboardSetter = std::function; - /** */ InputField(); @@ -165,16 +162,14 @@ class AX_DLL InputField : public Widget, public IMEDelegate void setSelectionColor(const Color& color); const Color& getSelectionColor() const; - static void setClipboardGetter(ClipboardGetter getter); - static void setClipboardSetter(ClipboardSetter setter); static std::string getClipboardText(); static void setClipboardText(std::string_view text); /// fonts - void setTextFontSize(float size); - float getTextFontSize() const; - void setTextFontName(std::string_view fontName); - std::string_view getTextFontName() const; + void setFontSize(float size); + float getFontSize() const; + void setFontName(std::string_view fontName); + std::string_view getFontName() const; /// text alignment void setTextHorizontalAlignment(TextHAlignment alignment); @@ -333,6 +328,15 @@ class AX_DLL InputField : public Widget, public IMEDelegate void onTouchEnded(Touch* touch, Event* event) override; void onTouchCancelled(Touch* touch, Event* event) override; + /** + * @brief Measure text extent using instance-specific label (optimal performance). + * @param text The text to measure. + * @return The content size of the text. + */ + Vec2 measureText(std::string_view text) const; + + void updateMeasureFont() const; + std::string _fontName; float _fontSize; @@ -392,17 +396,8 @@ class AX_DLL InputField : public Widget, public IMEDelegate static bool s_keyboardVisible; - // Shared measure label (reference counted, thread-safe in single-threaded rendering) + // Instance-specific measure label (lazy initialized, no sharing overhead) mutable Label* _measureLabel{nullptr}; - - static Label* s_sharedMeasureLabel; - - /** - * @brief Measure text extent using shared label (no temporary object creation). - * @param text The text to measure. - * @return The content size of the text. - */ - Vec2 measureTextExtent(std::string_view text) const; }; // end of input group From 8f854605745cdd41ced33d71b0390b176220e2e9 Mon Sep 17 00:00:00 2001 From: halx99 Date: Tue, 19 May 2026 10:17:12 +0800 Subject: [PATCH 13/52] up --- axmol/ui/UIInputField.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/axmol/ui/UIInputField.cpp b/axmol/ui/UIInputField.cpp index 273a658f0e5a..ded7de8d2b2a 100644 --- a/axmol/ui/UIInputField.cpp +++ b/axmol/ui/UIInputField.cpp @@ -185,7 +185,7 @@ Vec2 InputField::measureText(std::string_view text) const // Lazy initialize instance-specific measure label if (!_measureLabel) { - _measureLabel = Label::createWithSystemFont("", _fontName, _fontSize); + _measureLabel = Label::create(); _measureLabel->retain(); // Manual reference counting updateMeasureFont(); } From 211c21535134e7fd3dd842930b7f3a19b90df0b9 Mon Sep 17 00:00:00 2001 From: halx99 Date: Tue, 19 May 2026 11:34:12 +0800 Subject: [PATCH 14/52] up --- axmol/ui/UIInputField.cpp | 158 ++++++++++++++++---- axmol/ui/UIInputField.h | 294 +++++++++++++++++++++++++++++++------- 2 files changed, 368 insertions(+), 84 deletions(-) diff --git a/axmol/ui/UIInputField.cpp b/axmol/ui/UIInputField.cpp index ded7de8d2b2a..bb297b27d34e 100644 --- a/axmol/ui/UIInputField.cpp +++ b/axmol/ui/UIInputField.cpp @@ -129,7 +129,7 @@ InputField::InputField() , _selectionAnchorUtf8(0) , _kbdListener(nullptr) , _eventCallback(nullptr) - , _charLimit(std::numeric_limits::max()) + , _charLimit(0) , _systemFontUsed(false) , _fontSize(24) , _insertPosUtf8(0) @@ -191,8 +191,18 @@ Vec2 InputField::measureText(std::string_view text) const } // Measure text (font is already synced in setFontName/setFontSize) +#ifdef AX_INPUTFIELD_BENCHMARK + auto t1 = std::chrono::high_resolution_clock::now(); +#endif _measureLabel->setString(text); - return _measureLabel->getContentSize(); + Vec2 cs = _measureLabel->getContentSize(); +#ifdef AX_INPUTFIELD_BENCHMARK + auto t2 = std::chrono::high_resolution_clock::now(); + auto us = std::chrono::duration_cast(t2 - t1).count(); + g_measureTextCalls.fetch_add(1, std::memory_order_relaxed); + g_measureTextTimeUs.fetch_add(static_cast(us), std::memory_order_relaxed); +#endif + return cs; } ////////////////////////////////////////////////////////////////////////// @@ -387,6 +397,7 @@ void InputField::setFontName(std::string_view fontName) _cursor->setContentSize(Vec2{_cursor->getContentSize().width, cursorHeight}); updateCursorPosition(); updateSelectionLayer(); + invalidatePrefixWidths(); } void InputField::setFontSize(float size) @@ -411,6 +422,7 @@ void InputField::setFontSize(float size) _passwordCharWidth = measureText(_passwordChar).width; updateCursorPosition(); updateSelectionLayer(); + invalidatePrefixWidths(); } float InputField::getFontSize() const @@ -505,6 +517,24 @@ bool InputField::canDetachWithIME() return true; } +void InputField::setCharLimit(size_t limit) +{ + _charLimit = limit; + + // If the new limit is non-zero and shorter than current text, truncate + // the stored input so the control remains in a valid state. Use + // setString() to ensure rendering, prefix caches and cursor are updated + // consistently. + if (_charLimit > 0 && _charCount > _charLimit) + { + auto byteOffset = getByteOffset(static_cast(_charLimit)); + std::string newText(_inputText.substr(0, byteOffset)); + setString(newText); + // Ensure cursor is not past the new limit + setCursorPosition(static_cast(_charLimit), false); + } +} + void InputField::insertText(const char* text, size_t len) { if (!_editable || !this->_enabled) @@ -752,6 +782,9 @@ void InputField::setString(std::string_view text) _selectionEndUtf8 = std::min(_selectionEndUtf8, _charCount); updateSelectionLayer(); + // Invalidate cached prefix widths when text changes + invalidatePrefixWidths(); + // Update content size to match the rendered text updateContentSize(); } @@ -825,6 +858,7 @@ void InputField::setPasswordChar(std::string_view ch) { setString(getString()); } + invalidatePrefixWidths(); } } @@ -854,6 +888,7 @@ void InputField::setPasswordEnabled(bool value) _passwordEnabled = value; this->setString(this->getString()); updateCursorPosition(); + invalidatePrefixWidths(); } } @@ -959,7 +994,14 @@ void InputField::showCursor(void) if (_cursor) { _cursor->setVisible(true); - _cursor->runAction(RepeatForever::create(Blink::create(1, 1))); + _cursor->setOpacity(255); // Ensure full opacity + + // Use opacity-based blinking for better performance + // Fade out to 0 over 0.5s, then fade in over 0.5s (total 1s cycle) + auto fadeOut = FadeOut::create(0.5f); + auto fadeIn = FadeIn::create(0.5f); + auto blinkSequence = Sequence::create(fadeOut, fadeIn, nullptr); + _cursor->runAction(RepeatForever::create(blinkSequence)); } } @@ -967,8 +1009,9 @@ void InputField::hideCursor(void) { if (_cursor) { - _cursor->setVisible(false); _cursor->stopAllActions(); + _cursor->setOpacity(255); // Reset to full opacity + _cursor->setVisible(false); } } @@ -1267,7 +1310,7 @@ float InputField::cursorXFromPosition(std::size_t cursorPosition) const if (_renderLabel) { float labelWidth = _renderLabel->getContentSize().width; - float totalTextWidth = measureText(_inputText).width; + float totalTextWidth = (_charCount > 0) ? getPrefixWidth(_charCount) : 0.0f; // Label is positioned at center of InputField with ANCHOR_MIDDLE // So label's left edge is at: contentSize.width/2 - labelWidth/2 @@ -1298,11 +1341,7 @@ float InputField::cursorXFromPosition(std::size_t cursorPosition) const if (_passwordEnabled) return textStartOffset + _passwordCharWidth * cursorPosition; - auto byteOffset = text_utils::getUTF8ByteOffset(_inputText, cursorPosition); - if (byteOffset == std::string::npos) - byteOffset = _inputText.length(); - - float textWidth = measureText(std::string_view(_inputText.data(), byteOffset)).width; + float textWidth = getPrefixWidth(cursorPosition); return textStartOffset + textWidth; } @@ -1318,7 +1357,7 @@ std::size_t InputField::positionFromCursorX(float x) const if (_renderLabel) { float labelWidth = _renderLabel->getContentSize().width; - totalTextWidth = measureText(_inputText).width; + totalTextWidth = (_charCount > 0) ? getPrefixWidth(_charCount) : 0.0f; // Label is positioned at center of InputField with ANCHOR_MIDDLE float labelLeftEdge = _contentSize.width / 2.0f - labelWidth / 2.0f; @@ -1348,29 +1387,23 @@ std::size_t InputField::positionFromCursorX(float x) const if (adjustedX >= totalTextWidth) return _charCount; - float previousX = 0; - for (std::size_t i = 1; i <= _charCount; ++i) + // Binary search using cached prefix widths. We choose the smallest index i + // such that adjustedX < midpoint(prefix[i], prefix[i+1]). Returns i. + std::size_t low = 0; + std::size_t high = _charCount; + while (low < high) { - float currentX = 0.0f; - if (_passwordEnabled) - { - currentX = _passwordCharWidth * i; - } + std::size_t mid = (low + high) / 2; + float leftX = getPrefixWidth(mid); + float rightX = getPrefixWidth(mid + 1); + float midPoint = (leftX + rightX) * 0.5f; + if (adjustedX < midPoint) + high = mid; else - { - auto byteOffset = text_utils::getUTF8ByteOffset(_inputText, i); - if (byteOffset == std::string::npos) - byteOffset = _inputText.length(); - - currentX = measureText(std::string_view(_inputText.data(), byteOffset)).width; - } - - if (adjustedX < (previousX + currentX) * 0.5f) - return i - 1; - previousX = currentX; + low = mid + 1; } - return _charCount; + return low; } void InputField::updateMeasureFont() const @@ -1386,6 +1419,71 @@ void InputField::updateMeasureFont() const } } +float InputField::getPrefixWidth(std::size_t charIndex) const +{ + if (charIndex == 0) + return 0.0f; + + if (_passwordEnabled) + return static_cast(charIndex) * _passwordCharWidth; + // If precomputed cache is enabled and available, return directly + if (_precomputePrefixWidthsEnabled && _prefixWidths.size() == (_charCount + 1)) + { + return _prefixWidths[charIndex]; + } + // Fallback to on-demand measurement for missing cache or when precompute disabled + auto byteOffset = text_utils::getUTF8ByteOffset(_inputText, charIndex); + if (byteOffset == std::string::npos) + byteOffset = _inputText.length(); + + float w = measureText(std::string_view(_inputText.data(), byteOffset)).width; + return w; +} + +void InputField::invalidatePrefixWidths() const +{ + _prefixWidths.clear(); + if (_precomputePrefixWidthsEnabled) + { + // Precompute all prefix widths at once to avoid repeated measureText calls + _prefixWidths.resize(_charCount + 1); + _prefixWidths[0] = 0.0f; + if (_passwordEnabled) + { + for (std::size_t i = 1; i <= _charCount; ++i) + _prefixWidths[i] = static_cast(i) * _passwordCharWidth; + } + else + { + for (std::size_t i = 1; i <= _charCount; ++i) + { + auto byteOffset = text_utils::getUTF8ByteOffset(_inputText, i); + if (byteOffset == std::string::npos) + byteOffset = _inputText.length(); + + _prefixWidths[i] = measureText(std::string_view(_inputText.data(), byteOffset)).width; + } + } + _prefixWidthsDirty = false; + } + else + { + _prefixWidthsDirty = true; + } +} +void InputField::setPrefixWidthCachingEnabled(bool enabled) +{ + if (_precomputePrefixWidthsEnabled == enabled) + return; + _precomputePrefixWidthsEnabled = enabled; + invalidatePrefixWidths(); +} + +bool InputField::isPrefixWidthCachingEnabled() const +{ + return _precomputePrefixWidthsEnabled; +} + } // namespace ui } // namespace ax diff --git a/axmol/ui/UIInputField.h b/axmol/ui/UIInputField.h index 25125cb52665..674d5ca94d62 100644 --- a/axmol/ui/UIInputField.h +++ b/axmol/ui/UIInputField.h @@ -29,6 +29,7 @@ THE SOFTWARE. #include "axmol/2d/DrawNode.h" #include "axmol/2d/Label.h" #include "axmol/base/EventListenerKeyboard.h" +#include namespace ax { @@ -43,45 +44,110 @@ class AX_DLL InputField : public Widget, public IMEDelegate { public: /** + * @brief Construct a new InputField. + * + * The constructor performs minimal initialization; call initWithPlaceHolder + * or use the static create() helper to construct a fully initialized + * instance. */ InputField(); + /** - * @lua NA + * @brief Destroy the InputField instance. */ virtual ~InputField(); + /** + * @brief Create and initialize an InputField. + * @param placeholder Placeholder text shown when the field is empty. + * @param fontName Font path or system font name. + * @param fontSize Font size in points. + * @param cursorWidth Cursor visual width in pixels. + * @param color Cursor color. + * @return A new InputField instance or nullptr on failure. + */ static InputField* create(std::string_view placeholder, std::string_view fontName, float fontSize, float cursorWidth = 2, const Color32& color = Color32::WHITE); + /** + * @brief Initialize the InputField with placeholder and font settings. + * @return True if initialization succeeded. + */ bool initWithPlaceHolder(std::string_view placeholder, std::string_view fontName, float fontSize, float cursorWidth = 2, const Color32& color = Color32::WHITE); + /** + * @brief Returns the internal `Label` used for rendering text. + */ Label* getRenderLabel(); + /** + * @brief Get the text character count (in UTF-8 characters/graphemes). + * @return Character count. + */ inline int getCharCount() const { return static_cast(_charCount); }; + /** + * @brief Set placeholder text color. + */ virtual void setPlaceholderColor(const Color32& color); + + /** + * @brief Get placeholder text color. + */ virtual const Color32& getPlaceholderColor() const; + /** + * @brief Set the color used to render input text. + */ virtual void setTextColor(const Color32& textColor); + + /** + * @brief Get the color used for input text. + */ virtual const Color32& getTextColor(void) const; + /** + * @brief Set cursor color. + */ void setCursorColor(const Color32& color); + + /** + * @brief Get current cursor color. + */ const Color32& getCursorColor(void) const; - // input text property + /** + * @brief Set the input text. This updates rendering and cursor state. + * @param text New UTF-8 text for the field. + */ virtual void setString(std::string_view text); + + /** + * @brief Get the current input text (UTF-8 string view). + */ virtual std::string_view getString() const; - // Continuous touch event trigger support. + /** + * @brief Configure continuous touch delay. + * @param delay Delay in seconds before continuous touch callback fires. + */ void setContinuousTouchDelayTime(float delay) { _continuousTouchDelayTime = delay; } + + /** + * @brief Get the continuous touch delay time. + */ float getContinuousTouchDelayTime() const { return _continuousTouchDelayTime; } + + /** + * @brief Set a callback invoked after continuous touch delay elapses. + */ void setContinuousTouchCallback(std::function callback) { _continuousTouchCallback = std::move(callback); @@ -89,116 +155,222 @@ class AX_DLL InputField : public Widget, public IMEDelegate /** * @brief Set the single visible mask character used when password mode is enabled. - * - * This configures the character that will be rendered in place of each actual input - * character when password mode is active (setPasswordEnabled(true)). The mask affects - * only visual rendering; the underlying stored text (_inputText) remains unchanged. - * - * Behavior - * - The function treats the provided input as a single visible character unit (a - * grapheme cluster). If the input contains multiple grapheme clusters, only the - * first cluster is used and the remainder is ignored. - * - Passing an empty string ("") restores the default mask character (for example, '•'). - * - After setting the mask the control will refresh its display and cursor position - * (internally calls setString(getString()) and updateCursorPosition()) so the change - * takes effect immediately. - * - * Implementation notes - * - Prefer extracting the first grapheme cluster (not merely the first UTF-8 code point) - * to correctly support composite emoji and other combined characters. If a grapheme - * library is not available, document the limitation of using the first code point. - * - Always measure the mask's rendered width using the font and size in use and cache - * that width for cursor/selection calculations; do not rely on byte length or codepoint - * count for layout. - * - Validate input: ignore or replace control/invisible characters and fall back to the - * default mask if the provided character is not renderable. - * - * Threading and performance - * - Call from the UI/main thread. Setting the mask triggers a redraw and cursor recalculation; - * avoid calling this repeatedly in tight loops. - * - * @param[in] ch UTF-8 string view containing the desired mask character. Only the first - * visible character unit is used; empty string restores the default mask. - * - * @note The mask is purely visual. For accessibility, consider exposing a separate API - * or policy for whether the real text may be read by assistive technologies. - * - * @example - * @code - * inputField->setPasswordEnabled(true); - * inputField->setPasswordChar("•"); // use bullet - * inputField->setPasswordChar("*"); // use asterisk - * @endcode + * @param ch UTF-8 string view for the visible mask character (uses first grapheme). */ void setPasswordChar(std::string_view ch); + + /** + * @brief Get the current password mask character. + */ std::string_view getPasswordChar() const { return _passwordChar; } - // place holder text property - // place holder text displayed when there is no text in the text field. + /** + * @brief Enable or disable prefix width caching. + * + * See setPrefixWidthCachingEnabled() for details on behaviour and trade-offs. + */ + void setPrefixWidthCachingEnabled(bool enabled); + + /** + * @brief Query whether prefix width caching is enabled. + */ + bool isPrefixWidthCachingEnabled() const; + + /** + * @brief Set placeholder text string. + */ virtual void setPlaceholderText(std::string_view text); + + /** + * @brief Get placeholder text string. + */ virtual std::string_view getPlaceholderText(void) const; + /** + * @brief Enable or disable password (secure) entry mode. + */ virtual void setPasswordEnabled(bool value); + + /** + * @brief Return whether password entry is enabled. + */ virtual bool isPasswordEnabled() const; - bool empty(void) const { return _charCount == 0 || _inputText.empty(); } + /** + * @brief Check whether the field contains no visible characters. + */ + bool isEmpty(void) const { return _charCount == 0 || _inputText.empty(); } + /** + * @brief Enable or disable the widget. + */ void setEnabled(bool bEnabled) override; + /** + * @brief Mark the field editable or read-only. + */ void setEditable(bool bEditable) { _editable = bEditable; } + + /** + * @brief Query whether the field is editable. + */ bool isEditable(void) const { return _editable; } + /** + * @brief Set maximum allowed character length (UTF-8 characters). + */ void setMaxLength(int maxLength) { setCharLimit(maxLength); } + /** + * @brief Query whether there is an active selection. + */ bool hasSelection() const; + + /** + * @brief Select all text. + */ void selectAll(); + + /** + * @brief Clear any text selection. + */ void clearSelection(); + + /** + * @brief Return the selected substring (UTF-8). + */ std::string getSelectedText() const; + /** + * @brief Copy current selection to clipboard. Returns false if nothing copied. + */ bool copySelectionToClipboard() const; + + /** + * @brief Cut current selection to clipboard. + */ bool cutSelectionToClipboard(); + + /** + * @brief Paste text from clipboard at the cursor position. + */ bool pasteFromClipboard(); + /** + * @brief Set selection (highlight) color. + */ void setSelectionColor(const Color& color); + + /** + * @brief Get current selection color. + */ const Color& getSelectionColor() const; + /** + * @brief Read text from system clipboard. + */ static std::string getClipboardText(); + + /** + * @brief Write text to the system clipboard. + */ static void setClipboardText(std::string_view text); /// fonts + /** + * @brief Set font size used for rendering the text. + */ void setFontSize(float size); + + /** + * @brief Get current font size. + */ float getFontSize() const; + + /** + * @brief Set the font used for rendering (path or system name). + */ void setFontName(std::string_view fontName); + + /** + * @brief Get the configured font name. + */ std::string_view getFontName() const; /// text alignment + /** + * @brief Set horizontal alignment of rendered text. + */ void setTextHorizontalAlignment(TextHAlignment alignment); + + /** + * @brief Get horizontal alignment. + */ TextHAlignment getTextHorizontalAlignment() const; + + /** + * @brief Set vertical alignment of rendered text. + */ void setTextVerticalAlignment(TextVAlignment alignment); + + /** + * @brief Get vertical alignment. + */ TextVAlignment getTextVerticalAlignment() const; /// touch area + /** + * @brief Set the custom touch area size for hit testing. + */ void setTouchAreaSize(const Vec2& size); + + /** + * @brief Get the touch area size. + */ Vec2 getTouchAreaSize() const; + + /** + * @brief Enable or disable the custom touch area hit test. + */ void setTouchAreaEnabled(bool enable); + + /** + * @brief Test whether a point hits the field (respecting touch area if enabled). + */ bool hitTest(const Vec2& pt, const Camera* camera, Vec3* p) const override; - AX_SYNTHESIZE(size_t, _charLimit, CharLimit); + /** + * @brief Set the maximum allowed character count for this input field. + * + * The limit is interpreted as a maximum number of UTF-8 characters (user + * level characters/grapheme clusters as counted by the control). Calling + * this affects subsequent input/insert operations which will be clipped to + * this limit. Use `0` to indicate no limit. + * + * @param limit Maximum characters allowed (0 = unlimited). + */ + void setCharLimit(size_t limit); + /** + * @brief Get the configured character limit. + * @return The maximum number of characters allowed (0 means unlimited). + */ + size_t getCharLimit() const { return _charLimit; } + + /** + * @brief Return whether the control uses a system font. + */ bool isSystemFont(void) const { return _systemFontUsed; } /** - * Gets the inner Renderer node of widget. - * - * For example, a button's Virtual Renderer is it's texture renderer. - * - * @return Node pointer. + * @brief Get the internal renderer node. + * @return Pointer to the renderer node. */ Node* getRenderNode() override; /** - * Get the virtual renderer's size - *@return Widget virtual renderer size. + * @brief Get preferred size based on rendered text. + * @return Preferred size. */ Vec2 getPreferredSize() const override; @@ -337,6 +509,18 @@ class AX_DLL InputField : public Widget, public IMEDelegate void updateMeasureFont() const; + // Cached prefix widths for fast cursor position <-> x conversions. + // _prefixWidths[i] stores width of first i characters (i from 0.._charCount). + mutable std::vector _prefixWidths; + mutable bool _prefixWidthsDirty{true}; + + bool _precomputePrefixWidthsEnabled{false}; + + // Get measured width of first `charIndex` characters (0.._charCount). Populates + // cache entries on demand. + float getPrefixWidth(std::size_t charIndex) const; + void invalidatePrefixWidths() const; + std::string _fontName; float _fontSize; @@ -353,6 +537,8 @@ class AX_DLL InputField : public Widget, public IMEDelegate Label* _renderLabel; + size_t _charLimit; + size_t _charCount; std::string _inputText; std::string _placeHolder; From 486ec1eb11bcd87b800bb0f9979facf0a2edaeb3 Mon Sep 17 00:00:00 2001 From: halx99 Date: Tue, 19 May 2026 14:49:30 +0800 Subject: [PATCH 15/52] up --- axmol/2d/Label.cpp | 48 +++- axmol/2d/Label.h | 44 +++ axmol/ui/UIInputField.cpp | 269 ++++++++---------- axmol/ui/UIInputField.h | 94 +++--- axmol/ui/UITabControl.h | 6 - axmol/ui/UIWidget.h | 7 + .../TextFieldReader/TextFieldExReader.cpp | 2 +- 7 files changed, 257 insertions(+), 213 deletions(-) diff --git a/axmol/2d/Label.cpp b/axmol/2d/Label.cpp index 4ed93429c17a..79398e386958 100644 --- a/axmol/2d/Label.cpp +++ b/axmol/2d/Label.cpp @@ -50,6 +50,7 @@ #include "axmol/renderer/Shaders.h" #include "axmol/rhi/ProgramState.h" #include "axmol/renderer/ProgramStateRegistry.h" +#include "yasio/tlx/string_view.hpp" namespace ax { @@ -227,11 +228,31 @@ std::array Label::BatchCommand::getCommandArray() Label* Label::create() { - auto ret = new Label; + auto ret = new Label(); ret->autorelease(); return ret; } +Label* Label::create(std::string_view text, std::string_view fontName, float fontSize) +{ + if (FileUtils::getInstance()->isFileExist(fontName)) + { + if (tlx::ic::ends_with(fontName, ".fnt")) + { + return Label::createWithBMFont(fontName, text); + } + else + { + TTFConfig config(fontName, fontSize); + return Label::createWithTTF(config, text); + } + } + else + { + return Label::createWithSystemFont(text, fontName, fontSize); + } +} + Label* Label::createWithSystemFont(std::string_view text, std::string_view font, float fontSize, @@ -392,6 +413,31 @@ Label* Label::createWithCharMap(std::string_view charMapFile, int itemWidth, int return nullptr; } +void Label::setFontInfo(std::string_view fontName, float fontSize) +{ + auto prevLableType = _currentLabelType; + if (FileUtils::getInstance()->isFileExist(fontName)) + { + if (tlx::ic::ends_with(fontName, ".fnt"sv)) + { + setBMFontFilePath(fontName); + } + else + { + TTFConfig ttfConfig(fontName, fontSize, GlyphCollection::DYNAMIC); + setTTFConfig(ttfConfig); + } + } + else + { + setSystemFontName(fontName); + setSystemFontSize(fontSize); + + if (prevLableType == LabelType::STRING_TEXTURE) + requestSystemFontRefresh(); + } +} + bool Label::setCharMap(std::string_view plistFile) { auto newAtlas = FontAtlasCache::getFontAtlasCharMap(plistFile); diff --git a/axmol/2d/Label.h b/axmol/2d/Label.h index 94f8484eb6c9..cbc48b027aa3 100644 --- a/axmol/2d/Label.h +++ b/axmol/2d/Label.h @@ -148,6 +148,31 @@ class AX_DLL Label : public Node, public LabelProtocol, public BlendProtocol */ static Label* create(); + /** + * @brief Create a Label with automatic font type detection. + * + * This unified factory method creates a Label using the given text and font name. + * The fontName parameter can be: + * - A TTF font file path (e.g. "fonts/arial.ttf") + * - A system font name (e.g. "Arial", "Helvetica") + * - A BMFont file path (e.g. "fonts/myfont.fnt") + * + * Internally, the method will: + * - Use createWithBMFont() if fontName ends with ".fnt" + * - Use createWithTTF() if fontName exists as a TTF file + * - Otherwise, fall back to createWithSystemFont() + * + * @param text The text string to render. + * @param fontName The font resource identifier (TTF path, system font name, or BMFont path). + * @param fontSize The font size in points. + * @return A new Label instance, or nullptr if creation fails. + * + * @note This method simplifies font handling by providing a single entry point. + * Specific createWithTTF(), createWithSystemFont(), and createWithBMFont() + * methods remain available for explicit control. + */ + static Label* create(std::string_view text, std::string_view fontName, float fontSize); + /** * Allocates and initializes a Label, base on platform-dependent API. * @@ -297,6 +322,25 @@ class AX_DLL Label : public Node, public LabelProtocol, public BlendProtocol /// @{ /// @name Font methods + /** + * @brief Set font information for the Label. + * + * This method updates the Label's font using the given fontName and fontSize. + * The fontName parameter can be: + * - A TTF font file path (e.g. "fonts/arial.ttf") + * - A system font name (e.g. "Arial", "Helvetica") + * - A BMFont file path (e.g. "fonts/myfont.fnt") + * + * Internally, the method will: + * - Use BMFont if fontName ends with ".fnt" + * - Use TTF if fontName exists as a TTF file + * - Otherwise, fall back to system font + * + * @param fontName The font resource identifier (TTF path, system font name, or BMFont path). + * @param fontSize The font size in points. + */ + void setFontInfo(std::string_view fontName, float fontSize); + /** * Sets a new TTF configuration to Label. * @see `TTFConfig` diff --git a/axmol/ui/UIInputField.cpp b/axmol/ui/UIInputField.cpp index bb297b27d34e..926fc557668f 100644 --- a/axmol/ui/UIInputField.cpp +++ b/axmol/ui/UIInputField.cpp @@ -105,6 +105,24 @@ static std::pair _truncateUTF8String(const char* text, int charLimit) } return std::make_pair(charCount, numOfBytes); } + +static FontType labelTypeToFontType(Label::LabelType type) +{ + switch (type) + { + case Label::LabelType::STRING_TEXTURE: + return FontType::SYSTEM; + case Label::LabelType::TTF: + return FontType::TTF; + case Label::LabelType::BMFONT: + return FontType::BMFONT; + default: + return FontType::SYSTEM; + } +} + +static constexpr std::string_view DEFAULT_PASSWORD_CHAR = "\xe2\x80\xa2"sv; + } // namespace ////////////////////////////////////////////////////////////////////////// @@ -113,41 +131,9 @@ static std::pair _truncateUTF8String(const char* text, int charLimit) bool InputField::s_keyboardVisible = false; InputField::InputField() - : _editable(true) - , _renderLabel(nullptr) - , _charCount(0) - , _inputText("") - , _placeHolder("") - , _colorText(Color32::WHITE) - , _colorSpaceHolder(Color32::GRAY) - , _passwordEnabled(false) - , _cursor(nullptr) - , _selectionLayer(nullptr) - , _selectionColor(0.26f, 0.52f, 1.0f, 0.35f) - , _selectionStartUtf8(0) - , _selectionEndUtf8(0) - , _selectionAnchorUtf8(0) - , _kbdListener(nullptr) - , _eventCallback(nullptr) - , _charLimit(0) - , _systemFontUsed(false) - , _fontSize(24) - , _insertPosUtf8(0) - , _insertPos(0) - , _selectingByTouch(false) - , _selectionTouchMoved(false) - , _ctrlKeyPressed(false) - , _shiftKeyPressed(false) - , _continuousTouchPending(false) - , _continuousTouchElapsedTime(0.0f) - , _continuousTouchDelayTime(0.6f) - , _continuousTouchWorldPoint(Point::ZERO) - , _useTouchArea(false) - , _textHAlignment(TextHAlignment::LEFT) - , _textVAlignment(TextVAlignment::TOP) - , _passwordChar("*"sv) - -{} +{ + _passwordChar = DEFAULT_PASSWORD_CHAR; +} InputField::~InputField() { @@ -185,24 +171,13 @@ Vec2 InputField::measureText(std::string_view text) const // Lazy initialize instance-specific measure label if (!_measureLabel) { - _measureLabel = Label::create(); + _measureLabel = Label::create(""sv, _fontName, _fontSize); _measureLabel->retain(); // Manual reference counting - updateMeasureFont(); } // Measure text (font is already synced in setFontName/setFontSize) -#ifdef AX_INPUTFIELD_BENCHMARK - auto t1 = std::chrono::high_resolution_clock::now(); -#endif _measureLabel->setString(text); - Vec2 cs = _measureLabel->getContentSize(); -#ifdef AX_INPUTFIELD_BENCHMARK - auto t2 = std::chrono::high_resolution_clock::now(); - auto us = std::chrono::duration_cast(t2 - t1).count(); - g_measureTextCalls.fetch_add(1, std::memory_order_relaxed); - g_measureTextTimeUs.fetch_add(static_cast(us), std::memory_order_relaxed); -#endif - return cs; + return _measureLabel->getContentSize(); } ////////////////////////////////////////////////////////////////////////// @@ -217,21 +192,15 @@ bool InputField::initWithPlaceHolder(std::string_view placeholder, ui::Widget::init(); - _fontName = fontName; - _fontSize = fontSize; - _systemFontUsed = !FileUtils::getInstance()->isFileExist(fontName); - _placeHolder = placeholder; + _fontName = fontName; + _fontSize = fontSize; + _placeHolder = placeholder; /// render label - if (FileUtils::getInstance()->isFileExist(fontName)) - { - TTFConfig config(fontName, fontSize); - _renderLabel = Label::createWithTTF(config, placeholder); - } - else - { - _renderLabel = Label::createWithSystemFont(placeholder, fontName, fontSize); - } + // Create render label according to font type: BMFont (.fnt), TTF file, or system font + _renderLabel = Label::create(placeholder, fontName, fontSize); + AXASSERT(_renderLabel, "Failed to create render label for InputField"); + _fontType = labelTypeToFontType(_renderLabel->getLabelType()); if (!placeholder.empty()) _renderLabel->setTextColor(_colorSpaceHolder); @@ -368,29 +337,14 @@ std::string_view InputField::getFontName() const void InputField::setFontName(std::string_view fontName) { - if (FileUtils::getInstance()->isFileExist(fontName)) - { - TTFConfig config = _renderLabel->getTTFConfig(); - config.fontFilePath = fontName; - config.fontSize = _fontSize; - _renderLabel->setTTFConfig(config); - _systemFontUsed = false; - } - else - { - _renderLabel->setSystemFontName(fontName); - if (!_systemFontUsed) - { - _renderLabel->requestSystemFontRefresh(); - } - _renderLabel->setSystemFontSize(_fontSize); - _systemFontUsed = true; - } + _renderLabel->setFontInfo(fontName, _fontSize); + _fontName = fontName; + _fontType = labelTypeToFontType(_renderLabel->getLabelType()); // Sync measure label font if (_measureLabel) - updateMeasureFont(); + _measureLabel->setFontInfo(fontName, _fontSize); _passwordCharWidth = measureText(_passwordChar).width; auto cursorHeight = measureText("M"sv).height; @@ -402,11 +356,19 @@ void InputField::setFontName(std::string_view fontName) void InputField::setFontSize(float size) { - if (_systemFontUsed) + if (_fontSize == size) + return; + + if (_fontType == FontType::BMFONT) + { + // BMFont size cannot be changed at runtime; ignore size change + return; + } + if (_fontType == FontType::SYSTEM) { _renderLabel->setSystemFontSize(size); } - else + else if (_fontType == FontType::TTF) { TTFConfig config = _renderLabel->getTTFConfig(); config.fontSize = size; @@ -415,9 +377,14 @@ void InputField::setFontSize(float size) _fontSize = size; - // Sync measure label font + // Sync measure label to the same font type and configuration as the render label. if (_measureLabel) - updateMeasureFont(); + { + if (_fontType == FontType::SYSTEM) + _measureLabel->setSystemFontSize(_fontSize); + else if (_fontType == FontType::TTF) + _measureLabel->setTTFConfig(_renderLabel->getTTFConfig()); + } _passwordCharWidth = measureText(_passwordChar).width; updateCursorPosition(); @@ -537,7 +504,7 @@ void InputField::setCharLimit(size_t limit) void InputField::insertText(const char* text, size_t len) { - if (!_editable || !this->_enabled) + if (_readOnly || !this->_enabled) { return; } @@ -567,8 +534,8 @@ void InputField::insertText(const char* text, size_t len) if (len > 0) { std::string sText(_inputText); - auto cursorPosition = static_cast(_insertPosUtf8); - sText.insert(_insertPos, insert); // original is: sText.append(insert); + auto cursorPosition = static_cast(_cursorCharIndex); + sText.insert(_cursorByteIndex, insert); // original is: sText.append(insert); this->setString(sText); setCursorPosition(cursorPosition + numOfChars, false); @@ -593,23 +560,23 @@ void InputField::deleteBackward(size_t numChars) return; } - if (!_editable || !this->_enabled || 0 == _charCount) + if (_readOnly || !this->_enabled || 0 == _charCount) { axbeep(0); return; } size_t len = _inputText.length(); - if (0 == len || _insertPos == 0) + if (0 == len || _cursorByteIndex == 0) { axbeep(0); return; } - auto deleteChars = std::min(numChars, static_cast(_insertPosUtf8)); - auto startUtf8 = static_cast(_insertPosUtf8) - deleteChars; + auto deleteChars = (std::min)(numChars, static_cast(_cursorCharIndex)); + auto startUtf8 = static_cast(_cursorCharIndex) - deleteChars; auto startByte = getByteOffset(startUtf8); - auto totalDeleteLen = static_cast(_insertPos) - startByte; + auto totalDeleteLen = static_cast(_cursorByteIndex) - startByte; // if all text deleted, show placeholder string if (len <= totalDeleteLen) @@ -639,21 +606,21 @@ void InputField::handleDeleteKeyEvent() return; } - if (!_editable || !this->_enabled || 0 == _charCount) + if (_readOnly || !this->_enabled || 0 == _charCount) { axbeep(0); return; } size_t len = _inputText.length(); - if (0 == len || _insertPosUtf8 == _charCount) + if (0 == len || _cursorCharIndex == _charCount) { axbeep(0); return; } - auto nextByte = getByteOffset(static_cast(_insertPosUtf8) + 1); - auto deleteLen = nextByte - static_cast(_insertPos); + auto nextByte = getByteOffset(static_cast(_cursorCharIndex) + 1); + auto deleteLen = nextByte - static_cast(_cursorByteIndex); // if all text deleted, show placeholder string if (len <= deleteLen) @@ -667,10 +634,10 @@ void InputField::handleDeleteKeyEvent() // set new input text std::string text = _inputText; - text.erase(_insertPos, deleteLen); + text.erase(_cursorByteIndex, deleteLen); this->setString(text); - setCursorPosition(_insertPosUtf8, false); + setCursorPosition(_cursorCharIndex, false); dispatchEvent(EventType::DELETE_BACKWARD); } @@ -731,7 +698,7 @@ Vec2 InputField::getPreferredSize() const // input text property void InputField::setString(std::string_view text) { - auto oldInsertPosUtf8 = static_cast(_insertPosUtf8); + auto oldInsertPosUtf8 = static_cast(_cursorCharIndex); bool bInsertAtEnd = (oldInsertPosUtf8 == _charCount); _inputText = text; auto newCharCount = text_utils::countUTF8Chars(_inputText); @@ -775,11 +742,12 @@ void InputField::setString(std::string_view text) } else { - setCursorPosition(std::min(oldInsertPosUtf8, _charCount), hasSelection()); + setCursorPosition((std::min)(oldInsertPosUtf8, static_cast(_charCount)), + hasSelection()); } - _selectionStartUtf8 = std::min(_selectionStartUtf8, _charCount); - _selectionEndUtf8 = std::min(_selectionEndUtf8, _charCount); + _selectionStart = (std::min)(_selectionStart, static_cast(_charCount)); + _selectionEnd = (std::min)(_selectionEnd, static_cast(_charCount)); updateSelectionLayer(); // Invalidate cached prefix widths when text changes @@ -852,7 +820,7 @@ void InputField::setPasswordChar(std::string_view ch) { if (ch != _passwordChar) { - _passwordChar = !ch.empty() ? ch : "*"sv; + _passwordChar = !ch.empty() ? ch : DEFAULT_PASSWORD_CHAR; _passwordCharWidth = measureText(_passwordChar).width; if (_passwordEnabled) { @@ -909,20 +877,20 @@ void InputField::setEnabled(bool bEnabled) bool InputField::hasSelection() const { - return _selectionStartUtf8 != _selectionEndUtf8; + return _selectionStart != _selectionEnd; } void InputField::selectAll() { setSelection(0, _charCount); - _selectionAnchorUtf8 = 0; + _selectionAnchor = 0; setCursorPosition(_charCount, true); } void InputField::clearSelection() { - _selectionStartUtf8 = _selectionEndUtf8 = static_cast(_insertPosUtf8); - _selectionAnchorUtf8 = static_cast(_insertPosUtf8); + _selectionStart = _selectionEnd = static_cast(_cursorCharIndex); + _selectionAnchor = static_cast(_cursorCharIndex); updateSelectionLayer(); } @@ -931,8 +899,8 @@ std::string InputField::getSelectedText() const if (!hasSelection()) return {}; - auto startByte = getByteOffset(_selectionStartUtf8); - auto endByte = getByteOffset(_selectionEndUtf8); + auto startByte = getByteOffset(_selectionStart); + auto endByte = getByteOffset(_selectionEnd); return _inputText.substr(startByte, endByte - startByte); } @@ -949,7 +917,7 @@ bool InputField::copySelectionToClipboard() const bool InputField::cutSelectionToClipboard() { - if (!_editable || !this->_enabled || !copySelectionToClipboard()) + if (_readOnly || !this->_enabled || !copySelectionToClipboard()) return false; return deleteSelection(true); @@ -957,7 +925,7 @@ bool InputField::cutSelectionToClipboard() bool InputField::pasteFromClipboard() { - if (!_editable || !this->_enabled) + if (_readOnly || !this->_enabled) return false; auto text = getClipboardText(); @@ -995,11 +963,11 @@ void InputField::showCursor(void) { _cursor->setVisible(true); _cursor->setOpacity(255); // Ensure full opacity - + // Use opacity-based blinking for better performance // Fade out to 0 over 0.5s, then fade in over 0.5s (total 1s cycle) - auto fadeOut = FadeOut::create(0.5f); - auto fadeIn = FadeIn::create(0.5f); + auto fadeOut = FadeOut::create(0.5f); + auto fadeIn = FadeIn::create(0.5f); auto blinkSequence = Sequence::create(fadeOut, fadeIn, nullptr); _cursor->runAction(RepeatForever::create(blinkSequence)); } @@ -1017,7 +985,7 @@ void InputField::hideCursor(void) void InputField::updateCursorPosition(void) { - setCursorPosition(static_cast(_insertPosUtf8), hasSelection()); + setCursorPosition(static_cast(_cursorCharIndex), hasSelection()); } void InputField::moveCursor(int direction) @@ -1027,7 +995,7 @@ void InputField::moveCursor(int direction) void InputField::moveCursor(int direction, bool keepSelection) { - auto cursorPosition = static_cast(_insertPosUtf8) + direction; + auto cursorPosition = static_cast(_cursorCharIndex) + direction; cursorPosition = std::clamp(cursorPosition, 0, static_cast(_charCount)); setCursorPosition(static_cast(cursorPosition), keepSelection); } @@ -1044,21 +1012,21 @@ void InputField::moveCursorTo(float x, bool keepSelection) void InputField::setCursorPosition(std::size_t cursorPosition, bool keepSelection) { - cursorPosition = std::min(cursorPosition, _charCount); + cursorPosition = (std::min)(cursorPosition, static_cast(_charCount)); if (keepSelection) { - setSelection(_selectionAnchorUtf8, cursorPosition); + setSelection(_selectionAnchor, cursorPosition); } else { - _selectionAnchorUtf8 = cursorPosition; - _selectionStartUtf8 = cursorPosition; - _selectionEndUtf8 = cursorPosition; + _selectionAnchor = cursorPosition; + _selectionStart = cursorPosition; + _selectionEnd = cursorPosition; } - _insertPosUtf8 = static_cast(cursorPosition); - _insertPos = static_cast(getByteOffset(cursorPosition)); + _cursorCharIndex = static_cast(cursorPosition); + _cursorByteIndex = static_cast(getByteOffset(cursorPosition)); if (_cursor) _cursor->setPosition(Point(cursorXFromPosition(cursorPosition), this->getContentSize().height / 2)); @@ -1077,10 +1045,10 @@ std::size_t InputField::getByteOffset(std::size_t cursorPosition) const void InputField::setSelection(std::size_t start, std::size_t end) { - _selectionStartUtf8 = std::min(start, _charCount); - _selectionEndUtf8 = std::min(end, _charCount); - if (_selectionStartUtf8 > _selectionEndUtf8) - std::swap(_selectionStartUtf8, _selectionEndUtf8); + _selectionStart = static_cast((std::min)(start, static_cast(_charCount))); + _selectionEnd = static_cast((std::min)(end, static_cast(_charCount))); + if (_selectionStart > _selectionEnd) + std::swap(_selectionStart, _selectionEnd); updateSelectionLayer(); } @@ -1093,12 +1061,12 @@ void InputField::updateSelectionLayer(void) if (!hasSelection()) return; - auto startX = cursorXFromPosition(_selectionStartUtf8); - auto endX = cursorXFromPosition(_selectionEndUtf8); + auto startX = cursorXFromPosition(_selectionStart); + auto endX = cursorXFromPosition(_selectionEnd); if (endX <= startX) return; - auto height = std::max(_renderLabel->getContentSize().height, this->getContentSize().height); + auto height = (std::max)(_renderLabel->getContentSize().height, this->getContentSize().height); if (height <= 0) height = _fontSize; @@ -1108,12 +1076,12 @@ void InputField::updateSelectionLayer(void) bool InputField::deleteSelection(bool notify) { - if (!_editable || !this->_enabled || !hasSelection()) + if (_readOnly || !this->_enabled || !hasSelection()) return false; - auto startByte = getByteOffset(_selectionStartUtf8); - auto endByte = getByteOffset(_selectionEndUtf8); - auto newCursor = _selectionStartUtf8; + auto startByte = getByteOffset(_selectionStart); + auto endByte = getByteOffset(_selectionEnd); + auto newCursor = _selectionStart; std::string text = _inputText; text.erase(startByte, endByte - startByte); @@ -1215,7 +1183,7 @@ bool InputField::onTouchBegan(Touch* touch, Event* event) } // InputField specific touch handling - if (!_editable || !_enabled) + if (_readOnly || !_enabled) { return false; } @@ -1232,13 +1200,13 @@ bool InputField::onTouchBegan(Touch* touch, Event* event) // Initialize selection state _selectingByTouch = focus; _selectionTouchMoved = false; - _selectionAnchorUtf8 = _insertPosUtf8; + _selectionAnchor = _cursorCharIndex; // Handle cursor positioning if (focus) { auto inputFieldPoint = this->convertToNodeSpace(touch->getLocation()); - _selectionAnchorUtf8 = positionFromCursorX(inputFieldPoint.x); + _selectionAnchor = positionFromCursorX(inputFieldPoint.x); } return true; @@ -1250,7 +1218,7 @@ void InputField::onTouchMoved(Touch* touch, Event* event) Widget::onTouchMoved(touch, event); // InputField specific touch move handling - if (!_selectingByTouch || !_editable || !_enabled) + if (!_selectingByTouch || _readOnly || !_enabled) { return; } @@ -1269,7 +1237,7 @@ void InputField::onTouchEnded(Touch* touch, Event* event) Widget::onTouchEnded(touch, event); // InputField specific touch end handling - bool focus = _hitted && _editable && _enabled; + bool focus = _hitted && !_readOnly && _enabled; if (focus) { @@ -1303,7 +1271,7 @@ void InputField::onTouchCancelled(Touch* touch, Event* event) float InputField::cursorXFromPosition(std::size_t cursorPosition) const { - cursorPosition = std::min(cursorPosition, _charCount); + cursorPosition = (std::min)(cursorPosition, static_cast(_charCount)); // Calculate the offset from InputField origin to text start position float textStartOffset = 0.0f; @@ -1389,14 +1357,14 @@ std::size_t InputField::positionFromCursorX(float x) const // Binary search using cached prefix widths. We choose the smallest index i // such that adjustedX < midpoint(prefix[i], prefix[i+1]). Returns i. - std::size_t low = 0; + std::size_t low = 0; std::size_t high = _charCount; while (low < high) { std::size_t mid = (low + high) / 2; - float leftX = getPrefixWidth(mid); - float rightX = getPrefixWidth(mid + 1); - float midPoint = (leftX + rightX) * 0.5f; + float leftX = getPrefixWidth(mid); + float rightX = getPrefixWidth(mid + 1); + float midPoint = (leftX + rightX) * 0.5f; if (adjustedX < midPoint) high = mid; else @@ -1406,19 +1374,6 @@ std::size_t InputField::positionFromCursorX(float x) const return low; } -void InputField::updateMeasureFont() const -{ - if (_systemFontUsed) - { - _measureLabel->setSystemFontName(_fontName); - _measureLabel->setSystemFontSize(_fontSize); - } - else - { - _measureLabel->setTTFConfig(_renderLabel->getTTFConfig()); - } -} - float InputField::getPrefixWidth(std::size_t charIndex) const { if (charIndex == 0) diff --git a/axmol/ui/UIInputField.h b/axmol/ui/UIInputField.h index 674d5ca94d62..9ad5cec19692 100644 --- a/axmol/ui/UIInputField.h +++ b/axmol/ui/UIInputField.h @@ -134,6 +134,8 @@ class AX_DLL InputField : public Widget, public IMEDelegate */ virtual std::string_view getString() const; + FontType getFontType() const { return _fontType; } + /** * @brief Configure continuous touch delay. * @param delay Delay in seconds before continuous touch callback fires. @@ -209,12 +211,12 @@ class AX_DLL InputField : public Widget, public IMEDelegate /** * @brief Mark the field editable or read-only. */ - void setEditable(bool bEditable) { _editable = bEditable; } + void setReadOnly(bool bReadOnly) { _readOnly = bReadOnly; } /** - * @brief Query whether the field is editable. + * @brief Query whether the field is read-only. */ - bool isEditable(void) const { return _editable; } + bool isReadOnly(void) const { return _readOnly; } /** * @brief Set maximum allowed character length (UTF-8 characters). @@ -357,11 +359,6 @@ class AX_DLL InputField : public Widget, public IMEDelegate */ size_t getCharLimit() const { return _charLimit; } - /** - * @brief Return whether the control uses a system font. - */ - bool isSystemFont(void) const { return _systemFontUsed; } - /** * @brief Get the internal renderer node. * @return Pointer to the renderer node. @@ -507,83 +504,84 @@ class AX_DLL InputField : public Widget, public IMEDelegate */ Vec2 measureText(std::string_view text) const; - void updateMeasureFont() const; + void invalidatePrefixWidths() const; // Cached prefix widths for fast cursor position <-> x conversions. // _prefixWidths[i] stores width of first i characters (i from 0.._charCount). mutable std::vector _prefixWidths; - mutable bool _prefixWidthsDirty{true}; - - bool _precomputePrefixWidthsEnabled{false}; // Get measured width of first `charIndex` characters (0.._charCount). Populates // cache entries on demand. float getPrefixWidth(std::size_t charIndex) const; - void invalidatePrefixWidths() const; std::string _fontName; - float _fontSize; + float _fontSize{24.0f}; + + mutable bool _prefixWidthsDirty{true}; + bool _precomputePrefixWidthsEnabled{false}; - bool _systemFontUsed; - bool _editable; + bool _readOnly{false}; bool _layoutDirty{true}; - bool _passwordEnabled; - bool _cursorVisible; - bool _selectingByTouch; - bool _selectionTouchMoved; - bool _ctrlKeyPressed; - bool _shiftKeyPressed; - bool _useTouchArea; + bool _passwordEnabled{false}; + bool _cursorVisible{false}; + bool _selectingByTouch{false}; + bool _selectionTouchMoved{false}; + bool _ctrlKeyPressed{false}; + bool _shiftKeyPressed{false}; + bool _useTouchArea{false}; - Label* _renderLabel; + // Continuous touch delay state (manual timing, no external timer dependency) + bool _continuousTouchPending{false}; + float _continuousTouchElapsedTime{0.0f}; + float _continuousTouchDelayTime{0.6f}; + Vec2 _continuousTouchWorldPoint{Vec2::ZERO}; - size_t _charLimit; + Label* _renderLabel{nullptr}; - size_t _charCount; std::string _inputText; std::string _placeHolder; std::string _passwordChar; - Color32 _colorSpaceHolder; - Color32 _colorText; + Color32 _colorSpaceHolder{Color32::GRAY}; + Color32 _colorText{Color32::WHITE}; - Sprite* _cursor; + Sprite* _cursor{nullptr}; - DrawNode* _selectionLayer; - Color _selectionColor; - std::size_t _selectionStartUtf8; - std::size_t _selectionEndUtf8; - std::size_t _selectionAnchorUtf8; + DrawNode* _selectionLayer{nullptr}; + Color _selectionColor{0.26f, 0.52f, 1.0f, 0.35f}; - int _insertPosUtf8; - int _insertPos; // The actual input content insertPos, step: bytes + FontType _fontType{FontType::SYSTEM}; - EventListenerKeyboard* _kbdListener; + uint32_t _charLimit{0}; + uint32_t _charCount{0}; - float _passwordCharWidth; + int _selectionStart{0}; // Start character index of current selection (UTF-8) + int _selectionEnd{0}; // End character index of current selection (UTF-8) + int _selectionAnchor{0}; // Anchor character index used for extending selection (UTF-8) - // Continuous touch delay state (manual timing, no external timer dependency) - bool _continuousTouchPending; - float _continuousTouchElapsedTime; - float _continuousTouchDelayTime; - Vec2 _continuousTouchWorldPoint; + int _cursorCharIndex{0}; // Cursor position as character index (UTF-8) + int _cursorByteIndex{0}; // Cursor position as byte offset in string + + float _passwordCharWidth{0.0f}; + + EventListenerKeyboard* _kbdListener{nullptr}; /// Touch area Vec2 _touchAreaSize; /// Text alignment - TextHAlignment _textHAlignment; - TextVAlignment _textVAlignment; + TextHAlignment _textHAlignment{TextHAlignment::LEFT}; + TextVAlignment _textVAlignment{TextVAlignment::TOP}; std::function _continuousTouchCallback; /// Event callback - InputFieldCallback _eventCallback; - - static bool s_keyboardVisible; + InputFieldCallback _eventCallback{nullptr}; // Instance-specific measure label (lazy initialized, no sharing overhead) mutable Label* _measureLabel{nullptr}; + + static bool s_keyboardVisible; }; // end of input group diff --git a/axmol/ui/UITabControl.h b/axmol/ui/UITabControl.h index 4f31a37dc8fa..868fc40427c2 100644 --- a/axmol/ui/UITabControl.h +++ b/axmol/ui/UITabControl.h @@ -177,12 +177,6 @@ class AX_GUI_DLL TabHeader : public AbstractCheckButton typedef std::function ccTabCallback; ccTabCallback _tabSelectedEvent; - enum class FontType - { - SYSTEM, - TTF, - BMFONT - }; FontType _fontType; }; diff --git a/axmol/ui/UIWidget.h b/axmol/ui/UIWidget.h index 4c8102b388ea..8aa60c2b17d1 100644 --- a/axmol/ui/UIWidget.h +++ b/axmol/ui/UIWidget.h @@ -47,6 +47,13 @@ namespace ui { class LayoutComponent; +enum class FontType +{ + SYSTEM, + TTF, + BMFONT +}; + /** *@brief Base class for all ui widgets. * This class inherent from `ProtectedNode` and `LayoutParameterProtocol`. diff --git a/extensions/sceneio/src/sceneio/WidgetReader/TextFieldReader/TextFieldExReader.cpp b/extensions/sceneio/src/sceneio/WidgetReader/TextFieldReader/TextFieldExReader.cpp index 48e9700078bb..d768b8a1386a 100644 --- a/extensions/sceneio/src/sceneio/WidgetReader/TextFieldReader/TextFieldExReader.cpp +++ b/extensions/sceneio/src/sceneio/WidgetReader/TextFieldReader/TextFieldExReader.cpp @@ -367,7 +367,7 @@ void TextFieldExReader::setPropsWithFlatBuffers(ax::Node* node, const flatbuffer textField->setContentSize(contentSize); textField->setEnabled(options->enabled()); - textField->setEditable(options->editable()); + textField->setReadOnly(!options->editable()); // InputField will enable IME when user interacts with it /*if (!textField->isIgnoreContentAdaptWithSize()) From 42c0610c6eae21b9faebb92515958eccd6fd886b Mon Sep 17 00:00:00 2001 From: halx99 Date: Wed, 20 May 2026 08:35:25 +0800 Subject: [PATCH 16/52] luabindings --- axmol/ui/UIInputField.cpp | 18 +- axmol/ui/UIMediaPlayer.cpp | 7 +- axmol/ui/UIWidget.cpp | 10 +- .../lua-bindings/auto/axlua_base_auto.cpp | 93 +- .../lua-bindings/auto/axlua_ui_auto.cpp | 3344 ++--------------- .../UIVideoPlayerTest/UIVideoPlayerTest.cpp | 1 + 6 files changed, 458 insertions(+), 3015 deletions(-) diff --git a/axmol/ui/UIInputField.cpp b/axmol/ui/UIInputField.cpp index 926fc557668f..41289cc7c914 100644 --- a/axmol/ui/UIInputField.cpp +++ b/axmol/ui/UIInputField.cpp @@ -543,13 +543,7 @@ void InputField::insertText(const char* text, size_t len) dispatchEvent(EventType::INSERT_TEXT); } - if (insert.npos == pos) - { - return; - } - - // if delegate hasn't processed, detach from IME by default - detachWithIME(); + assert(insert.npos == pos); } void InputField::deleteBackward(size_t numChars) @@ -698,6 +692,8 @@ Vec2 InputField::getPreferredSize() const // input text property void InputField::setString(std::string_view text) { + _layoutDirty = true; + auto oldInsertPosUtf8 = static_cast(_cursorCharIndex); bool bInsertAtEnd = (oldInsertPosUtf8 == _charCount); _inputText = text; @@ -778,10 +774,8 @@ void InputField::updateLayout() { _layoutDirty = false; - if (_autoSize) - { - _renderLabel->setDimensions(this->getContentSize().width, _renderLabel->getContentSize().height); - } + if (!_autoSize) + _renderLabel->setDimensions(_contentSize.width, _contentSize.height); updateCursorPosition(); updateSelectionLayer(); @@ -839,7 +833,7 @@ void InputField::setPlaceholderText(std::string_view text) _renderLabel->setTextColor(_colorSpaceHolder); _renderLabel->setString(_placeHolder); } - + _layoutDirty = true; updateContentSize(); } diff --git a/axmol/ui/UIMediaPlayer.cpp b/axmol/ui/UIMediaPlayer.cpp index 5a45853fa8e4..f55d216a84b6 100644 --- a/axmol/ui/UIMediaPlayer.cpp +++ b/axmol/ui/UIMediaPlayer.cpp @@ -1247,7 +1247,12 @@ void MediaPlayer::setContentSize(const Size& contentSize) Vec2 MediaPlayer::getPreferredSize() const { auto pvd = reinterpret_cast(_videoContext); - return pvd ? pvd->_vrender->getContentSize() : getContentSize(); + if (!pvd) + return _contentSize; + auto videoSize = pvd->_vrender->getContentSize(); + if (videoSize.equals(Vec2::ZERO)) + return _contentSize; + return videoSize; } MediaPlayer::MediaState MediaPlayer::getState() const diff --git a/axmol/ui/UIWidget.cpp b/axmol/ui/UIWidget.cpp index bc71a758d38e..0983ec3f975b 100644 --- a/axmol/ui/UIWidget.cpp +++ b/axmol/ui/UIWidget.cpp @@ -287,15 +287,7 @@ void Widget::setContentSize(const Vec2& contentSize) _customSize = contentSize; - // When developer explicitly sets content size, disable auto-size mode - // This ensures the manually set size is respected and not overridden by content adaptation - if (_autoSize) - { - _autoSize = false; - } - - // Fixed size mode: use the size set by developer - ProtectedNode::setContentSize(_customSize); + ProtectedNode::setContentSize(_autoSize ? getPreferredSize() : _customSize); if (!_usingLayoutComponent && _running) { diff --git a/extensions/scripting/lua-bindings/auto/axlua_base_auto.cpp b/extensions/scripting/lua-bindings/auto/axlua_base_auto.cpp index 1a46fe0d8064..59aac2aab9e9 100644 --- a/extensions/scripting/lua-bindings/auto/axlua_base_auto.cpp +++ b/extensions/scripting/lua-bindings/auto/axlua_base_auto.cpp @@ -54702,6 +54702,59 @@ int lua_register_ax_base_DrawNode(lua_State* tolua_S) return 1; } +int lua_ax_base_Label_setFontInfo(lua_State* tolua_S) +{ + int argc = 0; + ax::Label* obj = nullptr; + bool ok = true; + +#if _AX_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if _AX_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"ax.Label",0,&tolua_err)) goto tolua_lerror; +#endif + + obj = (ax::Label*)tolua_tousertype(tolua_S,1,0); + +#if _AX_DEBUG >= 1 + if (!obj) + { + tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_base_Label_setFontInfo'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 2) + { + std::string_view arg0; + double arg1; + + ok &= luaval_to_std_string_view(tolua_S, 2,&arg0, "ax.Label:setFontInfo"); + + ok &= luaval_to_number(tolua_S, 3, &arg1, "ax.Label:setFontInfo"); + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_ax_base_Label_setFontInfo'", nullptr); + return 0; + } + obj->setFontInfo(arg0, arg1); + lua_settop(tolua_S, 1); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ax.Label:setFontInfo",argc, 2); + return 0; + +#if _AX_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_ax_base_Label_setFontInfo'.",&tolua_err); +#endif + + return 0; +} int lua_ax_base_Label_setTTFConfig(lua_State* tolua_S) { int argc = 0; @@ -58553,7 +58606,6 @@ int lua_ax_base_Label_create(lua_State* tolua_S) { int argc = 0; bool ok = true; - #if _AX_DEBUG >= 1 tolua_Error tolua_err; #endif @@ -58562,20 +58614,36 @@ int lua_ax_base_Label_create(lua_State* tolua_S) if (!tolua_isusertable(tolua_S,1,"ax.Label",0,&tolua_err)) goto tolua_lerror; #endif - argc = lua_gettop(tolua_S) - 1; + argc = lua_gettop(tolua_S)-1; - if (argc == 0) - { - if(!ok) + do { + if (argc == 3) { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_base_Label_create'", nullptr); - return 0; + std::string_view arg0; + ok &= luaval_to_std_string_view(tolua_S, 2,&arg0, "ax.Label:create"); + if (!ok) { break; } + std::string_view arg1; + ok &= luaval_to_std_string_view(tolua_S, 3,&arg1, "ax.Label:create"); + if (!ok) { break; } + double arg2; + ok &= luaval_to_number(tolua_S, 4, &arg2, "ax.Label:create"); + if (!ok) { break; } + ax::Label* ret = ax::Label::create(arg0, arg1, arg2); + object_to_luaval(tolua_S, "ax.Label",(ax::Label*)ret); + return 1; } - auto&& ret = ax::Label::create(); - object_to_luaval(tolua_S, "ax.Label",(ax::Label*)ret); - return 1; - } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d\n ", "ax.Label:create",argc, 0); + } while (0); + ok = true; + do { + if (argc == 0) + { + ax::Label* ret = ax::Label::create(); + object_to_luaval(tolua_S, "ax.Label",(ax::Label*)ret); + return 1; + } + } while (0); + ok = true; + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d", "ax.Label:create",argc, 0); return 0; #if _AX_DEBUG >= 1 tolua_lerror: @@ -58901,6 +58969,7 @@ int lua_register_ax_base_Label(lua_State* tolua_S) tolua_cclass(tolua_S,"Label","ax.Label","ax.Node",nullptr); tolua_beginmodule(tolua_S,"Label"); + tolua_function(tolua_S,"setFontInfo",lua_ax_base_Label_setFontInfo); tolua_function(tolua_S,"setTTFConfig",lua_ax_base_Label_setTTFConfig); tolua_function(tolua_S,"getTTFConfig",lua_ax_base_Label_getTTFConfig); tolua_function(tolua_S,"setBMFontFilePath",lua_ax_base_Label_setBMFontFilePath); diff --git a/extensions/scripting/lua-bindings/auto/axlua_ui_auto.cpp b/extensions/scripting/lua-bindings/auto/axlua_ui_auto.cpp index 12ec4f7e5a4d..433a1d26a0ea 100644 --- a/extensions/scripting/lua-bindings/auto/axlua_ui_auto.cpp +++ b/extensions/scripting/lua-bindings/auto/axlua_ui_auto.cpp @@ -2813,103 +2813,6 @@ int lua_ax_ui_Widget_getLayoutParameter(lua_State* tolua_S) return 0; } -int lua_ax_ui_Widget_ignoreContentAdaptWithSize(lua_State* tolua_S) -{ - int argc = 0; - ax::ui::Widget* obj = nullptr; - bool ok = true; - -#if _AX_DEBUG >= 1 - tolua_Error tolua_err; -#endif - - -#if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.Widget",0,&tolua_err)) goto tolua_lerror; -#endif - - obj = (ax::ui::Widget*)tolua_tousertype(tolua_S,1,0); - -#if _AX_DEBUG >= 1 - if (!obj) - { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_Widget_ignoreContentAdaptWithSize'", nullptr); - return 0; - } -#endif - - argc = lua_gettop(tolua_S)-1; - if (argc == 1) - { - bool arg0; - - ok &= luaval_to_boolean(tolua_S, 2, &arg0, "axui.Widget:ignoreContentAdaptWithSize"); - if(!ok) - { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_Widget_ignoreContentAdaptWithSize'", nullptr); - return 0; - } - obj->ignoreContentAdaptWithSize(arg0); - lua_settop(tolua_S, 1); - return 1; - } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.Widget:ignoreContentAdaptWithSize",argc, 1); - return 0; - -#if _AX_DEBUG >= 1 - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_Widget_ignoreContentAdaptWithSize'.",&tolua_err); -#endif - - return 0; -} -int lua_ax_ui_Widget_isIgnoreContentAdaptWithSize(lua_State* tolua_S) -{ - int argc = 0; - ax::ui::Widget* obj = nullptr; - bool ok = true; - -#if _AX_DEBUG >= 1 - tolua_Error tolua_err; -#endif - - -#if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.Widget",0,&tolua_err)) goto tolua_lerror; -#endif - - obj = (ax::ui::Widget*)tolua_tousertype(tolua_S,1,0); - -#if _AX_DEBUG >= 1 - if (!obj) - { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_Widget_isIgnoreContentAdaptWithSize'", nullptr); - return 0; - } -#endif - - argc = lua_gettop(tolua_S)-1; - if (argc == 0) - { - if(!ok) - { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_Widget_isIgnoreContentAdaptWithSize'", nullptr); - return 0; - } - auto&& ret = obj->isIgnoreContentAdaptWithSize(); - tolua_pushboolean(tolua_S,(bool)ret); - return 1; - } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.Widget:isIgnoreContentAdaptWithSize",argc, 0); - return 0; - -#if _AX_DEBUG >= 1 - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_Widget_isIgnoreContentAdaptWithSize'.",&tolua_err); -#endif - - return 0; -} int lua_ax_ui_Widget_getRenderNode(lua_State* tolua_S) { int argc = 0; @@ -3784,7 +3687,7 @@ int lua_ax_ui_Widget_requestFocus(lua_State* tolua_S) return 0; } -int lua_ax_ui_Widget_setUnifySizeEnabled(lua_State* tolua_S) +int lua_ax_ui_Widget_setAutoSizeEnabled(lua_State* tolua_S) { int argc = 0; ax::ui::Widget* obj = nullptr; @@ -3804,7 +3707,7 @@ int lua_ax_ui_Widget_setUnifySizeEnabled(lua_State* tolua_S) #if _AX_DEBUG >= 1 if (!obj) { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_Widget_setUnifySizeEnabled'", nullptr); + tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_Widget_setAutoSizeEnabled'", nullptr); return 0; } #endif @@ -3814,27 +3717,27 @@ int lua_ax_ui_Widget_setUnifySizeEnabled(lua_State* tolua_S) { bool arg0; - ok &= luaval_to_boolean(tolua_S, 2, &arg0, "axui.Widget:setUnifySizeEnabled"); + ok &= luaval_to_boolean(tolua_S, 2, &arg0, "axui.Widget:setAutoSizeEnabled"); if(!ok) { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_Widget_setUnifySizeEnabled'", nullptr); + tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_Widget_setAutoSizeEnabled'", nullptr); return 0; } - obj->setUnifySizeEnabled(arg0); + obj->setAutoSizeEnabled(arg0); lua_settop(tolua_S, 1); return 1; } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.Widget:setUnifySizeEnabled",argc, 1); + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.Widget:setAutoSizeEnabled",argc, 1); return 0; #if _AX_DEBUG >= 1 tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_Widget_setUnifySizeEnabled'.",&tolua_err); + tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_Widget_setAutoSizeEnabled'.",&tolua_err); #endif return 0; } -int lua_ax_ui_Widget_isUnifySizeEnabled(lua_State* tolua_S) +int lua_ax_ui_Widget_isAutoSizeEnabled(lua_State* tolua_S) { int argc = 0; ax::ui::Widget* obj = nullptr; @@ -3854,7 +3757,7 @@ int lua_ax_ui_Widget_isUnifySizeEnabled(lua_State* tolua_S) #if _AX_DEBUG >= 1 if (!obj) { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_Widget_isUnifySizeEnabled'", nullptr); + tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_Widget_isAutoSizeEnabled'", nullptr); return 0; } #endif @@ -3864,19 +3767,19 @@ int lua_ax_ui_Widget_isUnifySizeEnabled(lua_State* tolua_S) { if(!ok) { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_Widget_isUnifySizeEnabled'", nullptr); + tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_Widget_isAutoSizeEnabled'", nullptr); return 0; } - auto&& ret = obj->isUnifySizeEnabled(); + auto&& ret = obj->isAutoSizeEnabled(); tolua_pushboolean(tolua_S,(bool)ret); return 1; } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.Widget:isUnifySizeEnabled",argc, 0); + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.Widget:isAutoSizeEnabled",argc, 0); return 0; #if _AX_DEBUG >= 1 tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_Widget_isUnifySizeEnabled'.",&tolua_err); + tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_Widget_isAutoSizeEnabled'.",&tolua_err); #endif return 0; @@ -4584,8 +4487,6 @@ int lua_register_ax_ui_Widget(lua_State* tolua_S) tolua_function(tolua_S,"onMouseScroll",lua_ax_ui_Widget_onMouseScroll); tolua_function(tolua_S,"setLayoutParameter",lua_ax_ui_Widget_setLayoutParameter); tolua_function(tolua_S,"getLayoutParameter",lua_ax_ui_Widget_getLayoutParameter); - tolua_function(tolua_S,"ignoreContentAdaptWithSize",lua_ax_ui_Widget_ignoreContentAdaptWithSize); - tolua_function(tolua_S,"isIgnoreContentAdaptWithSize",lua_ax_ui_Widget_isIgnoreContentAdaptWithSize); tolua_function(tolua_S,"getRenderNode",lua_ax_ui_Widget_getRenderNode); tolua_function(tolua_S,"getPreferredSize",lua_ax_ui_Widget_getPreferredSize); tolua_function(tolua_S,"clone",lua_ax_ui_Widget_clone); @@ -4604,8 +4505,8 @@ int lua_register_ax_ui_Widget(lua_State* tolua_S) tolua_function(tolua_S,"setFocusEnabled",lua_ax_ui_Widget_setFocusEnabled); tolua_function(tolua_S,"findNextFocusedWidget",lua_ax_ui_Widget_findNextFocusedWidget); tolua_function(tolua_S,"requestFocus",lua_ax_ui_Widget_requestFocus); - tolua_function(tolua_S,"setUnifySizeEnabled",lua_ax_ui_Widget_setUnifySizeEnabled); - tolua_function(tolua_S,"isUnifySizeEnabled",lua_ax_ui_Widget_isUnifySizeEnabled); + tolua_function(tolua_S,"setAutoSizeEnabled",lua_ax_ui_Widget_setAutoSizeEnabled); + tolua_function(tolua_S,"isAutoSizeEnabled",lua_ax_ui_Widget_isAutoSizeEnabled); tolua_function(tolua_S,"setCallbackName",lua_ax_ui_Widget_setCallbackName); tolua_function(tolua_S,"getCallbackName",lua_ax_ui_Widget_getCallbackName); tolua_function(tolua_S,"setCallbackType",lua_ax_ui_Widget_setCallbackType); @@ -13917,7 +13818,7 @@ int lua_ax_ui_TextAtlas_getStringLength(lua_State* tolua_S) return 0; } -int lua_ax_ui_TextAtlas_adaptRenderers(lua_State* tolua_S) +int lua_ax_ui_TextAtlas_updateLayout(lua_State* tolua_S) { int argc = 0; ax::ui::TextAtlas* obj = nullptr; @@ -13937,7 +13838,7 @@ int lua_ax_ui_TextAtlas_adaptRenderers(lua_State* tolua_S) #if _AX_DEBUG >= 1 if (!obj) { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextAtlas_adaptRenderers'", nullptr); + tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextAtlas_updateLayout'", nullptr); return 0; } #endif @@ -13947,19 +13848,19 @@ int lua_ax_ui_TextAtlas_adaptRenderers(lua_State* tolua_S) { if(!ok) { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextAtlas_adaptRenderers'", nullptr); + tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextAtlas_updateLayout'", nullptr); return 0; } - obj->adaptRenderers(); + obj->updateLayout(); lua_settop(tolua_S, 1); return 1; } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextAtlas:adaptRenderers",argc, 0); + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextAtlas:updateLayout",argc, 0); return 0; #if _AX_DEBUG >= 1 tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextAtlas_adaptRenderers'.",&tolua_err); + tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextAtlas_updateLayout'.",&tolua_err); #endif return 0; @@ -14154,7 +14055,7 @@ int lua_register_ax_ui_TextAtlas(lua_State* tolua_S) tolua_function(tolua_S,"setString",lua_ax_ui_TextAtlas_setString); tolua_function(tolua_S,"getString",lua_ax_ui_TextAtlas_getString); tolua_function(tolua_S,"getStringLength",lua_ax_ui_TextAtlas_getStringLength); - tolua_function(tolua_S,"adaptRenderers",lua_ax_ui_TextAtlas_adaptRenderers); + tolua_function(tolua_S,"updateLayout",lua_ax_ui_TextAtlas_updateLayout); tolua_function(tolua_S,"getRenderFile",lua_ax_ui_TextAtlas_getRenderFile); tolua_function(tolua_S,"createInstance", lua_ax_ui_TextAtlas_createInstance); tolua_function(tolua_S,"create", lua_ax_ui_TextAtlas_create); @@ -22220,10 +22121,10 @@ int lua_register_ax_ui_Slider(lua_State* tolua_S) return 1; } -int lua_ax_ui_TextField_setTouchSize(lua_State* tolua_S) +int lua_ax_ui_TextBMFont_setFntFile(lua_State* tolua_S) { int argc = 0; - ax::ui::TextField* obj = nullptr; + ax::ui::TextBMFont* obj = nullptr; bool ok = true; #if _AX_DEBUG >= 1 @@ -22232,15 +22133,15 @@ int lua_ax_ui_TextField_setTouchSize(lua_State* tolua_S) #if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.TextField",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(tolua_S,1,"axui.TextBMFont",0,&tolua_err)) goto tolua_lerror; #endif - obj = (ax::ui::TextField*)tolua_tousertype(tolua_S,1,0); + obj = (ax::ui::TextBMFont*)tolua_tousertype(tolua_S,1,0); #if _AX_DEBUG >= 1 if (!obj) { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextField_setTouchSize'", nullptr); + tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextBMFont_setFntFile'", nullptr); return 0; } #endif @@ -22248,32 +22149,32 @@ int lua_ax_ui_TextField_setTouchSize(lua_State* tolua_S) argc = lua_gettop(tolua_S)-1; if (argc == 1) { - ax::Vec2 arg0; + std::string_view arg0; - ok &= luaval_to_vec2(tolua_S, 2, &arg0, "axui.TextField:setTouchSize"); + ok &= luaval_to_std_string_view(tolua_S, 2,&arg0, "axui.TextBMFont:setFntFile"); if(!ok) { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextField_setTouchSize'", nullptr); + tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextBMFont_setFntFile'", nullptr); return 0; } - obj->setTouchSize(arg0); + obj->setFntFile(arg0); lua_settop(tolua_S, 1); return 1; } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextField:setTouchSize",argc, 1); + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextBMFont:setFntFile",argc, 1); return 0; #if _AX_DEBUG >= 1 tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextField_setTouchSize'.",&tolua_err); + tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextBMFont_setFntFile'.",&tolua_err); #endif return 0; } -int lua_ax_ui_TextField_getTouchSize(lua_State* tolua_S) +int lua_ax_ui_TextBMFont_setString(lua_State* tolua_S) { int argc = 0; - ax::ui::TextField* obj = nullptr; + ax::ui::TextBMFont* obj = nullptr; bool ok = true; #if _AX_DEBUG >= 1 @@ -22282,45 +22183,48 @@ int lua_ax_ui_TextField_getTouchSize(lua_State* tolua_S) #if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.TextField",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(tolua_S,1,"axui.TextBMFont",0,&tolua_err)) goto tolua_lerror; #endif - obj = (ax::ui::TextField*)tolua_tousertype(tolua_S,1,0); + obj = (ax::ui::TextBMFont*)tolua_tousertype(tolua_S,1,0); #if _AX_DEBUG >= 1 if (!obj) { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextField_getTouchSize'", nullptr); + tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextBMFont_setString'", nullptr); return 0; } #endif argc = lua_gettop(tolua_S)-1; - if (argc == 0) + if (argc == 1) { + std::string_view arg0; + + ok &= luaval_to_std_string_view(tolua_S, 2,&arg0, "axui.TextBMFont:setString"); if(!ok) { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextField_getTouchSize'", nullptr); + tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextBMFont_setString'", nullptr); return 0; } - auto&& ret = obj->getTouchSize(); - vec2_to_luaval(tolua_S, ret); + obj->setString(arg0); + lua_settop(tolua_S, 1); return 1; } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextField:getTouchSize",argc, 0); + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextBMFont:setString",argc, 1); return 0; #if _AX_DEBUG >= 1 tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextField_getTouchSize'.",&tolua_err); + tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextBMFont_setString'.",&tolua_err); #endif return 0; } -int lua_ax_ui_TextField_setTouchAreaEnabled(lua_State* tolua_S) +int lua_ax_ui_TextBMFont_getString(lua_State* tolua_S) { int argc = 0; - ax::ui::TextField* obj = nullptr; + ax::ui::TextBMFont* obj = nullptr; bool ok = true; #if _AX_DEBUG >= 1 @@ -22329,48 +22233,45 @@ int lua_ax_ui_TextField_setTouchAreaEnabled(lua_State* tolua_S) #if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.TextField",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(tolua_S,1,"axui.TextBMFont",0,&tolua_err)) goto tolua_lerror; #endif - obj = (ax::ui::TextField*)tolua_tousertype(tolua_S,1,0); + obj = (ax::ui::TextBMFont*)tolua_tousertype(tolua_S,1,0); #if _AX_DEBUG >= 1 if (!obj) { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextField_setTouchAreaEnabled'", nullptr); + tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextBMFont_getString'", nullptr); return 0; } #endif argc = lua_gettop(tolua_S)-1; - if (argc == 1) + if (argc == 0) { - bool arg0; - - ok &= luaval_to_boolean(tolua_S, 2, &arg0, "axui.TextField:setTouchAreaEnabled"); if(!ok) { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextField_setTouchAreaEnabled'", nullptr); + tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextBMFont_getString'", nullptr); return 0; } - obj->setTouchAreaEnabled(arg0); - lua_settop(tolua_S, 1); + auto&& ret = obj->getString(); + lua_pushlstring(tolua_S,ret.data(),ret.length()); return 1; } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextField:setTouchAreaEnabled",argc, 1); + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextBMFont:getString",argc, 0); return 0; #if _AX_DEBUG >= 1 tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextField_setTouchAreaEnabled'.",&tolua_err); + tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextBMFont_getString'.",&tolua_err); #endif return 0; } -int lua_ax_ui_TextField_setPlaceHolder(lua_State* tolua_S) +int lua_ax_ui_TextBMFont_getStringLength(lua_State* tolua_S) { int argc = 0; - ax::ui::TextField* obj = nullptr; + ax::ui::TextBMFont* obj = nullptr; bool ok = true; #if _AX_DEBUG >= 1 @@ -22379,48 +22280,45 @@ int lua_ax_ui_TextField_setPlaceHolder(lua_State* tolua_S) #if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.TextField",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(tolua_S,1,"axui.TextBMFont",0,&tolua_err)) goto tolua_lerror; #endif - obj = (ax::ui::TextField*)tolua_tousertype(tolua_S,1,0); + obj = (ax::ui::TextBMFont*)tolua_tousertype(tolua_S,1,0); #if _AX_DEBUG >= 1 if (!obj) { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextField_setPlaceHolder'", nullptr); + tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextBMFont_getStringLength'", nullptr); return 0; } #endif argc = lua_gettop(tolua_S)-1; - if (argc == 1) + if (argc == 0) { - std::string_view arg0; - - ok &= luaval_to_std_string_view(tolua_S, 2,&arg0, "axui.TextField:setPlaceHolder"); if(!ok) { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextField_setPlaceHolder'", nullptr); + tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextBMFont_getStringLength'", nullptr); return 0; } - obj->setPlaceHolder(arg0); - lua_settop(tolua_S, 1); + auto&& ret = obj->getStringLength(); + tolua_pushnumber(tolua_S,(lua_Number)ret); return 1; } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextField:setPlaceHolder",argc, 1); + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextBMFont:getStringLength",argc, 0); return 0; #if _AX_DEBUG >= 1 tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextField_setPlaceHolder'.",&tolua_err); + tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextBMFont_getStringLength'.",&tolua_err); #endif return 0; } -int lua_ax_ui_TextField_getPlaceHolder(lua_State* tolua_S) +int lua_ax_ui_TextBMFont_getRenderFile(lua_State* tolua_S) { int argc = 0; - ax::ui::TextField* obj = nullptr; + ax::ui::TextBMFont* obj = nullptr; bool ok = true; #if _AX_DEBUG >= 1 @@ -22429,15 +22327,15 @@ int lua_ax_ui_TextField_getPlaceHolder(lua_State* tolua_S) #if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.TextField",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(tolua_S,1,"axui.TextBMFont",0,&tolua_err)) goto tolua_lerror; #endif - obj = (ax::ui::TextField*)tolua_tousertype(tolua_S,1,0); + obj = (ax::ui::TextBMFont*)tolua_tousertype(tolua_S,1,0); #if _AX_DEBUG >= 1 if (!obj) { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextField_getPlaceHolder'", nullptr); + tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextBMFont_getRenderFile'", nullptr); return 0; } #endif @@ -22447,27 +22345,27 @@ int lua_ax_ui_TextField_getPlaceHolder(lua_State* tolua_S) { if(!ok) { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextField_getPlaceHolder'", nullptr); + tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextBMFont_getRenderFile'", nullptr); return 0; } - auto&& ret = obj->getPlaceHolder(); - lua_pushlstring(tolua_S,ret.data(),ret.length()); + auto&& ret = obj->getRenderFile(); + resourceData_to_luaval(tolua_S, ret); return 1; } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextField:getPlaceHolder",argc, 0); + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextBMFont:getRenderFile",argc, 0); return 0; #if _AX_DEBUG >= 1 tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextField_getPlaceHolder'.",&tolua_err); + tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextBMFont_getRenderFile'.",&tolua_err); #endif return 0; } -int lua_ax_ui_TextField_getPlaceHolderColor(lua_State* tolua_S) +int lua_ax_ui_TextBMFont_resetRender(lua_State* tolua_S) { int argc = 0; - ax::ui::TextField* obj = nullptr; + ax::ui::TextBMFont* obj = nullptr; bool ok = true; #if _AX_DEBUG >= 1 @@ -22476,15 +22374,15 @@ int lua_ax_ui_TextField_getPlaceHolderColor(lua_State* tolua_S) #if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.TextField",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(tolua_S,1,"axui.TextBMFont",0,&tolua_err)) goto tolua_lerror; #endif - obj = (ax::ui::TextField*)tolua_tousertype(tolua_S,1,0); + obj = (ax::ui::TextBMFont*)tolua_tousertype(tolua_S,1,0); #if _AX_DEBUG >= 1 if (!obj) { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextField_getPlaceHolderColor'", nullptr); + tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextBMFont_resetRender'", nullptr); return 0; } #endif @@ -22494,124 +22392,172 @@ int lua_ax_ui_TextField_getPlaceHolderColor(lua_State* tolua_S) { if(!ok) { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextField_getPlaceHolderColor'", nullptr); + tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextBMFont_resetRender'", nullptr); return 0; } - auto&& ret = obj->getPlaceHolderColor(); - color32_to_luaval(tolua_S, ret); + obj->resetRender(); + lua_settop(tolua_S, 1); return 1; } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextField:getPlaceHolderColor",argc, 0); + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextBMFont:resetRender",argc, 0); return 0; #if _AX_DEBUG >= 1 tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextField_getPlaceHolderColor'.",&tolua_err); + tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextBMFont_resetRender'.",&tolua_err); #endif return 0; } -int lua_ax_ui_TextField_setPlaceHolderColor(lua_State* tolua_S) +int lua_ax_ui_TextBMFont_createInstance(lua_State* tolua_S) { int argc = 0; - ax::ui::TextField* obj = nullptr; bool ok = true; #if _AX_DEBUG >= 1 tolua_Error tolua_err; #endif - #if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.TextField",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertable(tolua_S,1,"axui.TextBMFont",0,&tolua_err)) goto tolua_lerror; #endif - obj = (ax::ui::TextField*)tolua_tousertype(tolua_S,1,0); - -#if _AX_DEBUG >= 1 - if (!obj) - { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextField_setPlaceHolderColor'", nullptr); - return 0; - } -#endif + argc = lua_gettop(tolua_S) - 1; - argc = lua_gettop(tolua_S)-1; - if (argc == 1) + if (argc == 0) { - ax::Color32 arg0; - - ok &=luaval_to_color32(tolua_S, 2, &arg0, "axui.TextField:setPlaceHolderColor"); if(!ok) { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextField_setPlaceHolderColor'", nullptr); + tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextBMFont_createInstance'", nullptr); return 0; } - obj->setPlaceHolderColor(arg0); - lua_settop(tolua_S, 1); + auto&& ret = ax::ui::TextBMFont::createInstance(); + object_to_luaval(tolua_S, "ax.Object",(ax::Object*)ret); return 1; } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextField:setPlaceHolderColor",argc, 1); + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d\n ", "axui.TextBMFont:createInstance",argc, 0); return 0; - #if _AX_DEBUG >= 1 tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextField_setPlaceHolderColor'.",&tolua_err); + tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextBMFont_createInstance'.",&tolua_err); #endif - return 0; } -int lua_ax_ui_TextField_getTextColor(lua_State* tolua_S) +int lua_ax_ui_TextBMFont_create(lua_State* tolua_S) { int argc = 0; - ax::ui::TextField* obj = nullptr; bool ok = true; - #if _AX_DEBUG >= 1 tolua_Error tolua_err; #endif - #if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.TextField",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertable(tolua_S,1,"axui.TextBMFont",0,&tolua_err)) goto tolua_lerror; #endif - obj = (ax::ui::TextField*)tolua_tousertype(tolua_S,1,0); + argc = lua_gettop(tolua_S)-1; + do { + if (argc == 2) + { + std::string_view arg0; + ok &= luaval_to_std_string_view(tolua_S, 2,&arg0, "axui.TextBMFont:create"); + if (!ok) { break; } + std::string_view arg1; + ok &= luaval_to_std_string_view(tolua_S, 3,&arg1, "axui.TextBMFont:create"); + if (!ok) { break; } + ax::ui::TextBMFont* ret = ax::ui::TextBMFont::create(arg0, arg1); + object_to_luaval(tolua_S, "axui.TextBMFont",(ax::ui::TextBMFont*)ret); + return 1; + } + } while (0); + ok = true; + do { + if (argc == 0) + { + ax::ui::TextBMFont* ret = ax::ui::TextBMFont::create(); + object_to_luaval(tolua_S, "axui.TextBMFont",(ax::ui::TextBMFont*)ret); + return 1; + } + } while (0); + ok = true; + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d", "axui.TextBMFont:create",argc, 0); + return 0; #if _AX_DEBUG >= 1 - if (!obj) - { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextField_getTextColor'", nullptr); - return 0; - } + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextBMFont_create'.",&tolua_err); +#endif + return 0; +} +int lua_ax_ui_TextBMFont_constructor(lua_State* tolua_S) +{ + int argc = 0; + ax::ui::TextBMFont* obj = nullptr; + bool ok = true; + +#if _AX_DEBUG >= 1 + tolua_Error tolua_err; #endif + + argc = lua_gettop(tolua_S)-1; if (argc == 0) { if(!ok) { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextField_getTextColor'", nullptr); + tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextBMFont_constructor'", nullptr); return 0; } - auto&& ret = obj->getTextColor(); - color32_to_luaval(tolua_S, ret); + obj = new ax::ui::TextBMFont(); + obj->autorelease(); + int ID = (int)obj->_ID ; + int* luaID = &obj->_luaID ; + toluafix_pushusertype_object(tolua_S, ID, luaID, (void*)obj,"axui.TextBMFont"); return 1; } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextField:getTextColor",argc, 0); + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextBMFont:TextBMFont",argc, 0); return 0; #if _AX_DEBUG >= 1 - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextField_getTextColor'.",&tolua_err); + tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextBMFont_constructor'.",&tolua_err); #endif return 0; } -int lua_ax_ui_TextField_setTextColor(lua_State* tolua_S) + +static int lua_ax_ui_TextBMFont_finalize(lua_State* tolua_S) +{ + AXLOGV("luabindings: finalizing LUA object (TextBMFont)"); + return 0; +} + +int lua_register_ax_ui_TextBMFont(lua_State* tolua_S) +{ + tolua_usertype(tolua_S,"axui.TextBMFont"); + tolua_cclass(tolua_S,"TextBMFont","axui.TextBMFont","axui.Widget",nullptr); + + tolua_beginmodule(tolua_S,"TextBMFont"); + tolua_function(tolua_S,"new",lua_ax_ui_TextBMFont_constructor); + tolua_function(tolua_S,"setFntFile",lua_ax_ui_TextBMFont_setFntFile); + tolua_function(tolua_S,"setString",lua_ax_ui_TextBMFont_setString); + tolua_function(tolua_S,"getString",lua_ax_ui_TextBMFont_getString); + tolua_function(tolua_S,"getStringLength",lua_ax_ui_TextBMFont_getStringLength); + tolua_function(tolua_S,"getRenderFile",lua_ax_ui_TextBMFont_getRenderFile); + tolua_function(tolua_S,"resetRender",lua_ax_ui_TextBMFont_resetRender); + tolua_function(tolua_S,"createInstance", lua_ax_ui_TextBMFont_createInstance); + tolua_function(tolua_S,"create", lua_ax_ui_TextBMFont_create); + tolua_endmodule(tolua_S); + auto typeName = typeid(ax::ui::TextBMFont).name(); // rtti is literal storage + g_luaType[reinterpret_cast(typeName)] = "axui.TextBMFont"; + g_typeCast[typeName] = "axui.TextBMFont"; + return 1; +} + +int lua_ax_ui_PageView_addPage(lua_State* tolua_S) { int argc = 0; - ax::ui::TextField* obj = nullptr; + ax::ui::PageView* obj = nullptr; bool ok = true; #if _AX_DEBUG >= 1 @@ -22620,15 +22566,15 @@ int lua_ax_ui_TextField_setTextColor(lua_State* tolua_S) #if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.TextField",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(tolua_S,1,"axui.PageView",0,&tolua_err)) goto tolua_lerror; #endif - obj = (ax::ui::TextField*)tolua_tousertype(tolua_S,1,0); + obj = (ax::ui::PageView*)tolua_tousertype(tolua_S,1,0); #if _AX_DEBUG >= 1 if (!obj) { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextField_setTextColor'", nullptr); + tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_PageView_addPage'", nullptr); return 0; } #endif @@ -22636,32 +22582,32 @@ int lua_ax_ui_TextField_setTextColor(lua_State* tolua_S) argc = lua_gettop(tolua_S)-1; if (argc == 1) { - ax::Color32 arg0; + ax::ui::Widget* arg0; - ok &=luaval_to_color32(tolua_S, 2, &arg0, "axui.TextField:setTextColor"); + ok &= luaval_to_object(tolua_S, 2, "axui.Widget",&arg0, "axui.PageView:addPage"); if(!ok) { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextField_setTextColor'", nullptr); + tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_PageView_addPage'", nullptr); return 0; } - obj->setTextColor(arg0); + obj->addPage(arg0); lua_settop(tolua_S, 1); return 1; } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextField:setTextColor",argc, 1); + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.PageView:addPage",argc, 1); return 0; #if _AX_DEBUG >= 1 tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextField_setTextColor'.",&tolua_err); + tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_PageView_addPage'.",&tolua_err); #endif return 0; } -int lua_ax_ui_TextField_setFontSize(lua_State* tolua_S) +int lua_ax_ui_PageView_insertPage(lua_State* tolua_S) { int argc = 0; - ax::ui::TextField* obj = nullptr; + ax::ui::PageView* obj = nullptr; bool ok = true; #if _AX_DEBUG >= 1 @@ -22670,48 +22616,51 @@ int lua_ax_ui_TextField_setFontSize(lua_State* tolua_S) #if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.TextField",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(tolua_S,1,"axui.PageView",0,&tolua_err)) goto tolua_lerror; #endif - obj = (ax::ui::TextField*)tolua_tousertype(tolua_S,1,0); + obj = (ax::ui::PageView*)tolua_tousertype(tolua_S,1,0); #if _AX_DEBUG >= 1 if (!obj) { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextField_setFontSize'", nullptr); + tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_PageView_insertPage'", nullptr); return 0; } #endif argc = lua_gettop(tolua_S)-1; - if (argc == 1) + if (argc == 2) { - int arg0; + ax::ui::Widget* arg0; + int arg1; + + ok &= luaval_to_object(tolua_S, 2, "axui.Widget",&arg0, "axui.PageView:insertPage"); - ok &= luaval_to_int(tolua_S, 2, &arg0, "axui.TextField:setFontSize"); + ok &= luaval_to_int(tolua_S, 3, &arg1, "axui.PageView:insertPage"); if(!ok) { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextField_setFontSize'", nullptr); + tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_PageView_insertPage'", nullptr); return 0; } - obj->setFontSize(arg0); + obj->insertPage(arg0, arg1); lua_settop(tolua_S, 1); return 1; } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextField:setFontSize",argc, 1); + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.PageView:insertPage",argc, 2); return 0; #if _AX_DEBUG >= 1 tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextField_setFontSize'.",&tolua_err); + tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_PageView_insertPage'.",&tolua_err); #endif return 0; } -int lua_ax_ui_TextField_getFontSize(lua_State* tolua_S) +int lua_ax_ui_PageView_removePage(lua_State* tolua_S) { int argc = 0; - ax::ui::TextField* obj = nullptr; + ax::ui::PageView* obj = nullptr; bool ok = true; #if _AX_DEBUG >= 1 @@ -22720,45 +22669,48 @@ int lua_ax_ui_TextField_getFontSize(lua_State* tolua_S) #if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.TextField",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(tolua_S,1,"axui.PageView",0,&tolua_err)) goto tolua_lerror; #endif - obj = (ax::ui::TextField*)tolua_tousertype(tolua_S,1,0); + obj = (ax::ui::PageView*)tolua_tousertype(tolua_S,1,0); #if _AX_DEBUG >= 1 if (!obj) { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextField_getFontSize'", nullptr); + tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_PageView_removePage'", nullptr); return 0; } #endif argc = lua_gettop(tolua_S)-1; - if (argc == 0) + if (argc == 1) { + ax::ui::Widget* arg0; + + ok &= luaval_to_object(tolua_S, 2, "axui.Widget",&arg0, "axui.PageView:removePage"); if(!ok) { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextField_getFontSize'", nullptr); + tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_PageView_removePage'", nullptr); return 0; } - auto&& ret = obj->getFontSize(); - tolua_pushnumber(tolua_S,(lua_Number)ret); + obj->removePage(arg0); + lua_settop(tolua_S, 1); return 1; } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextField:getFontSize",argc, 0); + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.PageView:removePage",argc, 1); return 0; #if _AX_DEBUG >= 1 tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextField_getFontSize'.",&tolua_err); + tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_PageView_removePage'.",&tolua_err); #endif return 0; } -int lua_ax_ui_TextField_setFontName(lua_State* tolua_S) +int lua_ax_ui_PageView_removePageAtIndex(lua_State* tolua_S) { int argc = 0; - ax::ui::TextField* obj = nullptr; + ax::ui::PageView* obj = nullptr; bool ok = true; #if _AX_DEBUG >= 1 @@ -22767,15 +22719,15 @@ int lua_ax_ui_TextField_setFontName(lua_State* tolua_S) #if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.TextField",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(tolua_S,1,"axui.PageView",0,&tolua_err)) goto tolua_lerror; #endif - obj = (ax::ui::TextField*)tolua_tousertype(tolua_S,1,0); + obj = (ax::ui::PageView*)tolua_tousertype(tolua_S,1,0); #if _AX_DEBUG >= 1 if (!obj) { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextField_setFontName'", nullptr); + tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_PageView_removePageAtIndex'", nullptr); return 0; } #endif @@ -22783,32 +22735,32 @@ int lua_ax_ui_TextField_setFontName(lua_State* tolua_S) argc = lua_gettop(tolua_S)-1; if (argc == 1) { - std::string_view arg0; + ssize_t arg0; - ok &= luaval_to_std_string_view(tolua_S, 2,&arg0, "axui.TextField:setFontName"); + ok &= luaval_to_ssize_t(tolua_S, 2, &arg0, "axui.PageView:removePageAtIndex"); if(!ok) { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextField_setFontName'", nullptr); + tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_PageView_removePageAtIndex'", nullptr); return 0; } - obj->setFontName(arg0); + obj->removePageAtIndex(arg0); lua_settop(tolua_S, 1); return 1; } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextField:setFontName",argc, 1); + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.PageView:removePageAtIndex",argc, 1); return 0; #if _AX_DEBUG >= 1 tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextField_setFontName'.",&tolua_err); + tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_PageView_removePageAtIndex'.",&tolua_err); #endif return 0; } -int lua_ax_ui_TextField_getFontName(lua_State* tolua_S) +int lua_ax_ui_PageView_removeAllPages(lua_State* tolua_S) { int argc = 0; - ax::ui::TextField* obj = nullptr; + ax::ui::PageView* obj = nullptr; bool ok = true; #if _AX_DEBUG >= 1 @@ -22817,15 +22769,15 @@ int lua_ax_ui_TextField_getFontName(lua_State* tolua_S) #if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.TextField",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(tolua_S,1,"axui.PageView",0,&tolua_err)) goto tolua_lerror; #endif - obj = (ax::ui::TextField*)tolua_tousertype(tolua_S,1,0); + obj = (ax::ui::PageView*)tolua_tousertype(tolua_S,1,0); #if _AX_DEBUG >= 1 if (!obj) { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextField_getFontName'", nullptr); + tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_PageView_removeAllPages'", nullptr); return 0; } #endif @@ -22835,124 +22787,145 @@ int lua_ax_ui_TextField_getFontName(lua_State* tolua_S) { if(!ok) { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextField_getFontName'", nullptr); + tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_PageView_removeAllPages'", nullptr); return 0; } - auto&& ret = obj->getFontName(); - lua_pushlstring(tolua_S,ret.data(),ret.length()); + obj->removeAllPages(); + lua_settop(tolua_S, 1); return 1; } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextField:getFontName",argc, 0); + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.PageView:removeAllPages",argc, 0); return 0; #if _AX_DEBUG >= 1 tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextField_getFontName'.",&tolua_err); + tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_PageView_removeAllPages'.",&tolua_err); #endif return 0; } -int lua_ax_ui_TextField_didNotSelectSelf(lua_State* tolua_S) +int lua_ax_ui_PageView_scrollToPage(lua_State* tolua_S) { int argc = 0; - ax::ui::TextField* obj = nullptr; + ax::ui::PageView* obj = nullptr; bool ok = true; - #if _AX_DEBUG >= 1 tolua_Error tolua_err; #endif - #if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.TextField",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(tolua_S,1,"axui.PageView",0,&tolua_err)) goto tolua_lerror; #endif - - obj = (ax::ui::TextField*)tolua_tousertype(tolua_S,1,0); - + obj = (ax::ui::PageView*)tolua_tousertype(tolua_S,1,0); #if _AX_DEBUG >= 1 if (!obj) { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextField_didNotSelectSelf'", nullptr); + tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_PageView_scrollToPage'", nullptr); return 0; } #endif - argc = lua_gettop(tolua_S)-1; - if (argc == 0) - { - if(!ok) - { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextField_didNotSelectSelf'", nullptr); - return 0; + do { + if (argc == 2) { + ssize_t arg0; + ok &= luaval_to_ssize_t(tolua_S, 2, &arg0, "axui.PageView:scrollToPage"); + + if (!ok) { break; } + double arg1; + ok &= luaval_to_number(tolua_S, 3, &arg1, "axui.PageView:scrollToPage"); + + if (!ok) { break; } + obj->scrollToPage(arg0, arg1); + lua_settop(tolua_S, 1); + return 1; } - obj->didNotSelectSelf(); - lua_settop(tolua_S, 1); - return 1; - } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextField:didNotSelectSelf",argc, 0); + }while(0); + ok = true; + do { + if (argc == 1) { + ssize_t arg0; + ok &= luaval_to_ssize_t(tolua_S, 2, &arg0, "axui.PageView:scrollToPage"); + + if (!ok) { break; } + obj->scrollToPage(arg0); + lua_settop(tolua_S, 1); + return 1; + } + }while(0); + ok = true; + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.PageView:scrollToPage",argc, 1); return 0; #if _AX_DEBUG >= 1 tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextField_didNotSelectSelf'.",&tolua_err); + tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_PageView_scrollToPage'.",&tolua_err); #endif return 0; } -int lua_ax_ui_TextField_setString(lua_State* tolua_S) +int lua_ax_ui_PageView_scrollToItem(lua_State* tolua_S) { int argc = 0; - ax::ui::TextField* obj = nullptr; + ax::ui::PageView* obj = nullptr; bool ok = true; - #if _AX_DEBUG >= 1 tolua_Error tolua_err; #endif - #if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.TextField",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(tolua_S,1,"axui.PageView",0,&tolua_err)) goto tolua_lerror; #endif - - obj = (ax::ui::TextField*)tolua_tousertype(tolua_S,1,0); - + obj = (ax::ui::PageView*)tolua_tousertype(tolua_S,1,0); #if _AX_DEBUG >= 1 if (!obj) { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextField_setString'", nullptr); + tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_PageView_scrollToItem'", nullptr); return 0; } #endif - argc = lua_gettop(tolua_S)-1; - if (argc == 1) - { - std::string_view arg0; + do { + if (argc == 2) { + ssize_t arg0; + ok &= luaval_to_ssize_t(tolua_S, 2, &arg0, "axui.PageView:scrollToItem"); - ok &= luaval_to_std_string_view(tolua_S, 2,&arg0, "axui.TextField:setString"); - if(!ok) - { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextField_setString'", nullptr); - return 0; + if (!ok) { break; } + double arg1; + ok &= luaval_to_number(tolua_S, 3, &arg1, "axui.PageView:scrollToItem"); + + if (!ok) { break; } + obj->scrollToItem(arg0, arg1); + lua_settop(tolua_S, 1); + return 1; } - obj->setString(arg0); - lua_settop(tolua_S, 1); - return 1; - } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextField:setString",argc, 1); + }while(0); + ok = true; + do { + if (argc == 1) { + ssize_t arg0; + ok &= luaval_to_ssize_t(tolua_S, 2, &arg0, "axui.PageView:scrollToItem"); + + if (!ok) { break; } + obj->scrollToItem(arg0); + lua_settop(tolua_S, 1); + return 1; + } + }while(0); + ok = true; + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.PageView:scrollToItem",argc, 1); return 0; #if _AX_DEBUG >= 1 tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextField_setString'.",&tolua_err); + tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_PageView_scrollToItem'.",&tolua_err); #endif return 0; } -int lua_ax_ui_TextField_getString(lua_State* tolua_S) +int lua_ax_ui_PageView_getCurrentPageIndex(lua_State* tolua_S) { int argc = 0; - ax::ui::TextField* obj = nullptr; + ax::ui::PageView* obj = nullptr; bool ok = true; #if _AX_DEBUG >= 1 @@ -22961,15 +22934,15 @@ int lua_ax_ui_TextField_getString(lua_State* tolua_S) #if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.TextField",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(tolua_S,1,"axui.PageView",0,&tolua_err)) goto tolua_lerror; #endif - obj = (ax::ui::TextField*)tolua_tousertype(tolua_S,1,0); + obj = (ax::ui::PageView*)tolua_tousertype(tolua_S,1,0); #if _AX_DEBUG >= 1 if (!obj) { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextField_getString'", nullptr); + tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_PageView_getCurrentPageIndex'", nullptr); return 0; } #endif @@ -22979,27 +22952,27 @@ int lua_ax_ui_TextField_getString(lua_State* tolua_S) { if(!ok) { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextField_getString'", nullptr); + tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_PageView_getCurrentPageIndex'", nullptr); return 0; } - auto&& ret = obj->getString(); - lua_pushlstring(tolua_S,ret.data(),ret.length()); + auto&& ret = obj->getCurrentPageIndex(); + tolua_pushnumber(tolua_S,(lua_Number)ret); return 1; } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextField:getString",argc, 0); + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.PageView:getCurrentPageIndex",argc, 0); return 0; #if _AX_DEBUG >= 1 tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextField_getString'.",&tolua_err); + tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_PageView_getCurrentPageIndex'.",&tolua_err); #endif return 0; } -int lua_ax_ui_TextField_setMaxLengthEnabled(lua_State* tolua_S) +int lua_ax_ui_PageView_setCurrentPageIndex(lua_State* tolua_S) { int argc = 0; - ax::ui::TextField* obj = nullptr; + ax::ui::PageView* obj = nullptr; bool ok = true; #if _AX_DEBUG >= 1 @@ -23008,15 +22981,15 @@ int lua_ax_ui_TextField_setMaxLengthEnabled(lua_State* tolua_S) #if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.TextField",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(tolua_S,1,"axui.PageView",0,&tolua_err)) goto tolua_lerror; #endif - obj = (ax::ui::TextField*)tolua_tousertype(tolua_S,1,0); + obj = (ax::ui::PageView*)tolua_tousertype(tolua_S,1,0); #if _AX_DEBUG >= 1 if (!obj) { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextField_setMaxLengthEnabled'", nullptr); + tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_PageView_setCurrentPageIndex'", nullptr); return 0; } #endif @@ -23024,32 +22997,32 @@ int lua_ax_ui_TextField_setMaxLengthEnabled(lua_State* tolua_S) argc = lua_gettop(tolua_S)-1; if (argc == 1) { - bool arg0; + ssize_t arg0; - ok &= luaval_to_boolean(tolua_S, 2, &arg0, "axui.TextField:setMaxLengthEnabled"); + ok &= luaval_to_ssize_t(tolua_S, 2, &arg0, "axui.PageView:setCurrentPageIndex"); if(!ok) { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextField_setMaxLengthEnabled'", nullptr); + tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_PageView_setCurrentPageIndex'", nullptr); return 0; } - obj->setMaxLengthEnabled(arg0); + obj->setCurrentPageIndex(arg0); lua_settop(tolua_S, 1); return 1; } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextField:setMaxLengthEnabled",argc, 1); + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.PageView:setCurrentPageIndex",argc, 1); return 0; #if _AX_DEBUG >= 1 tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextField_setMaxLengthEnabled'.",&tolua_err); + tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_PageView_setCurrentPageIndex'.",&tolua_err); #endif return 0; } -int lua_ax_ui_TextField_isMaxLengthEnabled(lua_State* tolua_S) +int lua_ax_ui_PageView_addEventListener(lua_State* tolua_S) { int argc = 0; - ax::ui::TextField* obj = nullptr; + ax::ui::PageView* obj = nullptr; bool ok = true; #if _AX_DEBUG >= 1 @@ -23058,45 +23031,52 @@ int lua_ax_ui_TextField_isMaxLengthEnabled(lua_State* tolua_S) #if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.TextField",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(tolua_S,1,"axui.PageView",0,&tolua_err)) goto tolua_lerror; #endif - obj = (ax::ui::TextField*)tolua_tousertype(tolua_S,1,0); + obj = (ax::ui::PageView*)tolua_tousertype(tolua_S,1,0); #if _AX_DEBUG >= 1 if (!obj) { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextField_isMaxLengthEnabled'", nullptr); + tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_PageView_addEventListener'", nullptr); return 0; } #endif argc = lua_gettop(tolua_S)-1; - if (argc == 0) + if (argc == 1) { + std::function arg0; + + do { + // Lambda binding for lua is not supported. + assert(false); + } while(0) + ; if(!ok) { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextField_isMaxLengthEnabled'", nullptr); + tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_PageView_addEventListener'", nullptr); return 0; } - auto&& ret = obj->isMaxLengthEnabled(); - tolua_pushboolean(tolua_S,(bool)ret); + obj->addEventListener(arg0); + lua_settop(tolua_S, 1); return 1; } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextField:isMaxLengthEnabled",argc, 0); + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.PageView:addEventListener",argc, 1); return 0; #if _AX_DEBUG >= 1 tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextField_isMaxLengthEnabled'.",&tolua_err); + tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_PageView_addEventListener'.",&tolua_err); #endif return 0; } -int lua_ax_ui_TextField_setMaxLength(lua_State* tolua_S) +int lua_ax_ui_PageView_setIndicatorEnabled(lua_State* tolua_S) { int argc = 0; - ax::ui::TextField* obj = nullptr; + ax::ui::PageView* obj = nullptr; bool ok = true; #if _AX_DEBUG >= 1 @@ -23105,15 +23085,15 @@ int lua_ax_ui_TextField_setMaxLength(lua_State* tolua_S) #if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.TextField",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(tolua_S,1,"axui.PageView",0,&tolua_err)) goto tolua_lerror; #endif - obj = (ax::ui::TextField*)tolua_tousertype(tolua_S,1,0); + obj = (ax::ui::PageView*)tolua_tousertype(tolua_S,1,0); #if _AX_DEBUG >= 1 if (!obj) { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextField_setMaxLength'", nullptr); + tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_PageView_setIndicatorEnabled'", nullptr); return 0; } #endif @@ -23121,32 +23101,32 @@ int lua_ax_ui_TextField_setMaxLength(lua_State* tolua_S) argc = lua_gettop(tolua_S)-1; if (argc == 1) { - int arg0; + bool arg0; - ok &= luaval_to_int(tolua_S, 2, &arg0, "axui.TextField:setMaxLength"); + ok &= luaval_to_boolean(tolua_S, 2, &arg0, "axui.PageView:setIndicatorEnabled"); if(!ok) { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextField_setMaxLength'", nullptr); + tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_PageView_setIndicatorEnabled'", nullptr); return 0; } - obj->setMaxLength(arg0); + obj->setIndicatorEnabled(arg0); lua_settop(tolua_S, 1); return 1; } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextField:setMaxLength",argc, 1); + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.PageView:setIndicatorEnabled",argc, 1); return 0; #if _AX_DEBUG >= 1 tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextField_setMaxLength'.",&tolua_err); + tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_PageView_setIndicatorEnabled'.",&tolua_err); #endif return 0; } -int lua_ax_ui_TextField_getMaxLength(lua_State* tolua_S) +int lua_ax_ui_PageView_getIndicatorEnabled(lua_State* tolua_S) { int argc = 0; - ax::ui::TextField* obj = nullptr; + ax::ui::PageView* obj = nullptr; bool ok = true; #if _AX_DEBUG >= 1 @@ -23155,15 +23135,15 @@ int lua_ax_ui_TextField_getMaxLength(lua_State* tolua_S) #if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.TextField",0,&tolua_err)) goto tolua_lerror; + if (!tolua_isusertype(tolua_S,1,"axui.PageView",0,&tolua_err)) goto tolua_lerror; #endif - obj = (ax::ui::TextField*)tolua_tousertype(tolua_S,1,0); + obj = (ax::ui::PageView*)tolua_tousertype(tolua_S,1,0); #if _AX_DEBUG >= 1 if (!obj) { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextField_getMaxLength'", nullptr); + tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_PageView_getIndicatorEnabled'", nullptr); return 0; } #endif @@ -23173,2464 +23153,7 @@ int lua_ax_ui_TextField_getMaxLength(lua_State* tolua_S) { if(!ok) { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextField_getMaxLength'", nullptr); - return 0; - } - auto&& ret = obj->getMaxLength(); - tolua_pushnumber(tolua_S,(lua_Number)ret); - return 1; - } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextField:getMaxLength",argc, 0); - return 0; - -#if _AX_DEBUG >= 1 - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextField_getMaxLength'.",&tolua_err); -#endif - - return 0; -} -int lua_ax_ui_TextField_getStringLength(lua_State* tolua_S) -{ - int argc = 0; - ax::ui::TextField* obj = nullptr; - bool ok = true; - -#if _AX_DEBUG >= 1 - tolua_Error tolua_err; -#endif - - -#if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.TextField",0,&tolua_err)) goto tolua_lerror; -#endif - - obj = (ax::ui::TextField*)tolua_tousertype(tolua_S,1,0); - -#if _AX_DEBUG >= 1 - if (!obj) - { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextField_getStringLength'", nullptr); - return 0; - } -#endif - - argc = lua_gettop(tolua_S)-1; - if (argc == 0) - { - if(!ok) - { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextField_getStringLength'", nullptr); - return 0; - } - auto&& ret = obj->getStringLength(); - tolua_pushnumber(tolua_S,(lua_Number)ret); - return 1; - } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextField:getStringLength",argc, 0); - return 0; - -#if _AX_DEBUG >= 1 - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextField_getStringLength'.",&tolua_err); -#endif - - return 0; -} -int lua_ax_ui_TextField_setPasswordEnabled(lua_State* tolua_S) -{ - int argc = 0; - ax::ui::TextField* obj = nullptr; - bool ok = true; - -#if _AX_DEBUG >= 1 - tolua_Error tolua_err; -#endif - - -#if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.TextField",0,&tolua_err)) goto tolua_lerror; -#endif - - obj = (ax::ui::TextField*)tolua_tousertype(tolua_S,1,0); - -#if _AX_DEBUG >= 1 - if (!obj) - { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextField_setPasswordEnabled'", nullptr); - return 0; - } -#endif - - argc = lua_gettop(tolua_S)-1; - if (argc == 1) - { - bool arg0; - - ok &= luaval_to_boolean(tolua_S, 2, &arg0, "axui.TextField:setPasswordEnabled"); - if(!ok) - { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextField_setPasswordEnabled'", nullptr); - return 0; - } - obj->setPasswordEnabled(arg0); - lua_settop(tolua_S, 1); - return 1; - } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextField:setPasswordEnabled",argc, 1); - return 0; - -#if _AX_DEBUG >= 1 - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextField_setPasswordEnabled'.",&tolua_err); -#endif - - return 0; -} -int lua_ax_ui_TextField_isPasswordEnabled(lua_State* tolua_S) -{ - int argc = 0; - ax::ui::TextField* obj = nullptr; - bool ok = true; - -#if _AX_DEBUG >= 1 - tolua_Error tolua_err; -#endif - - -#if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.TextField",0,&tolua_err)) goto tolua_lerror; -#endif - - obj = (ax::ui::TextField*)tolua_tousertype(tolua_S,1,0); - -#if _AX_DEBUG >= 1 - if (!obj) - { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextField_isPasswordEnabled'", nullptr); - return 0; - } -#endif - - argc = lua_gettop(tolua_S)-1; - if (argc == 0) - { - if(!ok) - { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextField_isPasswordEnabled'", nullptr); - return 0; - } - auto&& ret = obj->isPasswordEnabled(); - tolua_pushboolean(tolua_S,(bool)ret); - return 1; - } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextField:isPasswordEnabled",argc, 0); - return 0; - -#if _AX_DEBUG >= 1 - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextField_isPasswordEnabled'.",&tolua_err); -#endif - - return 0; -} -int lua_ax_ui_TextField_setPasswordStyleText(lua_State* tolua_S) -{ - int argc = 0; - ax::ui::TextField* obj = nullptr; - bool ok = true; - -#if _AX_DEBUG >= 1 - tolua_Error tolua_err; -#endif - - -#if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.TextField",0,&tolua_err)) goto tolua_lerror; -#endif - - obj = (ax::ui::TextField*)tolua_tousertype(tolua_S,1,0); - -#if _AX_DEBUG >= 1 - if (!obj) - { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextField_setPasswordStyleText'", nullptr); - return 0; - } -#endif - - argc = lua_gettop(tolua_S)-1; - if (argc == 1) - { - std::string_view arg0; - - ok &= luaval_to_std_string_view(tolua_S, 2,&arg0, "axui.TextField:setPasswordStyleText"); - if(!ok) - { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextField_setPasswordStyleText'", nullptr); - return 0; - } - obj->setPasswordStyleText(arg0); - lua_settop(tolua_S, 1); - return 1; - } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextField:setPasswordStyleText",argc, 1); - return 0; - -#if _AX_DEBUG >= 1 - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextField_setPasswordStyleText'.",&tolua_err); -#endif - - return 0; -} -int lua_ax_ui_TextField_getPasswordStyleText(lua_State* tolua_S) -{ - int argc = 0; - ax::ui::TextField* obj = nullptr; - bool ok = true; - -#if _AX_DEBUG >= 1 - tolua_Error tolua_err; -#endif - - -#if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.TextField",0,&tolua_err)) goto tolua_lerror; -#endif - - obj = (ax::ui::TextField*)tolua_tousertype(tolua_S,1,0); - -#if _AX_DEBUG >= 1 - if (!obj) - { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextField_getPasswordStyleText'", nullptr); - return 0; - } -#endif - - argc = lua_gettop(tolua_S)-1; - if (argc == 0) - { - if(!ok) - { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextField_getPasswordStyleText'", nullptr); - return 0; - } - auto&& ret = obj->getPasswordStyleText(); - lua_pushlstring(tolua_S,ret.data(),ret.length()); - return 1; - } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextField:getPasswordStyleText",argc, 0); - return 0; - -#if _AX_DEBUG >= 1 - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextField_getPasswordStyleText'.",&tolua_err); -#endif - - return 0; -} -int lua_ax_ui_TextField_getAttachWithIME(lua_State* tolua_S) -{ - int argc = 0; - ax::ui::TextField* obj = nullptr; - bool ok = true; - -#if _AX_DEBUG >= 1 - tolua_Error tolua_err; -#endif - - -#if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.TextField",0,&tolua_err)) goto tolua_lerror; -#endif - - obj = (ax::ui::TextField*)tolua_tousertype(tolua_S,1,0); - -#if _AX_DEBUG >= 1 - if (!obj) - { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextField_getAttachWithIME'", nullptr); - return 0; - } -#endif - - argc = lua_gettop(tolua_S)-1; - if (argc == 0) - { - if(!ok) - { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextField_getAttachWithIME'", nullptr); - return 0; - } - auto&& ret = obj->getAttachWithIME(); - tolua_pushboolean(tolua_S,(bool)ret); - return 1; - } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextField:getAttachWithIME",argc, 0); - return 0; - -#if _AX_DEBUG >= 1 - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextField_getAttachWithIME'.",&tolua_err); -#endif - - return 0; -} -int lua_ax_ui_TextField_setAttachWithIME(lua_State* tolua_S) -{ - int argc = 0; - ax::ui::TextField* obj = nullptr; - bool ok = true; - -#if _AX_DEBUG >= 1 - tolua_Error tolua_err; -#endif - - -#if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.TextField",0,&tolua_err)) goto tolua_lerror; -#endif - - obj = (ax::ui::TextField*)tolua_tousertype(tolua_S,1,0); - -#if _AX_DEBUG >= 1 - if (!obj) - { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextField_setAttachWithIME'", nullptr); - return 0; - } -#endif - - argc = lua_gettop(tolua_S)-1; - if (argc == 1) - { - bool arg0; - - ok &= luaval_to_boolean(tolua_S, 2, &arg0, "axui.TextField:setAttachWithIME"); - if(!ok) - { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextField_setAttachWithIME'", nullptr); - return 0; - } - obj->setAttachWithIME(arg0); - lua_settop(tolua_S, 1); - return 1; - } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextField:setAttachWithIME",argc, 1); - return 0; - -#if _AX_DEBUG >= 1 - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextField_setAttachWithIME'.",&tolua_err); -#endif - - return 0; -} -int lua_ax_ui_TextField_getDetachWithIME(lua_State* tolua_S) -{ - int argc = 0; - ax::ui::TextField* obj = nullptr; - bool ok = true; - -#if _AX_DEBUG >= 1 - tolua_Error tolua_err; -#endif - - -#if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.TextField",0,&tolua_err)) goto tolua_lerror; -#endif - - obj = (ax::ui::TextField*)tolua_tousertype(tolua_S,1,0); - -#if _AX_DEBUG >= 1 - if (!obj) - { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextField_getDetachWithIME'", nullptr); - return 0; - } -#endif - - argc = lua_gettop(tolua_S)-1; - if (argc == 0) - { - if(!ok) - { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextField_getDetachWithIME'", nullptr); - return 0; - } - auto&& ret = obj->getDetachWithIME(); - tolua_pushboolean(tolua_S,(bool)ret); - return 1; - } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextField:getDetachWithIME",argc, 0); - return 0; - -#if _AX_DEBUG >= 1 - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextField_getDetachWithIME'.",&tolua_err); -#endif - - return 0; -} -int lua_ax_ui_TextField_setDetachWithIME(lua_State* tolua_S) -{ - int argc = 0; - ax::ui::TextField* obj = nullptr; - bool ok = true; - -#if _AX_DEBUG >= 1 - tolua_Error tolua_err; -#endif - - -#if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.TextField",0,&tolua_err)) goto tolua_lerror; -#endif - - obj = (ax::ui::TextField*)tolua_tousertype(tolua_S,1,0); - -#if _AX_DEBUG >= 1 - if (!obj) - { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextField_setDetachWithIME'", nullptr); - return 0; - } -#endif - - argc = lua_gettop(tolua_S)-1; - if (argc == 1) - { - bool arg0; - - ok &= luaval_to_boolean(tolua_S, 2, &arg0, "axui.TextField:setDetachWithIME"); - if(!ok) - { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextField_setDetachWithIME'", nullptr); - return 0; - } - obj->setDetachWithIME(arg0); - lua_settop(tolua_S, 1); - return 1; - } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextField:setDetachWithIME",argc, 1); - return 0; - -#if _AX_DEBUG >= 1 - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextField_setDetachWithIME'.",&tolua_err); -#endif - - return 0; -} -int lua_ax_ui_TextField_getInsertText(lua_State* tolua_S) -{ - int argc = 0; - ax::ui::TextField* obj = nullptr; - bool ok = true; - -#if _AX_DEBUG >= 1 - tolua_Error tolua_err; -#endif - - -#if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.TextField",0,&tolua_err)) goto tolua_lerror; -#endif - - obj = (ax::ui::TextField*)tolua_tousertype(tolua_S,1,0); - -#if _AX_DEBUG >= 1 - if (!obj) - { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextField_getInsertText'", nullptr); - return 0; - } -#endif - - argc = lua_gettop(tolua_S)-1; - if (argc == 0) - { - if(!ok) - { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextField_getInsertText'", nullptr); - return 0; - } - auto&& ret = obj->getInsertText(); - tolua_pushboolean(tolua_S,(bool)ret); - return 1; - } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextField:getInsertText",argc, 0); - return 0; - -#if _AX_DEBUG >= 1 - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextField_getInsertText'.",&tolua_err); -#endif - - return 0; -} -int lua_ax_ui_TextField_setInsertText(lua_State* tolua_S) -{ - int argc = 0; - ax::ui::TextField* obj = nullptr; - bool ok = true; - -#if _AX_DEBUG >= 1 - tolua_Error tolua_err; -#endif - - -#if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.TextField",0,&tolua_err)) goto tolua_lerror; -#endif - - obj = (ax::ui::TextField*)tolua_tousertype(tolua_S,1,0); - -#if _AX_DEBUG >= 1 - if (!obj) - { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextField_setInsertText'", nullptr); - return 0; - } -#endif - - argc = lua_gettop(tolua_S)-1; - if (argc == 1) - { - bool arg0; - - ok &= luaval_to_boolean(tolua_S, 2, &arg0, "axui.TextField:setInsertText"); - if(!ok) - { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextField_setInsertText'", nullptr); - return 0; - } - obj->setInsertText(arg0); - lua_settop(tolua_S, 1); - return 1; - } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextField:setInsertText",argc, 1); - return 0; - -#if _AX_DEBUG >= 1 - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextField_setInsertText'.",&tolua_err); -#endif - - return 0; -} -int lua_ax_ui_TextField_getDeleteBackward(lua_State* tolua_S) -{ - int argc = 0; - ax::ui::TextField* obj = nullptr; - bool ok = true; - -#if _AX_DEBUG >= 1 - tolua_Error tolua_err; -#endif - - -#if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.TextField",0,&tolua_err)) goto tolua_lerror; -#endif - - obj = (ax::ui::TextField*)tolua_tousertype(tolua_S,1,0); - -#if _AX_DEBUG >= 1 - if (!obj) - { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextField_getDeleteBackward'", nullptr); - return 0; - } -#endif - - argc = lua_gettop(tolua_S)-1; - if (argc == 0) - { - if(!ok) - { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextField_getDeleteBackward'", nullptr); - return 0; - } - auto&& ret = obj->getDeleteBackward(); - tolua_pushboolean(tolua_S,(bool)ret); - return 1; - } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextField:getDeleteBackward",argc, 0); - return 0; - -#if _AX_DEBUG >= 1 - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextField_getDeleteBackward'.",&tolua_err); -#endif - - return 0; -} -int lua_ax_ui_TextField_setDeleteBackward(lua_State* tolua_S) -{ - int argc = 0; - ax::ui::TextField* obj = nullptr; - bool ok = true; - -#if _AX_DEBUG >= 1 - tolua_Error tolua_err; -#endif - - -#if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.TextField",0,&tolua_err)) goto tolua_lerror; -#endif - - obj = (ax::ui::TextField*)tolua_tousertype(tolua_S,1,0); - -#if _AX_DEBUG >= 1 - if (!obj) - { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextField_setDeleteBackward'", nullptr); - return 0; - } -#endif - - argc = lua_gettop(tolua_S)-1; - if (argc == 1) - { - bool arg0; - - ok &= luaval_to_boolean(tolua_S, 2, &arg0, "axui.TextField:setDeleteBackward"); - if(!ok) - { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextField_setDeleteBackward'", nullptr); - return 0; - } - obj->setDeleteBackward(arg0); - lua_settop(tolua_S, 1); - return 1; - } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextField:setDeleteBackward",argc, 1); - return 0; - -#if _AX_DEBUG >= 1 - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextField_setDeleteBackward'.",&tolua_err); -#endif - - return 0; -} -int lua_ax_ui_TextField_addEventListener(lua_State* tolua_S) -{ - int argc = 0; - ax::ui::TextField* obj = nullptr; - bool ok = true; - -#if _AX_DEBUG >= 1 - tolua_Error tolua_err; -#endif - - -#if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.TextField",0,&tolua_err)) goto tolua_lerror; -#endif - - obj = (ax::ui::TextField*)tolua_tousertype(tolua_S,1,0); - -#if _AX_DEBUG >= 1 - if (!obj) - { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextField_addEventListener'", nullptr); - return 0; - } -#endif - - argc = lua_gettop(tolua_S)-1; - if (argc == 1) - { - std::function arg0; - - do { - // Lambda binding for lua is not supported. - assert(false); - } while(0) - ; - if(!ok) - { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextField_addEventListener'", nullptr); - return 0; - } - obj->addEventListener(arg0); - lua_settop(tolua_S, 1); - return 1; - } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextField:addEventListener",argc, 1); - return 0; - -#if _AX_DEBUG >= 1 - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextField_addEventListener'.",&tolua_err); -#endif - - return 0; -} -int lua_ax_ui_TextField_getAutoRenderSize(lua_State* tolua_S) -{ - int argc = 0; - ax::ui::TextField* obj = nullptr; - bool ok = true; - -#if _AX_DEBUG >= 1 - tolua_Error tolua_err; -#endif - - -#if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.TextField",0,&tolua_err)) goto tolua_lerror; -#endif - - obj = (ax::ui::TextField*)tolua_tousertype(tolua_S,1,0); - -#if _AX_DEBUG >= 1 - if (!obj) - { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextField_getAutoRenderSize'", nullptr); - return 0; - } -#endif - - argc = lua_gettop(tolua_S)-1; - if (argc == 0) - { - if(!ok) - { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextField_getAutoRenderSize'", nullptr); - return 0; - } - auto&& ret = obj->getAutoRenderSize(); - vec2_to_luaval(tolua_S, ret); - return 1; - } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextField:getAutoRenderSize",argc, 0); - return 0; - -#if _AX_DEBUG >= 1 - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextField_getAutoRenderSize'.",&tolua_err); -#endif - - return 0; -} -int lua_ax_ui_TextField_attachWithIME(lua_State* tolua_S) -{ - int argc = 0; - ax::ui::TextField* obj = nullptr; - bool ok = true; - -#if _AX_DEBUG >= 1 - tolua_Error tolua_err; -#endif - - -#if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.TextField",0,&tolua_err)) goto tolua_lerror; -#endif - - obj = (ax::ui::TextField*)tolua_tousertype(tolua_S,1,0); - -#if _AX_DEBUG >= 1 - if (!obj) - { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextField_attachWithIME'", nullptr); - return 0; - } -#endif - - argc = lua_gettop(tolua_S)-1; - if (argc == 0) - { - if(!ok) - { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextField_attachWithIME'", nullptr); - return 0; - } - obj->attachWithIME(); - lua_settop(tolua_S, 1); - return 1; - } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextField:attachWithIME",argc, 0); - return 0; - -#if _AX_DEBUG >= 1 - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextField_attachWithIME'.",&tolua_err); -#endif - - return 0; -} -int lua_ax_ui_TextField_detachWithIME(lua_State* tolua_S) -{ - int argc = 0; - ax::ui::TextField* obj = nullptr; - bool ok = true; - -#if _AX_DEBUG >= 1 - tolua_Error tolua_err; -#endif - - -#if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.TextField",0,&tolua_err)) goto tolua_lerror; -#endif - - obj = (ax::ui::TextField*)tolua_tousertype(tolua_S,1,0); - -#if _AX_DEBUG >= 1 - if (!obj) - { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextField_detachWithIME'", nullptr); - return 0; - } -#endif - - argc = lua_gettop(tolua_S)-1; - if (argc == 0) - { - if(!ok) - { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextField_detachWithIME'", nullptr); - return 0; - } - obj->detachWithIME(); - lua_settop(tolua_S, 1); - return 1; - } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextField:detachWithIME",argc, 0); - return 0; - -#if _AX_DEBUG >= 1 - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextField_detachWithIME'.",&tolua_err); -#endif - - return 0; -} -int lua_ax_ui_TextField_setTextAreaSize(lua_State* tolua_S) -{ - int argc = 0; - ax::ui::TextField* obj = nullptr; - bool ok = true; - -#if _AX_DEBUG >= 1 - tolua_Error tolua_err; -#endif - - -#if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.TextField",0,&tolua_err)) goto tolua_lerror; -#endif - - obj = (ax::ui::TextField*)tolua_tousertype(tolua_S,1,0); - -#if _AX_DEBUG >= 1 - if (!obj) - { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextField_setTextAreaSize'", nullptr); - return 0; - } -#endif - - argc = lua_gettop(tolua_S)-1; - if (argc == 1) - { - ax::Vec2 arg0; - - ok &= luaval_to_vec2(tolua_S, 2, &arg0, "axui.TextField:setTextAreaSize"); - if(!ok) - { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextField_setTextAreaSize'", nullptr); - return 0; - } - obj->setTextAreaSize(arg0); - lua_settop(tolua_S, 1); - return 1; - } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextField:setTextAreaSize",argc, 1); - return 0; - -#if _AX_DEBUG >= 1 - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextField_setTextAreaSize'.",&tolua_err); -#endif - - return 0; -} -int lua_ax_ui_TextField_setTextHorizontalAlignment(lua_State* tolua_S) -{ - int argc = 0; - ax::ui::TextField* obj = nullptr; - bool ok = true; - -#if _AX_DEBUG >= 1 - tolua_Error tolua_err; -#endif - - -#if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.TextField",0,&tolua_err)) goto tolua_lerror; -#endif - - obj = (ax::ui::TextField*)tolua_tousertype(tolua_S,1,0); - -#if _AX_DEBUG >= 1 - if (!obj) - { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextField_setTextHorizontalAlignment'", nullptr); - return 0; - } -#endif - - argc = lua_gettop(tolua_S)-1; - if (argc == 1) - { - ax::TextHAlignment arg0; - - ok &= luaval_to_int(tolua_S, 2, &arg0, "axui.TextField:setTextHorizontalAlignment"); - if(!ok) - { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextField_setTextHorizontalAlignment'", nullptr); - return 0; - } - obj->setTextHorizontalAlignment(arg0); - lua_settop(tolua_S, 1); - return 1; - } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextField:setTextHorizontalAlignment",argc, 1); - return 0; - -#if _AX_DEBUG >= 1 - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextField_setTextHorizontalAlignment'.",&tolua_err); -#endif - - return 0; -} -int lua_ax_ui_TextField_getTextHorizontalAlignment(lua_State* tolua_S) -{ - int argc = 0; - ax::ui::TextField* obj = nullptr; - bool ok = true; - -#if _AX_DEBUG >= 1 - tolua_Error tolua_err; -#endif - - -#if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.TextField",0,&tolua_err)) goto tolua_lerror; -#endif - - obj = (ax::ui::TextField*)tolua_tousertype(tolua_S,1,0); - -#if _AX_DEBUG >= 1 - if (!obj) - { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextField_getTextHorizontalAlignment'", nullptr); - return 0; - } -#endif - - argc = lua_gettop(tolua_S)-1; - if (argc == 0) - { - if(!ok) - { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextField_getTextHorizontalAlignment'", nullptr); - return 0; - } - int ret = (int)obj->getTextHorizontalAlignment(); - tolua_pushnumber(tolua_S,(lua_Number)ret); - return 1; - } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextField:getTextHorizontalAlignment",argc, 0); - return 0; - -#if _AX_DEBUG >= 1 - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextField_getTextHorizontalAlignment'.",&tolua_err); -#endif - - return 0; -} -int lua_ax_ui_TextField_setTextVerticalAlignment(lua_State* tolua_S) -{ - int argc = 0; - ax::ui::TextField* obj = nullptr; - bool ok = true; - -#if _AX_DEBUG >= 1 - tolua_Error tolua_err; -#endif - - -#if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.TextField",0,&tolua_err)) goto tolua_lerror; -#endif - - obj = (ax::ui::TextField*)tolua_tousertype(tolua_S,1,0); - -#if _AX_DEBUG >= 1 - if (!obj) - { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextField_setTextVerticalAlignment'", nullptr); - return 0; - } -#endif - - argc = lua_gettop(tolua_S)-1; - if (argc == 1) - { - ax::TextVAlignment arg0; - - ok &= luaval_to_int(tolua_S, 2, &arg0, "axui.TextField:setTextVerticalAlignment"); - if(!ok) - { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextField_setTextVerticalAlignment'", nullptr); - return 0; - } - obj->setTextVerticalAlignment(arg0); - lua_settop(tolua_S, 1); - return 1; - } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextField:setTextVerticalAlignment",argc, 1); - return 0; - -#if _AX_DEBUG >= 1 - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextField_setTextVerticalAlignment'.",&tolua_err); -#endif - - return 0; -} -int lua_ax_ui_TextField_getTextVerticalAlignment(lua_State* tolua_S) -{ - int argc = 0; - ax::ui::TextField* obj = nullptr; - bool ok = true; - -#if _AX_DEBUG >= 1 - tolua_Error tolua_err; -#endif - - -#if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.TextField",0,&tolua_err)) goto tolua_lerror; -#endif - - obj = (ax::ui::TextField*)tolua_tousertype(tolua_S,1,0); - -#if _AX_DEBUG >= 1 - if (!obj) - { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextField_getTextVerticalAlignment'", nullptr); - return 0; - } -#endif - - argc = lua_gettop(tolua_S)-1; - if (argc == 0) - { - if(!ok) - { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextField_getTextVerticalAlignment'", nullptr); - return 0; - } - int ret = (int)obj->getTextVerticalAlignment(); - tolua_pushnumber(tolua_S,(lua_Number)ret); - return 1; - } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextField:getTextVerticalAlignment",argc, 0); - return 0; - -#if _AX_DEBUG >= 1 - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextField_getTextVerticalAlignment'.",&tolua_err); -#endif - - return 0; -} -int lua_ax_ui_TextField_setCursorEnabled(lua_State* tolua_S) -{ - int argc = 0; - ax::ui::TextField* obj = nullptr; - bool ok = true; - -#if _AX_DEBUG >= 1 - tolua_Error tolua_err; -#endif - - -#if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.TextField",0,&tolua_err)) goto tolua_lerror; -#endif - - obj = (ax::ui::TextField*)tolua_tousertype(tolua_S,1,0); - -#if _AX_DEBUG >= 1 - if (!obj) - { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextField_setCursorEnabled'", nullptr); - return 0; - } -#endif - - argc = lua_gettop(tolua_S)-1; - if (argc == 1) - { - bool arg0; - - ok &= luaval_to_boolean(tolua_S, 2, &arg0, "axui.TextField:setCursorEnabled"); - if(!ok) - { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextField_setCursorEnabled'", nullptr); - return 0; - } - obj->setCursorEnabled(arg0); - lua_settop(tolua_S, 1); - return 1; - } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextField:setCursorEnabled",argc, 1); - return 0; - -#if _AX_DEBUG >= 1 - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextField_setCursorEnabled'.",&tolua_err); -#endif - - return 0; -} -int lua_ax_ui_TextField_setCursorChar(lua_State* tolua_S) -{ - int argc = 0; - ax::ui::TextField* obj = nullptr; - bool ok = true; - -#if _AX_DEBUG >= 1 - tolua_Error tolua_err; -#endif - - -#if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.TextField",0,&tolua_err)) goto tolua_lerror; -#endif - - obj = (ax::ui::TextField*)tolua_tousertype(tolua_S,1,0); - -#if _AX_DEBUG >= 1 - if (!obj) - { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextField_setCursorChar'", nullptr); - return 0; - } -#endif - - argc = lua_gettop(tolua_S)-1; - if (argc == 1) - { - int32_t arg0; - - ok &= luaval_to_int(tolua_S, 2, &arg0, "axui.TextField:setCursorChar"); - if(!ok) - { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextField_setCursorChar'", nullptr); - return 0; - } - obj->setCursorChar(arg0); - lua_settop(tolua_S, 1); - return 1; - } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextField:setCursorChar",argc, 1); - return 0; - -#if _AX_DEBUG >= 1 - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextField_setCursorChar'.",&tolua_err); -#endif - - return 0; -} -int lua_ax_ui_TextField_setCursorFromPoint(lua_State* tolua_S) -{ - int argc = 0; - ax::ui::TextField* obj = nullptr; - bool ok = true; - -#if _AX_DEBUG >= 1 - tolua_Error tolua_err; -#endif - - -#if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.TextField",0,&tolua_err)) goto tolua_lerror; -#endif - - obj = (ax::ui::TextField*)tolua_tousertype(tolua_S,1,0); - -#if _AX_DEBUG >= 1 - if (!obj) - { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextField_setCursorFromPoint'", nullptr); - return 0; - } -#endif - - argc = lua_gettop(tolua_S)-1; - if (argc == 2) - { - ax::Vec2 arg0; - const ax::Camera* arg1; - - ok &= luaval_to_vec2(tolua_S, 2, &arg0, "axui.TextField:setCursorFromPoint"); - - ok &= luaval_to_object(tolua_S, 3, "ax.Camera",&arg1, "axui.TextField:setCursorFromPoint"); - if(!ok) - { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextField_setCursorFromPoint'", nullptr); - return 0; - } - obj->setCursorFromPoint(arg0, arg1); - lua_settop(tolua_S, 1); - return 1; - } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextField:setCursorFromPoint",argc, 2); - return 0; - -#if _AX_DEBUG >= 1 - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextField_setCursorFromPoint'.",&tolua_err); -#endif - - return 0; -} -int lua_ax_ui_TextField_createInstance(lua_State* tolua_S) -{ - int argc = 0; - bool ok = true; - -#if _AX_DEBUG >= 1 - tolua_Error tolua_err; -#endif - -#if _AX_DEBUG >= 1 - if (!tolua_isusertable(tolua_S,1,"axui.TextField",0,&tolua_err)) goto tolua_lerror; -#endif - - argc = lua_gettop(tolua_S) - 1; - - if (argc == 0) - { - if(!ok) - { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextField_createInstance'", nullptr); - return 0; - } - auto&& ret = ax::ui::TextField::createInstance(); - object_to_luaval(tolua_S, "ax.Object",(ax::Object*)ret); - return 1; - } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d\n ", "axui.TextField:createInstance",argc, 0); - return 0; -#if _AX_DEBUG >= 1 - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextField_createInstance'.",&tolua_err); -#endif - return 0; -} -int lua_ax_ui_TextField_create(lua_State* tolua_S) -{ - int argc = 0; - bool ok = true; -#if _AX_DEBUG >= 1 - tolua_Error tolua_err; -#endif - -#if _AX_DEBUG >= 1 - if (!tolua_isusertable(tolua_S,1,"axui.TextField",0,&tolua_err)) goto tolua_lerror; -#endif - - argc = lua_gettop(tolua_S)-1; - - do { - if (argc == 3) - { - std::string_view arg0; - ok &= luaval_to_std_string_view(tolua_S, 2,&arg0, "axui.TextField:create"); - if (!ok) { break; } - std::string_view arg1; - ok &= luaval_to_std_string_view(tolua_S, 3,&arg1, "axui.TextField:create"); - if (!ok) { break; } - int arg2; - ok &= luaval_to_int(tolua_S, 4, &arg2, "axui.TextField:create"); - if (!ok) { break; } - ax::ui::TextField* ret = ax::ui::TextField::create(arg0, arg1, arg2); - object_to_luaval(tolua_S, "axui.TextField",(ax::ui::TextField*)ret); - return 1; - } - } while (0); - ok = true; - do { - if (argc == 0) - { - ax::ui::TextField* ret = ax::ui::TextField::create(); - object_to_luaval(tolua_S, "axui.TextField",(ax::ui::TextField*)ret); - return 1; - } - } while (0); - ok = true; - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d", "axui.TextField:create",argc, 0); - return 0; -#if _AX_DEBUG >= 1 - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextField_create'.",&tolua_err); -#endif - return 0; -} -int lua_ax_ui_TextField_constructor(lua_State* tolua_S) -{ - int argc = 0; - ax::ui::TextField* obj = nullptr; - bool ok = true; - -#if _AX_DEBUG >= 1 - tolua_Error tolua_err; -#endif - - - - argc = lua_gettop(tolua_S)-1; - if (argc == 0) - { - if(!ok) - { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextField_constructor'", nullptr); - return 0; - } - obj = new ax::ui::TextField(); - obj->autorelease(); - int ID = (int)obj->_ID ; - int* luaID = &obj->_luaID ; - toluafix_pushusertype_object(tolua_S, ID, luaID, (void*)obj,"axui.TextField"); - return 1; - } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextField:TextField",argc, 0); - return 0; - -#if _AX_DEBUG >= 1 - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextField_constructor'.",&tolua_err); -#endif - - return 0; -} - -static int lua_ax_ui_TextField_finalize(lua_State* tolua_S) -{ - AXLOGV("luabindings: finalizing LUA object (TextField)"); - return 0; -} - -int lua_register_ax_ui_TextField(lua_State* tolua_S) -{ - tolua_usertype(tolua_S,"axui.TextField"); - tolua_cclass(tolua_S,"TextField","axui.TextField","axui.Widget",nullptr); - - tolua_beginmodule(tolua_S,"TextField"); - tolua_function(tolua_S,"new",lua_ax_ui_TextField_constructor); - tolua_function(tolua_S,"setTouchSize",lua_ax_ui_TextField_setTouchSize); - tolua_function(tolua_S,"getTouchSize",lua_ax_ui_TextField_getTouchSize); - tolua_function(tolua_S,"setTouchAreaEnabled",lua_ax_ui_TextField_setTouchAreaEnabled); - tolua_function(tolua_S,"setPlaceHolder",lua_ax_ui_TextField_setPlaceHolder); - tolua_function(tolua_S,"getPlaceHolder",lua_ax_ui_TextField_getPlaceHolder); - tolua_function(tolua_S,"getPlaceHolderColor",lua_ax_ui_TextField_getPlaceHolderColor); - tolua_function(tolua_S,"setPlaceHolderColor",lua_ax_ui_TextField_setPlaceHolderColor); - tolua_function(tolua_S,"getTextColor",lua_ax_ui_TextField_getTextColor); - tolua_function(tolua_S,"setTextColor",lua_ax_ui_TextField_setTextColor); - tolua_function(tolua_S,"setFontSize",lua_ax_ui_TextField_setFontSize); - tolua_function(tolua_S,"getFontSize",lua_ax_ui_TextField_getFontSize); - tolua_function(tolua_S,"setFontName",lua_ax_ui_TextField_setFontName); - tolua_function(tolua_S,"getFontName",lua_ax_ui_TextField_getFontName); - tolua_function(tolua_S,"didNotSelectSelf",lua_ax_ui_TextField_didNotSelectSelf); - tolua_function(tolua_S,"setString",lua_ax_ui_TextField_setString); - tolua_function(tolua_S,"getString",lua_ax_ui_TextField_getString); - tolua_function(tolua_S,"setMaxLengthEnabled",lua_ax_ui_TextField_setMaxLengthEnabled); - tolua_function(tolua_S,"isMaxLengthEnabled",lua_ax_ui_TextField_isMaxLengthEnabled); - tolua_function(tolua_S,"setMaxLength",lua_ax_ui_TextField_setMaxLength); - tolua_function(tolua_S,"getMaxLength",lua_ax_ui_TextField_getMaxLength); - tolua_function(tolua_S,"getStringLength",lua_ax_ui_TextField_getStringLength); - tolua_function(tolua_S,"setPasswordEnabled",lua_ax_ui_TextField_setPasswordEnabled); - tolua_function(tolua_S,"isPasswordEnabled",lua_ax_ui_TextField_isPasswordEnabled); - tolua_function(tolua_S,"setPasswordStyleText",lua_ax_ui_TextField_setPasswordStyleText); - tolua_function(tolua_S,"getPasswordStyleText",lua_ax_ui_TextField_getPasswordStyleText); - tolua_function(tolua_S,"getAttachWithIME",lua_ax_ui_TextField_getAttachWithIME); - tolua_function(tolua_S,"setAttachWithIME",lua_ax_ui_TextField_setAttachWithIME); - tolua_function(tolua_S,"getDetachWithIME",lua_ax_ui_TextField_getDetachWithIME); - tolua_function(tolua_S,"setDetachWithIME",lua_ax_ui_TextField_setDetachWithIME); - tolua_function(tolua_S,"getInsertText",lua_ax_ui_TextField_getInsertText); - tolua_function(tolua_S,"setInsertText",lua_ax_ui_TextField_setInsertText); - tolua_function(tolua_S,"getDeleteBackward",lua_ax_ui_TextField_getDeleteBackward); - tolua_function(tolua_S,"setDeleteBackward",lua_ax_ui_TextField_setDeleteBackward); - tolua_function(tolua_S,"addEventListener",lua_ax_ui_TextField_addEventListener); - tolua_function(tolua_S,"getAutoRenderSize",lua_ax_ui_TextField_getAutoRenderSize); - tolua_function(tolua_S,"attachWithIME",lua_ax_ui_TextField_attachWithIME); - tolua_function(tolua_S,"detachWithIME",lua_ax_ui_TextField_detachWithIME); - tolua_function(tolua_S,"setTextAreaSize",lua_ax_ui_TextField_setTextAreaSize); - tolua_function(tolua_S,"setTextHorizontalAlignment",lua_ax_ui_TextField_setTextHorizontalAlignment); - tolua_function(tolua_S,"getTextHorizontalAlignment",lua_ax_ui_TextField_getTextHorizontalAlignment); - tolua_function(tolua_S,"setTextVerticalAlignment",lua_ax_ui_TextField_setTextVerticalAlignment); - tolua_function(tolua_S,"getTextVerticalAlignment",lua_ax_ui_TextField_getTextVerticalAlignment); - tolua_function(tolua_S,"setCursorEnabled",lua_ax_ui_TextField_setCursorEnabled); - tolua_function(tolua_S,"setCursorChar",lua_ax_ui_TextField_setCursorChar); - tolua_function(tolua_S,"setCursorFromPoint",lua_ax_ui_TextField_setCursorFromPoint); - tolua_function(tolua_S,"createInstance", lua_ax_ui_TextField_createInstance); - tolua_function(tolua_S,"create", lua_ax_ui_TextField_create); - tolua_endmodule(tolua_S); - auto typeName = typeid(ax::ui::TextField).name(); // rtti is literal storage - g_luaType[reinterpret_cast(typeName)] = "axui.TextField"; - g_typeCast[typeName] = "axui.TextField"; - return 1; -} - -int lua_ax_ui_TextBMFont_setFntFile(lua_State* tolua_S) -{ - int argc = 0; - ax::ui::TextBMFont* obj = nullptr; - bool ok = true; - -#if _AX_DEBUG >= 1 - tolua_Error tolua_err; -#endif - - -#if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.TextBMFont",0,&tolua_err)) goto tolua_lerror; -#endif - - obj = (ax::ui::TextBMFont*)tolua_tousertype(tolua_S,1,0); - -#if _AX_DEBUG >= 1 - if (!obj) - { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextBMFont_setFntFile'", nullptr); - return 0; - } -#endif - - argc = lua_gettop(tolua_S)-1; - if (argc == 1) - { - std::string_view arg0; - - ok &= luaval_to_std_string_view(tolua_S, 2,&arg0, "axui.TextBMFont:setFntFile"); - if(!ok) - { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextBMFont_setFntFile'", nullptr); - return 0; - } - obj->setFntFile(arg0); - lua_settop(tolua_S, 1); - return 1; - } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextBMFont:setFntFile",argc, 1); - return 0; - -#if _AX_DEBUG >= 1 - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextBMFont_setFntFile'.",&tolua_err); -#endif - - return 0; -} -int lua_ax_ui_TextBMFont_setString(lua_State* tolua_S) -{ - int argc = 0; - ax::ui::TextBMFont* obj = nullptr; - bool ok = true; - -#if _AX_DEBUG >= 1 - tolua_Error tolua_err; -#endif - - -#if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.TextBMFont",0,&tolua_err)) goto tolua_lerror; -#endif - - obj = (ax::ui::TextBMFont*)tolua_tousertype(tolua_S,1,0); - -#if _AX_DEBUG >= 1 - if (!obj) - { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextBMFont_setString'", nullptr); - return 0; - } -#endif - - argc = lua_gettop(tolua_S)-1; - if (argc == 1) - { - std::string_view arg0; - - ok &= luaval_to_std_string_view(tolua_S, 2,&arg0, "axui.TextBMFont:setString"); - if(!ok) - { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextBMFont_setString'", nullptr); - return 0; - } - obj->setString(arg0); - lua_settop(tolua_S, 1); - return 1; - } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextBMFont:setString",argc, 1); - return 0; - -#if _AX_DEBUG >= 1 - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextBMFont_setString'.",&tolua_err); -#endif - - return 0; -} -int lua_ax_ui_TextBMFont_getString(lua_State* tolua_S) -{ - int argc = 0; - ax::ui::TextBMFont* obj = nullptr; - bool ok = true; - -#if _AX_DEBUG >= 1 - tolua_Error tolua_err; -#endif - - -#if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.TextBMFont",0,&tolua_err)) goto tolua_lerror; -#endif - - obj = (ax::ui::TextBMFont*)tolua_tousertype(tolua_S,1,0); - -#if _AX_DEBUG >= 1 - if (!obj) - { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextBMFont_getString'", nullptr); - return 0; - } -#endif - - argc = lua_gettop(tolua_S)-1; - if (argc == 0) - { - if(!ok) - { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextBMFont_getString'", nullptr); - return 0; - } - auto&& ret = obj->getString(); - lua_pushlstring(tolua_S,ret.data(),ret.length()); - return 1; - } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextBMFont:getString",argc, 0); - return 0; - -#if _AX_DEBUG >= 1 - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextBMFont_getString'.",&tolua_err); -#endif - - return 0; -} -int lua_ax_ui_TextBMFont_getStringLength(lua_State* tolua_S) -{ - int argc = 0; - ax::ui::TextBMFont* obj = nullptr; - bool ok = true; - -#if _AX_DEBUG >= 1 - tolua_Error tolua_err; -#endif - - -#if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.TextBMFont",0,&tolua_err)) goto tolua_lerror; -#endif - - obj = (ax::ui::TextBMFont*)tolua_tousertype(tolua_S,1,0); - -#if _AX_DEBUG >= 1 - if (!obj) - { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextBMFont_getStringLength'", nullptr); - return 0; - } -#endif - - argc = lua_gettop(tolua_S)-1; - if (argc == 0) - { - if(!ok) - { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextBMFont_getStringLength'", nullptr); - return 0; - } - auto&& ret = obj->getStringLength(); - tolua_pushnumber(tolua_S,(lua_Number)ret); - return 1; - } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextBMFont:getStringLength",argc, 0); - return 0; - -#if _AX_DEBUG >= 1 - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextBMFont_getStringLength'.",&tolua_err); -#endif - - return 0; -} -int lua_ax_ui_TextBMFont_getRenderFile(lua_State* tolua_S) -{ - int argc = 0; - ax::ui::TextBMFont* obj = nullptr; - bool ok = true; - -#if _AX_DEBUG >= 1 - tolua_Error tolua_err; -#endif - - -#if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.TextBMFont",0,&tolua_err)) goto tolua_lerror; -#endif - - obj = (ax::ui::TextBMFont*)tolua_tousertype(tolua_S,1,0); - -#if _AX_DEBUG >= 1 - if (!obj) - { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextBMFont_getRenderFile'", nullptr); - return 0; - } -#endif - - argc = lua_gettop(tolua_S)-1; - if (argc == 0) - { - if(!ok) - { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextBMFont_getRenderFile'", nullptr); - return 0; - } - auto&& ret = obj->getRenderFile(); - resourceData_to_luaval(tolua_S, ret); - return 1; - } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextBMFont:getRenderFile",argc, 0); - return 0; - -#if _AX_DEBUG >= 1 - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextBMFont_getRenderFile'.",&tolua_err); -#endif - - return 0; -} -int lua_ax_ui_TextBMFont_resetRender(lua_State* tolua_S) -{ - int argc = 0; - ax::ui::TextBMFont* obj = nullptr; - bool ok = true; - -#if _AX_DEBUG >= 1 - tolua_Error tolua_err; -#endif - - -#if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.TextBMFont",0,&tolua_err)) goto tolua_lerror; -#endif - - obj = (ax::ui::TextBMFont*)tolua_tousertype(tolua_S,1,0); - -#if _AX_DEBUG >= 1 - if (!obj) - { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextBMFont_resetRender'", nullptr); - return 0; - } -#endif - - argc = lua_gettop(tolua_S)-1; - if (argc == 0) - { - if(!ok) - { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextBMFont_resetRender'", nullptr); - return 0; - } - obj->resetRender(); - lua_settop(tolua_S, 1); - return 1; - } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextBMFont:resetRender",argc, 0); - return 0; - -#if _AX_DEBUG >= 1 - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextBMFont_resetRender'.",&tolua_err); -#endif - - return 0; -} -int lua_ax_ui_TextBMFont_createInstance(lua_State* tolua_S) -{ - int argc = 0; - bool ok = true; - -#if _AX_DEBUG >= 1 - tolua_Error tolua_err; -#endif - -#if _AX_DEBUG >= 1 - if (!tolua_isusertable(tolua_S,1,"axui.TextBMFont",0,&tolua_err)) goto tolua_lerror; -#endif - - argc = lua_gettop(tolua_S) - 1; - - if (argc == 0) - { - if(!ok) - { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextBMFont_createInstance'", nullptr); - return 0; - } - auto&& ret = ax::ui::TextBMFont::createInstance(); - object_to_luaval(tolua_S, "ax.Object",(ax::Object*)ret); - return 1; - } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d\n ", "axui.TextBMFont:createInstance",argc, 0); - return 0; -#if _AX_DEBUG >= 1 - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextBMFont_createInstance'.",&tolua_err); -#endif - return 0; -} -int lua_ax_ui_TextBMFont_create(lua_State* tolua_S) -{ - int argc = 0; - bool ok = true; -#if _AX_DEBUG >= 1 - tolua_Error tolua_err; -#endif - -#if _AX_DEBUG >= 1 - if (!tolua_isusertable(tolua_S,1,"axui.TextBMFont",0,&tolua_err)) goto tolua_lerror; -#endif - - argc = lua_gettop(tolua_S)-1; - - do { - if (argc == 2) - { - std::string_view arg0; - ok &= luaval_to_std_string_view(tolua_S, 2,&arg0, "axui.TextBMFont:create"); - if (!ok) { break; } - std::string_view arg1; - ok &= luaval_to_std_string_view(tolua_S, 3,&arg1, "axui.TextBMFont:create"); - if (!ok) { break; } - ax::ui::TextBMFont* ret = ax::ui::TextBMFont::create(arg0, arg1); - object_to_luaval(tolua_S, "axui.TextBMFont",(ax::ui::TextBMFont*)ret); - return 1; - } - } while (0); - ok = true; - do { - if (argc == 0) - { - ax::ui::TextBMFont* ret = ax::ui::TextBMFont::create(); - object_to_luaval(tolua_S, "axui.TextBMFont",(ax::ui::TextBMFont*)ret); - return 1; - } - } while (0); - ok = true; - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d", "axui.TextBMFont:create",argc, 0); - return 0; -#if _AX_DEBUG >= 1 - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextBMFont_create'.",&tolua_err); -#endif - return 0; -} -int lua_ax_ui_TextBMFont_constructor(lua_State* tolua_S) -{ - int argc = 0; - ax::ui::TextBMFont* obj = nullptr; - bool ok = true; - -#if _AX_DEBUG >= 1 - tolua_Error tolua_err; -#endif - - - - argc = lua_gettop(tolua_S)-1; - if (argc == 0) - { - if(!ok) - { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextBMFont_constructor'", nullptr); - return 0; - } - obj = new ax::ui::TextBMFont(); - obj->autorelease(); - int ID = (int)obj->_ID ; - int* luaID = &obj->_luaID ; - toluafix_pushusertype_object(tolua_S, ID, luaID, (void*)obj,"axui.TextBMFont"); - return 1; - } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextBMFont:TextBMFont",argc, 0); - return 0; - -#if _AX_DEBUG >= 1 - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextBMFont_constructor'.",&tolua_err); -#endif - - return 0; -} - -static int lua_ax_ui_TextBMFont_finalize(lua_State* tolua_S) -{ - AXLOGV("luabindings: finalizing LUA object (TextBMFont)"); - return 0; -} - -int lua_register_ax_ui_TextBMFont(lua_State* tolua_S) -{ - tolua_usertype(tolua_S,"axui.TextBMFont"); - tolua_cclass(tolua_S,"TextBMFont","axui.TextBMFont","axui.Widget",nullptr); - - tolua_beginmodule(tolua_S,"TextBMFont"); - tolua_function(tolua_S,"new",lua_ax_ui_TextBMFont_constructor); - tolua_function(tolua_S,"setFntFile",lua_ax_ui_TextBMFont_setFntFile); - tolua_function(tolua_S,"setString",lua_ax_ui_TextBMFont_setString); - tolua_function(tolua_S,"getString",lua_ax_ui_TextBMFont_getString); - tolua_function(tolua_S,"getStringLength",lua_ax_ui_TextBMFont_getStringLength); - tolua_function(tolua_S,"getRenderFile",lua_ax_ui_TextBMFont_getRenderFile); - tolua_function(tolua_S,"resetRender",lua_ax_ui_TextBMFont_resetRender); - tolua_function(tolua_S,"createInstance", lua_ax_ui_TextBMFont_createInstance); - tolua_function(tolua_S,"create", lua_ax_ui_TextBMFont_create); - tolua_endmodule(tolua_S); - auto typeName = typeid(ax::ui::TextBMFont).name(); // rtti is literal storage - g_luaType[reinterpret_cast(typeName)] = "axui.TextBMFont"; - g_typeCast[typeName] = "axui.TextBMFont"; - return 1; -} - -int lua_ax_ui_PageView_addPage(lua_State* tolua_S) -{ - int argc = 0; - ax::ui::PageView* obj = nullptr; - bool ok = true; - -#if _AX_DEBUG >= 1 - tolua_Error tolua_err; -#endif - - -#if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.PageView",0,&tolua_err)) goto tolua_lerror; -#endif - - obj = (ax::ui::PageView*)tolua_tousertype(tolua_S,1,0); - -#if _AX_DEBUG >= 1 - if (!obj) - { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_PageView_addPage'", nullptr); - return 0; - } -#endif - - argc = lua_gettop(tolua_S)-1; - if (argc == 1) - { - ax::ui::Widget* arg0; - - ok &= luaval_to_object(tolua_S, 2, "axui.Widget",&arg0, "axui.PageView:addPage"); - if(!ok) - { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_PageView_addPage'", nullptr); - return 0; - } - obj->addPage(arg0); - lua_settop(tolua_S, 1); - return 1; - } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.PageView:addPage",argc, 1); - return 0; - -#if _AX_DEBUG >= 1 - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_PageView_addPage'.",&tolua_err); -#endif - - return 0; -} -int lua_ax_ui_PageView_insertPage(lua_State* tolua_S) -{ - int argc = 0; - ax::ui::PageView* obj = nullptr; - bool ok = true; - -#if _AX_DEBUG >= 1 - tolua_Error tolua_err; -#endif - - -#if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.PageView",0,&tolua_err)) goto tolua_lerror; -#endif - - obj = (ax::ui::PageView*)tolua_tousertype(tolua_S,1,0); - -#if _AX_DEBUG >= 1 - if (!obj) - { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_PageView_insertPage'", nullptr); - return 0; - } -#endif - - argc = lua_gettop(tolua_S)-1; - if (argc == 2) - { - ax::ui::Widget* arg0; - int arg1; - - ok &= luaval_to_object(tolua_S, 2, "axui.Widget",&arg0, "axui.PageView:insertPage"); - - ok &= luaval_to_int(tolua_S, 3, &arg1, "axui.PageView:insertPage"); - if(!ok) - { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_PageView_insertPage'", nullptr); - return 0; - } - obj->insertPage(arg0, arg1); - lua_settop(tolua_S, 1); - return 1; - } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.PageView:insertPage",argc, 2); - return 0; - -#if _AX_DEBUG >= 1 - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_PageView_insertPage'.",&tolua_err); -#endif - - return 0; -} -int lua_ax_ui_PageView_removePage(lua_State* tolua_S) -{ - int argc = 0; - ax::ui::PageView* obj = nullptr; - bool ok = true; - -#if _AX_DEBUG >= 1 - tolua_Error tolua_err; -#endif - - -#if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.PageView",0,&tolua_err)) goto tolua_lerror; -#endif - - obj = (ax::ui::PageView*)tolua_tousertype(tolua_S,1,0); - -#if _AX_DEBUG >= 1 - if (!obj) - { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_PageView_removePage'", nullptr); - return 0; - } -#endif - - argc = lua_gettop(tolua_S)-1; - if (argc == 1) - { - ax::ui::Widget* arg0; - - ok &= luaval_to_object(tolua_S, 2, "axui.Widget",&arg0, "axui.PageView:removePage"); - if(!ok) - { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_PageView_removePage'", nullptr); - return 0; - } - obj->removePage(arg0); - lua_settop(tolua_S, 1); - return 1; - } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.PageView:removePage",argc, 1); - return 0; - -#if _AX_DEBUG >= 1 - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_PageView_removePage'.",&tolua_err); -#endif - - return 0; -} -int lua_ax_ui_PageView_removePageAtIndex(lua_State* tolua_S) -{ - int argc = 0; - ax::ui::PageView* obj = nullptr; - bool ok = true; - -#if _AX_DEBUG >= 1 - tolua_Error tolua_err; -#endif - - -#if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.PageView",0,&tolua_err)) goto tolua_lerror; -#endif - - obj = (ax::ui::PageView*)tolua_tousertype(tolua_S,1,0); - -#if _AX_DEBUG >= 1 - if (!obj) - { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_PageView_removePageAtIndex'", nullptr); - return 0; - } -#endif - - argc = lua_gettop(tolua_S)-1; - if (argc == 1) - { - ssize_t arg0; - - ok &= luaval_to_ssize_t(tolua_S, 2, &arg0, "axui.PageView:removePageAtIndex"); - if(!ok) - { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_PageView_removePageAtIndex'", nullptr); - return 0; - } - obj->removePageAtIndex(arg0); - lua_settop(tolua_S, 1); - return 1; - } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.PageView:removePageAtIndex",argc, 1); - return 0; - -#if _AX_DEBUG >= 1 - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_PageView_removePageAtIndex'.",&tolua_err); -#endif - - return 0; -} -int lua_ax_ui_PageView_removeAllPages(lua_State* tolua_S) -{ - int argc = 0; - ax::ui::PageView* obj = nullptr; - bool ok = true; - -#if _AX_DEBUG >= 1 - tolua_Error tolua_err; -#endif - - -#if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.PageView",0,&tolua_err)) goto tolua_lerror; -#endif - - obj = (ax::ui::PageView*)tolua_tousertype(tolua_S,1,0); - -#if _AX_DEBUG >= 1 - if (!obj) - { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_PageView_removeAllPages'", nullptr); - return 0; - } -#endif - - argc = lua_gettop(tolua_S)-1; - if (argc == 0) - { - if(!ok) - { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_PageView_removeAllPages'", nullptr); - return 0; - } - obj->removeAllPages(); - lua_settop(tolua_S, 1); - return 1; - } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.PageView:removeAllPages",argc, 0); - return 0; - -#if _AX_DEBUG >= 1 - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_PageView_removeAllPages'.",&tolua_err); -#endif - - return 0; -} -int lua_ax_ui_PageView_scrollToPage(lua_State* tolua_S) -{ - int argc = 0; - ax::ui::PageView* obj = nullptr; - bool ok = true; -#if _AX_DEBUG >= 1 - tolua_Error tolua_err; -#endif - -#if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.PageView",0,&tolua_err)) goto tolua_lerror; -#endif - obj = (ax::ui::PageView*)tolua_tousertype(tolua_S,1,0); -#if _AX_DEBUG >= 1 - if (!obj) - { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_PageView_scrollToPage'", nullptr); - return 0; - } -#endif - argc = lua_gettop(tolua_S)-1; - do { - if (argc == 2) { - ssize_t arg0; - ok &= luaval_to_ssize_t(tolua_S, 2, &arg0, "axui.PageView:scrollToPage"); - - if (!ok) { break; } - double arg1; - ok &= luaval_to_number(tolua_S, 3, &arg1, "axui.PageView:scrollToPage"); - - if (!ok) { break; } - obj->scrollToPage(arg0, arg1); - lua_settop(tolua_S, 1); - return 1; - } - }while(0); - ok = true; - do { - if (argc == 1) { - ssize_t arg0; - ok &= luaval_to_ssize_t(tolua_S, 2, &arg0, "axui.PageView:scrollToPage"); - - if (!ok) { break; } - obj->scrollToPage(arg0); - lua_settop(tolua_S, 1); - return 1; - } - }while(0); - ok = true; - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.PageView:scrollToPage",argc, 1); - return 0; - -#if _AX_DEBUG >= 1 - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_PageView_scrollToPage'.",&tolua_err); -#endif - - return 0; -} -int lua_ax_ui_PageView_scrollToItem(lua_State* tolua_S) -{ - int argc = 0; - ax::ui::PageView* obj = nullptr; - bool ok = true; -#if _AX_DEBUG >= 1 - tolua_Error tolua_err; -#endif - -#if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.PageView",0,&tolua_err)) goto tolua_lerror; -#endif - obj = (ax::ui::PageView*)tolua_tousertype(tolua_S,1,0); -#if _AX_DEBUG >= 1 - if (!obj) - { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_PageView_scrollToItem'", nullptr); - return 0; - } -#endif - argc = lua_gettop(tolua_S)-1; - do { - if (argc == 2) { - ssize_t arg0; - ok &= luaval_to_ssize_t(tolua_S, 2, &arg0, "axui.PageView:scrollToItem"); - - if (!ok) { break; } - double arg1; - ok &= luaval_to_number(tolua_S, 3, &arg1, "axui.PageView:scrollToItem"); - - if (!ok) { break; } - obj->scrollToItem(arg0, arg1); - lua_settop(tolua_S, 1); - return 1; - } - }while(0); - ok = true; - do { - if (argc == 1) { - ssize_t arg0; - ok &= luaval_to_ssize_t(tolua_S, 2, &arg0, "axui.PageView:scrollToItem"); - - if (!ok) { break; } - obj->scrollToItem(arg0); - lua_settop(tolua_S, 1); - return 1; - } - }while(0); - ok = true; - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.PageView:scrollToItem",argc, 1); - return 0; - -#if _AX_DEBUG >= 1 - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_PageView_scrollToItem'.",&tolua_err); -#endif - - return 0; -} -int lua_ax_ui_PageView_getCurrentPageIndex(lua_State* tolua_S) -{ - int argc = 0; - ax::ui::PageView* obj = nullptr; - bool ok = true; - -#if _AX_DEBUG >= 1 - tolua_Error tolua_err; -#endif - - -#if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.PageView",0,&tolua_err)) goto tolua_lerror; -#endif - - obj = (ax::ui::PageView*)tolua_tousertype(tolua_S,1,0); - -#if _AX_DEBUG >= 1 - if (!obj) - { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_PageView_getCurrentPageIndex'", nullptr); - return 0; - } -#endif - - argc = lua_gettop(tolua_S)-1; - if (argc == 0) - { - if(!ok) - { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_PageView_getCurrentPageIndex'", nullptr); - return 0; - } - auto&& ret = obj->getCurrentPageIndex(); - tolua_pushnumber(tolua_S,(lua_Number)ret); - return 1; - } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.PageView:getCurrentPageIndex",argc, 0); - return 0; - -#if _AX_DEBUG >= 1 - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_PageView_getCurrentPageIndex'.",&tolua_err); -#endif - - return 0; -} -int lua_ax_ui_PageView_setCurrentPageIndex(lua_State* tolua_S) -{ - int argc = 0; - ax::ui::PageView* obj = nullptr; - bool ok = true; - -#if _AX_DEBUG >= 1 - tolua_Error tolua_err; -#endif - - -#if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.PageView",0,&tolua_err)) goto tolua_lerror; -#endif - - obj = (ax::ui::PageView*)tolua_tousertype(tolua_S,1,0); - -#if _AX_DEBUG >= 1 - if (!obj) - { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_PageView_setCurrentPageIndex'", nullptr); - return 0; - } -#endif - - argc = lua_gettop(tolua_S)-1; - if (argc == 1) - { - ssize_t arg0; - - ok &= luaval_to_ssize_t(tolua_S, 2, &arg0, "axui.PageView:setCurrentPageIndex"); - if(!ok) - { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_PageView_setCurrentPageIndex'", nullptr); - return 0; - } - obj->setCurrentPageIndex(arg0); - lua_settop(tolua_S, 1); - return 1; - } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.PageView:setCurrentPageIndex",argc, 1); - return 0; - -#if _AX_DEBUG >= 1 - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_PageView_setCurrentPageIndex'.",&tolua_err); -#endif - - return 0; -} -int lua_ax_ui_PageView_addEventListener(lua_State* tolua_S) -{ - int argc = 0; - ax::ui::PageView* obj = nullptr; - bool ok = true; - -#if _AX_DEBUG >= 1 - tolua_Error tolua_err; -#endif - - -#if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.PageView",0,&tolua_err)) goto tolua_lerror; -#endif - - obj = (ax::ui::PageView*)tolua_tousertype(tolua_S,1,0); - -#if _AX_DEBUG >= 1 - if (!obj) - { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_PageView_addEventListener'", nullptr); - return 0; - } -#endif - - argc = lua_gettop(tolua_S)-1; - if (argc == 1) - { - std::function arg0; - - do { - // Lambda binding for lua is not supported. - assert(false); - } while(0) - ; - if(!ok) - { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_PageView_addEventListener'", nullptr); - return 0; - } - obj->addEventListener(arg0); - lua_settop(tolua_S, 1); - return 1; - } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.PageView:addEventListener",argc, 1); - return 0; - -#if _AX_DEBUG >= 1 - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_PageView_addEventListener'.",&tolua_err); -#endif - - return 0; -} -int lua_ax_ui_PageView_setIndicatorEnabled(lua_State* tolua_S) -{ - int argc = 0; - ax::ui::PageView* obj = nullptr; - bool ok = true; - -#if _AX_DEBUG >= 1 - tolua_Error tolua_err; -#endif - - -#if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.PageView",0,&tolua_err)) goto tolua_lerror; -#endif - - obj = (ax::ui::PageView*)tolua_tousertype(tolua_S,1,0); - -#if _AX_DEBUG >= 1 - if (!obj) - { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_PageView_setIndicatorEnabled'", nullptr); - return 0; - } -#endif - - argc = lua_gettop(tolua_S)-1; - if (argc == 1) - { - bool arg0; - - ok &= luaval_to_boolean(tolua_S, 2, &arg0, "axui.PageView:setIndicatorEnabled"); - if(!ok) - { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_PageView_setIndicatorEnabled'", nullptr); - return 0; - } - obj->setIndicatorEnabled(arg0); - lua_settop(tolua_S, 1); - return 1; - } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.PageView:setIndicatorEnabled",argc, 1); - return 0; - -#if _AX_DEBUG >= 1 - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_PageView_setIndicatorEnabled'.",&tolua_err); -#endif - - return 0; -} -int lua_ax_ui_PageView_getIndicatorEnabled(lua_State* tolua_S) -{ - int argc = 0; - ax::ui::PageView* obj = nullptr; - bool ok = true; - -#if _AX_DEBUG >= 1 - tolua_Error tolua_err; -#endif - - -#if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.PageView",0,&tolua_err)) goto tolua_lerror; -#endif - - obj = (ax::ui::PageView*)tolua_tousertype(tolua_S,1,0); - -#if _AX_DEBUG >= 1 - if (!obj) - { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_PageView_getIndicatorEnabled'", nullptr); - return 0; - } -#endif - - argc = lua_gettop(tolua_S)-1; - if (argc == 0) - { - if(!ok) - { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_PageView_getIndicatorEnabled'", nullptr); + tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_PageView_getIndicatorEnabled'", nullptr); return 0; } auto&& ret = obj->getIndicatorEnabled(); @@ -32629,103 +30152,6 @@ int lua_ax_ui_Scale9Sprite_getOriginalSize(lua_State* tolua_S) return 0; } -int lua_ax_ui_Scale9Sprite_setPreferredSize(lua_State* tolua_S) -{ - int argc = 0; - ax::ui::Scale9Sprite* obj = nullptr; - bool ok = true; - -#if _AX_DEBUG >= 1 - tolua_Error tolua_err; -#endif - - -#if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.Scale9Sprite",0,&tolua_err)) goto tolua_lerror; -#endif - - obj = (ax::ui::Scale9Sprite*)tolua_tousertype(tolua_S,1,0); - -#if _AX_DEBUG >= 1 - if (!obj) - { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_Scale9Sprite_setPreferredSize'", nullptr); - return 0; - } -#endif - - argc = lua_gettop(tolua_S)-1; - if (argc == 1) - { - ax::Vec2 arg0; - - ok &= luaval_to_vec2(tolua_S, 2, &arg0, "axui.Scale9Sprite:setPreferredSize"); - if(!ok) - { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_Scale9Sprite_setPreferredSize'", nullptr); - return 0; - } - obj->setPreferredSize(arg0); - lua_settop(tolua_S, 1); - return 1; - } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.Scale9Sprite:setPreferredSize",argc, 1); - return 0; - -#if _AX_DEBUG >= 1 - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_Scale9Sprite_setPreferredSize'.",&tolua_err); -#endif - - return 0; -} -int lua_ax_ui_Scale9Sprite_getPreferredSize(lua_State* tolua_S) -{ - int argc = 0; - ax::ui::Scale9Sprite* obj = nullptr; - bool ok = true; - -#if _AX_DEBUG >= 1 - tolua_Error tolua_err; -#endif - - -#if _AX_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"axui.Scale9Sprite",0,&tolua_err)) goto tolua_lerror; -#endif - - obj = (ax::ui::Scale9Sprite*)tolua_tousertype(tolua_S,1,0); - -#if _AX_DEBUG >= 1 - if (!obj) - { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_Scale9Sprite_getPreferredSize'", nullptr); - return 0; - } -#endif - - argc = lua_gettop(tolua_S)-1; - if (argc == 0) - { - if(!ok) - { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_Scale9Sprite_getPreferredSize'", nullptr); - return 0; - } - auto&& ret = obj->getPreferredSize(); - vec2_to_luaval(tolua_S, ret); - return 1; - } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.Scale9Sprite:getPreferredSize",argc, 0); - return 0; - -#if _AX_DEBUG >= 1 - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_Scale9Sprite_getPreferredSize'.",&tolua_err); -#endif - - return 0; -} int lua_ax_ui_Scale9Sprite_setInsetLeft(lua_State* tolua_S) { int argc = 0; @@ -32776,13 +30202,6 @@ int lua_ax_ui_Scale9Sprite_setInsetLeft(lua_State* tolua_S) return 0; } -int lua_ax_ui_Scale9Sprite_setInsetLeft(lua_State* tolua_S) -{ - int argc = 0; - ax::ui::Scale9Sprite* obj = nullptr; - bool ok = true; -} - int lua_ax_ui_Scale9Sprite_getInsetLeft(lua_State* tolua_S) { int argc = 0; @@ -32830,32 +30249,6 @@ int lua_ax_ui_Scale9Sprite_getInsetLeft(lua_State* tolua_S) return 0; } -int lua_ax_ui_Scale9Sprite_setInsetLeft(lua_State* tolua_S) -{ - int argc = 0; - ax::ui::Scale9Sprite* obj = nullptr; - bool ok = true; - -#if _AX_DEBUG >= 1 -#endif - - argc = lua_gettop(tolua_S)-1; - - if (argc == 1) - { - double arg0; - ok &= luaval_to_number(tolua_S, 2,&arg0, "ax::ui::Scale9Sprite:setInsetLeft"); - if(!ok) - { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_Scale9Sprite_setInsetLeft'", nullptr); - return 0; - } - obj->setInsetLeft(arg0); - return 0; - } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d\n ", "ax::ui::Scale9Sprite:setInsetLeft",argc, 1); - return 0; -} int lua_ax_ui_Scale9Sprite_setInsetTop(lua_State* tolua_S) { int argc = 0; @@ -33839,16 +31232,6 @@ int lua_register_ax_ui_Scale9Sprite(lua_State* tolua_S) tolua_function(tolua_S,"getInsetRight",lua_ax_ui_Scale9Sprite_getInsetRight); tolua_function(tolua_S,"setInsetBottom",lua_ax_ui_Scale9Sprite_setInsetBottom); tolua_function(tolua_S,"getInsetBottom",lua_ax_ui_Scale9Sprite_getInsetBottom); - tolua_function(tolua_S,"setPreferredSize",lua_ax_ui_Scale9Sprite_setPreferredSize); - tolua_function(tolua_S,"getPreferredSize",lua_ax_ui_Scale9Sprite_getPreferredSize); - tolua_function(tolua_S,"setInsetLeft",lua_ax_ui_Scale9Sprite_setInsetLeft); - tolua_function(tolua_S,"getInsetLeft",lua_ax_ui_Scale9Sprite_getInsetLeft); - tolua_function(tolua_S,"setInsetTop",lua_ax_ui_Scale9Sprite_setInsetTop); - tolua_function(tolua_S,"getInsetTop",lua_ax_ui_Scale9Sprite_getInsetTop); - tolua_function(tolua_S,"setInsetRight",lua_ax_ui_Scale9Sprite_setInsetRight); - tolua_function(tolua_S,"getInsetRight",lua_ax_ui_Scale9Sprite_getInsetRight); - tolua_function(tolua_S,"setInsetBottom",lua_ax_ui_Scale9Sprite_setInsetBottom); - tolua_function(tolua_S,"getInsetBottom",lua_ax_ui_Scale9Sprite_getInsetBottom); tolua_function(tolua_S,"setScale9Enabled",lua_ax_ui_Scale9Sprite_setScale9Enabled); tolua_function(tolua_S,"isScale9Enabled",lua_ax_ui_Scale9Sprite_isScale9Enabled); tolua_function(tolua_S,"getSprite",lua_ax_ui_Scale9Sprite_getSprite); @@ -41059,7 +38442,6 @@ TOLUA_API int register_all_ax_ui(lua_State* tolua_S) lua_register_ax_ui_ScrollView(tolua_S); lua_register_ax_ui_ListView(tolua_S); lua_register_ax_ui_Slider(tolua_S); - lua_register_ax_ui_TextField(tolua_S); lua_register_ax_ui_TextBMFont(tolua_S); lua_register_ax_ui_PageView(tolua_S); lua_register_ax_ui_Helper(tolua_S); diff --git a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIVideoPlayerTest/UIVideoPlayerTest.cpp b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIVideoPlayerTest/UIVideoPlayerTest.cpp index 81356cb7727c..89e410c609a9 100644 --- a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIVideoPlayerTest/UIVideoPlayerTest.cpp +++ b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIVideoPlayerTest/UIVideoPlayerTest.cpp @@ -438,6 +438,7 @@ void SimpleVideoPlayerTest::createVideo() _videoPlayer = VideoPlayer::create(); _videoPlayer->setPosition(centerPos); _videoPlayer->setAnchorPoint(Vec2::ANCHOR_MIDDLE); + _videoPlayer->setAutoSizeEnabled(false); _videoPlayer->setContentSize(Size(widgetSize.width * 0.4f, widgetSize.height * 0.4f)); _videoPlayer->setLooping(true); _videoPlayer->setStyle(_style); From 3d383c01d60ae5c37835278de5688fe055ea3c8e Mon Sep 17 00:00:00 2001 From: halx99 Date: Wed, 20 May 2026 09:28:18 +0800 Subject: [PATCH 17/52] Fix luabindings --- .../manual/ui/axlua_ui_manual.cpp | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/extensions/scripting/lua-bindings/manual/ui/axlua_ui_manual.cpp b/extensions/scripting/lua-bindings/manual/ui/axlua_ui_manual.cpp index d9cccd295820..44456f63f6cc 100644 --- a/extensions/scripting/lua-bindings/manual/ui/axlua_ui_manual.cpp +++ b/extensions/scripting/lua-bindings/manual/ui/axlua_ui_manual.cpp @@ -465,26 +465,26 @@ static void extendSlider(lua_State* L) lua_pop(L, 1); } -static int axlua_TextField_addEventListener(lua_State* L) +static int axlua_InputField_addEventListener(lua_State* L) { if (nullptr == L) return 0; int argc = 0; - TextField* self = nullptr; + InputField* self = nullptr; #if _AX_DEBUG >= 1 tolua_Error tolua_err; - if (!tolua_isusertype(L, 1, "axui.TextField", 0, &tolua_err)) + if (!tolua_isusertype(L, 1, "axui.InputField", 0, &tolua_err)) goto tolua_lerror; #endif - self = static_cast(tolua_tousertype(L, 1, 0)); + self = static_cast(tolua_tousertype(L, 1, 0)); #if _AX_DEBUG >= 1 if (nullptr == self) { - tolua_error(L, "invalid 'self' in function 'axlua_TextField_addEventListener'\n", NULL); + tolua_error(L, "invalid 'self' in function 'axlua_InputField_addEventListener'\n", NULL); return 0; } #endif @@ -500,13 +500,13 @@ static int axlua_TextField_addEventListener(lua_State* L) LUA_FUNCTION handler = (toluafix_ref_function(L, 2, 0)); self->addEventListener( - [=](ax::Object* ref, TextField::EventType eventType) { handleUIEvent(handler, ref, (int)eventType); }); + [=](ax::Object* ref, InputField::EventType eventType) { handleUIEvent(handler, ref, (int)eventType); }); ScriptHandlerMgr::getInstance()->addCustomHandler((void*)self, handler); return 0; } - luaL_error(L, "'addEventListener' function of TextField has wrong number of arguments: %d, was expecting %d\n", + luaL_error(L, "'addEventListener' function of InputField has wrong number of arguments: %d, was expecting %d\n", argc, 1); return 0; @@ -518,13 +518,13 @@ static int axlua_TextField_addEventListener(lua_State* L) #endif } -static void extendTextField(lua_State* L) +static void extendInputField(lua_State* L) { - lua_pushstring(L, "axui.TextField"); + lua_pushstring(L, "axui.InputField"); lua_rawget(L, LUA_REGISTRYINDEX); if (lua_istable(L, -1)) { - tolua_function(L, "addEventListener", axlua_TextField_addEventListener); + tolua_function(L, "addEventListener", axlua_InputField_addEventListener); } lua_pop(L, 1); } @@ -1045,7 +1045,7 @@ int register_all_ax_ui_manual(lua_State* L) extendRadioButton(L); extendRadioButtonGroup(L); extendSlider(L); - extendTextField(L); + extendInputField(L); extendPageView(L); extendScrollView(L); extendListView(L); From 1368c5a79e68c9b2aae09e7655bc15e4ac0eb689 Mon Sep 17 00:00:00 2001 From: halx99 Date: Wed, 20 May 2026 11:22:18 +0800 Subject: [PATCH 18/52] Improve API style --- axmol/base/IMEDelegate.h | 4 +- axmol/base/IMEDispatcher.cpp | 4 +- axmol/base/IMEDispatcher.h | 4 +- axmol/platform/android/jni/AxmolPlayerJni.cpp | 5 +- axmol/platform/desktop/RenderViewImpl.cpp | 2 +- axmol/platform/ios/InputView-ios.mm | 6 +- axmol/platform/winrt/InputEvent.cpp | 6 +- axmol/ui/UIButton.cpp | 24 ++-- axmol/ui/UIButton.h | 2 +- axmol/ui/UIImageView.cpp | 8 +- axmol/ui/UIImageView.h | 2 +- axmol/ui/UIInputField.cpp | 120 ++++++++++-------- axmol/ui/UIInputField.h | 72 +++++++++-- axmol/ui/UILayout.cpp | 2 +- axmol/ui/UILoadingBar.cpp | 8 +- axmol/ui/UILoadingBar.h | 2 +- axmol/ui/UIRichText.cpp | 4 +- axmol/ui/UIRichText.h | 2 +- axmol/ui/UISlider.cpp | 8 +- axmol/ui/UISlider.h | 4 +- axmol/ui/UITabControl.cpp | 4 +- axmol/ui/UIWidget.cpp | 24 ++-- axmol/ui/UIWidget.h | 8 +- .../sceneext/src/sceneext/SGUIReader.cpp | 4 +- .../ButtonReader/ButtonReader.cpp | 2 +- .../ImageViewReader/ImageViewReader.cpp | 2 +- .../LayoutReader/LayoutReader.cpp | 2 +- .../ListViewReader/ListViewReader.cpp | 2 +- .../PageViewReader/PageViewReader.cpp | 2 +- .../ScrollViewReader/ScrollViewReader.cpp | 2 +- .../TextAtlasReader/TextAtlasReader.cpp | 2 +- .../TextBMFontReader/TextBMFontReader.cpp | 2 +- .../WidgetReader/TextReader/TextReader.cpp | 4 +- .../src/sceneio/WidgetReader/WidgetReader.cpp | 8 +- .../src/sceneio/WidgetReader/WidgetReader.h | 2 +- .../lua-bindings/auto/axlua_ui_auto.cpp | 30 ++--- tests/cpp-tests/Source/BaseTest.cpp | 2 +- .../cpp-tests/Source/LabelTest/LabelTest.cpp | 2 +- .../DownloaderTest/DownloaderTest.cpp | 2 +- .../UIButtonTest/UIButtonTest.cpp | 10 +- .../UICheckBoxTest/UICheckBoxTest.cpp | 2 +- .../UIImageViewTest/UIImageViewTest.cpp | 4 +- .../UILayoutTest/UILayoutTest.cpp | 8 +- .../UILoadingBarTest/UILoadingBarTest.cpp | 4 +- .../UIRichTextTest/UIRichTextTest.cpp | 52 ++++---- .../UISliderTest/UISliderTest.cpp | 2 +- .../UITextFieldTest/UIInputFieldTest.cpp | 2 + .../UITextTest/UITextTest.cpp | 6 +- .../UIVideoPlayerTest/UIVideoPlayerTest.cpp | 2 +- 49 files changed, 272 insertions(+), 215 deletions(-) diff --git a/axmol/base/IMEDelegate.h b/axmol/base/IMEDelegate.h index 83d1b0fde02d..da72cbcf4c59 100644 --- a/axmol/base/IMEDelegate.h +++ b/axmol/base/IMEDelegate.h @@ -108,13 +108,13 @@ class AX_DLL IMEDelegate @brief Called by IMEDispatcher when text input received from the IME. * @lua NA */ - virtual void insertText(const char* /*text*/, size_t /*len*/) {} + virtual void insertText(const char* /*text*/, unsigned int /*len*/) {} /** @brief Called by IMEDispatcher after the user clicks the backward key. * @lua NA */ - virtual void deleteBackward(size_t numChars) {} + virtual void deleteBackward(unsigned int numChars) {} /** @brief Called by IMEDispatcher after the user press control key. diff --git a/axmol/base/IMEDispatcher.cpp b/axmol/base/IMEDispatcher.cpp index 7c24cac92c7a..1cf9d941c87f 100644 --- a/axmol/base/IMEDispatcher.cpp +++ b/axmol/base/IMEDispatcher.cpp @@ -200,7 +200,7 @@ void IMEDispatcher::removeDelegate(IMEDelegate* delegate) // dispatch text message ////////////////////////////////////////////////////////////////////////// -void IMEDispatcher::dispatchInsertText(const char* text, size_t len) +void IMEDispatcher::dispatchInsertText(const char* text, unsigned int len) { do { @@ -213,7 +213,7 @@ void IMEDispatcher::dispatchInsertText(const char* text, size_t len) } while (0); } -void IMEDispatcher::dispatchDeleteBackward(int numChars) +void IMEDispatcher::dispatchDeleteBackward(unsigned int numChars) { do { diff --git a/axmol/base/IMEDispatcher.h b/axmol/base/IMEDispatcher.h index 71bb82ce9304..5c9bf948853a 100644 --- a/axmol/base/IMEDispatcher.h +++ b/axmol/base/IMEDispatcher.h @@ -56,13 +56,13 @@ class AX_DLL IMEDispatcher * @brief Dispatches the input text from IME. * @lua NA */ - void dispatchInsertText(const char* text, size_t len); + void dispatchInsertText(const char* text, unsigned int len); /** * @brief Dispatches the delete-backward operation. * @lua NA */ - void dispatchDeleteBackward(int numChars); + void dispatchDeleteBackward(unsigned int numChars); /** * @brief Dispatches the press control key operation. diff --git a/axmol/platform/android/jni/AxmolPlayerJni.cpp b/axmol/platform/android/jni/AxmolPlayerJni.cpp index e65c5cde1116..f38d3ae952e5 100644 --- a/axmol/platform/android/jni/AxmolPlayerJni.cpp +++ b/axmol/platform/android/jni/AxmolPlayerJni.cpp @@ -256,12 +256,13 @@ JNIEXPORT void JNICALL Java_dev_axmol_lib_AxmolPlayer_nativeOnResume(JNIEnv*, jc JNIEXPORT void JNICALL Java_dev_axmol_lib_AxmolPlayer_nativeInsertText(JNIEnv* env, jclass, jstring text) { std::string strValue = ax::text_utils::getStringUTFCharsJNI(env, text); - ax::IMEDispatcher::sharedDispatcher()->dispatchInsertText(strValue.c_str(), strValue.size()); + ax::IMEDispatcher::sharedDispatcher()->dispatchInsertText(strValue.c_str(), + static_cast(strValue.size())); } JNIEXPORT void JNICALL Java_dev_axmol_lib_AxmolPlayer_nativeDeleteBackward(JNIEnv*, jclass, jint numChars) { - ax::IMEDispatcher::sharedDispatcher()->dispatchDeleteBackward(numChars); + ax::IMEDispatcher::sharedDispatcher()->dispatchDeleteBackward(static_cast(numChars)); } JNIEXPORT jstring JNICALL Java_dev_axmol_lib_AxmolPlayer_nativeGetContentText(JNIEnv* env, jclass) diff --git a/axmol/platform/desktop/RenderViewImpl.cpp b/axmol/platform/desktop/RenderViewImpl.cpp index 40b0f4446811..e9c53de52521 100644 --- a/axmol/platform/desktop/RenderViewImpl.cpp +++ b/axmol/platform/desktop/RenderViewImpl.cpp @@ -1447,7 +1447,7 @@ void RenderViewImpl::onGLFWCharCallback(GLFWwindow* /*window*/, unsigned int cha // Check for send control key if (controlUnicode.find(utf8String) == controlUnicode.end()) { - IMEDispatcher::sharedDispatcher()->dispatchInsertText(utf8String.c_str(), utf8String.size()); + IMEDispatcher::sharedDispatcher()->dispatchInsertText(utf8String.c_str(), static_cast(utf8String.size())); } } diff --git a/axmol/platform/ios/InputView-ios.mm b/axmol/platform/ios/InputView-ios.mm index 3ffd437b7988..16071f24a833 100644 --- a/axmol/platform/ios/InputView-ios.mm +++ b/axmol/platform/ios/InputView-ios.mm @@ -98,7 +98,7 @@ - (void)deleteBackward [self.myMarkedText release]; self.myMarkedText = nil; } - ax::IMEDispatcher::sharedDispatcher()->dispatchDeleteBackward(1); + ax::IMEDispatcher::sharedDispatcher()->dispatchDeleteBackward(static_cast(1)); } - (void)insertText:(nonnull NSString*)text @@ -109,7 +109,7 @@ - (void)insertText:(nonnull NSString*)text self.myMarkedText = nil; } const char* pszText = [text cStringUsingEncoding:NSUTF8StringEncoding]; - ax::IMEDispatcher::sharedDispatcher()->dispatchInsertText(pszText, strlen(pszText)); + ax::IMEDispatcher::sharedDispatcher()->dispatchInsertText(pszText, static_cast(strlen(pszText))); } - (NSWritingDirection)baseWritingDirectionForPosition:(nonnull UITextPosition*)position @@ -251,7 +251,7 @@ - (void)unmarkText return; } const char* pszText = [self.myMarkedText cStringUsingEncoding:NSUTF8StringEncoding]; - ax::IMEDispatcher::sharedDispatcher()->dispatchInsertText(pszText, strlen(pszText)); + ax::IMEDispatcher::sharedDispatcher()->dispatchInsertText(pszText, static_cast(strlen(pszText))); [self.myMarkedText release]; self.myMarkedText = nil; } diff --git a/axmol/platform/winrt/InputEvent.cpp b/axmol/platform/winrt/InputEvent.cpp index ea9dd1496b42..3a6be1612c7b 100644 --- a/axmol/platform/winrt/InputEvent.cpp +++ b/axmol/platform/winrt/InputEvent.cpp @@ -88,16 +88,14 @@ void KeyboardEvent::execute() case AxmolKeyEvent::Text: { std::string utf8String = PlatformStringToString(m_text); - IMEDispatcher::sharedDispatcher()->dispatchInsertText(utf8String.c_str(), utf8String.size()); + IMEDispatcher::sharedDispatcher()->dispatchInsertText(utf8String.c_str(), + static_cast(utf8String.size())); break; } default: switch (m_type) { - case AxmolKeyEvent::Escape: - // Director::getInstance()()->getKeypadDispatcher()->dispatchKeypadMSG(kTypeBackClicked); - break; case AxmolKeyEvent::Back: IMEDispatcher::sharedDispatcher()->dispatchDeleteBackward(1); break; diff --git a/axmol/ui/UIButton.cpp b/axmol/ui/UIButton.cpp index 4c3c72be27e5..0b57583f0a93 100644 --- a/axmol/ui/UIButton.cpp +++ b/axmol/ui/UIButton.cpp @@ -218,18 +218,18 @@ void Button::setScale9Enabled(bool able) // or keep state. The original code forced disabled autoSize (ignoreContentAdaptWithSize(true) in old terms meant adapt, false meant fixed? // Wait, old ignoreContentAdaptWithSize(true) meant "ignore content size" -> use custom size? // In Cocos2d-x/UI: ignoreContentAdaptWithSize(true) usually means the widget resizes to its content. - // Let's look at original: setAutoSizeEnabled(false) was called. - // In new API: setAutoSizeEnabled(false) means "Do NOT adapt to content" -> Fixed Size. + // Let's look at original: setAutoSize(false) was called. + // In new API: setAutoSize(false) means "Do NOT adapt to content" -> Fixed Size. // Original: // bool autoSizeBefore = _autoSize; // true if adapting - // setAutoSizeEnabled(false); // Switch to fixed size + // setAutoSize(false); // Switch to fixed size // _prevIgnoreSize = !autoSizeBefore; // If autoSizeBefore was true (adapting), _prevIgnoreSize becomes false. // If autoSizeBefore was false (fixed), _prevIgnoreSize becomes true. - setAutoSizeEnabled(false); + setAutoSize(false); _prevIgnoreSize = !autoSizeBefore; } else @@ -243,25 +243,25 @@ void Button::setScale9Enabled(bool able) // Let's stick to the behavior: // Old: _prevIgnoreSize stored the value passed to ignoreContentAdaptWithSize. // ignoreContentAdaptWithSize(true) -> Adapt to content. - // New: setAutoSizeEnabled(true) -> Adapt to content. + // New: setAutoSize(true) -> Adapt to content. // So _prevIgnoreSize actually corresponds directly to autoSize now? // In constructor: _prevIgnoreSize = true. - // In setScale9Enabled else block: setAutoSizeEnabled(!_prevIgnoreSize). + // In setScale9Enabled else block: setAutoSize(!_prevIgnoreSize). // If _prevIgnoreSize is true, it sets false. This seems inverted compared to typical defaults. // Let's look at the reference code provided in prompt: // _prevIgnoreSize = !autoSize; - // If we use the reference implementation for setAutoSizeEnabled: + // If we use the reference implementation for setAutoSize: // It sets _prevIgnoreSize = !autoSize. // So in setScale9Enabled: - // else { setAutoSizeEnabled(!_prevIgnoreSize); } + // else { setAutoSize(!_prevIgnoreSize); } // If _prevIgnoreSize = !autoSize, then !_prevIgnoreSize = autoSize. // So it restores the autoSize value. This is correct. - setAutoSizeEnabled(!_prevIgnoreSize); + setAutoSize(!_prevIgnoreSize); } setCapInsetsNormalRenderer(_capInsetsNormal); @@ -281,7 +281,7 @@ bool Button::isScale9Enabled() const return _scale9Enabled; } -void Button::setAutoSizeEnabled(bool autoSize) +void Button::setAutoSize(bool autoSize) { if (_autoSize == autoSize) { @@ -292,7 +292,7 @@ void Button::setAutoSizeEnabled(bool autoSize) // For Scale9Sprite, we need special handling if (!_scale9Enabled || (_scale9Enabled && autoSize)) { - Widget::setAutoSizeEnabled(autoSize); + Widget::setAutoSize(autoSize); _prevIgnoreSize = !autoSize; // Store the inverse for backward compatibility logic if needed elsewhere } else @@ -302,7 +302,7 @@ void Button::setAutoSizeEnabled(bool autoSize) // In original code, ignoreContentAdaptWithSize(false) [which means fixed size] was blocked if scale9 enabled. // Here we strictly follow the prompt's reference logic which implies allowing it only if (!scale9 || (scale9 && autoSize)). // If we reach here, it means scale9 is enabled AND autoSize is false. - // The reference code doesn't explicitly call Widget::setAutoSizeEnabled in this branch, + // The reference code doesn't explicitly call Widget::setAutoSize in this branch, // effectively preventing disabling autoSize when scale9 is on, similar to original logic. // However, usually we should still update state or log if ignored. diff --git a/axmol/ui/UIButton.h b/axmol/ui/UIButton.h index 4ab8ef5e31ba..4f7c52a1ea07 100644 --- a/axmol/ui/UIButton.h +++ b/axmol/ui/UIButton.h @@ -190,7 +190,7 @@ class AX_GUI_DLL Button : public Widget void setPressedActionEnabled(bool enabled); // override methods - void setAutoSizeEnabled(bool autoSize) override; + void setAutoSize(bool autoSize) override; Vec2 getPreferredSize() const override; Node* getRenderNode() override; std::string getDescription() const override; diff --git a/axmol/ui/UIImageView.cpp b/axmol/ui/UIImageView.cpp index b1682f466f9c..525a06c69e15 100644 --- a/axmol/ui/UIImageView.cpp +++ b/axmol/ui/UIImageView.cpp @@ -198,12 +198,12 @@ void ImageView::setScale9Enabled(bool able) if (_scale9Enabled) { bool autoSizeBefore = _autoSize; - setAutoSizeEnabled(false); + setAutoSize(false); _prevIgnoreSize = !autoSizeBefore; } else { - setAutoSizeEnabled(!_prevIgnoreSize); + setAutoSize(!_prevIgnoreSize); } setCapInsets(_capInsets); _imageRendererAdaptDirty = true; @@ -305,13 +305,13 @@ const BlendFunc& ImageView::getBlendFunc() const return _imageRenderer->getBlendFunc(); } -void ImageView::setAutoSizeEnabled(bool autoSize) +void ImageView::setAutoSize(bool autoSize) { // Note: autoSize=true means adapt to content, autoSize=false means fixed size // For Scale9Sprite, we need special handling if (!_scale9Enabled || (_scale9Enabled && autoSize)) { - Widget::setAutoSizeEnabled(autoSize); + Widget::setAutoSize(autoSize); _prevIgnoreSize = !autoSize; // Store the inverse for backward compatibility } } diff --git a/axmol/ui/UIImageView.h b/axmol/ui/UIImageView.h index 0b5d16e259d7..58d51c1d62da 100644 --- a/axmol/ui/UIImageView.h +++ b/axmol/ui/UIImageView.h @@ -136,7 +136,7 @@ class AX_GUI_DLL ImageView : public Widget, public ax::BlendProtocol const BlendFunc& getBlendFunc() const override; // override methods. - void setAutoSizeEnabled(bool autoSize) override; + void setAutoSize(bool autoSize) override; std::string getDescription() const override; Vec2 getPreferredSize() const override; Node* getRenderNode() override; diff --git a/axmol/ui/UIInputField.cpp b/axmol/ui/UIInputField.cpp index 41289cc7c914..a3885d63f87e 100644 --- a/axmol/ui/UIInputField.cpp +++ b/axmol/ui/UIInputField.cpp @@ -484,7 +484,7 @@ bool InputField::canDetachWithIME() return true; } -void InputField::setCharLimit(size_t limit) +void InputField::setCharLimit(uint32_t limit) { _charLimit = limit; @@ -494,15 +494,15 @@ void InputField::setCharLimit(size_t limit) // consistently. if (_charLimit > 0 && _charCount > _charLimit) { - auto byteOffset = getByteOffset(static_cast(_charLimit)); + auto byteOffset = getByteOffset(static_cast(_charLimit)); std::string newText(_inputText.substr(0, byteOffset)); setString(newText); // Ensure cursor is not past the new limit - setCursorPosition(static_cast(_charLimit), false); + setCursorPosition(static_cast(_charLimit), false); } } -void InputField::insertText(const char* text, size_t len) +void InputField::insertText(const char* text, unsigned int len) { if (_readOnly || !this->_enabled) { @@ -534,7 +534,7 @@ void InputField::insertText(const char* text, size_t len) if (len > 0) { std::string sText(_inputText); - auto cursorPosition = static_cast(_cursorCharIndex); + auto cursorPosition = static_cast(_cursorCharIndex); sText.insert(_cursorByteIndex, insert); // original is: sText.append(insert); this->setString(sText); @@ -546,7 +546,7 @@ void InputField::insertText(const char* text, size_t len) assert(insert.npos == pos); } -void InputField::deleteBackward(size_t numChars) +void InputField::deleteBackward(unsigned int numChars) { if (hasSelection()) { @@ -560,17 +560,17 @@ void InputField::deleteBackward(size_t numChars) return; } - size_t len = _inputText.length(); + int len = static_cast(_inputText.length()); if (0 == len || _cursorByteIndex == 0) { axbeep(0); return; } - auto deleteChars = (std::min)(numChars, static_cast(_cursorCharIndex)); - auto startUtf8 = static_cast(_cursorCharIndex) - deleteChars; - auto startByte = getByteOffset(startUtf8); - auto totalDeleteLen = static_cast(_cursorByteIndex) - startByte; + auto deleteChars = (std::min)(static_cast(numChars), _cursorCharIndex); + auto startCharIndex = _cursorCharIndex - deleteChars; + auto startByteIndex = getByteOffset(startCharIndex); + auto totalDeleteLen = _cursorByteIndex - startByteIndex; // if all text deleted, show placeholder string if (len <= totalDeleteLen) @@ -584,10 +584,10 @@ void InputField::deleteBackward(size_t numChars) // set new input text std::string text = _inputText; - text.erase(startByte, totalDeleteLen); + text.erase(startByteIndex, totalDeleteLen); this->setString(text); - setCursorPosition(startUtf8, false); + setCursorPosition(startCharIndex, false); dispatchEvent(EventType::DELETE_BACKWARD); } @@ -606,15 +606,15 @@ void InputField::handleDeleteKeyEvent() return; } - size_t len = _inputText.length(); - if (0 == len || _cursorCharIndex == _charCount) + int len = static_cast(_inputText.length()); + if (0 == len || _cursorCharIndex == static_cast(_charCount)) { axbeep(0); return; } - auto nextByte = getByteOffset(static_cast(_cursorCharIndex) + 1); - auto deleteLen = nextByte - static_cast(_cursorByteIndex); + auto nextByteIndex = getByteOffset(_cursorCharIndex + 1); + auto deleteLen = nextByteIndex - _cursorByteIndex; // if all text deleted, show placeholder string if (len <= deleteLen) @@ -679,6 +679,22 @@ void InputField::setPlaceholderColor(const Color32& color) // properties ////////////////////////////////////////////////////////////////////////// +void InputField::setMultilineEnabled(bool enabled) +{ + if (_multilineEnabled == enabled) + return; + + _multilineEnabled = enabled; +} + +void InputField::setAutoWrap(bool enabled) { + if (_autoWrap == enabled || !_multilineEnabled) + return; + + _autoWrap = enabled; + _renderLabel->setLineBreakWithoutSpace(_autoWrap); +} + Node* InputField::getRenderNode() { return _renderLabel; @@ -694,8 +710,8 @@ void InputField::setString(std::string_view text) { _layoutDirty = true; - auto oldInsertPosUtf8 = static_cast(_cursorCharIndex); - bool bInsertAtEnd = (oldInsertPosUtf8 == _charCount); + auto oldInsertCharIndex = static_cast(_cursorCharIndex); + bool bInsertAtEnd = (oldInsertCharIndex == static_cast(_charCount)); _inputText = text; auto newCharCount = text_utils::countUTF8Chars(_inputText); @@ -730,7 +746,7 @@ void InputField::setString(std::string_view text) _renderLabel->setString(*displayText); } - _charCount = newCharCount; + _charCount = static_cast(newCharCount); if (bInsertAtEnd) { @@ -738,12 +754,12 @@ void InputField::setString(std::string_view text) } else { - setCursorPosition((std::min)(oldInsertPosUtf8, static_cast(_charCount)), + setCursorPosition((std::min)(oldInsertCharIndex, static_cast(_charCount)), hasSelection()); } - _selectionStart = (std::min)(_selectionStart, static_cast(_charCount)); - _selectionEnd = (std::min)(_selectionEnd, static_cast(_charCount)); + _selectionStart = (std::min)(_selectionStart, static_cast(_charCount)); + _selectionEnd = (std::min)(_selectionEnd, static_cast(_charCount)); updateSelectionLayer(); // Invalidate cached prefix widths when text changes @@ -883,8 +899,8 @@ void InputField::selectAll() void InputField::clearSelection() { - _selectionStart = _selectionEnd = static_cast(_cursorCharIndex); - _selectionAnchor = static_cast(_cursorCharIndex); + _selectionStart = _selectionEnd = _cursorCharIndex; + _selectionAnchor = _cursorCharIndex; updateSelectionLayer(); } @@ -979,7 +995,7 @@ void InputField::hideCursor(void) void InputField::updateCursorPosition(void) { - setCursorPosition(static_cast(_cursorCharIndex), hasSelection()); + setCursorPosition(_cursorCharIndex, hasSelection()); } void InputField::moveCursor(int direction) @@ -991,7 +1007,7 @@ void InputField::moveCursor(int direction, bool keepSelection) { auto cursorPosition = static_cast(_cursorCharIndex) + direction; cursorPosition = std::clamp(cursorPosition, 0, static_cast(_charCount)); - setCursorPosition(static_cast(cursorPosition), keepSelection); + setCursorPosition(cursorPosition, keepSelection); } void InputField::moveCursorTo(float x) @@ -1004,9 +1020,9 @@ void InputField::moveCursorTo(float x, bool keepSelection) setCursorPosition(positionFromCursorX(x), keepSelection); } -void InputField::setCursorPosition(std::size_t cursorPosition, bool keepSelection) +void InputField::setCursorPosition(int cursorPosition, bool keepSelection) { - cursorPosition = (std::min)(cursorPosition, static_cast(_charCount)); + cursorPosition = (std::min)(cursorPosition, static_cast(_charCount)); if (keepSelection) { @@ -1019,28 +1035,28 @@ void InputField::setCursorPosition(std::size_t cursorPosition, bool keepSelectio _selectionEnd = cursorPosition; } - _cursorCharIndex = static_cast(cursorPosition); - _cursorByteIndex = static_cast(getByteOffset(cursorPosition)); + _cursorCharIndex = cursorPosition; + _cursorByteIndex = getByteOffset(cursorPosition); if (_cursor) - _cursor->setPosition(Point(cursorXFromPosition(cursorPosition), this->getContentSize().height / 2)); + _cursor->setPosition(Vec2(cursorXFromPosition(cursorPosition), this->getContentSize().height / 2)); updateSelectionLayer(); } -std::size_t InputField::getByteOffset(std::size_t cursorPosition) const +int InputField::getByteOffset(int cursorPosition) const { if (cursorPosition >= _charCount) return _inputText.length(); auto byteOffset = text_utils::getUTF8ByteOffset(_inputText, cursorPosition); - return byteOffset == std::string::npos ? _inputText.length() : byteOffset; + return byteOffset == std::string::npos ? static_cast(_inputText.length()) : static_cast(byteOffset); } -void InputField::setSelection(std::size_t start, std::size_t end) +void InputField::setSelection(int start, int end) { - _selectionStart = static_cast((std::min)(start, static_cast(_charCount))); - _selectionEnd = static_cast((std::min)(end, static_cast(_charCount))); + _selectionStart = (std::min)(start, static_cast(_charCount)); + _selectionEnd = (std::min)(end, static_cast(_charCount)); if (_selectionStart > _selectionEnd) std::swap(_selectionStart, _selectionEnd); updateSelectionLayer(); @@ -1167,10 +1183,10 @@ TextVAlignment InputField::getTextVerticalAlignment() const bool InputField::onTouchBegan(Touch* touch, Event* event) { // Call parent class to handle basic touch logic (hit test, highlight, etc.) - bool pass = Widget::onTouchBegan(touch, event); + auto hitted = Widget::onTouchBegan(touch, event); // If clicked outside the input field, detach IME (like axmol3 UITextField does) - if (!_hitted) + if (!hitted) { detachWithIME(); return false; @@ -1263,9 +1279,9 @@ void InputField::onTouchCancelled(Touch* touch, Event* event) _selectingByTouch = false; } -float InputField::cursorXFromPosition(std::size_t cursorPosition) const +float InputField::cursorXFromPosition(int cursorPosition) const { - cursorPosition = (std::min)(cursorPosition, static_cast(_charCount)); + cursorPosition = (std::min)(cursorPosition, static_cast(_charCount)); // Calculate the offset from InputField origin to text start position float textStartOffset = 0.0f; @@ -1308,7 +1324,7 @@ float InputField::cursorXFromPosition(std::size_t cursorPosition) const return textStartOffset + textWidth; } -std::size_t InputField::positionFromCursorX(float x) const +int InputField::positionFromCursorX(float x) const { if (x <= 0 || _charCount == 0) return 0; @@ -1351,24 +1367,24 @@ std::size_t InputField::positionFromCursorX(float x) const // Binary search using cached prefix widths. We choose the smallest index i // such that adjustedX < midpoint(prefix[i], prefix[i+1]). Returns i. - std::size_t low = 0; - std::size_t high = _charCount; + uint32_t low = 0; + uint32_t high = _charCount; while (low < high) { - std::size_t mid = (low + high) / 2; - float leftX = getPrefixWidth(mid); - float rightX = getPrefixWidth(mid + 1); - float midPoint = (leftX + rightX) * 0.5f; + uint32_t mid = (low + high) / 2; + float leftX = getPrefixWidth(mid); + float rightX = getPrefixWidth(mid + 1); + float midPoint = (leftX + rightX) * 0.5f; if (adjustedX < midPoint) high = mid; else low = mid + 1; } - return low; + return static_cast(low); } -float InputField::getPrefixWidth(std::size_t charIndex) const +float InputField::getPrefixWidth(int charIndex) const { if (charIndex == 0) return 0.0f; @@ -1399,12 +1415,12 @@ void InputField::invalidatePrefixWidths() const _prefixWidths[0] = 0.0f; if (_passwordEnabled) { - for (std::size_t i = 1; i <= _charCount; ++i) + for (uint32_t i = 1; i <= _charCount; ++i) _prefixWidths[i] = static_cast(i) * _passwordCharWidth; } else { - for (std::size_t i = 1; i <= _charCount; ++i) + for (uint32_t i = 1; i <= _charCount; ++i) { auto byteOffset = text_utils::getUTF8ByteOffset(_inputText, i); if (byteOffset == std::string::npos) diff --git a/axmol/ui/UIInputField.h b/axmol/ui/UIInputField.h index 9ad5cec19692..dc4efa5f3298 100644 --- a/axmol/ui/UIInputField.h +++ b/axmol/ui/UIInputField.h @@ -351,13 +351,13 @@ class AX_DLL InputField : public Widget, public IMEDelegate * * @param limit Maximum characters allowed (0 = unlimited). */ - void setCharLimit(size_t limit); + void setCharLimit(uint32_t limit); /** * @brief Get the configured character limit. * @return The maximum number of characters allowed (0 means unlimited). */ - size_t getCharLimit() const { return _charLimit; } + uint32_t getCharLimit() const { return _charLimit; } /** * @brief Get the internal renderer node. @@ -371,7 +371,50 @@ class AX_DLL InputField : public Widget, public IMEDelegate */ Vec2 getPreferredSize() const override; -public: + /** + * @brief Enable or disable multiline text rendering. + * + * When enabled, the label will allow line breaks even without spaces, + * effectively supporting multiline display. When disabled, the label + * will restrict text to a single line. + * + * @param enabled True to enable multiline rendering, false to disable. + */ + void setMultilineEnabled(bool enabled); + + /** + * @brief Check whether multiline text rendering is enabled. + * + * @return True if multiline rendering is enabled, false otherwise. + */ + bool isMultilineEnabled() const { return _multilineEnabled; } + + /** + * @brief Enable or disable automatic line wrapping. + * + * When enabled, the label will automatically wrap text to the next line + * once it exceeds the defined dimensions. Wrapping is performed at the + * character level. + * + * @param enabled True to enable automatic wrapping, false to keep text on a single line. + */ + void setAutoWrap(bool enabled); + + /** + * @brief Check whether automatic line wrapping is enabled. + * + * When enabled, the label will automatically wrap text to the next line + * once it exceeds the defined dimensions. Wrapping is performed at the + * character level, meaning line breaks can occur even without spaces. + * + * @return True if automatic wrapping is enabled, false otherwise. + * + * @note This setting only takes effect when multiline mode is enabled + * (see setMultilineEnabled). If multiline is disabled, auto wrap + * will be ignored and text will remain on a single line. + */ + bool isAutoWrap() const { return _autoWrap; } + /** * @brief InputField event types - follows TextField's design for consistency. */ @@ -415,9 +458,6 @@ class AX_DLL InputField : public Widget, public IMEDelegate */ void addEventListener(const InputFieldCallback& callback); - // IMEDelegate interface - void insertText(const char* text, size_t len) override; - protected: ////////////////////////////////////////////////////////////////////////// @@ -427,7 +467,10 @@ class AX_DLL InputField : public Widget, public IMEDelegate bool canAttachWithIME() override; bool canDetachWithIME() override; - void deleteBackward(size_t numChars) override; + // IMEDelegate interface + void insertText(const char* text, unsigned int len) override; + void deleteBackward(unsigned int numChars) override; + std::string_view getContentText() const override; void handleDeleteKeyEvent(); @@ -456,25 +499,25 @@ class AX_DLL InputField : public Widget, public IMEDelegate void moveCursorTo(float x); void moveCursorTo(float x, bool keepSelection); - void setCursorPosition(std::size_t cursorPosition, bool keepSelection); + void setCursorPosition(int cursorPosition, bool keepSelection); /** * @brief Calculate the X coordinate for a given cursor position. * @param cursorPosition UTF-8 character index (0 = before first char) * @return X coordinate in local node space, accounting for text alignment */ - float cursorXFromPosition(std::size_t cursorPosition) const; + float cursorXFromPosition(int cursorPosition) const; /** * @brief Find the cursor position at a given X coordinate. * @param x X coordinate in local node space * @return UTF-8 character index (inverse of cursorXFromPosition) */ - std::size_t positionFromCursorX(float x) const; + int positionFromCursorX(float x) const; - std::size_t getByteOffset(std::size_t cursorPosition) const; + int getByteOffset(int cursorPosition) const; - void setSelection(std::size_t start, std::size_t end); + void setSelection(int start, int end); void updateSelectionLayer(void); bool deleteSelection(bool notify); @@ -512,7 +555,7 @@ class AX_DLL InputField : public Widget, public IMEDelegate // Get measured width of first `charIndex` characters (0.._charCount). Populates // cache entries on demand. - float getPrefixWidth(std::size_t charIndex) const; + float getPrefixWidth(int charIndex) const; std::string _fontName; float _fontSize{24.0f}; @@ -530,6 +573,9 @@ class AX_DLL InputField : public Widget, public IMEDelegate bool _shiftKeyPressed{false}; bool _useTouchArea{false}; + bool _multilineEnabled{false}; + bool _autoWrap{false}; + // Continuous touch delay state (manual timing, no external timer dependency) bool _continuousTouchPending{false}; float _continuousTouchElapsedTime{0.0f}; diff --git a/axmol/ui/UILayout.cpp b/axmol/ui/UILayout.cpp index e4f0a64117ed..9e8f1a4fbe18 100644 --- a/axmol/ui/UILayout.cpp +++ b/axmol/ui/UILayout.cpp @@ -135,7 +135,7 @@ bool Layout::init() { if (Widget::init()) { - setAutoSizeEnabled(false); + setAutoSize(false); setContentSize(Vec2::ZERO); setAnchorPoint(Vec2::ZERO); onPassFocusToChild = AX_CALLBACK_2(Layout::findNearestChildWidgetIndex, this); diff --git a/axmol/ui/UILoadingBar.cpp b/axmol/ui/UILoadingBar.cpp index 965ec66a9f53..f524fd239fde 100644 --- a/axmol/ui/UILoadingBar.cpp +++ b/axmol/ui/UILoadingBar.cpp @@ -221,12 +221,12 @@ void LoadingBar::setScale9Enabled(bool enabled) if (_scale9Enabled) { bool autoSizeBefore = _autoSize; - setAutoSizeEnabled(false); + setAutoSize(false); _prevIgnoreSize = !autoSizeBefore; } else { - setAutoSizeEnabled(!_prevIgnoreSize); + setAutoSize(!_prevIgnoreSize); } setCapInsets(_capInsets); @@ -317,13 +317,13 @@ void LoadingBar::updateLayout() } } -void LoadingBar::setAutoSizeEnabled(bool autoSize) +void LoadingBar::setAutoSize(bool autoSize) { // Note: autoSize=true means adapt to content, autoSize=false means fixed size // For Scale9Sprite, we need special handling if (!_scale9Enabled || (_scale9Enabled && autoSize)) { - Widget::setAutoSizeEnabled(autoSize); + Widget::setAutoSize(autoSize); _prevIgnoreSize = !autoSize; // Store the inverse for backward compatibility } } diff --git a/axmol/ui/UILoadingBar.h b/axmol/ui/UILoadingBar.h index 3ee82bedf812..53ffc99da066 100644 --- a/axmol/ui/UILoadingBar.h +++ b/axmol/ui/UILoadingBar.h @@ -164,7 +164,7 @@ class AX_GUI_DLL LoadingBar : public Widget const Rect& getCapInsets() const; // override methods. - void setAutoSizeEnabled(bool autoSize) override; + void setAutoSize(bool autoSize) override; Vec2 getPreferredSize() const override; Node* getRenderNode() override; std::string getDescription() const override; diff --git a/axmol/ui/UIRichText.cpp b/axmol/ui/UIRichText.cpp index d9ebbc4fd6a5..7a301aa245dd 100644 --- a/axmol/ui/UIRichText.cpp +++ b/axmol/ui/UIRichText.cpp @@ -2475,12 +2475,12 @@ void RichText::setVerticalSpace(float space) _defaults[KEY_VERTICAL_SPACE] = space; } -void RichText::setAutoSizeEnabled(bool autoSize) +void RichText::setAutoSize(bool autoSize) { if (_autoSize != autoSize) { _formatTextDirty = true; - Widget::setAutoSizeEnabled(autoSize); + Widget::setAutoSize(autoSize); } } diff --git a/axmol/ui/UIRichText.h b/axmol/ui/UIRichText.h index 90b8f09a96ea..e6c7f4d36d6b 100644 --- a/axmol/ui/UIRichText.h +++ b/axmol/ui/UIRichText.h @@ -503,7 +503,7 @@ class AX_GUI_DLL RichText : public Widget void formatText(bool force = false); // override functions. - void setAutoSizeEnabled(bool autoSize) override; + void setAutoSize(bool autoSize) override; std::string getDescription() const override; void setWrapMode(WrapMode wrapMode); /*!< sets the wrapping mode: WRAP_PER_CHAR or WRAP_PER_WORD */ diff --git a/axmol/ui/UISlider.cpp b/axmol/ui/UISlider.cpp index a59787c9a23b..ccd1c21c00c9 100644 --- a/axmol/ui/UISlider.cpp +++ b/axmol/ui/UISlider.cpp @@ -258,12 +258,12 @@ void Slider::setScale9Enabled(bool able) if (_scale9Enabled) { bool autoSizeBefore = _autoSize; - setAutoSizeEnabled(false); + setAutoSize(false); _prevIgnoreSize = !autoSizeBefore; } else { - setAutoSizeEnabled(!_prevIgnoreSize); + setAutoSize(!_prevIgnoreSize); } setCapInsetsBarRenderer(_capInsetsBarRenderer); setCapInsetProgressBarRenderer(_capInsetsProgressBarRenderer); @@ -276,13 +276,13 @@ bool Slider::isScale9Enabled() const return _scale9Enabled; } -void Slider::setAutoSizeEnabled(bool autoSize) +void Slider::setAutoSize(bool autoSize) { // Note: autoSize=true means adapt to content, autoSize=false means fixed size // For Scale9Sprite, we need special handling if (!_scale9Enabled || (_scale9Enabled && autoSize)) { - Widget::setAutoSizeEnabled(autoSize); + Widget::setAutoSize(autoSize); _prevIgnoreSize = !autoSize; // Store the inverse for backward compatibility } } diff --git a/axmol/ui/UISlider.h b/axmol/ui/UISlider.h index 71561cf9ca08..27a6e609f96a 100644 --- a/axmol/ui/UISlider.h +++ b/axmol/ui/UISlider.h @@ -246,8 +246,8 @@ class AX_GUI_DLL Slider : public Widget // override "getRenderNode" method of widget. Node* getRenderNode() override; - // override "setAutoSizeEnabled" method of widget. - void setAutoSizeEnabled(bool autoSize) override; + // override "setAutoSize" method of widget. + void setAutoSize(bool autoSize) override; // override the widget's hitTest function to perform its own bool hitTest(const Vec2& pt, const Camera* camera, Vec3* p) const override; diff --git a/axmol/ui/UITabControl.cpp b/axmol/ui/UITabControl.cpp index 6f5c458f7ce2..4479fb9fa2d1 100644 --- a/axmol/ui/UITabControl.cpp +++ b/axmol/ui/UITabControl.cpp @@ -100,7 +100,7 @@ void TabControl::initAfterInsert(int index) headerCell->setAnchorPoint(getHeaderAnchorWithDock()); if (headerCell->_autoSize == !_ignoreHeaderTextureSize) { - headerCell->setAutoSizeEnabled(_ignoreHeaderTextureSize); + headerCell->setAutoSize(_ignoreHeaderTextureSize); if (_ignoreHeaderTextureSize) headerCell->setContentSize(Vec2(_headerWidth, _headerHeight)); headerCell->backGroundDisabledTextureScaleChangedWithSize(); @@ -444,7 +444,7 @@ void TabControl::ignoreHeadersTextureSize(bool ignore) _ignoreHeaderTextureSize = ignore; for (auto&& item : _tabItems) { - item->header->setAutoSizeEnabled(ignore); + item->header->setAutoSize(ignore); if (ignore) item->header->setContentSize(Vec2(_headerWidth, _headerHeight)); item->header->backGroundDisabledTextureScaleChangedWithSize(); diff --git a/axmol/ui/UIWidget.cpp b/axmol/ui/UIWidget.cpp index 0983ec3f975b..2990554a51cb 100644 --- a/axmol/ui/UIWidget.cpp +++ b/axmol/ui/UIWidget.cpp @@ -222,7 +222,7 @@ bool Widget::init() onNextFocusedWidget = nullptr; this->setAnchorPoint(Vec2(0.5f, 0.5f)); - setAutoSizeEnabled(true); + setAutoSize(true); return true; } @@ -342,7 +342,7 @@ void Widget::setSizePercent(const Vec2& percent) cSize = Vec2(_parent->getContentSize().width * percent.x, _parent->getContentSize().height * percent.y); } } - if (isAutoSizeEnabled()) + if (_autoSize) { ProtectedNode::setContentSize(getPreferredSize()); } @@ -368,7 +368,7 @@ void Widget::updateSizeAndPosition(const Vec2& parentSize) { case SizeType::ABSOLUTE: { - if (isAutoSizeEnabled()) + if (_autoSize) { this->setContentSize(getPreferredSize()); } @@ -392,7 +392,7 @@ void Widget::updateSizeAndPosition(const Vec2& parentSize) case SizeType::PERCENT: { Vec2 cSize = Vec2(parentSize.width * _sizePercent.x, parentSize.height * _sizePercent.y); - if (isAutoSizeEnabled()) + if (_autoSize) { this->setContentSize(getPreferredSize()); } @@ -1268,15 +1268,13 @@ void Widget::copyProperties(Widget* widget) setTag(widget->getTag()); setName(widget->getName()); setActionTag(widget->getActionTag()); - _autoSize = widget->_autoSize; - _isInternalSizeUpdate = true; + _autoSize = widget->_autoSize; this->setContentSize(widget->_contentSize); - _isInternalSizeUpdate = false; - _customSize = widget->_customSize; - _sizeType = widget->getSizeType(); - _sizePercent = widget->_sizePercent; - _positionType = widget->_positionType; - _positionPercent = widget->_positionPercent; + _customSize = widget->_customSize; + _sizeType = widget->getSizeType(); + _sizePercent = widget->_sizePercent; + _positionType = widget->_positionType; + _positionPercent = widget->_positionPercent; setPosition(widget->getPosition()); setAnchorPoint(widget->getAnchorPoint()); setScaleX(widget->getScaleX()); @@ -1540,7 +1538,7 @@ void Widget::enableDpadNavigation(bool enable) } } -void Widget::setAutoSizeEnabled(bool enable) +void Widget::setAutoSize(bool enable) { if (_autoSize == enable) return; diff --git a/axmol/ui/UIWidget.h b/axmol/ui/UIWidget.h index 8aa60c2b17d1..ae539275f123 100644 --- a/axmol/ui/UIWidget.h +++ b/axmol/ui/UIWidget.h @@ -713,13 +713,13 @@ class AX_GUI_DLL Widget : public ProtectedNode, public LayoutParameterProtocol * When enabled, the widget will automatically adapt its size to its content (virtual renderer). * @param enable True to enable auto size, false to use custom size. */ - virtual void setAutoSizeEnabled(bool enable); + virtual void setAutoSize(bool enable); /** * Query whether auto size mode is enabled. * @return true if auto size is enabled, false otherwise. */ - bool isAutoSizeEnabled() const { return _autoSize; } + bool isAutoSize() const { return _autoSize; } /** * Set callback name. @@ -847,10 +847,6 @@ class AX_GUI_DLL Widget : public ProtectedNode, public LayoutParameterProtocol bool _focusEnabled; bool _mouseHitted; - // Internal flag to bypass auto-size disabling in setContentSize - // Used when updateContentSize() needs to set size without changing _autoSize state - bool _isInternalSizeUpdate; - BrightStyle _brightStyle; SizeType _sizeType; PositionType _positionType; diff --git a/extensions/sceneext/src/sceneext/SGUIReader.cpp b/extensions/sceneext/src/sceneext/SGUIReader.cpp index 2e57e3d14348..d237378d0f76 100644 --- a/extensions/sceneext/src/sceneext/SGUIReader.cpp +++ b/extensions/sceneext/src/sceneext/SGUIReader.cpp @@ -597,8 +597,8 @@ void WidgetPropertiesReader0250::setPropsForWidgetFromJsonDictionary(Widget* wid bool ignoreSizeExsit = DICTOOL->checkObjectExist_json(options, "ignoreSize"); if (ignoreSizeExsit) { - // ignoreSize=true means fixed size, so setAutoSizeEnabled=false - widget->setAutoSizeEnabled(!DICTOOL->getBooleanValue_json(options, "ignoreSize")); + // ignoreSize=true means fixed size, so setAutoSize=false + widget->setAutoSize(!DICTOOL->getBooleanValue_json(options, "ignoreSize")); } float w = DICTOOL->getFloatValue_json(options, "width"); diff --git a/extensions/sceneio/src/sceneio/WidgetReader/ButtonReader/ButtonReader.cpp b/extensions/sceneio/src/sceneio/WidgetReader/ButtonReader/ButtonReader.cpp index 91cd85d7ecc3..7645e726df60 100644 --- a/extensions/sceneio/src/sceneio/WidgetReader/ButtonReader/ButtonReader.cpp +++ b/extensions/sceneio/src/sceneio/WidgetReader/ButtonReader/ButtonReader.cpp @@ -985,7 +985,7 @@ void ButtonReader::setPropsWithFlatBuffers(ax::Node* node, const flatbuffers::Ta if (scale9Enabled) { - button->setAutoSizeEnabled(false); + button->setAutoSize(false); auto f_capInsets = options->capInsets(); Rect capInsets(f_capInsets->x(), f_capInsets->y(), f_capInsets->width(), f_capInsets->height()); diff --git a/extensions/sceneio/src/sceneio/WidgetReader/ImageViewReader/ImageViewReader.cpp b/extensions/sceneio/src/sceneio/WidgetReader/ImageViewReader/ImageViewReader.cpp index fdf89dd49722..e1bf562db106 100644 --- a/extensions/sceneio/src/sceneio/WidgetReader/ImageViewReader/ImageViewReader.cpp +++ b/extensions/sceneio/src/sceneio/WidgetReader/ImageViewReader/ImageViewReader.cpp @@ -378,7 +378,7 @@ void ImageViewReader::setPropsWithFlatBuffers(ax::Node* node, const flatbuffers: if (scale9Enabled) { - imageView->setAutoSizeEnabled(false); + imageView->setAutoSize(false); auto f_scale9Size = options->scale9Size(); Size scale9Size(f_scale9Size->width(), f_scale9Size->height()); diff --git a/extensions/sceneio/src/sceneio/WidgetReader/LayoutReader/LayoutReader.cpp b/extensions/sceneio/src/sceneio/WidgetReader/LayoutReader/LayoutReader.cpp index 2e8029eaa77c..4d4201700156 100644 --- a/extensions/sceneio/src/sceneio/WidgetReader/LayoutReader/LayoutReader.cpp +++ b/extensions/sceneio/src/sceneio/WidgetReader/LayoutReader/LayoutReader.cpp @@ -729,7 +729,7 @@ void LayoutReader::setPropsWithFlatBuffers(ax::Node* node, const flatbuffers::Ta } else { - if (!panel->isAutoSizeEnabled()) + if (!panel->isAutoSize()) { Size contentSize(widgetOptions->size()->width(), widgetOptions->size()->height()); panel->setContentSize(contentSize); diff --git a/extensions/sceneio/src/sceneio/WidgetReader/ListViewReader/ListViewReader.cpp b/extensions/sceneio/src/sceneio/WidgetReader/ListViewReader/ListViewReader.cpp index 814ef0efef20..eb04906c105d 100644 --- a/extensions/sceneio/src/sceneio/WidgetReader/ListViewReader/ListViewReader.cpp +++ b/extensions/sceneio/src/sceneio/WidgetReader/ListViewReader/ListViewReader.cpp @@ -562,7 +562,7 @@ void ListViewReader::setPropsWithFlatBuffers(ax::Node* node, const flatbuffers:: } else { - if (!listView->isAutoSizeEnabled()) + if (!listView->isAutoSize()) { Size contentSize(widgetOptions->size()->width(), widgetOptions->size()->height()); listView->setContentSize(contentSize); diff --git a/extensions/sceneio/src/sceneio/WidgetReader/PageViewReader/PageViewReader.cpp b/extensions/sceneio/src/sceneio/WidgetReader/PageViewReader/PageViewReader.cpp index cd4e1b5bbd2b..0bcc00ead3ae 100644 --- a/extensions/sceneio/src/sceneio/WidgetReader/PageViewReader/PageViewReader.cpp +++ b/extensions/sceneio/src/sceneio/WidgetReader/PageViewReader/PageViewReader.cpp @@ -401,7 +401,7 @@ void PageViewReader::setPropsWithFlatBuffers(ax::Node* node, const flatbuffers:: } else { - if (!pageView->isAutoSizeEnabled()) + if (!pageView->isAutoSize()) { Size contentSize(widgetOptions->size()->width(), widgetOptions->size()->height()); pageView->setContentSize(contentSize); diff --git a/extensions/sceneio/src/sceneio/WidgetReader/ScrollViewReader/ScrollViewReader.cpp b/extensions/sceneio/src/sceneio/WidgetReader/ScrollViewReader/ScrollViewReader.cpp index 82ac600defe8..cbb690c27154 100644 --- a/extensions/sceneio/src/sceneio/WidgetReader/ScrollViewReader/ScrollViewReader.cpp +++ b/extensions/sceneio/src/sceneio/WidgetReader/ScrollViewReader/ScrollViewReader.cpp @@ -542,7 +542,7 @@ void ScrollViewReader::setPropsWithFlatBuffers(ax::Node* node, const flatbuffers } else { - if (!scrollView->isAutoSizeEnabled()) + if (!scrollView->isAutoSize()) { Size contentSize(widgetOptions->size()->width(), widgetOptions->size()->height()); scrollView->setContentSize(contentSize); diff --git a/extensions/sceneio/src/sceneio/WidgetReader/TextAtlasReader/TextAtlasReader.cpp b/extensions/sceneio/src/sceneio/WidgetReader/TextAtlasReader/TextAtlasReader.cpp index d18882cdefc5..c2d9342cf19f 100644 --- a/extensions/sceneio/src/sceneio/WidgetReader/TextAtlasReader/TextAtlasReader.cpp +++ b/extensions/sceneio/src/sceneio/WidgetReader/TextAtlasReader/TextAtlasReader.cpp @@ -273,7 +273,7 @@ void TextAtlasReader::setPropsWithFlatBuffers(ax::Node* node, const flatbuffers: auto widgetReader = WidgetReader::getInstance(); widgetReader->setPropsWithFlatBuffers(node, (Table*)options->widgetOptions()); - labelAtlas->setAutoSizeEnabled(false); + labelAtlas->setAutoSize(false); } Node* TextAtlasReader::createNodeWithFlatBuffers(const flatbuffers::Table* textAtlasOptions) diff --git a/extensions/sceneio/src/sceneio/WidgetReader/TextBMFontReader/TextBMFontReader.cpp b/extensions/sceneio/src/sceneio/WidgetReader/TextBMFontReader/TextBMFontReader.cpp index a0638c561d95..9392ecef4596 100644 --- a/extensions/sceneio/src/sceneio/WidgetReader/TextBMFontReader/TextBMFontReader.cpp +++ b/extensions/sceneio/src/sceneio/WidgetReader/TextBMFontReader/TextBMFontReader.cpp @@ -263,7 +263,7 @@ void TextBMFontReader::setPropsWithFlatBuffers(ax::Node* node, const flatbuffers auto widgetReader = WidgetReader::getInstance(); widgetReader->setPropsWithFlatBuffers(node, (Table*)options->widgetOptions()); - labelBMFont->setAutoSizeEnabled(false); + labelBMFont->setAutoSize(false); } Node* TextBMFontReader::createNodeWithFlatBuffers(const flatbuffers::Table* textBMFontOptions) diff --git a/extensions/sceneio/src/sceneio/WidgetReader/TextReader/TextReader.cpp b/extensions/sceneio/src/sceneio/WidgetReader/TextReader/TextReader.cpp index 26af2c0dbd6b..355883559f27 100644 --- a/extensions/sceneio/src/sceneio/WidgetReader/TextReader/TextReader.cpp +++ b/extensions/sceneio/src/sceneio/WidgetReader/TextReader/TextReader.cpp @@ -557,10 +557,10 @@ void TextReader::setPropsWithFlatBuffers(ax::Node* node, const flatbuffers::Tabl Color32 color(f_color->r(), f_color->g(), f_color->b(), f_color->a()); ((Text*)node)->setTextColor(color); - label->setAutoSizeEnabled(!options->isCustomSize()); + label->setAutoSize(!options->isCustomSize()); auto widgetOptions = options->widgetOptions(); - if (!label->isAutoSizeEnabled()) + if (!label->isAutoSize()) { Size contentSize(widgetOptions->size()->width(), widgetOptions->size()->height()); label->setContentSize(contentSize); diff --git a/extensions/sceneio/src/sceneio/WidgetReader/WidgetReader.cpp b/extensions/sceneio/src/sceneio/WidgetReader/WidgetReader.cpp index 6e6947683aab..21e13ba43eca 100644 --- a/extensions/sceneio/src/sceneio/WidgetReader/WidgetReader.cpp +++ b/extensions/sceneio/src/sceneio/WidgetReader/WidgetReader.cpp @@ -134,8 +134,8 @@ void WidgetReader::setPropsFromJsonDictionary(Widget* widget, const rapidjson::V bool ignoreSizeExsit = DICTOOL->checkObjectExist_json(options, P_IgnoreSize); if (ignoreSizeExsit) { - // ignoreSize=true means fixed size, so setAutoSizeEnabled=false - widget->setAutoSizeEnabled(!DICTOOL->getBooleanValue_json(options, P_IgnoreSize)); + // ignoreSize=true means fixed size, so setAutoSize=false + widget->setAutoSize(!DICTOOL->getBooleanValue_json(options, P_IgnoreSize)); } widget->setSizeType((Widget::SizeType)DICTOOL->getIntValue_json(options, P_SizeType)); @@ -282,7 +282,7 @@ void WidgetReader::endSetBasicProperties(Widget* widget) } widget->setColor(_color); // the setSize method will be conflict with scale9Width & scale9Height - if (!widget->isAutoSizeEnabled()) + if (!widget->isAutoSize()) { widget->setContentSize(Size(_width, _height)); } @@ -771,7 +771,7 @@ void WidgetReader::setPropsWithFlatBuffers(ax::Node* node, const flatbuffers::Ta widget->setAnchorPoint(Vec2::ZERO); - widget->setAutoSizeEnabled(!options->ignoreSize()); + widget->setAutoSize(!options->ignoreSize()); widget->setLayoutComponentEnabled(true); Size contentSize(options->size()->width(), options->size()->height()); widget->setContentSize(contentSize); diff --git a/extensions/sceneio/src/sceneio/WidgetReader/WidgetReader.h b/extensions/sceneio/src/sceneio/WidgetReader/WidgetReader.h index c10024b2f6fa..f8f74acc2eb3 100644 --- a/extensions/sceneio/src/sceneio/WidgetReader/WidgetReader.h +++ b/extensions/sceneio/src/sceneio/WidgetReader/WidgetReader.h @@ -139,7 +139,7 @@ extern const char* P_Path; #define AX_BASIC_PROPERTY_BINARY_READER \ if (key == P_IgnoreSize) \ { \ - widget->setAutoSizeEnabled(!valueToBool(value)); \ + widget->setAutoSize(!valueToBool(value)); \ } \ else if (key == P_SizeType) \ { \ diff --git a/extensions/scripting/lua-bindings/auto/axlua_ui_auto.cpp b/extensions/scripting/lua-bindings/auto/axlua_ui_auto.cpp index 433a1d26a0ea..d8d6df9fe41f 100644 --- a/extensions/scripting/lua-bindings/auto/axlua_ui_auto.cpp +++ b/extensions/scripting/lua-bindings/auto/axlua_ui_auto.cpp @@ -3687,7 +3687,7 @@ int lua_ax_ui_Widget_requestFocus(lua_State* tolua_S) return 0; } -int lua_ax_ui_Widget_setAutoSizeEnabled(lua_State* tolua_S) +int lua_ax_ui_Widget_setAutoSize(lua_State* tolua_S) { int argc = 0; ax::ui::Widget* obj = nullptr; @@ -3707,7 +3707,7 @@ int lua_ax_ui_Widget_setAutoSizeEnabled(lua_State* tolua_S) #if _AX_DEBUG >= 1 if (!obj) { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_Widget_setAutoSizeEnabled'", nullptr); + tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_Widget_setAutoSize'", nullptr); return 0; } #endif @@ -3717,27 +3717,27 @@ int lua_ax_ui_Widget_setAutoSizeEnabled(lua_State* tolua_S) { bool arg0; - ok &= luaval_to_boolean(tolua_S, 2, &arg0, "axui.Widget:setAutoSizeEnabled"); + ok &= luaval_to_boolean(tolua_S, 2, &arg0, "axui.Widget:setAutoSize"); if(!ok) { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_Widget_setAutoSizeEnabled'", nullptr); + tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_Widget_setAutoSize'", nullptr); return 0; } - obj->setAutoSizeEnabled(arg0); + obj->setAutoSize(arg0); lua_settop(tolua_S, 1); return 1; } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.Widget:setAutoSizeEnabled",argc, 1); + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.Widget:setAutoSize",argc, 1); return 0; #if _AX_DEBUG >= 1 tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_Widget_setAutoSizeEnabled'.",&tolua_err); + tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_Widget_setAutoSize'.",&tolua_err); #endif return 0; } -int lua_ax_ui_Widget_isAutoSizeEnabled(lua_State* tolua_S) +int lua_ax_ui_Widget_isAutoSize(lua_State* tolua_S) { int argc = 0; ax::ui::Widget* obj = nullptr; @@ -3757,7 +3757,7 @@ int lua_ax_ui_Widget_isAutoSizeEnabled(lua_State* tolua_S) #if _AX_DEBUG >= 1 if (!obj) { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_Widget_isAutoSizeEnabled'", nullptr); + tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_Widget_isAutoSize'", nullptr); return 0; } #endif @@ -3767,19 +3767,19 @@ int lua_ax_ui_Widget_isAutoSizeEnabled(lua_State* tolua_S) { if(!ok) { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_Widget_isAutoSizeEnabled'", nullptr); + tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_Widget_isAutoSize'", nullptr); return 0; } - auto&& ret = obj->isAutoSizeEnabled(); + auto&& ret = obj->isAutoSize(); tolua_pushboolean(tolua_S,(bool)ret); return 1; } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.Widget:isAutoSizeEnabled",argc, 0); + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.Widget:isAutoSize",argc, 0); return 0; #if _AX_DEBUG >= 1 tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_Widget_isAutoSizeEnabled'.",&tolua_err); + tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_Widget_isAutoSize'.",&tolua_err); #endif return 0; @@ -4505,8 +4505,8 @@ int lua_register_ax_ui_Widget(lua_State* tolua_S) tolua_function(tolua_S,"setFocusEnabled",lua_ax_ui_Widget_setFocusEnabled); tolua_function(tolua_S,"findNextFocusedWidget",lua_ax_ui_Widget_findNextFocusedWidget); tolua_function(tolua_S,"requestFocus",lua_ax_ui_Widget_requestFocus); - tolua_function(tolua_S,"setAutoSizeEnabled",lua_ax_ui_Widget_setAutoSizeEnabled); - tolua_function(tolua_S,"isAutoSizeEnabled",lua_ax_ui_Widget_isAutoSizeEnabled); + tolua_function(tolua_S,"setAutoSize",lua_ax_ui_Widget_setAutoSize); + tolua_function(tolua_S,"isAutoSize",lua_ax_ui_Widget_isAutoSize); tolua_function(tolua_S,"setCallbackName",lua_ax_ui_Widget_setCallbackName); tolua_function(tolua_S,"getCallbackName",lua_ax_ui_Widget_getCallbackName); tolua_function(tolua_S,"setCallbackType",lua_ax_ui_Widget_setCallbackType); diff --git a/tests/cpp-tests/Source/BaseTest.cpp b/tests/cpp-tests/Source/BaseTest.cpp index 75d1f09f5e9c..6d7fb16c77be 100644 --- a/tests/cpp-tests/Source/BaseTest.cpp +++ b/tests/cpp-tests/Source/BaseTest.cpp @@ -483,7 +483,7 @@ bool TestCase::init() auto keyEvent = static_cast(event); auto renderView = static_cast(_director->getRenderView()); bool altPressed = renderView->isKeyPressed(GLFW_KEY_LEFT_ALT); - if (code == EventKeyboard::KeyCode::KEY_ENTER && !keyEvent->isRepeat()) + if (altPressed && code == EventKeyboard::KeyCode::KEY_ENTER && !keyEvent->isRepeat()) { if (!renderView->isFullscreen()) { diff --git a/tests/cpp-tests/Source/LabelTest/LabelTest.cpp b/tests/cpp-tests/Source/LabelTest/LabelTest.cpp index fed2d569c93e..5382a5ea22e2 100644 --- a/tests/cpp-tests/Source/LabelTest/LabelTest.cpp +++ b/tests/cpp-tests/Source/LabelTest/LabelTest.cpp @@ -3423,7 +3423,7 @@ LabelRichText::LabelRichText() "Mixing UIRichText with non UIWidget code. For more samples, see the UIRichTextTest.cpp file"); if (richText2) { - richText2->setAutoSizeEnabled(true); + richText2->setAutoSize(true); richText2->setContentSize(Size(400.0f, 400.0f)); richText2->setPosition(center); diff --git a/tests/cpp-tests/Source/NetworkTest/DownloaderTest/DownloaderTest.cpp b/tests/cpp-tests/Source/NetworkTest/DownloaderTest/DownloaderTest.cpp index 113868732c0a..fa03243ceecb 100644 --- a/tests/cpp-tests/Source/NetworkTest/DownloaderTest/DownloaderTest.cpp +++ b/tests/cpp-tests/Source/NetworkTest/DownloaderTest/DownloaderTest.cpp @@ -100,7 +100,7 @@ struct DownloaderTest : public TestCase // add a progress bar auto bar = ui::LoadingBar::create("ccs-res/cocosui/sliderProgress.png"); bar->setTag(TAG_PROGRESS_BAR); - bar->setAutoSizeEnabled(true); + bar->setAutoSize(true); bar->setAnchorPoint(Vec2(0.5f, 0.0f)); bar->setContentSize(Size(viewSize.width - margin * 2, btn->getContentSize().height)); bar->setPosition(btn->getPosition()); diff --git a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest.cpp b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest.cpp index e421a250ce67..9968894bf74f 100644 --- a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest.cpp +++ b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest.cpp @@ -267,7 +267,7 @@ bool UIButtonTest_Scale9_State_Change::init() // Create the button Button* button = Button::create("cocosui/button.png"); // open scale9 render - button->setAutoSizeEnabled(true); + button->setAutoSize(true); button->setScale9Enabled(true); button->setPosition(Vec2(widgetSize.width / 2.0f - 100, widgetSize.height / 2.0f)); button->setContentSize(Size(180.0f, 60.0f)); @@ -278,7 +278,7 @@ bool UIButtonTest_Scale9_State_Change::init() Button* button2 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png"); // open scale9 render - button2->setAutoSizeEnabled(true); + button2->setAutoSize(true); button2->setScale9Enabled(true); button2->setTitleText("Hello scale9"); button2->setPosition(Vec2(widgetSize.width / 2.0f + 100, widgetSize.height / 2.0f)); @@ -600,7 +600,7 @@ bool UIButtonTestSwitchScale9::init() button->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); button->addTouchEventListener(AX_CALLBACK_2(UIButtonTestSwitchScale9::touchEvent, this)); button->setTitleText("Button Title"); - button->setAutoSizeEnabled(true); + button->setAutoSize(true); _uiLayer->addChild(button); @@ -746,7 +746,7 @@ bool UIButtonIgnoreContentSizeTest::init() // Create the button auto button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); - button->setAutoSizeEnabled(true); + button->setAutoSize(true); button->setContentSize(Size(200.0f, 100.0f)); button->setPositionNormalized(Vec2(0.3f, 0.5f)); button->setTitleText("PLAY GAME"); @@ -760,7 +760,7 @@ bool UIButtonIgnoreContentSizeTest::init() // Create the button auto button2 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); - button2->setAutoSizeEnabled(true); + button2->setAutoSize(true); button2->setContentSize(Size(200.0f, 100.0f)); button2->setPositionNormalized(Vec2(0.8f, 0.5f)); button2->setTitleText("PLAY GAME"); diff --git a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest.cpp b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest.cpp index 392bd5a3af49..45fc5457a36b 100644 --- a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest.cpp +++ b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest.cpp @@ -148,7 +148,7 @@ bool UICheckBoxDefaultBehaviorTest::init() // Create the checkbox CheckBox* checkBox2 = CheckBox::create("cocosui/check_box_normal.png", "cocosui/check_box_active.png"); checkBox2->setPosition(Vec2(widgetSize.width / 2.0f - 150, widgetSize.height / 2.0f)); - checkBox2->setAutoSizeEnabled(true); + checkBox2->setAutoSize(true); checkBox2->setZoomScale(0.5f); checkBox2->setContentSize(Size(80.0f, 80.0f)); checkBox2->setName("bigCheckBox"); diff --git a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.cpp b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.cpp index 99ca9dd8e53c..8afa061d7f85 100644 --- a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.cpp +++ b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.cpp @@ -129,7 +129,7 @@ bool UIImageViewTest_Scale9_State_Change::init() // Create the imageview ImageView* imageView = ImageView::create("cocosui/ccicon.png"); - imageView->setAutoSizeEnabled(true); + imageView->setAutoSize(true); imageView->setScale9Enabled(true); imageView->setContentSize(Size(100.0f, 100.0f)); imageView->setCapInsets(Rect(20.0f, 20.0f, 20.0f, 20.0f)); @@ -243,7 +243,7 @@ bool UIImageViewFlipTest::init() imageView->setContentSize(Size(250, 115)); imageView->setFlippedX(true); imageView->setScale(0.5); - imageView->setAutoSizeEnabled(true); + imageView->setAutoSize(true); imageView->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); _uiLayer->addChild(imageView); diff --git a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest.cpp b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest.cpp index 24d56bd829aa..bd29762fe563 100644 --- a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest.cpp +++ b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest.cpp @@ -968,7 +968,7 @@ bool UILayoutComponent_Berth_Stretch_Test::init() if (UILayoutComponentTest::init()) { ImageView* leftTopSprite = ImageView::create("cocosui/CloseSelected.png"); - leftTopSprite->setAutoSizeEnabled(true); + leftTopSprite->setAutoSize(true); LayoutComponent* leftTop = LayoutComponent::bindLayoutComponent(leftTopSprite); leftTop->setHorizontalEdge(LayoutComponent::HorizontalEdge::Left); leftTop->setVerticalEdge(LayoutComponent::VerticalEdge::Top); @@ -980,7 +980,7 @@ bool UILayoutComponent_Berth_Stretch_Test::init() leftTop->setTopMargin(0); ImageView* leftBottomSprite = ImageView::create("cocosui/CloseSelected.png"); - leftBottomSprite->setAutoSizeEnabled(true); + leftBottomSprite->setAutoSize(true); LayoutComponent* leftBottom = LayoutComponent::bindLayoutComponent(leftBottomSprite); leftBottom->setHorizontalEdge(LayoutComponent::HorizontalEdge::Left); leftBottom->setVerticalEdge(LayoutComponent::VerticalEdge::Bottom); @@ -992,7 +992,7 @@ bool UILayoutComponent_Berth_Stretch_Test::init() leftBottom->setBottomMargin(0); ImageView* rightTopSprite = ImageView::create("cocosui/CloseSelected.png"); - rightTopSprite->setAutoSizeEnabled(true); + rightTopSprite->setAutoSize(true); LayoutComponent* rightTop = LayoutComponent::bindLayoutComponent(rightTopSprite); rightTop->setHorizontalEdge(LayoutComponent::HorizontalEdge::Right); rightTop->setVerticalEdge(LayoutComponent::VerticalEdge::Top); @@ -1004,7 +1004,7 @@ bool UILayoutComponent_Berth_Stretch_Test::init() rightTop->setRightMargin(0); ImageView* rightBottomSprite = ImageView::create("cocosui/CloseSelected.png"); - rightBottomSprite->setAutoSizeEnabled(true); + rightBottomSprite->setAutoSize(true); LayoutComponent* rightBottom = LayoutComponent::bindLayoutComponent(rightBottomSprite); rightBottom->setHorizontalEdge(LayoutComponent::HorizontalEdge::Right); rightBottom->setVerticalEdge(LayoutComponent::VerticalEdge::Bottom); diff --git a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.cpp b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.cpp index c87f9637328a..d89fdcf0cb6b 100644 --- a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.cpp +++ b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.cpp @@ -309,7 +309,7 @@ bool UILoadingBarTest_Scale9_State_Change::init() // Create the loading bar LoadingBar* loadingBar = LoadingBar::create("cocosui/sliderThumb.png"); loadingBar->setTag(0); - loadingBar->setAutoSizeEnabled(true); + loadingBar->setAutoSize(true); // loadingBar->setScale9Enabled(true); loadingBar->setCapInsets(Rect(0, 0, 0, 0)); loadingBar->setContentSize(Size(200, 80)); @@ -360,7 +360,7 @@ bool UILoadingBarReloadTexture::init() LoadingBar* loadingBar = LoadingBar::create("cocosui/slider_bar_active_9patch.png"); loadingBar->setTag(0); - loadingBar->setAutoSizeEnabled(true); + loadingBar->setAutoSize(true); // loadingBar->setScale9Enabled(true); loadingBar->setCapInsets(Rect(0, 0, 0, 0)); loadingBar->setContentSize(Size(300, 13)); diff --git a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIRichTextTest/UIRichTextTest.cpp b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIRichTextTest/UIRichTextTest.cpp index 467d1d0d837d..45d7e93b437d 100644 --- a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIRichTextTest/UIRichTextTest.cpp +++ b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIRichTextTest/UIRichTextTest.cpp @@ -78,14 +78,14 @@ void UIRichTextTestBase::touchEvent(Object* pSender, Widget::TouchEventType type { case Widget::TouchEventType::ENDED: { - if (_richText->isAutoSizeEnabled()) + if (_richText->isAutoSize()) { - _richText->setAutoSizeEnabled(true); + _richText->setAutoSize(true); _richText->setContentSize(_defaultContentSize); } else { - _richText->setAutoSizeEnabled(false); + _richText->setAutoSize(false); } } break; @@ -201,7 +201,7 @@ bool UIRichTextTest::init() // RichText _richText = RichText::create(); - _richText->setAutoSizeEnabled(true); + _richText->setAutoSize(true); _richText->setContentSize(_defaultContentSize); RichElementText* re1 = RichElementText::create(1, Color32::WHITE, str1, "SimSun", 10); @@ -265,7 +265,7 @@ bool UIRichTextXMLBasic::init() "This is just simple text, with no XML tags. Testing the basics. Testing word-wrapping. Testing " "(\"punctuation\") " "Testing, Testing"); - _richText->setAutoSizeEnabled(true); + _richText->setAutoSize(true); _richText->setContentSize(_defaultContentSize); _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); @@ -302,7 +302,7 @@ bool UIRichTextXMLSmallBig::init() // RichText _richText = RichText::createWithXML( "Regular size.smaller size.bigger.normal.bigger.normal."); - _richText->setAutoSizeEnabled(true); + _richText->setAutoSize(true); _richText->setContentSize(_defaultContentSize); _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); @@ -339,7 +339,7 @@ bool UIRichTextXMLColor::init() // RichText _richText = RichText::createWithXML( "Default color.red.greenred again.default again"); - _richText->setAutoSizeEnabled(true); + _richText->setAutoSize(true); _richText->setContentSize(_defaultContentSize); _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); @@ -376,7 +376,7 @@ bool UIRichTextXMLSUIB::init() // RichText _richText = RichText::createWithXML("system font: underlineitalicsboldstrike-through"); - _richText->setAutoSizeEnabled(true); + _richText->setAutoSize(true); _richText->setContentSize(_defaultContentSize); _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); @@ -414,7 +414,7 @@ bool UIRichTextXMLSUIB2::init() _richText = RichText::createWithXML( "ttf font: " "underlineitalicsboldstrike-through"); - _richText->setAutoSizeEnabled(true); + _richText->setAutoSize(true); _richText->setContentSize(_defaultContentSize); _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); @@ -452,7 +452,7 @@ bool UIRichTextXMLSUIB3::init() _richText = RichText::createWithXML( "ttf font: italics and underlinebold " "and strike-through"); - _richText->setAutoSizeEnabled(true); + _richText->setAutoSize(true); _richText->setContentSize(_defaultContentSize); _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); @@ -501,7 +501,7 @@ bool UIRichTextXMLImg::init() "Image with w/h/sX/sY: and " "goes text again"); - _richText->setAutoSizeEnabled(true); + _richText->setAutoSize(true); _richText->setContentSize(_defaultContentSize); _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); @@ -538,7 +538,7 @@ bool UIRichTextXMLUrl::init() // RichText _richText = RichText::createWithXML( "This link will redirect you to google: click me"); - _richText->setAutoSizeEnabled(true); + _richText->setAutoSize(true); _richText->setContentSize(_defaultContentSize); _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); @@ -576,7 +576,7 @@ bool UIRichTextXMLUrlImg::init() _richText = RichText::createWithXML( "This link will redirect you to google: "); - _richText->setAutoSizeEnabled(true); + _richText->setAutoSize(true); _richText->setContentSize(_defaultContentSize); _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); @@ -616,7 +616,7 @@ bool UIRichTextXMLFace::init() _richText = RichText::createWithXML( "Marker Felt 20.Arial " "20.Thonburi 24 blue"); - _richText->setAutoSizeEnabled(true); + _richText->setAutoSize(true); _richText->setContentSize(_defaultContentSize); _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); @@ -653,7 +653,7 @@ bool UIRichTextXMLBR::init() // RichText _richText = RichText::createWithXML( "this is one line.
this should be in another line.
and this is another line"); - _richText->setAutoSizeEnabled(true); + _richText->setAutoSize(true); _richText->setContentSize(_defaultContentSize); _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); @@ -689,7 +689,7 @@ bool UIRichTextXMLInvalid::init() _richText = RichText::createWithXML("this is an invalid xml. no closing tag"); if (_richText) { - _richText->setAutoSizeEnabled(true); + _richText->setAutoSize(true); _richText->setContentSize(_defaultContentSize); _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); @@ -727,7 +727,7 @@ bool UIRichTextXMLOutline::init() _richText = RichText::createWithXML( "OUTLINE"); - _richText->setAutoSizeEnabled(true); + _richText->setAutoSize(true); _richText->setContentSize(_defaultContentSize); _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); @@ -767,7 +767,7 @@ bool UIRichTextXMLShadow::init() _richText = RichText::createWithXML( "SHADOW"); - _richText->setAutoSizeEnabled(true); + _richText->setAutoSize(true); _richText->setContentSize(_defaultContentSize); _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); @@ -804,7 +804,7 @@ bool UIRichTextXMLGlow::init() // RichText _richText = RichText::createWithXML( "GLOW"); - _richText->setAutoSizeEnabled(true); + _richText->setAutoSize(true); _richText->setContentSize(_defaultContentSize); _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); @@ -876,7 +876,7 @@ bool UIRichTextXMLExtend::init() "CloseNormal-tag:


CloseSelected-tag:
", defaults, [](std::string_view url) { Application::getInstance()->openURL(url); }); - _richText->setAutoSizeEnabled(true); + _richText->setAutoSize(true); _richText->setContentSize(_defaultContentSize); _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); @@ -917,7 +917,7 @@ bool UIRichTextXMLSpace::init() "words should be divided with space.

HELLO " "WORLD

HELLO WORLD"); - _richText->setAutoSizeEnabled(true); + _richText->setAutoSize(true); _richText->setContentSize(_defaultContentSize); _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); _richText->setLocalZOrder(10); @@ -959,7 +959,7 @@ bool UIRichTextNewline::init() _richText->pushBackElement(textElement); textElement = ui::RichElementText::create(2, Color32::WHITE, "Line3", "fonts/Marker Felt.ttf", 32, 0); _richText->pushBackElement(textElement); - _richText->setAutoSizeEnabled(true); + _richText->setAutoSize(true); _richText->setContentSize(_defaultContentSize); _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); _richText->setLocalZOrder(10); @@ -996,7 +996,7 @@ bool UIRichTextHeadings::init() // RichText _richText = RichText::createWithXML( R"(

h1. HEADING

h2. HEADING

h3. HEADING

h4. HEADING

h5. HEADING
h6. HEADING
)"); - _richText->setAutoSizeEnabled(true); + _richText->setAutoSize(true); _richText->setContentSize(_defaultContentSize); _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); @@ -1034,7 +1034,7 @@ bool UIRichTextDynamicFontSize::init() // RichText _richText = RichText::createWithXML( R"(

Paragraph 1 with default size font

Paragraph 2 with font size="1.5em"

Paragraph 3 with font size="150%"

)"); - _richText->setAutoSizeEnabled(true); + _richText->setAutoSize(true); _richText->setContentSize(_defaultContentSize); _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); @@ -1078,7 +1078,7 @@ bool UIRichTextParagraph::init() "interdum velit. " "Convallis a cras semper auctor neque vitae tempus quam pellentesque. Congue quisque egestas diam in arcu " "cursus euismod quis.

"); - _richText->setAutoSizeEnabled(true); + _richText->setAutoSize(true); _richText->setContentSize(_defaultContentSize); _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); @@ -1162,7 +1162,7 @@ Cursus metus aliquam eleifend mi in. Euismod lacinia at quis risus sed vulputate Sit amet mattis vulputate enim nulla aliquet porttitor lacus luctus.

Google!)", valMap); - _richText->setAutoSizeEnabled(true); + _richText->setAutoSize(true); _richText->setContentSize(Size(_defaultContentSize.width, 0)); _richText->setAnchorPoint(Vec2::ANCHOR_MIDDLE_TOP); _richText->setOpenUrlHandler([this](std::string_view url) { diff --git a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UISliderTest/UISliderTest.cpp b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UISliderTest/UISliderTest.cpp index 28566995ba78..881a0cbaf5da 100644 --- a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UISliderTest/UISliderTest.cpp +++ b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UISliderTest/UISliderTest.cpp @@ -200,7 +200,7 @@ bool UISliderTest_Scale9_State_Change::init() slider->loadBarTexture("cocosui/sliderballnormal.png"); slider->loadSlidBallTextures("cocosui/sliderThumb.png", "cocosui/sliderThumb.png", ""); slider->loadProgressBarTexture("cocosui/slider_bar_active_9patch.png"); - slider->setAutoSizeEnabled(true); + slider->setAutoSize(true); slider->setScale9Enabled(true); slider->setCapInsets(Rect(0.0f, 0.0f, 0.0f, 0.0f)); slider->setContentSize(Size(200.0f, 60.0f)); diff --git a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextFieldTest/UIInputFieldTest.cpp b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextFieldTest/UIInputFieldTest.cpp index b41433315f8a..81538248ba70 100644 --- a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextFieldTest/UIInputFieldTest.cpp +++ b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextFieldTest/UIInputFieldTest.cpp @@ -232,6 +232,8 @@ bool UIInputFieldTest_LineWrap::init() // Create the inputfield InputField* inputField = InputField::create("input words here", "fonts/Marker Felt.ttf", 30); + inputField->setMultilineEnabled(true); + inputField->setAutoSize(false); inputField->setContentSize(Vec2(240.0f, 170.0f)); inputField->setString("input words here"); inputField->setTextHorizontalAlignment(TextHAlignment::CENTER); diff --git a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextTest/UITextTest.cpp b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextTest/UITextTest.cpp index cf2a921492d7..d2ebd2e5cb62 100644 --- a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextTest/UITextTest.cpp +++ b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextTest/UITextTest.cpp @@ -80,7 +80,7 @@ bool UITextTest_LineWrap::init() // Create the line wrap Text* text = Text::create("TextArea Widget can line wrap", "AmericanTypewriter", 32); - text->setAutoSizeEnabled(true); + text->setAutoSize(true); text->setContentSize(Size(280.0f, 150.0f)); text->setTextHorizontalAlignment(TextHAlignment::CENTER); text->setTouchScaleChangeEnabled(true); @@ -225,7 +225,7 @@ bool UITextTest_IgnoreContentSize::init() Text* leftText = Text::create("ignore content", "fonts/Marker Felt.ttf", 10); leftText->setPosition(Vec2(widgetSize.width / 2.0f - 50, widgetSize.height / 2.0f)); - leftText->setAutoSizeEnabled(true); + leftText->setAutoSize(true); leftText->setTextAreaSize(Size(60.0f, 60.0f)); leftText->setString("Text line with break\nText line with break\nText line with break\nText line with break\n"); leftText->setTouchScaleChangeEnabled(true); @@ -238,7 +238,7 @@ bool UITextTest_IgnoreContentSize::init() "Text line with break\nText line with break\nText line with break\nText line with break\n"); // note:setTextAreaSize must be used with ignoreContentAdaptWithSize(false) rightText->setTextAreaSize(Size(100.0f, 30.0f)); - rightText->setAutoSizeEnabled(true); + rightText->setAutoSize(true); _uiLayer->addChild(rightText); auto halighButton = Button::create(); diff --git a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIVideoPlayerTest/UIVideoPlayerTest.cpp b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIVideoPlayerTest/UIVideoPlayerTest.cpp index 89e410c609a9..72afa7ecef41 100644 --- a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIVideoPlayerTest/UIVideoPlayerTest.cpp +++ b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIVideoPlayerTest/UIVideoPlayerTest.cpp @@ -438,7 +438,7 @@ void SimpleVideoPlayerTest::createVideo() _videoPlayer = VideoPlayer::create(); _videoPlayer->setPosition(centerPos); _videoPlayer->setAnchorPoint(Vec2::ANCHOR_MIDDLE); - _videoPlayer->setAutoSizeEnabled(false); + _videoPlayer->setAutoSize(false); _videoPlayer->setContentSize(Size(widgetSize.width * 0.4f, widgetSize.height * 0.4f)); _videoPlayer->setLooping(true); _videoPlayer->setStyle(_style); From bb6dff52fbcec85e8b7a30b520894b130bacdaee Mon Sep 17 00:00:00 2001 From: halx99 Date: Wed, 20 May 2026 11:27:57 +0800 Subject: [PATCH 19/52] up --- axmol/ui/UIInputField.cpp | 16 ----- axmol/ui/UIInputField.h | 58 +++---------------- .../UITextFieldTest/UIInputFieldTest.cpp | 1 - 3 files changed, 9 insertions(+), 66 deletions(-) diff --git a/axmol/ui/UIInputField.cpp b/axmol/ui/UIInputField.cpp index a3885d63f87e..599d2fa382ca 100644 --- a/axmol/ui/UIInputField.cpp +++ b/axmol/ui/UIInputField.cpp @@ -679,22 +679,6 @@ void InputField::setPlaceholderColor(const Color32& color) // properties ////////////////////////////////////////////////////////////////////////// -void InputField::setMultilineEnabled(bool enabled) -{ - if (_multilineEnabled == enabled) - return; - - _multilineEnabled = enabled; -} - -void InputField::setAutoWrap(bool enabled) { - if (_autoWrap == enabled || !_multilineEnabled) - return; - - _autoWrap = enabled; - _renderLabel->setLineBreakWithoutSpace(_autoWrap); -} - Node* InputField::getRenderNode() { return _renderLabel; diff --git a/axmol/ui/UIInputField.h b/axmol/ui/UIInputField.h index dc4efa5f3298..8024ef43e36c 100644 --- a/axmol/ui/UIInputField.h +++ b/axmol/ui/UIInputField.h @@ -38,8 +38,15 @@ namespace ui { /** -@brief Modern editable text input implementation used by ui::InputField. -*/ + * @brief Editable text input widget for UI. + * + * InputField provides a modern implementation of editable text input + * within the UI system. It supports text entry, cursor management, + * selection handling, and integration with the platform IME (Input Method Editor). + * + * This class is the base component for single-line input fields, and can be + * extended or configured to support multiline input scenarios. + */ class AX_DLL InputField : public Widget, public IMEDelegate { public: @@ -371,50 +378,6 @@ class AX_DLL InputField : public Widget, public IMEDelegate */ Vec2 getPreferredSize() const override; - /** - * @brief Enable or disable multiline text rendering. - * - * When enabled, the label will allow line breaks even without spaces, - * effectively supporting multiline display. When disabled, the label - * will restrict text to a single line. - * - * @param enabled True to enable multiline rendering, false to disable. - */ - void setMultilineEnabled(bool enabled); - - /** - * @brief Check whether multiline text rendering is enabled. - * - * @return True if multiline rendering is enabled, false otherwise. - */ - bool isMultilineEnabled() const { return _multilineEnabled; } - - /** - * @brief Enable or disable automatic line wrapping. - * - * When enabled, the label will automatically wrap text to the next line - * once it exceeds the defined dimensions. Wrapping is performed at the - * character level. - * - * @param enabled True to enable automatic wrapping, false to keep text on a single line. - */ - void setAutoWrap(bool enabled); - - /** - * @brief Check whether automatic line wrapping is enabled. - * - * When enabled, the label will automatically wrap text to the next line - * once it exceeds the defined dimensions. Wrapping is performed at the - * character level, meaning line breaks can occur even without spaces. - * - * @return True if automatic wrapping is enabled, false otherwise. - * - * @note This setting only takes effect when multiline mode is enabled - * (see setMultilineEnabled). If multiline is disabled, auto wrap - * will be ignored and text will remain on a single line. - */ - bool isAutoWrap() const { return _autoWrap; } - /** * @brief InputField event types - follows TextField's design for consistency. */ @@ -573,9 +536,6 @@ class AX_DLL InputField : public Widget, public IMEDelegate bool _shiftKeyPressed{false}; bool _useTouchArea{false}; - bool _multilineEnabled{false}; - bool _autoWrap{false}; - // Continuous touch delay state (manual timing, no external timer dependency) bool _continuousTouchPending{false}; float _continuousTouchElapsedTime{0.0f}; diff --git a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextFieldTest/UIInputFieldTest.cpp b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextFieldTest/UIInputFieldTest.cpp index 81538248ba70..0ef8e43f014d 100644 --- a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextFieldTest/UIInputFieldTest.cpp +++ b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextFieldTest/UIInputFieldTest.cpp @@ -232,7 +232,6 @@ bool UIInputFieldTest_LineWrap::init() // Create the inputfield InputField* inputField = InputField::create("input words here", "fonts/Marker Felt.ttf", 30); - inputField->setMultilineEnabled(true); inputField->setAutoSize(false); inputField->setContentSize(Vec2(240.0f, 170.0f)); inputField->setString("input words here"); From d2aff1905bdd164c5189f5217c7fee1f2c334a42 Mon Sep 17 00:00:00 2001 From: axmol-bot <116471739+axmol-bot@users.noreply.github.com> Date: Wed, 20 May 2026 03:29:49 +0000 Subject: [PATCH 20/52] Committing clang-format changes --- axmol/platform/desktop/RenderViewImpl.cpp | 3 +- axmol/ui/UIButton.cpp | 18 +- axmol/ui/UIInputField.cpp | 11 +- axmol/ui/UISlider.cpp | 9 +- .../src/sceneio/ActionTimeline/CSLoader.cpp | 6 +- .../TextFieldReader/TextFieldExReader.cpp | 2 +- .../TextFieldReader/TextFieldReader.cpp | 4 +- .../src/sceneio/WidgetReader/WidgetReader.h | 2 +- .../manual/ui/axlua_ui_manual.cpp | 2 +- .../UITextFieldTest/UIInputFieldTest.cpp | 193 +++++++++--------- 10 files changed, 128 insertions(+), 122 deletions(-) diff --git a/axmol/platform/desktop/RenderViewImpl.cpp b/axmol/platform/desktop/RenderViewImpl.cpp index e9c53de52521..4e026bd81453 100644 --- a/axmol/platform/desktop/RenderViewImpl.cpp +++ b/axmol/platform/desktop/RenderViewImpl.cpp @@ -1447,7 +1447,8 @@ void RenderViewImpl::onGLFWCharCallback(GLFWwindow* /*window*/, unsigned int cha // Check for send control key if (controlUnicode.find(utf8String) == controlUnicode.end()) { - IMEDispatcher::sharedDispatcher()->dispatchInsertText(utf8String.c_str(), static_cast(utf8String.size())); + IMEDispatcher::sharedDispatcher()->dispatchInsertText(utf8String.c_str(), + static_cast(utf8String.size())); } } diff --git a/axmol/ui/UIButton.cpp b/axmol/ui/UIButton.cpp index 0b57583f0a93..cd40134bb92b 100644 --- a/axmol/ui/UIButton.cpp +++ b/axmol/ui/UIButton.cpp @@ -215,11 +215,11 @@ void Button::setScale9Enabled(bool able) { bool autoSizeBefore = _autoSize; // When enabling scale9, we often switch to fixed size mode if it was adapting, - // or keep state. The original code forced disabled autoSize (ignoreContentAdaptWithSize(true) in old terms meant adapt, false meant fixed? - // Wait, old ignoreContentAdaptWithSize(true) meant "ignore content size" -> use custom size? - // In Cocos2d-x/UI: ignoreContentAdaptWithSize(true) usually means the widget resizes to its content. - // Let's look at original: setAutoSize(false) was called. - // In new API: setAutoSize(false) means "Do NOT adapt to content" -> Fixed Size. + // or keep state. The original code forced disabled autoSize (ignoreContentAdaptWithSize(true) in old terms + // meant adapt, false meant fixed? Wait, old ignoreContentAdaptWithSize(true) meant "ignore content size" -> use + // custom size? In Cocos2d-x/UI: ignoreContentAdaptWithSize(true) usually means the widget resizes to its + // content. Let's look at original: setAutoSize(false) was called. In new API: setAutoSize(false) means "Do NOT + // adapt to content" -> Fixed Size. // Original: // bool autoSizeBefore = _autoSize; // true if adapting @@ -300,10 +300,10 @@ void Button::setAutoSize(bool autoSize) // If scale9 is enabled and we want to disable autoSize (fixed size), // we might need to handle it differently or just allow Widget to handle it if supported. // In original code, ignoreContentAdaptWithSize(false) [which means fixed size] was blocked if scale9 enabled. - // Here we strictly follow the prompt's reference logic which implies allowing it only if (!scale9 || (scale9 && autoSize)). - // If we reach here, it means scale9 is enabled AND autoSize is false. - // The reference code doesn't explicitly call Widget::setAutoSize in this branch, - // effectively preventing disabling autoSize when scale9 is on, similar to original logic. + // Here we strictly follow the prompt's reference logic which implies allowing it only if (!scale9 || (scale9 && + // autoSize)). If we reach here, it means scale9 is enabled AND autoSize is false. The reference code doesn't + // explicitly call Widget::setAutoSize in this branch, effectively preventing disabling autoSize when scale9 is + // on, similar to original logic. // However, usually we should still update state or log if ignored. // For strict replacement based on reference: diff --git a/axmol/ui/UIInputField.cpp b/axmol/ui/UIInputField.cpp index 599d2fa382ca..dbec283b87fa 100644 --- a/axmol/ui/UIInputField.cpp +++ b/axmol/ui/UIInputField.cpp @@ -613,7 +613,7 @@ void InputField::handleDeleteKeyEvent() return; } - auto nextByteIndex = getByteOffset(_cursorCharIndex + 1); + auto nextByteIndex = getByteOffset(_cursorCharIndex + 1); auto deleteLen = nextByteIndex - _cursorByteIndex; // if all text deleted, show placeholder string @@ -695,9 +695,9 @@ void InputField::setString(std::string_view text) _layoutDirty = true; auto oldInsertCharIndex = static_cast(_cursorCharIndex); - bool bInsertAtEnd = (oldInsertCharIndex == static_cast(_charCount)); - _inputText = text; - auto newCharCount = text_utils::countUTF8Chars(_inputText); + bool bInsertAtEnd = (oldInsertCharIndex == static_cast(_charCount)); + _inputText = text; + auto newCharCount = text_utils::countUTF8Chars(_inputText); std::string secureText; @@ -738,8 +738,7 @@ void InputField::setString(std::string_view text) } else { - setCursorPosition((std::min)(oldInsertCharIndex, static_cast(_charCount)), - hasSelection()); + setCursorPosition((std::min)(oldInsertCharIndex, static_cast(_charCount)), hasSelection()); } _selectionStart = (std::min)(_selectionStart, static_cast(_charCount)); diff --git a/axmol/ui/UISlider.cpp b/axmol/ui/UISlider.cpp index ccd1c21c00c9..adf2cc25e2fa 100644 --- a/axmol/ui/UISlider.cpp +++ b/axmol/ui/UISlider.cpp @@ -194,11 +194,10 @@ void Slider::loadBarTexture(SpriteFrame* spriteframe) void Slider::setupBarTexture() { - _barRendererAdaptDirty = true; _progressBarRendererDirty = true; - _barTextureSize = _barRenderer->getContentSize(); - _originalBarRect = _barRenderer->getTextureRect(); + _barTextureSize = _barRenderer->getContentSize(); + _originalBarRect = _barRenderer->getTextureRect(); updateChildrenDisplayedRGBA(); updateContentSize(); @@ -604,7 +603,7 @@ void Slider::barRendererScaleChangedWithSize() _barLength = _contentSize.width; _barRenderer->setContentSize(_contentSize); } - else if (!_autoSize) // Previously isIgnoreContentAdaptWithSize() + else if (!_autoSize) // Previously isIgnoreContentAdaptWithSize() { _barRenderer->setScale(1.0f); @@ -644,7 +643,7 @@ void Slider::progressBarRendererScaleChangedWithSize() { _progressBarRenderer->setContentSize(_contentSize); } - else if (!_autoSize) // Previously isIgnoreContentAdaptWithSize() + else if (!_autoSize) // Previously isIgnoreContentAdaptWithSize() { if (!_scale9Enabled) { diff --git a/extensions/sceneio/src/sceneio/ActionTimeline/CSLoader.cpp b/extensions/sceneio/src/sceneio/ActionTimeline/CSLoader.cpp index a79a9c386ff3..e8c81b48041a 100644 --- a/extensions/sceneio/src/sceneio/ActionTimeline/CSLoader.cpp +++ b/extensions/sceneio/src/sceneio/ActionTimeline/CSLoader.cpp @@ -1273,9 +1273,9 @@ bool CSLoader::isWidget(std::string_view type) return (type == ClassName_Panel || type == ClassName_Button || type == ClassName_CheckBox || type == ClassName_ImageView || type == ClassName_TextAtlas || type == ClassName_LabelAtlas || type == ClassName_LabelBMFont || type == ClassName_TextBMFont || type == ClassName_Text || - type == ClassName_LoadingBar || type == ClassName_Slider || - type == ClassName_Layout || type == ClassName_ScrollView || type == ClassName_ListView || - type == ClassName_PageView || type == ClassName_Widget || type == ClassName_Label); + type == ClassName_LoadingBar || type == ClassName_Slider || type == ClassName_Layout || + type == ClassName_ScrollView || type == ClassName_ListView || type == ClassName_PageView || + type == ClassName_Widget || type == ClassName_Label); } bool CSLoader::isCustomWidget(std::string_view type) diff --git a/extensions/sceneio/src/sceneio/WidgetReader/TextFieldReader/TextFieldExReader.cpp b/extensions/sceneio/src/sceneio/WidgetReader/TextFieldReader/TextFieldExReader.cpp index d768b8a1386a..b54725138a57 100644 --- a/extensions/sceneio/src/sceneio/WidgetReader/TextFieldReader/TextFieldExReader.cpp +++ b/extensions/sceneio/src/sceneio/WidgetReader/TextFieldReader/TextFieldExReader.cpp @@ -291,7 +291,7 @@ Offset
TextFieldExReader::createOptionsWithFlatBuffers(pugi::xml_node obj void TextFieldExReader::setPropsWithFlatBuffers(ax::Node* node, const flatbuffers::Table* textFieldOptions) { InputField** pTextField = (InputField**)(node); - auto options = (TextFieldExOptions*)textFieldOptions; + auto options = (TextFieldExOptions*)textFieldOptions; std::string placeholder = options->placeholderText()->c_str(); diff --git a/extensions/sceneio/src/sceneio/WidgetReader/TextFieldReader/TextFieldReader.cpp b/extensions/sceneio/src/sceneio/WidgetReader/TextFieldReader/TextFieldReader.cpp index 4e559b64ddca..30f862a83c5a 100644 --- a/extensions/sceneio/src/sceneio/WidgetReader/TextFieldReader/TextFieldReader.cpp +++ b/extensions/sceneio/src/sceneio/WidgetReader/TextFieldReader/TextFieldReader.cpp @@ -137,7 +137,7 @@ void TextFieldReader::setPropsFromJsonDictionary(Widget* widget, const rapidjson WidgetReader::setPropsFromJsonDictionary(widget, options); InputField* textField = static_cast(widget); - bool ph = DICTOOL->checkObjectExist_json(options, P_PlaceHolder); + bool ph = DICTOOL->checkObjectExist_json(options, P_PlaceHolder); if (ph) { textField->setPlaceholderText(DICTOOL->getStringValue_json(options, P_PlaceHolder, "input words here")); @@ -308,7 +308,7 @@ Offset
TextFieldReader::createOptionsWithFlatBuffers(pugi::xml_node objec void TextFieldReader::setPropsWithFlatBuffers(ax::Node* node, const flatbuffers::Table* textFieldOptions) { InputField* textField = static_cast(node); - auto options = (TextFieldOptions*)textFieldOptions; + auto options = (TextFieldOptions*)textFieldOptions; std::string placeholder = options->placeHolder()->c_str(); textField->setPlaceholderText(placeholder); diff --git a/extensions/sceneio/src/sceneio/WidgetReader/WidgetReader.h b/extensions/sceneio/src/sceneio/WidgetReader/WidgetReader.h index f8f74acc2eb3..4e3531f6d828 100644 --- a/extensions/sceneio/src/sceneio/WidgetReader/WidgetReader.h +++ b/extensions/sceneio/src/sceneio/WidgetReader/WidgetReader.h @@ -139,7 +139,7 @@ extern const char* P_Path; #define AX_BASIC_PROPERTY_BINARY_READER \ if (key == P_IgnoreSize) \ { \ - widget->setAutoSize(!valueToBool(value)); \ + widget->setAutoSize(!valueToBool(value)); \ } \ else if (key == P_SizeType) \ { \ diff --git a/extensions/scripting/lua-bindings/manual/ui/axlua_ui_manual.cpp b/extensions/scripting/lua-bindings/manual/ui/axlua_ui_manual.cpp index 44456f63f6cc..e42f878212c8 100644 --- a/extensions/scripting/lua-bindings/manual/ui/axlua_ui_manual.cpp +++ b/extensions/scripting/lua-bindings/manual/ui/axlua_ui_manual.cpp @@ -470,7 +470,7 @@ static int axlua_InputField_addEventListener(lua_State* L) if (nullptr == L) return 0; - int argc = 0; + int argc = 0; InputField* self = nullptr; #if _AX_DEBUG >= 1 diff --git a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextFieldTest/UIInputFieldTest.cpp b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextFieldTest/UIInputFieldTest.cpp index 0ef8e43f014d..a14d271e37a0 100644 --- a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextFieldTest/UIInputFieldTest.cpp +++ b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextFieldTest/UIInputFieldTest.cpp @@ -70,19 +70,20 @@ bool UIInputFieldTest::init() // Set up event listener for InputField inputField->addEventListener([this](InputField* sender, InputField::EventType type) { - switch (type) { - case InputField::EventType::ATTACH_WITH_IME: - _displayValueLabel->setString("attach with IME"); - break; - case InputField::EventType::DETACH_WITH_IME: - _displayValueLabel->setString("detach with IME"); - break; - case InputField::EventType::INSERT_TEXT: - _displayValueLabel->setString("insert words"); - break; - case InputField::EventType::DELETE_BACKWARD: - _displayValueLabel->setString("delete word"); - break; + switch (type) + { + case InputField::EventType::ATTACH_WITH_IME: + _displayValueLabel->setString("attach with IME"); + break; + case InputField::EventType::DETACH_WITH_IME: + _displayValueLabel->setString("detach with IME"); + break; + case InputField::EventType::INSERT_TEXT: + _displayValueLabel->setString("insert words"); + break; + case InputField::EventType::DELETE_BACKWARD: + _displayValueLabel->setString("delete word"); + break; } }); @@ -126,19 +127,20 @@ bool UIInputFieldTest_MaxLength::init() // Set up event listener for InputField inputField->addEventListener([this, inputField](InputField* sender, InputField::EventType type) { - switch (type) { - case InputField::EventType::ATTACH_WITH_IME: - _displayValueLabel->setString(fmt::format("attach with IME max length {}", inputField->getCharLimit())); - break; - case InputField::EventType::DETACH_WITH_IME: - _displayValueLabel->setString(fmt::format("detach with IME max length {}", inputField->getCharLimit())); - break; - case InputField::EventType::INSERT_TEXT: - _displayValueLabel->setString(fmt::format("insert words max length {}", inputField->getCharLimit())); - break; - case InputField::EventType::DELETE_BACKWARD: - _displayValueLabel->setString(fmt::format("delete word max length {}", inputField->getCharLimit())); - break; + switch (type) + { + case InputField::EventType::ATTACH_WITH_IME: + _displayValueLabel->setString(fmt::format("attach with IME max length {}", inputField->getCharLimit())); + break; + case InputField::EventType::DETACH_WITH_IME: + _displayValueLabel->setString(fmt::format("detach with IME max length {}", inputField->getCharLimit())); + break; + case InputField::EventType::INSERT_TEXT: + _displayValueLabel->setString(fmt::format("insert words max length {}", inputField->getCharLimit())); + break; + case InputField::EventType::DELETE_BACKWARD: + _displayValueLabel->setString(fmt::format("delete word max length {}", inputField->getCharLimit())); + break; } }); @@ -182,19 +184,20 @@ bool UIInputFieldTest_Password::init() // Set up event listener for InputField inputField->addEventListener([this](InputField* sender, InputField::EventType type) { - switch (type) { - case InputField::EventType::ATTACH_WITH_IME: - _displayValueLabel->setString("attach with IME password"); - break; - case InputField::EventType::DETACH_WITH_IME: - _displayValueLabel->setString("detach with IME password"); - break; - case InputField::EventType::INSERT_TEXT: - _displayValueLabel->setString("insert words password"); - break; - case InputField::EventType::DELETE_BACKWARD: - _displayValueLabel->setString("delete word password"); - break; + switch (type) + { + case InputField::EventType::ATTACH_WITH_IME: + _displayValueLabel->setString("attach with IME password"); + break; + case InputField::EventType::DETACH_WITH_IME: + _displayValueLabel->setString("detach with IME password"); + break; + case InputField::EventType::INSERT_TEXT: + _displayValueLabel->setString("insert words password"); + break; + case InputField::EventType::DELETE_BACKWARD: + _displayValueLabel->setString("delete word password"); + break; } }); @@ -241,19 +244,20 @@ bool UIInputFieldTest_LineWrap::init() // Set up event listener for InputField inputField->addEventListener([this](InputField* sender, InputField::EventType type) { - switch (type) { - case InputField::EventType::ATTACH_WITH_IME: - _displayValueLabel->setString("attach with IME"); - break; - case InputField::EventType::DETACH_WITH_IME: - _displayValueLabel->setString("detach with IME"); - break; - case InputField::EventType::INSERT_TEXT: - _displayValueLabel->setString("insert words"); - break; - case InputField::EventType::DELETE_BACKWARD: - _displayValueLabel->setString("delete word"); - break; + switch (type) + { + case InputField::EventType::ATTACH_WITH_IME: + _displayValueLabel->setString("attach with IME"); + break; + case InputField::EventType::DETACH_WITH_IME: + _displayValueLabel->setString("detach with IME"); + break; + case InputField::EventType::INSERT_TEXT: + _displayValueLabel->setString("insert words"); + break; + case InputField::EventType::DELETE_BACKWARD: + _displayValueLabel->setString("delete word"); + break; } }); @@ -295,19 +299,20 @@ bool UIInputFieldTest_TrueTypeFont::init() // Set up event listener for InputField inputField->addEventListener([this](InputField* sender, InputField::EventType type) { - switch (type) { - case InputField::EventType::ATTACH_WITH_IME: - _displayValueLabel->setString("attach with IME"); - break; - case InputField::EventType::DETACH_WITH_IME: - _displayValueLabel->setString("detach with IME"); - break; - case InputField::EventType::INSERT_TEXT: - _displayValueLabel->setString("insert words"); - break; - case InputField::EventType::DELETE_BACKWARD: - _displayValueLabel->setString("delete word"); - break; + switch (type) + { + case InputField::EventType::ATTACH_WITH_IME: + _displayValueLabel->setString("attach with IME"); + break; + case InputField::EventType::DETACH_WITH_IME: + _displayValueLabel->setString("detach with IME"); + break; + case InputField::EventType::INSERT_TEXT: + _displayValueLabel->setString("insert words"); + break; + case InputField::EventType::DELETE_BACKWARD: + _displayValueLabel->setString("delete word"); + break; } }); @@ -349,19 +354,20 @@ bool UIInputFieldTest_BMFont::init() // Set up event listener for InputField inputField->addEventListener([this](InputField* sender, InputField::EventType type) { - switch (type) { - case InputField::EventType::ATTACH_WITH_IME: - _displayValueLabel->setString("attach with IME"); - break; - case InputField::EventType::DETACH_WITH_IME: - _displayValueLabel->setString("detach with IME"); - break; - case InputField::EventType::INSERT_TEXT: - _displayValueLabel->setString("insert words"); - break; - case InputField::EventType::DELETE_BACKWARD: - _displayValueLabel->setString("delete word"); - break; + switch (type) + { + case InputField::EventType::ATTACH_WITH_IME: + _displayValueLabel->setString("attach with IME"); + break; + case InputField::EventType::DETACH_WITH_IME: + _displayValueLabel->setString("detach with IME"); + break; + case InputField::EventType::INSERT_TEXT: + _displayValueLabel->setString("insert words"); + break; + case InputField::EventType::DELETE_BACKWARD: + _displayValueLabel->setString("delete word"); + break; } }); @@ -408,21 +414,22 @@ bool UIInputFieldTest_PlaceHolderColor::init() // Set up event listener for InputField inputField->addEventListener([this, inputField](InputField* sender, InputField::EventType type) { - switch (type) { - case InputField::EventType::ATTACH_WITH_IME: - _displayValueLabel->setString("attach with IME"); - break; - case InputField::EventType::DETACH_WITH_IME: - _displayValueLabel->setString("detach with IME"); - break; - case InputField::EventType::INSERT_TEXT: - _displayValueLabel->setString("text modified"); - AXLOGD("{}, {}", inputField->getContentSize().width, inputField->getContentSize().height); - break; - case InputField::EventType::DELETE_BACKWARD: - _displayValueLabel->setString("text modified"); - AXLOGD("{}, {}", inputField->getContentSize().width, inputField->getContentSize().height); - break; + switch (type) + { + case InputField::EventType::ATTACH_WITH_IME: + _displayValueLabel->setString("attach with IME"); + break; + case InputField::EventType::DETACH_WITH_IME: + _displayValueLabel->setString("detach with IME"); + break; + case InputField::EventType::INSERT_TEXT: + _displayValueLabel->setString("text modified"); + AXLOGD("{}, {}", inputField->getContentSize().width, inputField->getContentSize().height); + break; + case InputField::EventType::DELETE_BACKWARD: + _displayValueLabel->setString("text modified"); + AXLOGD("{}, {}", inputField->getContentSize().width, inputField->getContentSize().height); + break; } }); From d95931b0f923b6432c8deb58b23b40fc3b813f23 Mon Sep 17 00:00:00 2001 From: halx99 Date: Wed, 20 May 2026 12:07:53 +0800 Subject: [PATCH 21/52] fix reviews --- axmol/ui/UIWidget.cpp | 8 +- .../sceneext/src/sceneext/SGUIReader.cpp | 3 +- .../src/sceneio/WidgetReader/WidgetReader.cpp | 3 +- tests/cpp-tests/CMakeLists.txt | 4 +- tests/cpp-tests/Source/BugsTest/Bug-12847.cpp | 11 +- tests/cpp-tests/Source/BugsTest/Bug-12847.h | 5 +- tests/cpp-tests/Source/BugsTest/Bug-14327.cpp | 9 - tests/cpp-tests/Source/BugsTest/Bug-14327.h | 5 +- tests/cpp-tests/Source/BugsTest/Bug-15594.cpp | 8 +- tests/cpp-tests/Source/BugsTest/Bug-15594.h | 5 +- tests/cpp-tests/Source/BugsTest/Bug-15776.cpp | 8 - tests/cpp-tests/Source/BugsTest/Bug-15776.h | 13 +- tests/cpp-tests/Source/BugsTest/Bug-Child.h | 13 +- .../SpritePolygonTest/SpritePolygonTest.h | 4 +- .../Source/TextInputTest/TextInputTest.cpp | 430 ------------------ .../Source/TextInputTest/TextInputTest.h | 131 ------ .../CocoStudioGUITest/CocosGUIScene.cpp | 2 +- .../UITest/CocoStudioGUITest/UIEditBoxTest.h | 5 +- .../UIFocusTest/UIFocusTest.cpp | 8 - .../UIFocusTest/UIFocusTest.h | 13 +- .../UIInputFieldTest.cpp | 0 .../UIInputFieldTest.h | 0 .../CocoStudioGUITest/UIScale9SpriteTest.h | 5 +- .../UIWebViewTest/UIWebViewTest.h | 5 +- tests/cpp-tests/Source/UITest/UITest.h | 5 +- 25 files changed, 20 insertions(+), 683 deletions(-) delete mode 100644 tests/cpp-tests/Source/TextInputTest/TextInputTest.cpp delete mode 100644 tests/cpp-tests/Source/TextInputTest/TextInputTest.h rename tests/cpp-tests/Source/UITest/CocoStudioGUITest/{UITextFieldTest => UIInputFieldTest}/UIInputFieldTest.cpp (100%) rename tests/cpp-tests/Source/UITest/CocoStudioGUITest/{UITextFieldTest => UIInputFieldTest}/UIInputFieldTest.h (100%) diff --git a/axmol/ui/UIWidget.cpp b/axmol/ui/UIWidget.cpp index 2990554a51cb..165af43a4559 100644 --- a/axmol/ui/UIWidget.cpp +++ b/axmol/ui/UIWidget.cpp @@ -343,13 +343,9 @@ void Widget::setSizePercent(const Vec2& percent) } } if (_autoSize) - { - ProtectedNode::setContentSize(getPreferredSize()); - } + setContentSize(getPreferredSize()); else - { - ProtectedNode::setContentSize(cSize); - } + setContentSize(cSize); _customSize = cSize; } diff --git a/extensions/sceneext/src/sceneext/SGUIReader.cpp b/extensions/sceneext/src/sceneext/SGUIReader.cpp index d237378d0f76..e741b3ee39a4 100644 --- a/extensions/sceneext/src/sceneext/SGUIReader.cpp +++ b/extensions/sceneext/src/sceneext/SGUIReader.cpp @@ -597,8 +597,7 @@ void WidgetPropertiesReader0250::setPropsForWidgetFromJsonDictionary(Widget* wid bool ignoreSizeExsit = DICTOOL->checkObjectExist_json(options, "ignoreSize"); if (ignoreSizeExsit) { - // ignoreSize=true means fixed size, so setAutoSize=false - widget->setAutoSize(!DICTOOL->getBooleanValue_json(options, "ignoreSize")); + widget->setAutoSize(DICTOOL->getBooleanValue_json(options, "ignoreSize")); } float w = DICTOOL->getFloatValue_json(options, "width"); diff --git a/extensions/sceneio/src/sceneio/WidgetReader/WidgetReader.cpp b/extensions/sceneio/src/sceneio/WidgetReader/WidgetReader.cpp index 21e13ba43eca..099cd2726da4 100644 --- a/extensions/sceneio/src/sceneio/WidgetReader/WidgetReader.cpp +++ b/extensions/sceneio/src/sceneio/WidgetReader/WidgetReader.cpp @@ -134,8 +134,7 @@ void WidgetReader::setPropsFromJsonDictionary(Widget* widget, const rapidjson::V bool ignoreSizeExsit = DICTOOL->checkObjectExist_json(options, P_IgnoreSize); if (ignoreSizeExsit) { - // ignoreSize=true means fixed size, so setAutoSize=false - widget->setAutoSize(!DICTOOL->getBooleanValue_json(options, P_IgnoreSize)); + widget->setAutoSize(DICTOOL->getBooleanValue_json(options, P_IgnoreSize)); } widget->setSizeType((Widget::SizeType)DICTOOL->getIntValue_json(options, P_SizeType)); diff --git a/tests/cpp-tests/CMakeLists.txt b/tests/cpp-tests/CMakeLists.txt index 062c7ff8c2a6..6eb03f34d981 100644 --- a/tests/cpp-tests/CMakeLists.txt +++ b/tests/cpp-tests/CMakeLists.txt @@ -207,7 +207,7 @@ list(APPEND GAME_HEADER Source/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest.h Source/UITest/CocoStudioGUITest/UIFocusTest/UIFocusTest.h Source/UITest/CocoStudioGUITest/UITextTest/UITextTest.h - Source/UITest/CocoStudioGUITest/UITextFieldTest/UIInputFieldTest.h + Source/UITest/CocoStudioGUITest/UIInputFieldTest/UIInputFieldTest.h Source/BillBoardTest/BillBoardTest.h Source/SpriteFrameCacheTest/SpriteFrameCacheTest.h Source/EffectsAdvancedTest/EffectsAdvancedTest.h @@ -342,7 +342,7 @@ list(APPEND GAME_SOURCE Source/UITest/CocoStudioGUITest/UITextTest/UITextTest.cpp Source/UITest/CocoStudioGUITest/UIWidgetAddNodeTest/UIWidgetAddNodeTest.cpp Source/UITest/CocoStudioGUITest/UITabControlTest/UITabControlTest.cpp - Source/UITest/CocoStudioGUITest/UITextFieldTest/UIInputFieldTest.cpp + Source/UITest/CocoStudioGUITest/UIInputFieldTest/UIInputFieldTest.cpp Source/UITest/UITest.cpp Source/UserDefaultTest/UserDefaultTest.cpp Source/VisibleRect.cpp diff --git a/tests/cpp-tests/Source/BugsTest/Bug-12847.cpp b/tests/cpp-tests/Source/BugsTest/Bug-12847.cpp index 6feb3730eab4..4ae144070cc2 100644 --- a/tests/cpp-tests/Source/BugsTest/Bug-12847.cpp +++ b/tests/cpp-tests/Source/BugsTest/Bug-12847.cpp @@ -22,15 +22,6 @@ THE SOFTWARE. ****************************************************************************/ -// -// Bug-12847.cpp -// cocos2d_tests -// -// Issue: https://github.com/cocos2d/cocos2d-x/issues/12847 -// Please test in iPhone5 + -// -// - #include "Bug-12847.h" using namespace ax; @@ -104,4 +95,4 @@ void Bug12847Layer::onExit() { Director::getInstance()->setClearColor(Color::BLACK); BugsTestBase::onExit(); -} \ No newline at end of file +} diff --git a/tests/cpp-tests/Source/BugsTest/Bug-12847.h b/tests/cpp-tests/Source/BugsTest/Bug-12847.h index 6d903483efc9..39208688d0d7 100644 --- a/tests/cpp-tests/Source/BugsTest/Bug-12847.h +++ b/tests/cpp-tests/Source/BugsTest/Bug-12847.h @@ -22,8 +22,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef __cocos2d_tests__Bug_12847__ -#define __cocos2d_tests__Bug_12847__ +#pragma once #include "BugsTest.h" @@ -51,5 +50,3 @@ class Bug12847Layer : public BugsTestBase ax::Director::Projection _projection = ax::Director::Projection::_3D; }; - -#endif /* defined(__cocos2d_tests__Bug_12847__) */ diff --git a/tests/cpp-tests/Source/BugsTest/Bug-14327.cpp b/tests/cpp-tests/Source/BugsTest/Bug-14327.cpp index a5a8bcc25106..7355c50e0cd9 100644 --- a/tests/cpp-tests/Source/BugsTest/Bug-14327.cpp +++ b/tests/cpp-tests/Source/BugsTest/Bug-14327.cpp @@ -23,15 +23,6 @@ THE SOFTWARE. ****************************************************************************/ -// -// Bug-14327.cpp -// cocos2d_tests -// -// Issue: https://github.com/cocos2d/cocos2d-x/pull/14327 -// Please test in Windows -// -// - #include "Bug-14327.h" #include "axmol/tlx/format.hpp" diff --git a/tests/cpp-tests/Source/BugsTest/Bug-14327.h b/tests/cpp-tests/Source/BugsTest/Bug-14327.h index 09395ccc2a85..2c61c271481c 100644 --- a/tests/cpp-tests/Source/BugsTest/Bug-14327.h +++ b/tests/cpp-tests/Source/BugsTest/Bug-14327.h @@ -22,8 +22,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef __cocos2d_tests__Bug_14327__ -#define __cocos2d_tests__Bug_14327__ +#pragma once #include "BugsTest.h" @@ -55,5 +54,3 @@ class Bug14327Layer : public BugsTestBase, public ax::ui::EditBoxDelegate }; #endif - -#endif /* defined(__cocos2d_tests__Bug_14327__) */ diff --git a/tests/cpp-tests/Source/BugsTest/Bug-15594.cpp b/tests/cpp-tests/Source/BugsTest/Bug-15594.cpp index 54091761edad..771108e837b2 100644 --- a/tests/cpp-tests/Source/BugsTest/Bug-15594.cpp +++ b/tests/cpp-tests/Source/BugsTest/Bug-15594.cpp @@ -22,13 +22,7 @@ THE SOFTWARE. ****************************************************************************/ -// -// Bug-15594.cpp -// cocos2d_tests -// -// Created by Ricardo Quesada on 5/24/16. -// -// +#pragma once // https://github.com/cocos2d/cocos2d-x/pull/15594 diff --git a/tests/cpp-tests/Source/BugsTest/Bug-15594.h b/tests/cpp-tests/Source/BugsTest/Bug-15594.h index 4127ff42fa6a..6ee225d54dd3 100644 --- a/tests/cpp-tests/Source/BugsTest/Bug-15594.h +++ b/tests/cpp-tests/Source/BugsTest/Bug-15594.h @@ -23,8 +23,7 @@ ****************************************************************************/ // https://github.com/cocos2d/cocos2d-x/pull/15594 -#ifndef __cocos2d_tests__Bug_15594__ -#define __cocos2d_tests__Bug_15594__ +#pragma once #include "BugsTest.h" @@ -36,5 +35,3 @@ class Bug15594Layer : public BugsTestBase virtual bool init() override; virtual std::string title() const override { return "Bug15594"; } }; - -#endif /* defined(__cocos2d_tests__Bug_15594__) */ diff --git a/tests/cpp-tests/Source/BugsTest/Bug-15776.cpp b/tests/cpp-tests/Source/BugsTest/Bug-15776.cpp index 1ea761129be3..836462a56a79 100644 --- a/tests/cpp-tests/Source/BugsTest/Bug-15776.cpp +++ b/tests/cpp-tests/Source/BugsTest/Bug-15776.cpp @@ -22,14 +22,6 @@ THE SOFTWARE. ****************************************************************************/ -// -// Bug-15776.cpp -// cocos2d_tests -// -// Created by Ricardo Quesada on 6/17/16. -// -// - #include "Bug-15776.h" using namespace ax; diff --git a/tests/cpp-tests/Source/BugsTest/Bug-15776.h b/tests/cpp-tests/Source/BugsTest/Bug-15776.h index 4b5a9c874e18..d6d8cf3eeb4b 100644 --- a/tests/cpp-tests/Source/BugsTest/Bug-15776.h +++ b/tests/cpp-tests/Source/BugsTest/Bug-15776.h @@ -22,16 +22,7 @@ THE SOFTWARE. ****************************************************************************/ -// -// Bug-15776.hpp -// cocos2d_tests -// -// Created by Ricardo Quesada on 6/17/16. -// -// - -#ifndef Bug_15776_hpp -#define Bug_15776_hpp +#pragma once #include "BugsTest.h" @@ -45,5 +36,3 @@ class Bug15776Layer : public BugsTestBase virtual std::string title() const override; virtual std::string subtitle() const override; }; - -#endif /* Bug_15776_hpp */ diff --git a/tests/cpp-tests/Source/BugsTest/Bug-Child.h b/tests/cpp-tests/Source/BugsTest/Bug-Child.h index ba980688b865..f4feb4e99f05 100644 --- a/tests/cpp-tests/Source/BugsTest/Bug-Child.h +++ b/tests/cpp-tests/Source/BugsTest/Bug-Child.h @@ -22,16 +22,7 @@ THE SOFTWARE. ****************************************************************************/ -// -// Bug-Child.h -// cocos2d_tests -// -// Created by NiTe Luo on 5/12/14. -// -// - -#ifndef __Bug_Child__ -#define __Bug_Child__ +#pragma once #include "BugsTest.h" @@ -67,5 +58,3 @@ class BugCameraMask : public BugsTestBase Node* _sprite; ax::Label* _spriteMaskLabel; }; - -#endif /* defined(__Bug_Child__) */ diff --git a/tests/cpp-tests/Source/SpritePolygonTest/SpritePolygonTest.h b/tests/cpp-tests/Source/SpritePolygonTest/SpritePolygonTest.h index ceba0b155776..f811e12a5106 100644 --- a/tests/cpp-tests/Source/SpritePolygonTest/SpritePolygonTest.h +++ b/tests/cpp-tests/Source/SpritePolygonTest/SpritePolygonTest.h @@ -22,7 +22,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef __cocos2d_tests__SpritePolygonTest__ +#pragma once # include "../BaseTest.h" # include "axmol/ui/CocosGUI.h" @@ -260,5 +260,3 @@ class SpritePolygonTestPerformance : public SpritePolygonTestDemo Ticker _contFast = Ticker(2); Ticker _around30fps = Ticker(60 * 3); }; - -#endif /* defined(__cocos2d_tests__SpritePolygonTest__) */ diff --git a/tests/cpp-tests/Source/TextInputTest/TextInputTest.cpp b/tests/cpp-tests/Source/TextInputTest/TextInputTest.cpp deleted file mode 100644 index 901cdcac3045..000000000000 --- a/tests/cpp-tests/Source/TextInputTest/TextInputTest.cpp +++ /dev/null @@ -1,430 +0,0 @@ -/**************************************************************************** - Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. - - https://axmol.dev/ - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ - -#include "TextInputTest.h" - -using namespace ax; - -#define FONT_NAME "fonts/Thonburi.ttf" -#define FONT_SIZE 36 - -TextInputTests::TextInputTests() -{ - ADD_TEST_CASE(TextFieldTTFDefaultTest); - ADD_TEST_CASE(TextFieldTTFActionTest); - ADD_TEST_CASE(TextFieldTTFSecureTextEntryTest); - ADD_TEST_CASE(TextFieldTTSetCursorFromPoint); -} - -static Rect getRect(Node* node) -{ - Rect rc; - rc.origin = node->getPosition(); - rc.size = node->getContentSize(); - rc.origin.x -= rc.size.width / 2; - rc.origin.y -= rc.size.height / 2; - return rc; -} - -std::string KeyboardNotificationLayer::title() const -{ - return "text input test"; -} - -////////////////////////////////////////////////////////////////////////// -// implement KeyboardNotificationLayer -////////////////////////////////////////////////////////////////////////// - -KeyboardNotificationLayer::KeyboardNotificationLayer() : _trackNode(0) -{ - // Register Touch Event - auto listener = EventListenerTouchOneByOne::create(); - listener->onTouchBegan = AX_CALLBACK_2(KeyboardNotificationLayer::onTouchBegan, this); - listener->onTouchEnded = AX_CALLBACK_2(KeyboardNotificationLayer::onTouchEnded, this); - _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); -} - -void KeyboardNotificationLayer::keyboardWillShow(IMEKeyboardNotificationInfo& info) -{ - AXLOGD("TextInputTest:keyboardWillShowAt(origin:{},{}, size:{},{})", info.end.origin.x, info.end.origin.y, - info.end.size.width, info.end.size.height); - - if (!_trackNode) - { - return; - } - - auto rectTracked = getRect(_trackNode); - AXLOGD("TextInputTest:trackingNodeAt(origin:{},{}, size:{},{})", rectTracked.origin.x, rectTracked.origin.y, - rectTracked.size.width, rectTracked.size.height); - - // if the keyboard area doesn't intersect with the tracking node area, nothing need to do. - if (!rectTracked.intersectsRect(info.end)) - { - return; - } - - // assume keyboard at the bottom of screen, calculate the vertical adjustment. - float adjustVert = info.end.getMaxY() - rectTracked.getMinY(); - AXLOGD("TextInputTest:needAdjustVerticalPosition({})", adjustVert); - - // move all the children node of KeyboardNotificationLayer - auto& children = getChildren(); - Node* node = 0; - ssize_t count = children.size(); - Vec2 pos; - for (int i = 0; i < count; ++i) - { - node = children.at(i); - pos = node->getPosition(); - pos.y += adjustVert; - node->setPosition(pos); - } -} - -// Layer function - -bool KeyboardNotificationLayer::onTouchBegan(Touch* touch, Event* event) -{ - AXLOGD("++++++++++++++++++++++++++++++++++++++++++++"); - _beginPos = touch->getLocation(); - return true; -} - -void KeyboardNotificationLayer::onTouchEnded(Touch* touch, Event* event) -{ - if (!_trackNode) - { - return; - } - - auto endPos = touch->getLocation(); - - float delta = 5.0f; - if (std::abs(endPos.x - _beginPos.x) > delta || std::abs(endPos.y - _beginPos.y) > delta) - { - // not click - _beginPos.x = _beginPos.y = -1; - return; - } - - // decide the trackNode is clicked. - Rect rect; - rect.size = _trackNode->getContentSize(); - auto clicked = - isScreenPointInRect(endPos, Camera::getVisitingCamera(), _trackNode->getWorldToNodeTransform(), rect, nullptr); - this->onClickTrackNode(clicked, endPos); - AXLOGD("----------------------------------"); -} - -////////////////////////////////////////////////////////////////////////// -// implement TextFieldTTFDefaultTest -////////////////////////////////////////////////////////////////////////// - -std::string TextFieldTTFDefaultTest::subtitle() const -{ - return "TextFieldTTF with default behavior test"; -} - -void TextFieldTTFDefaultTest::onClickTrackNode(bool bClicked, const Vec2& touchPos) -{ - auto pTextField = (TextFieldTTF*)_trackNode; - if (bClicked) - { - // TextFieldTTFTest be clicked - AXLOGD("TextFieldTTFDefaultTest:TextFieldTTF attachWithIME"); - pTextField->attachWithIME(); - } - else - { - // TextFieldTTFTest not be clicked - AXLOGD("TextFieldTTFDefaultTest:TextFieldTTF detachWithIME"); - pTextField->detachWithIME(); - } -} - -void TextFieldTTFDefaultTest::onEnter() -{ - KeyboardNotificationLayer::onEnter(); - - // add TextFieldTTF - auto s = Director::getInstance()->getCanvasSize(); - - auto pTextField = TextFieldTTF::textFieldWithPlaceHolder("", FONT_NAME, FONT_SIZE); - addChild(pTextField); - -#if (AX_TARGET_PLATFORM == AX_PLATFORM_ANDROID) - // on android, TextFieldTTF cannot auto adjust its position when soft-keyboard pop up - // so we had to set a higher position to make it visible - pTextField->setPosition(Vec2(s.width / 2, s.height / 2 + 50)); -#else - pTextField->setPosition(Vec2(s.width / 2, s.height / 2)); -#endif - - _trackNode = pTextField; -} - -////////////////////////////////////////////////////////////////////////// -// implement TextFieldTTFActionTest -////////////////////////////////////////////////////////////////////////// - -std::string TextFieldTTFActionTest::subtitle() const -{ - return "TextFieldTTF with action and char limit test"; -} - -void TextFieldTTFActionTest::onClickTrackNode(bool bClicked, const Vec2& touchPos) -{ - auto pTextField = (TextFieldTTF*)_trackNode; - if (bClicked) - { - // TextFieldTTFTest be clicked - AXLOGD("TextFieldTTFActionTest:TextFieldTTF attachWithIME"); - pTextField->attachWithIME(); - } - else - { - // TextFieldTTFTest not be clicked - AXLOGD("TextFieldTTFActionTest:TextFieldTTF detachWithIME"); - pTextField->detachWithIME(); - } -} - -void TextFieldTTFActionTest::onEnter() -{ - KeyboardNotificationLayer::onEnter(); - - _charLimit = 12; - - _textFieldAction = RepeatForever::create(Sequence::create(FadeOut::create(0.25), FadeIn::create(0.25), nullptr)); - _textFieldAction->retain(); - _action = false; - - // add TextFieldTTF - auto s = Director::getInstance()->getCanvasSize(); - - _textField = TextFieldTTF::textFieldWithPlaceHolder("", FONT_NAME, FONT_SIZE); - addChild(_textField); - - _textField->setDelegate(this); - -#if (AX_TARGET_PLATFORM == AX_PLATFORM_ANDROID) - // on android, TextFieldTTF cannot auto adjust its position when soft-keyboard pop up - // so we had to set a higher position - _textField->setPosition(Vec2(s.width / 2, s.height / 2 + 50)); -#else - _textField->setPosition(Vec2(s.width / 2, s.height / 2)); -#endif - - _trackNode = _textField; -} - -void TextFieldTTFActionTest::onExit() -{ - KeyboardNotificationLayer::onExit(); - _textFieldAction->release(); -} - -// TextFieldDelegate protocol -bool TextFieldTTFActionTest::onTextFieldAttachWithIME(TextFieldTTF* sender) -{ - if (!_action) - { - _textField->runAction(_textFieldAction); - _action = true; - } - return false; -} - -bool TextFieldTTFActionTest::onTextFieldDetachWithIME(TextFieldTTF* sender) -{ - if (_action) - { - _textField->stopAction(_textFieldAction); - _textField->setOpacity(255); - _action = false; - } - return false; -} - -bool TextFieldTTFActionTest::onTextFieldInsertText(TextFieldTTF* sender, const char* text, size_t nLen) -{ - // if insert enter, treat as default to detach with ime - if ('\n' == *text) - { - return false; - } - - // if the textfield's char count more than _charLimit, doesn't insert text anymore. - if (sender->getCharCount() >= _charLimit) - { - return true; - } - - // create a insert text sprite and do some action - auto label = Label::createWithSystemFont(text, FONT_NAME, FONT_SIZE); - this->addChild(label); - Color32 color(226, 121, 7); - label->setColor(color); - - // move the sprite from top to position - auto endPos = sender->getPosition(); - if (sender->getCharCount()) - { - endPos.x += sender->getContentSize().width / 2; - } - auto inputTextSize = label->getContentSize(); - Vec2 beginPos(endPos.x, Director::getInstance()->getCanvasSize().height - inputTextSize.height * 2); - - float duration = 0.5; - label->setPosition(beginPos); - label->setScale(8); - - auto seq = Sequence::create( - Spawn::create(MoveTo::create(duration, endPos), ScaleTo::create(duration, 1), FadeOut::create(duration), - nullptr), - CallFuncN::create(AX_CALLBACK_1(TextFieldTTFActionTest::callbackRemoveNodeWhenDidAction, this)), nullptr); - label->runAction(seq); - return false; -} - -bool TextFieldTTFActionTest::onTextFieldDeleteBackward(TextFieldTTF* sender, const char* delText, size_t nLen) -{ - // create a delete text sprite and do some action - auto label = Label::createWithSystemFont(delText, FONT_NAME, FONT_SIZE); - this->addChild(label); - - // move the sprite to fly out - auto beginPos = sender->getPosition(); - auto textfieldSize = sender->getContentSize(); - auto labelSize = label->getContentSize(); - beginPos.x += (textfieldSize.width - labelSize.width) / 2.0f; - - auto canvasSize = Director::getInstance()->getCanvasSize(); - Vec2 endPos(-canvasSize.width / 4.0f, canvasSize.height * (0.5 + (float)rand() / (2.0f * RAND_MAX))); - - float duration = 1; - float rotateDuration = 0.2f; - int repeatTime = 5; - label->setPosition(beginPos); - - auto seq = Sequence::create( - Spawn::create(MoveTo::create(duration, endPos), - Repeat::create(RotateBy::create(rotateDuration, (rand() % 2) ? 360 : -360), repeatTime), - FadeOut::create(duration), nullptr), - CallFuncN::create(AX_CALLBACK_1(TextFieldTTFActionTest::callbackRemoveNodeWhenDidAction, this)), nullptr); - label->runAction(seq); - return false; -} - -bool TextFieldTTFActionTest::onDraw(TextFieldTTF* sender) -{ - return false; -} - -void TextFieldTTFActionTest::callbackRemoveNodeWhenDidAction(Node* node) -{ - this->removeChild(node, true); -} - -////////////////////////////////////////////////////////////////////////// -// implement TextFieldTTFSecureTextEntryTest -////////////////////////////////////////////////////////////////////////// - -std::string TextFieldTTFSecureTextEntryTest::subtitle() const -{ - return "TextFieldTTF with SecureTextEntry test"; -} - -void TextFieldTTFSecureTextEntryTest::onEnter() -{ - KeyboardNotificationLayer::onEnter(); - - // add TextFieldTTF - auto s = Director::getInstance()->getCanvasSize(); - - auto pTextField = TextFieldTTF::textFieldWithPlaceHolder("", FONT_NAME, FONT_SIZE); - addChild(pTextField); - -#if (AX_TARGET_PLATFORM == AX_PLATFORM_ANDROID) - // on android, TextFieldTTF cannot auto adjust its position when soft-keyboard pop up - // so we had to set a higher position to make it visible - pTextField->setPosition(Vec2(s.width / 2, s.height / 2 + 50)); -#else - pTextField->setPosition(Vec2(s.width / 2, s.height / 2)); -#endif - pTextField->setSecureTextEntry(true); - - _trackNode = pTextField; -} - -////////////////////////////////////////////////////////////////////////// -// implement TextFieldTTSetCursorFromPoint -////////////////////////////////////////////////////////////////////////// - -std::string TextFieldTTSetCursorFromPoint::subtitle() const -{ - return "TextFieldTTF with setCursorFromPoint test"; -} - -void TextFieldTTSetCursorFromPoint::onClickTrackNode(bool bClicked, const Vec2& touchPos) -{ - auto pTextField = (TextFieldTTF*)_trackNode; - if (bClicked) - { - // TextFieldTTFTest be clicked - AXLOGD("TextFieldTTSetCursorFromPoint:TextFieldTTF attachWithIME"); - pTextField->attachWithIME(); - - // Set new position cursor - pTextField->setCursorFromPoint(touchPos, Camera::getVisitingCamera()); - } - else - { - // TextFieldTTFTest not be clicked - AXLOGD("TextFieldTTSetCursorFromPoint:TextFieldTTF detachWithIME"); - pTextField->detachWithIME(); - } -} - -void TextFieldTTSetCursorFromPoint::onEnter() -{ - KeyboardNotificationLayer::onEnter(); - - // add TextFieldTTF - auto s = Director::getInstance()->getCanvasSize(); - - auto pTextField = TextFieldTTF::textFieldWithPlaceHolder("", FONT_NAME, FONT_SIZE); - addChild(pTextField); - -#if (AX_TARGET_PLATFORM == AX_PLATFORM_ANDROID) - // on android, TextFieldTTF cannot auto adjust its position when soft-keyboard pop up - // so we had to set a higher position to make it visible - pTextField->setPosition(Vec2(s.width / 2, s.height / 2 + 50)); -#else - pTextField->setPosition(Vec2(s.width / 2, s.height / 2)); -#endif - - _trackNode = pTextField; -} diff --git a/tests/cpp-tests/Source/TextInputTest/TextInputTest.h b/tests/cpp-tests/Source/TextInputTest/TextInputTest.h deleted file mode 100644 index c3419a4dd88b..000000000000 --- a/tests/cpp-tests/Source/TextInputTest/TextInputTest.h +++ /dev/null @@ -1,131 +0,0 @@ -/**************************************************************************** - Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. - - https://axmol.dev/ - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ - -#ifndef __TEXT_INPUT_TEST_H__ -#define __TEXT_INPUT_TEST_H__ - -#include "../BaseTest.h" - -class KeyboardNotificationLayer; - -DEFINE_TEST_SUITE(TextInputTests); - -////////////////////////////////////////////////////////////////////////// -// KeyboardNotificationLayer for test IME keyboard notification. -////////////////////////////////////////////////////////////////////////// - -class KeyboardNotificationLayer : public TestCase, public ax::IMEDelegate -{ -public: - KeyboardNotificationLayer(); - virtual std::string title() const override; - virtual void onClickTrackNode(bool bClicked, const ax::Vec2& touchPos) = 0; - - virtual void keyboardWillShow(ax::IMEKeyboardNotificationInfo& info) override; - - bool onTouchBegan(ax::Touch* touch, ax::Event* event); - void onTouchEnded(ax::Touch* touch, ax::Event* event); - -protected: - ax::Node* _trackNode; - ax::Vec2 _beginPos; -}; - -////////////////////////////////////////////////////////////////////////// -// TextFieldTTFDefaultTest for test TextFieldTTF default behavior. -////////////////////////////////////////////////////////////////////////// - -class TextFieldTTFDefaultTest : public KeyboardNotificationLayer -{ -public: - CREATE_FUNC(TextFieldTTFDefaultTest); - // KeyboardNotificationLayer - virtual std::string subtitle() const override; - virtual void onClickTrackNode(bool bClicked, const ax::Vec2& touchPos) override; - - // Layer - virtual void onEnter() override; -}; - -////////////////////////////////////////////////////////////////////////// -// TextFieldTTFActionTest -////////////////////////////////////////////////////////////////////////// - -class TextFieldTTFActionTest : public KeyboardNotificationLayer, public ax::TextFieldDelegate -{ - ax::TextFieldTTF* _textField; - ax::Action* _textFieldAction; - bool _action; - size_t _charLimit; // the textfield max char limit - -public: - CREATE_FUNC(TextFieldTTFActionTest); - void callbackRemoveNodeWhenDidAction(Node* node); - - // KeyboardNotificationLayer - virtual std::string subtitle() const override; - virtual void onClickTrackNode(bool bClicked, const ax::Vec2& touchPos) override; - - // Layer - virtual void onEnter() override; - virtual void onExit() override; - - // TextFieldDelegate - virtual bool onTextFieldAttachWithIME(ax::TextFieldTTF* sender) override; - virtual bool onTextFieldDetachWithIME(ax::TextFieldTTF* sender) override; - virtual bool onTextFieldInsertText(ax::TextFieldTTF* sender, const char* text, size_t nLen) override; - virtual bool onTextFieldDeleteBackward(ax::TextFieldTTF* sender, const char* delText, size_t nLen) override; - virtual bool onDraw(ax::TextFieldTTF* sender); -}; - -////////////////////////////////////////////////////////////////////////// -// TextFieldTTFSecureTextEntryTest for test TextFieldTTF SecureTextEntry. -////////////////////////////////////////////////////////////////////////// - -class TextFieldTTFSecureTextEntryTest : public TextFieldTTFDefaultTest -{ -public: - CREATE_FUNC(TextFieldTTFSecureTextEntryTest); - - virtual std::string subtitle() const override; - // Layer - virtual void onEnter() override; -}; - -////////////////////////////////////////////////////////////////////////// -// TextFieldTTSetCursorFromPoint for test TextFieldTTF setCursorFromPoint. -////////////////////////////////////////////////////////////////////////// - -class TextFieldTTSetCursorFromPoint : public KeyboardNotificationLayer -{ -public: - CREATE_FUNC(TextFieldTTSetCursorFromPoint); - // KeyboardNotificationLayer - virtual std::string subtitle() const override; - virtual void onClickTrackNode(bool bClicked, const ax::Vec2& touchPos) override; - - // Layer - virtual void onEnter() override; -}; -#endif // __TEXT_INPUT_TEST_H__ diff --git a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/CocosGUIScene.cpp b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/CocosGUIScene.cpp index d09f92a673db..813a4568d569 100644 --- a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/CocosGUIScene.cpp +++ b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/CocosGUIScene.cpp @@ -42,7 +42,7 @@ #include "UIRichTextTest/UIRichTextTest.h" #include "UIFocusTest/UIFocusTest.h" #include "UITabControlTest/UITabControlTest.h" -#include "UITextFieldTest/UIInputFieldTest.h" +#include "UIInputFieldTest/UIInputFieldTest.h" #if defined(AX_ENABLE_MEDIA) # include "UIVideoPlayerTest/UIVideoPlayerTest.h" diff --git a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIEditBoxTest.h b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIEditBoxTest.h index 77f15912abe3..2f46a2b4f89c 100644 --- a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIEditBoxTest.h +++ b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIEditBoxTest.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef __cocos2d_tests__UIEditBoxTest__ -#define __cocos2d_tests__UIEditBoxTest__ +#pragma once #include "UIScene.h" @@ -84,5 +83,3 @@ class UIEditBoxTestPressedAndDisabled : public UIScene CREATE_FUNC(UIEditBoxTestPressedAndDisabled); virtual bool init() override; }; - -#endif /* defined(__cocos2d_tests__UIEditBoxTest__) */ diff --git a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIFocusTest/UIFocusTest.cpp b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIFocusTest/UIFocusTest.cpp index 4f40430b9ca0..ae57bed371f7 100644 --- a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIFocusTest/UIFocusTest.cpp +++ b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIFocusTest/UIFocusTest.cpp @@ -22,14 +22,6 @@ THE SOFTWARE. ****************************************************************************/ -// -// UIFocusTest.cpp -// cocos2d_tests -// -// Created by guanghui on 5/4/14. -// -// - #include "UIFocusTest.h" using namespace ax; diff --git a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIFocusTest/UIFocusTest.h b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIFocusTest/UIFocusTest.h index bca885fd0f81..64c70f8e206e 100644 --- a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIFocusTest/UIFocusTest.h +++ b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIFocusTest/UIFocusTest.h @@ -22,16 +22,7 @@ THE SOFTWARE. ****************************************************************************/ -// -// UIFocusTest.h -// cocos2d_tests -// -// Created by guanghui on 5/4/14. -// -// - -#ifndef __cocos2d_tests__UIFocusTest__ -#define __cocos2d_tests__UIFocusTest__ +#pragma once #include "../UIScene.h" @@ -144,5 +135,3 @@ class UIFocusTestNestedLayout3 : public UIFocusTestBase ax::ui::Layout* _verticalLayout; ax::ui::Text* _loopText; }; - -#endif /* defined(__cocos2d_tests__UIFocusTest__) */ diff --git a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextFieldTest/UIInputFieldTest.cpp b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIInputFieldTest/UIInputFieldTest.cpp similarity index 100% rename from tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextFieldTest/UIInputFieldTest.cpp rename to tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIInputFieldTest/UIInputFieldTest.cpp diff --git a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextFieldTest/UIInputFieldTest.h b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIInputFieldTest/UIInputFieldTest.h similarity index 100% rename from tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextFieldTest/UIInputFieldTest.h rename to tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIInputFieldTest/UIInputFieldTest.h diff --git a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIScale9SpriteTest.h b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIScale9SpriteTest.h index a69c825a486d..0df9816ef758 100644 --- a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIScale9SpriteTest.h +++ b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIScale9SpriteTest.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef __cocos2d_tests__UIScale9SpriteTest__ -#define __cocos2d_tests__UIScale9SpriteTest__ +#pragma once #include "UIScene.h" DEFINE_TEST_SUITE(UIScale9SpriteTests); @@ -318,5 +317,3 @@ class UIS9GrayStateOpacityTest : public UIScene virtual bool init() override; }; - -#endif /* defined(__cocos2d_tests__UIScale9SpriteTest__) */ diff --git a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIWebViewTest/UIWebViewTest.h b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIWebViewTest/UIWebViewTest.h index 75f3ef03b18a..c5dc3708807e 100644 --- a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIWebViewTest/UIWebViewTest.h +++ b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIWebViewTest/UIWebViewTest.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef __cocos2d_tests__UIWebViewTest__ -#define __cocos2d_tests__UIWebViewTest__ +#pragma once #include "../UIScene.h" #include "axmol/ui/UIWebView/UIWebView.h" @@ -44,5 +43,3 @@ class WebViewTest : public UIScene private: ax::ui::WebView* _webView; }; - -#endif /* defined(__cocos2d_tests__UIWebViewTest__) */ diff --git a/tests/cpp-tests/Source/UITest/UITest.h b/tests/cpp-tests/Source/UITest/UITest.h index 216408d17c19..968ddccce698 100644 --- a/tests/cpp-tests/Source/UITest/UITest.h +++ b/tests/cpp-tests/Source/UITest/UITest.h @@ -22,8 +22,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef __cocos2d_tests__UITest__ -#define __cocos2d_tests__UITest__ +#pragma once #include "../BaseTest.h" @@ -35,5 +34,3 @@ class UITests : public TestList private: }; - -#endif /* defined(__cocos2d_tests__UITest__) */ From 06e07b865963141693875dcf9f4d2abaf31ce0d4 Mon Sep 17 00:00:00 2001 From: halx99 Date: Wed, 20 May 2026 12:12:31 +0800 Subject: [PATCH 22/52] fix reviews --- axmol/ui/UIButton.cpp | 40 +++++++++---------- axmol/ui/UIButton.h | 2 +- axmol/ui/UIImageView.cpp | 10 ++--- axmol/ui/UIImageView.h | 2 +- axmol/ui/UILoadingBar.cpp | 10 ++--- axmol/ui/UILoadingBar.h | 2 +- axmol/ui/UISlider.cpp | 10 ++--- axmol/ui/UISlider.h | 2 +- tests/cpp-tests/Source/BugsTest/Bug-Child.cpp | 8 ---- 9 files changed, 39 insertions(+), 47 deletions(-) diff --git a/axmol/ui/UIButton.cpp b/axmol/ui/UIButton.cpp index cd40134bb92b..aa12b580a096 100644 --- a/axmol/ui/UIButton.cpp +++ b/axmol/ui/UIButton.cpp @@ -53,7 +53,7 @@ Button::Button() , _buttonDisabledRenderer(nullptr) , _titleRenderer(nullptr) , _zoomScale(0.1f) - , _prevIgnoreSize(true) + , _prevAutoSize(true) , _scale9Enabled(false) , _pressedActionEnabled(false) , _capInsetsNormal(Rect::ZERO) @@ -224,44 +224,44 @@ void Button::setScale9Enabled(bool able) // Original: // bool autoSizeBefore = _autoSize; // true if adapting // setAutoSize(false); // Switch to fixed size - // _prevIgnoreSize = !autoSizeBefore; + // _prevAutoSize = autoSizeBefore; - // If autoSizeBefore was true (adapting), _prevIgnoreSize becomes false. - // If autoSizeBefore was false (fixed), _prevIgnoreSize becomes true. + // If autoSizeBefore was true (adapting), _prevAutoSize becomes false. + // If autoSizeBefore was false (fixed), _prevAutoSize becomes true. setAutoSize(false); - _prevIgnoreSize = !autoSizeBefore; + _prevAutoSize = autoSizeBefore; } else { // When disabling scale9, restore previous autoSize state. - // _prevIgnoreSize stored the INVERSE of autoSize in our new convention? - // Let's check constructor: _prevIgnoreSize(true). + // _prevAutoSize stored the INVERSE of autoSize in our new convention? + // Let's check constructor: _prevAutoSize(true). // Default button usually adapts. So _autoSize is true by default. - // If _prevIgnoreSize is true, then !true = false? No. + // If _prevAutoSize is true, then !true = false? No. // Let's stick to the behavior: - // Old: _prevIgnoreSize stored the value passed to ignoreContentAdaptWithSize. + // Old: _prevAutoSize stored the value passed to ignoreContentAdaptWithSize. // ignoreContentAdaptWithSize(true) -> Adapt to content. // New: setAutoSize(true) -> Adapt to content. - // So _prevIgnoreSize actually corresponds directly to autoSize now? + // So _prevAutoSize actually corresponds directly to autoSize now? - // In constructor: _prevIgnoreSize = true. - // In setScale9Enabled else block: setAutoSize(!_prevIgnoreSize). - // If _prevIgnoreSize is true, it sets false. This seems inverted compared to typical defaults. + // In constructor: _prevAutoSize = true. + // In setScale9Enabled else block: setAutoSize(!_prevAutoSize). + // If _prevAutoSize is true, it sets false. This seems inverted compared to typical defaults. // Let's look at the reference code provided in prompt: - // _prevIgnoreSize = !autoSize; + // _prevAutoSize = autoSize; // If we use the reference implementation for setAutoSize: - // It sets _prevIgnoreSize = !autoSize. + // It sets _prevAutoSize = autoSize. // So in setScale9Enabled: - // else { setAutoSize(!_prevIgnoreSize); } - // If _prevIgnoreSize = !autoSize, then !_prevIgnoreSize = autoSize. + // else { setAutoSize(_prevAutoSize); } + // If _prevAutoSize = autoSize, then _prevAutoSize = autoSize. // So it restores the autoSize value. This is correct. - setAutoSize(!_prevIgnoreSize); + setAutoSize(_prevAutoSize); } setCapInsetsNormalRenderer(_capInsetsNormal); @@ -293,7 +293,7 @@ void Button::setAutoSize(bool autoSize) if (!_scale9Enabled || (_scale9Enabled && autoSize)) { Widget::setAutoSize(autoSize); - _prevIgnoreSize = !autoSize; // Store the inverse for backward compatibility logic if needed elsewhere + _prevAutoSize = autoSize; // Store the value for backward compatibility logic if needed elsewhere } else { @@ -933,7 +933,7 @@ void Button::copySpecialProperties(Widget* widget) Button* button = dynamic_cast(widget); if (button) { - _prevIgnoreSize = button->_prevIgnoreSize; + _prevAutoSize = button->_prevAutoSize; setScale9Enabled(button->_scale9Enabled); // clone the inner sprite: https://github.com/cocos2d/cocos2d-x/issues/16924 diff --git a/axmol/ui/UIButton.h b/axmol/ui/UIButton.h index 4f7c52a1ea07..85a5bdc3149f 100644 --- a/axmol/ui/UIButton.h +++ b/axmol/ui/UIButton.h @@ -357,7 +357,7 @@ class AX_GUI_DLL Button : public Widget Label* _titleRenderer; float _zoomScale; - bool _prevIgnoreSize; + bool _prevAutoSize; bool _scale9Enabled; bool _pressedActionEnabled; diff --git a/axmol/ui/UIImageView.cpp b/axmol/ui/UIImageView.cpp index 525a06c69e15..4cd38e325a91 100644 --- a/axmol/ui/UIImageView.cpp +++ b/axmol/ui/UIImageView.cpp @@ -41,7 +41,7 @@ IMPLEMENT_CLASS_GUI_INFO(ImageView) ImageView::ImageView() : _scale9Enabled(false) - , _prevIgnoreSize(true) + , _prevAutoSize(true) , _capInsets(Rect::ZERO) , _imageRenderer(nullptr) , _imageTexType(TextureResType::LOCAL) @@ -199,11 +199,11 @@ void ImageView::setScale9Enabled(bool able) { bool autoSizeBefore = _autoSize; setAutoSize(false); - _prevIgnoreSize = !autoSizeBefore; + _prevAutoSize = autoSizeBefore; } else { - setAutoSize(!_prevIgnoreSize); + setAutoSize(_prevAutoSize); } setCapInsets(_capInsets); _imageRendererAdaptDirty = true; @@ -276,7 +276,7 @@ void ImageView::copySpecialProperties(Widget* widget) ImageView* imageView = dynamic_cast(widget); if (imageView) { - _prevIgnoreSize = imageView->_prevIgnoreSize; + _prevAutoSize = imageView->_prevAutoSize; setScale9Enabled(imageView->_scale9Enabled); auto imageSprite = imageView->_imageRenderer->getSprite(); if (nullptr != imageSprite) @@ -312,7 +312,7 @@ void ImageView::setAutoSize(bool autoSize) if (!_scale9Enabled || (_scale9Enabled && autoSize)) { Widget::setAutoSize(autoSize); - _prevIgnoreSize = !autoSize; // Store the inverse for backward compatibility + _prevAutoSize = autoSize; // Store the current value for backward compatibility } } diff --git a/axmol/ui/UIImageView.h b/axmol/ui/UIImageView.h index 58d51c1d62da..743cd1005ad5 100644 --- a/axmol/ui/UIImageView.h +++ b/axmol/ui/UIImageView.h @@ -161,7 +161,7 @@ class AX_GUI_DLL ImageView : public Widget, public ax::BlendProtocol protected: bool _scale9Enabled; - bool _prevIgnoreSize; + bool _prevAutoSize; Rect _capInsets; Scale9Sprite* _imageRenderer; TextureResType _imageTexType; diff --git a/axmol/ui/UILoadingBar.cpp b/axmol/ui/UILoadingBar.cpp index f524fd239fde..bf05f1d9c674 100644 --- a/axmol/ui/UILoadingBar.cpp +++ b/axmol/ui/UILoadingBar.cpp @@ -53,7 +53,7 @@ LoadingBar::LoadingBar() , _barRendererTextureSize(Vec2::ZERO) , _originalRect(Rect::ZERO) , _scale9Enabled(false) - , _prevIgnoreSize(true) + , _prevAutoSize(true) , _capInsets(Rect::ZERO) , _barRendererAdaptDirty(true) , _textureFile("") @@ -222,11 +222,11 @@ void LoadingBar::setScale9Enabled(bool enabled) { bool autoSizeBefore = _autoSize; setAutoSize(false); - _prevIgnoreSize = !autoSizeBefore; + _prevAutoSize = autoSizeBefore; } else { - setAutoSize(!_prevIgnoreSize); + setAutoSize(_prevAutoSize); } setCapInsets(_capInsets); @@ -324,7 +324,7 @@ void LoadingBar::setAutoSize(bool autoSize) if (!_scale9Enabled || (_scale9Enabled && autoSize)) { Widget::setAutoSize(autoSize); - _prevIgnoreSize = !autoSize; // Store the inverse for backward compatibility + _prevAutoSize = autoSize; // Store the current value for backward compatibility } } @@ -411,7 +411,7 @@ void LoadingBar::copySpecialProperties(Widget* widget) LoadingBar* loadingBar = dynamic_cast(widget); if (loadingBar) { - _prevIgnoreSize = loadingBar->_prevIgnoreSize; + _prevAutoSize = loadingBar->_prevAutoSize; setScale9Enabled(loadingBar->_scale9Enabled); // clone the inner sprite: https://github.com/cocos2d/cocos2d-x/issues/16930 diff --git a/axmol/ui/UILoadingBar.h b/axmol/ui/UILoadingBar.h index 53ffc99da066..d69ee431385b 100644 --- a/axmol/ui/UILoadingBar.h +++ b/axmol/ui/UILoadingBar.h @@ -197,7 +197,7 @@ class AX_GUI_DLL LoadingBar : public Widget Vec2 _barRendererTextureSize; Rect _originalRect; bool _scale9Enabled; - bool _prevIgnoreSize; + bool _prevAutoSize; Rect _capInsets; bool _barRendererAdaptDirty; std::string _textureFile; diff --git a/axmol/ui/UISlider.cpp b/axmol/ui/UISlider.cpp index adf2cc25e2fa..ee486e636826 100644 --- a/axmol/ui/UISlider.cpp +++ b/axmol/ui/UISlider.cpp @@ -62,7 +62,7 @@ Slider::Slider() , _percent(0) , _maxPercent(100) , _scale9Enabled(false) - , _prevIgnoreSize(true) + , _prevAutoSize(true) , _zoomScale(0.1f) , _sliderBallNormalTextureScaleX(1.0) , _sliderBallNormalTextureScaleY(1.0) @@ -258,11 +258,11 @@ void Slider::setScale9Enabled(bool able) { bool autoSizeBefore = _autoSize; setAutoSize(false); - _prevIgnoreSize = !autoSizeBefore; + _prevAutoSize = autoSizeBefore; } else { - setAutoSize(!_prevIgnoreSize); + setAutoSize(_prevAutoSize); } setCapInsetsBarRenderer(_capInsetsBarRenderer); setCapInsetProgressBarRenderer(_capInsetsProgressBarRenderer); @@ -282,7 +282,7 @@ void Slider::setAutoSize(bool autoSize) if (!_scale9Enabled || (_scale9Enabled && autoSize)) { Widget::setAutoSize(autoSize); - _prevIgnoreSize = !autoSize; // Store the inverse for backward compatibility + _prevAutoSize = autoSize; // Store the current value for backward compatibility } } @@ -749,7 +749,7 @@ void Slider::copySpecialProperties(Widget* widget) Slider* slider = dynamic_cast(widget); if (slider) { - _prevIgnoreSize = slider->_prevIgnoreSize; + _prevAutoSize = slider->_prevAutoSize; setScale9Enabled(slider->_scale9Enabled); // clone the inner sprite: https://github.com/cocos2d/cocos2d-x/issues/16928 diff --git a/axmol/ui/UISlider.h b/axmol/ui/UISlider.h index 27a6e609f96a..8fac2ee47a77 100644 --- a/axmol/ui/UISlider.h +++ b/axmol/ui/UISlider.h @@ -321,7 +321,7 @@ class AX_GUI_DLL Slider : public Widget int _maxPercent; bool _scale9Enabled; - bool _prevIgnoreSize; + bool _prevAutoSize; float _zoomScale; float _sliderBallNormalTextureScaleX; diff --git a/tests/cpp-tests/Source/BugsTest/Bug-Child.cpp b/tests/cpp-tests/Source/BugsTest/Bug-Child.cpp index 1b5f58bf2faa..3f1f4b43de89 100644 --- a/tests/cpp-tests/Source/BugsTest/Bug-Child.cpp +++ b/tests/cpp-tests/Source/BugsTest/Bug-Child.cpp @@ -22,14 +22,6 @@ THE SOFTWARE. ****************************************************************************/ -// -// Bug-Child.cpp -// cocos2d_tests -// -// Created by NiTe Luo on 5/12/14. -// -// - #include "Bug-Child.h" using namespace ax; From 5675846f28e962894a05cf989de9ce5dd5a72db2 Mon Sep 17 00:00:00 2001 From: halx99 Date: Wed, 20 May 2026 15:34:16 +0800 Subject: [PATCH 23/52] Refactor file name --- ...heckButton.cpp => AbstractCheckButton.cpp} | 2 +- ...actCheckButton.h => AbstractCheckButton.h} | 2 +- axmol/ui/{UIButton.cpp => Button.cpp} | 6 +- axmol/ui/{UIButton.h => Button.h} | 2 +- axmol/ui/CMakeLists.txt | 248 +++++++++--------- axmol/ui/{UICheckBox.cpp => CheckBox.cpp} | 2 +- axmol/ui/{UICheckBox.h => CheckBox.h} | 2 +- .../UIEditBox.cpp => EditBox/EditBox.cpp} | 6 +- .../UIEditBox.h => EditBox/EditBox.h} | 4 +- .../EditBoxImpl-android.cpp} | 6 +- .../EditBoxImpl-android.h} | 2 +- .../EditBoxImpl-common.cpp} | 6 +- .../EditBoxImpl-common.h} | 4 +- .../EditBoxImpl-ios.h} | 2 +- .../EditBoxImpl-ios.mm} | 6 +- .../EditBoxImpl-linux.cpp} | 4 +- .../EditBoxImpl-linux.h} | 2 +- .../EditBoxImpl-mac.h} | 2 +- .../EditBoxImpl-mac.mm} | 6 +- .../EditBoxImpl-stub.cpp} | 2 +- .../EditBoxImpl-wasm.cpp} | 4 +- .../EditBoxImpl-wasm.h} | 2 +- .../EditBoxImpl-win32.cpp} | 6 +- .../EditBoxImpl-win32.h} | 2 +- .../EditBoxImpl-winrt.cpp} | 4 +- .../EditBoxImpl-winrt.h} | 2 +- .../UIEditBoxImpl.h => EditBox/EditBoxImpl.h} | 2 +- .../Mac/EditBoxMac.h} | 4 +- .../Mac/EditBoxMac.mm} | 8 +- .../Mac/MultilineTextField.h} | 2 +- .../Mac/MultilineTextField.m} | 2 +- .../Mac/PasswordTextField.h} | 2 +- .../Mac/PasswordTextField.m} | 4 +- .../Mac/SingleLineTextField.h} | 2 +- .../Mac/SingleLineTextField.m} | 4 +- .../Mac/TextFieldFormatter.h} | 0 .../Mac/TextFieldFormatter.m} | 2 +- .../UITextInput.h => EditBox/Mac/TextInput.h} | 0 .../iOS/EditBoxIOS.h} | 4 +- .../iOS/EditBoxIOS.mm} | 6 +- .../iOS/MultilineTextField.h} | 2 +- .../iOS/MultilineTextField.mm} | 2 +- .../iOS/SingleLineTextField.h} | 2 +- .../iOS/SingleLineTextField.mm} | 4 +- .../iOS/TextField+UITextInput.h} | 2 +- .../iOS/TextField+UITextInput.mm} | 2 +- .../UITextInput.h => EditBox/iOS/TextInput.h} | 0 .../iOS/TextView+UITextInput.h} | 2 +- .../iOS/TextView+UITextInput.mm} | 2 +- axmol/ui/{UIHBox.cpp => HBox.cpp} | 2 +- axmol/ui/{UIHBox.h => HBox.h} | 2 +- axmol/ui/{UIHelper.cpp => Helper.cpp} | 6 +- axmol/ui/{UIHelper.h => Helper.h} | 2 +- axmol/ui/{UIImageView.cpp => ImageView.cpp} | 6 +- axmol/ui/{UIImageView.h => ImageView.h} | 2 +- axmol/ui/{UIInputField.cpp => InputField.cpp} | 2 +- axmol/ui/{UIInputField.h => InputField.h} | 2 +- axmol/ui/{UILayout.cpp => Layout.cpp} | 8 +- axmol/ui/{UILayout.h => Layout.h} | 2 +- ...ayoutComponent.cpp => LayoutComponent.cpp} | 6 +- ...{UILayoutComponent.h => LayoutComponent.h} | 0 ...{UILayoutManager.cpp => LayoutManager.cpp} | 4 +- .../ui/{UILayoutManager.h => LayoutManager.h} | 0 ...ayoutParameter.cpp => LayoutParameter.cpp} | 4 +- ...{UILayoutParameter.h => LayoutParameter.h} | 0 axmol/ui/{UIListView.cpp => ListView.cpp} | 4 +- axmol/ui/{UIListView.h => ListView.h} | 2 +- axmol/ui/{UILoadingBar.cpp => LoadingBar.cpp} | 6 +- axmol/ui/{UILoadingBar.h => LoadingBar.h} | 2 +- .../ui/{UIMediaPlayer.cpp => MediaPlayer.cpp} | 8 +- axmol/ui/{UIMediaPlayer.h => MediaPlayer.h} | 6 +- axmol/ui/{UIPageView.cpp => PageView.cpp} | 4 +- axmol/ui/{UIPageView.h => PageView.h} | 2 +- ...iewIndicator.cpp => PageViewIndicator.cpp} | 2 +- ...ageViewIndicator.h => PageViewIndicator.h} | 2 +- .../ui/{UIRadioButton.cpp => RadioButton.cpp} | 2 +- axmol/ui/{UIRadioButton.h => RadioButton.h} | 2 +- .../ui/{UIRelativeBox.cpp => RelativeBox.cpp} | 2 +- axmol/ui/{UIRelativeBox.h => RelativeBox.h} | 2 +- axmol/ui/{UIRichText.cpp => RichText.cpp} | 4 +- axmol/ui/{UIRichText.h => RichText.h} | 2 +- .../{UIScale9Sprite.cpp => Scale9Sprite.cpp} | 2 +- axmol/ui/{UIScale9Sprite.h => Scale9Sprite.h} | 0 axmol/ui/{UIScrollView.cpp => ScrollView.cpp} | 4 +- axmol/ui/{UIScrollView.h => ScrollView.h} | 2 +- ...{UIScrollViewBar.cpp => ScrollViewBar.cpp} | 2 +- .../ui/{UIScrollViewBar.h => ScrollViewBar.h} | 2 +- axmol/ui/{UISlider.cpp => Slider.cpp} | 6 +- axmol/ui/{UISlider.h => Slider.h} | 2 +- axmol/ui/{UITabControl.cpp => TabControl.cpp} | 4 +- axmol/ui/{UITabControl.h => TabControl.h} | 4 +- axmol/ui/{UIText.cpp => Text.cpp} | 2 +- axmol/ui/{UIText.h => Text.h} | 2 +- axmol/ui/{UITextAtlas.cpp => TextAtlas.cpp} | 2 +- axmol/ui/{UITextAtlas.h => TextAtlas.h} | 2 +- axmol/ui/{UITextBMFont.cpp => TextBMFont.cpp} | 2 +- axmol/ui/{UITextBMFont.h => TextBMFont.h} | 2 +- axmol/ui/{UIVBox.cpp => VBox.cpp} | 2 +- axmol/ui/{UIVBox.h => VBox.h} | 2 +- .../UIWebView-inl.h => WebView/WebView-inl.h} | 2 +- .../UIWebView.cpp => WebView/WebView.cpp} | 12 +- .../UIWebView.h => WebView/WebView.h} | 2 +- .../UIWebView.mm => WebView/WebView.mm} | 4 +- .../WebViewCommon.h} | 0 .../WebViewImpl-android.cpp} | 6 +- .../WebViewImpl-android.h} | 0 .../WebViewImpl-ios.h} | 0 .../WebViewImpl-ios.mm} | 4 +- .../WebViewImpl-linux.cpp} | 8 +- .../WebViewImpl-linux.h} | 0 .../WebViewImpl-win32.cpp} | 8 +- .../WebViewImpl-win32.h} | 0 axmol/ui/{UIWidget.cpp => Widget.cpp} | 10 +- axmol/ui/{UIWidget.h => Widget.h} | 2 +- axmol/ui/axmol-ui.h | 52 ++-- .../src/GUI/ControlExtension/ControlButton.h | 2 +- .../ImGui/backends/imgui_impl_axmol_sw.cpp | 4 +- extensions/fairygui/src/fairygui/GImage.h | 2 +- .../fairygui/src/fairygui/GTextInput.cpp | 2 +- .../fairygui/src/fairygui/display/FUIInput.h | 2 +- .../sceneext/src/sceneext/ActionNode.cpp | 6 +- extensions/sceneext/src/sceneext/SGUIReader.h | 2 +- .../sceneext/WidgetCallBackHandlerProtocol.h | 2 +- .../src/sceneio/ActionTimeline/CSLoader.h | 2 +- .../src/sceneio/FlatBuffersSerialize.h | 2 +- .../ButtonReader/ButtonReader.cpp | 2 +- .../CheckBoxReader/CheckBoxReader.cpp | 2 +- .../ImageViewReader/ImageViewReader.cpp | 2 +- .../LayoutReader/LayoutReader.cpp | 8 +- .../ListViewReader/ListViewReader.cpp | 2 +- .../LoadingBarReader/LoadingBarReader.cpp | 2 +- .../WidgetReader/NodeReader/NodeReader.cpp | 2 +- .../PageViewReader/PageViewReader.cpp | 4 +- .../RadioButtonGroupReader.cpp | 2 +- .../RadioButtonReader/RadioButtonReader.cpp | 2 +- .../RichTextReader/RichTextReader.cpp | 2 +- .../ScrollViewReader/ScrollViewReader.cpp | 2 +- .../SliderReader/SliderReader.cpp | 2 +- .../TabControlReader/TabControlReader.cpp | 2 +- .../TextAtlasReader/TextAtlasReader.cpp | 2 +- .../TextBMFontReader/TextBMFontReader.cpp | 2 +- .../TextFieldReader/TextFieldExReader.cpp | 2 +- .../TextFieldReader/TextFieldReader.cpp | 2 +- .../WidgetReader/TextReader/TextReader.cpp | 2 +- .../src/sceneio/WidgetReader/WidgetReader.cpp | 4 +- .../lua-bindings/auto/axlua_video_auto.cpp | 2 +- .../lua-bindings/auto/axlua_webview_auto.cpp | 2 +- .../manual/ui/axlua_video_manual.cpp | 2 +- .../manual/ui/axlua_webview_manual.cpp | 2 +- tests/cpp-tests/Source/BugsTest/Bug-14327.h | 2 +- .../Source/Camera3DTest/Camera3DTest.cpp | 2 +- .../cpp-tests/Source/LayerTest/LayerTest.cpp | 2 +- tests/cpp-tests/Source/LayerTest/LayerTest.h | 4 +- .../DownloaderTest/DownloaderTest.cpp | 4 +- .../Source/SchedulerTest/SchedulerTest.cpp | 2 +- .../UIListViewTest/UIListViewTest.h | 2 +- .../UITabControlTest/UITabControlTest.cpp | 2 +- .../UIWebViewTest/UIWebViewTest.h | 2 +- tests/unit-tests/CMakeLists.txt | 2 +- .../ui/{UIHelperTests.cpp => HelperTests.cpp} | 18 +- tools/tolua/ax_video.ini | 2 +- tools/tolua/ax_webview.ini | 2 +- 162 files changed, 390 insertions(+), 390 deletions(-) rename axmol/ui/{UIAbstractCheckButton.cpp => AbstractCheckButton.cpp} (99%) rename axmol/ui/{UIAbstractCheckButton.h => AbstractCheckButton.h} (99%) rename axmol/ui/{UIButton.cpp => Button.cpp} (99%) rename axmol/ui/{UIButton.h => Button.h} (99%) rename axmol/ui/{UICheckBox.cpp => CheckBox.cpp} (99%) rename axmol/ui/{UICheckBox.h => CheckBox.h} (99%) rename axmol/ui/{UIEditBox/UIEditBox.cpp => EditBox/EditBox.cpp} (99%) rename axmol/ui/{UIEditBox/UIEditBox.h => EditBox/EditBox.h} (99%) rename axmol/ui/{UIEditBox/UIEditBoxImpl-android.cpp => EditBox/EditBoxImpl-android.cpp} (98%) rename axmol/ui/{UIEditBox/UIEditBoxImpl-android.h => EditBox/EditBoxImpl-android.h} (98%) rename axmol/ui/{UIEditBox/UIEditBoxImpl-common.cpp => EditBox/EditBoxImpl-common.cpp} (99%) rename axmol/ui/{UIEditBox/UIEditBoxImpl-common.h => EditBox/EditBoxImpl-common.h} (98%) rename axmol/ui/{UIEditBox/UIEditBoxImpl-ios.h => EditBox/EditBoxImpl-ios.h} (98%) rename axmol/ui/{UIEditBox/UIEditBoxImpl-ios.mm => EditBox/EditBoxImpl-ios.mm} (98%) rename axmol/ui/{UIEditBox/UIEditBoxImpl-linux.cpp => EditBox/EditBoxImpl-linux.cpp} (99%) rename axmol/ui/{UIEditBox/UIEditBoxImpl-linux.h => EditBox/EditBoxImpl-linux.h} (98%) rename axmol/ui/{UIEditBox/UIEditBoxImpl-mac.h => EditBox/EditBoxImpl-mac.h} (98%) rename axmol/ui/{UIEditBox/UIEditBoxImpl-mac.mm => EditBox/EditBoxImpl-mac.mm} (97%) rename axmol/ui/{UIEditBox/UIEditBoxImpl-stub.cpp => EditBox/EditBoxImpl-stub.cpp} (97%) rename axmol/ui/{UIEditBox/UIEditBoxImpl-wasm.cpp => EditBox/EditBoxImpl-wasm.cpp} (99%) rename axmol/ui/{UIEditBox/UIEditBoxImpl-wasm.h => EditBox/EditBoxImpl-wasm.h} (98%) rename axmol/ui/{UIEditBox/UIEditBoxImpl-win32.cpp => EditBox/EditBoxImpl-win32.cpp} (99%) rename axmol/ui/{UIEditBox/UIEditBoxImpl-win32.h => EditBox/EditBoxImpl-win32.h} (98%) rename axmol/ui/{UIEditBox/UIEditBoxImpl-winrt.cpp => EditBox/EditBoxImpl-winrt.cpp} (99%) rename axmol/ui/{UIEditBox/UIEditBoxImpl-winrt.h => EditBox/EditBoxImpl-winrt.h} (99%) rename axmol/ui/{UIEditBox/UIEditBoxImpl.h => EditBox/EditBoxImpl.h} (99%) rename axmol/ui/{UIEditBox/Mac/UIEditBoxMac.h => EditBox/Mac/EditBoxMac.h} (96%) rename axmol/ui/{UIEditBox/Mac/UIEditBoxMac.mm => EditBox/Mac/EditBoxMac.mm} (98%) rename axmol/ui/{UIEditBox/Mac/UIMultilineTextField.h => EditBox/Mac/MultilineTextField.h} (96%) rename axmol/ui/{UIEditBox/Mac/UIMultilineTextField.m => EditBox/Mac/MultilineTextField.m} (98%) rename axmol/ui/{UIEditBox/Mac/UIPasswordTextField.h => EditBox/Mac/PasswordTextField.h} (96%) rename axmol/ui/{UIEditBox/Mac/UIPasswordTextField.m => EditBox/Mac/PasswordTextField.m} (97%) rename axmol/ui/{UIEditBox/Mac/UISingleLineTextField.h => EditBox/Mac/SingleLineTextField.h} (96%) rename axmol/ui/{UIEditBox/Mac/UISingleLineTextField.m => EditBox/Mac/SingleLineTextField.m} (97%) rename axmol/ui/{UIEditBox/Mac/UITextFieldFormatter.h => EditBox/Mac/TextFieldFormatter.h} (100%) rename axmol/ui/{UIEditBox/Mac/UITextFieldFormatter.m => EditBox/Mac/TextFieldFormatter.m} (97%) rename axmol/ui/{UIEditBox/Mac/UITextInput.h => EditBox/Mac/TextInput.h} (100%) rename axmol/ui/{UIEditBox/iOS/UIEditBoxIOS.h => EditBox/iOS/EditBoxIOS.h} (96%) rename axmol/ui/{UIEditBox/iOS/UIEditBoxIOS.mm => EditBox/iOS/EditBoxIOS.mm} (98%) rename axmol/ui/{UIEditBox/iOS/UIMultilineTextField.h => EditBox/iOS/MultilineTextField.h} (96%) rename axmol/ui/{UIEditBox/iOS/UIMultilineTextField.mm => EditBox/iOS/MultilineTextField.mm} (98%) rename axmol/ui/{UIEditBox/iOS/UISingleLineTextField.h => EditBox/iOS/SingleLineTextField.h} (96%) rename axmol/ui/{UIEditBox/iOS/UISingleLineTextField.mm => EditBox/iOS/SingleLineTextField.mm} (96%) rename axmol/ui/{UIEditBox/iOS/UITextField+UITextInput.h => EditBox/iOS/TextField+UITextInput.h} (97%) rename axmol/ui/{UIEditBox/iOS/UITextField+UITextInput.mm => EditBox/iOS/TextField+UITextInput.mm} (98%) rename axmol/ui/{UIEditBox/iOS/UITextInput.h => EditBox/iOS/TextInput.h} (100%) rename axmol/ui/{UIEditBox/iOS/UITextView+UITextInput.h => EditBox/iOS/TextView+UITextInput.h} (97%) rename axmol/ui/{UIEditBox/iOS/UITextView+UITextInput.mm => EditBox/iOS/TextView+UITextInput.mm} (98%) rename axmol/ui/{UIHBox.cpp => HBox.cpp} (98%) rename axmol/ui/{UIHBox.h => HBox.h} (98%) rename axmol/ui/{UIHelper.cpp => Helper.cpp} (99%) rename axmol/ui/{UIHelper.h => Helper.h} (99%) rename axmol/ui/{UIImageView.cpp => ImageView.cpp} (98%) rename axmol/ui/{UIImageView.h => ImageView.h} (99%) rename axmol/ui/{UIInputField.cpp => InputField.cpp} (99%) rename axmol/ui/{UIInputField.h => InputField.h} (99%) rename axmol/ui/{UILayout.cpp => Layout.cpp} (99%) rename axmol/ui/{UILayout.h => Layout.h} (99%) rename axmol/ui/{UILayoutComponent.cpp => LayoutComponent.cpp} (99%) rename axmol/ui/{UILayoutComponent.h => LayoutComponent.h} (100%) rename axmol/ui/{UILayoutManager.cpp => LayoutManager.cpp} (99%) rename axmol/ui/{UILayoutManager.h => LayoutManager.h} (100%) rename axmol/ui/{UILayoutParameter.cpp => LayoutParameter.cpp} (98%) rename axmol/ui/{UILayoutParameter.h => LayoutParameter.h} (100%) rename axmol/ui/{UIListView.cpp => ListView.cpp} (99%) rename axmol/ui/{UIListView.h => ListView.h} (99%) rename axmol/ui/{UILoadingBar.cpp => LoadingBar.cpp} (99%) rename axmol/ui/{UILoadingBar.h => LoadingBar.h} (99%) rename axmol/ui/{UIMediaPlayer.cpp => MediaPlayer.cpp} (99%) rename axmol/ui/{UIMediaPlayer.h => MediaPlayer.h} (99%) rename axmol/ui/{UIPageView.cpp => PageView.cpp} (99%) rename axmol/ui/{UIPageView.h => PageView.h} (99%) rename axmol/ui/{UIPageViewIndicator.cpp => PageViewIndicator.cpp} (99%) rename axmol/ui/{UIPageViewIndicator.h => PageViewIndicator.h} (99%) rename axmol/ui/{UIRadioButton.cpp => RadioButton.cpp} (99%) rename axmol/ui/{UIRadioButton.h => RadioButton.h} (99%) rename axmol/ui/{UIRelativeBox.cpp => RelativeBox.cpp} (98%) rename axmol/ui/{UIRelativeBox.h => RelativeBox.h} (98%) rename axmol/ui/{UIRichText.cpp => RichText.cpp} (99%) rename axmol/ui/{UIRichText.h => RichText.h} (99%) rename axmol/ui/{UIScale9Sprite.cpp => Scale9Sprite.cpp} (99%) rename axmol/ui/{UIScale9Sprite.h => Scale9Sprite.h} (100%) rename axmol/ui/{UIScrollView.cpp => ScrollView.cpp} (99%) rename axmol/ui/{UIScrollView.h => ScrollView.h} (99%) rename axmol/ui/{UIScrollViewBar.cpp => ScrollViewBar.cpp} (99%) rename axmol/ui/{UIScrollViewBar.h => ScrollViewBar.h} (99%) rename axmol/ui/{UISlider.cpp => Slider.cpp} (99%) rename axmol/ui/{UISlider.h => Slider.h} (99%) rename axmol/ui/{UITabControl.cpp => TabControl.cpp} (99%) rename axmol/ui/{UITabControl.h => TabControl.h} (99%) rename axmol/ui/{UIText.cpp => Text.cpp} (99%) rename axmol/ui/{UIText.h => Text.h} (99%) rename axmol/ui/{UITextAtlas.cpp => TextAtlas.cpp} (99%) rename axmol/ui/{UITextAtlas.h => TextAtlas.h} (99%) rename axmol/ui/{UITextBMFont.cpp => TextBMFont.cpp} (99%) rename axmol/ui/{UITextBMFont.h => TextBMFont.h} (99%) rename axmol/ui/{UIVBox.cpp => VBox.cpp} (98%) rename axmol/ui/{UIVBox.h => VBox.h} (98%) rename axmol/ui/{UIWebView/UIWebView-inl.h => WebView/WebView-inl.h} (99%) rename axmol/ui/{UIWebView/UIWebView.cpp => WebView/WebView.cpp} (83%) rename axmol/ui/{UIWebView/UIWebView.h => WebView/WebView.h} (99%) rename axmol/ui/{UIWebView/UIWebView.mm => WebView/WebView.mm} (93%) rename axmol/ui/{UIWebView/UIWebViewCommon.h => WebView/WebViewCommon.h} (100%) rename axmol/ui/{UIWebView/UIWebViewImpl-android.cpp => WebView/WebViewImpl-android.cpp} (98%) rename axmol/ui/{UIWebView/UIWebViewImpl-android.h => WebView/WebViewImpl-android.h} (100%) rename axmol/ui/{UIWebView/UIWebViewImpl-ios.h => WebView/WebViewImpl-ios.h} (100%) rename axmol/ui/{UIWebView/UIWebViewImpl-ios.mm => WebView/WebViewImpl-ios.mm} (99%) rename axmol/ui/{UIWebView/UIWebViewImpl-linux.cpp => WebView/WebViewImpl-linux.cpp} (99%) rename axmol/ui/{UIWebView/UIWebViewImpl-linux.h => WebView/WebViewImpl-linux.h} (100%) rename axmol/ui/{UIWebView/UIWebViewImpl-win32.cpp => WebView/WebViewImpl-win32.cpp} (99%) rename axmol/ui/{UIWebView/UIWebViewImpl-win32.h => WebView/WebViewImpl-win32.h} (100%) rename axmol/ui/{UIWidget.cpp => Widget.cpp} (99%) rename axmol/ui/{UIWidget.h => Widget.h} (99%) rename tests/unit-tests/Source/axmol/ui/{UIHelperTests.cpp => HelperTests.cpp} (91%) diff --git a/axmol/ui/UIAbstractCheckButton.cpp b/axmol/ui/AbstractCheckButton.cpp similarity index 99% rename from axmol/ui/UIAbstractCheckButton.cpp rename to axmol/ui/AbstractCheckButton.cpp index ef9f5ad61a07..341211c6a709 100644 --- a/axmol/ui/UIAbstractCheckButton.cpp +++ b/axmol/ui/AbstractCheckButton.cpp @@ -24,7 +24,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ -#include "axmol/ui/UIAbstractCheckButton.h" +#include "axmol/ui/AbstractCheckButton.h" #include "axmol/2d/Sprite.h" #include "axmol/renderer/Shaders.h" #include "axmol/renderer/ProgramStateRegistry.h" diff --git a/axmol/ui/UIAbstractCheckButton.h b/axmol/ui/AbstractCheckButton.h similarity index 99% rename from axmol/ui/UIAbstractCheckButton.h rename to axmol/ui/AbstractCheckButton.h index 4b58d4713820..58b80a436169 100644 --- a/axmol/ui/UIAbstractCheckButton.h +++ b/axmol/ui/AbstractCheckButton.h @@ -26,7 +26,7 @@ THE SOFTWARE. #pragma once -#include "axmol/ui/UIWidget.h" +#include "axmol/ui/Widget.h" #include "axmol/ui/GUIExport.h" /** diff --git a/axmol/ui/UIButton.cpp b/axmol/ui/Button.cpp similarity index 99% rename from axmol/ui/UIButton.cpp rename to axmol/ui/Button.cpp index aa12b580a096..98abe559eefb 100644 --- a/axmol/ui/UIButton.cpp +++ b/axmol/ui/Button.cpp @@ -24,13 +24,13 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ -#include "axmol/ui/UIButton.h" -#include "axmol/ui/UIScale9Sprite.h" +#include "axmol/ui/Button.h" +#include "axmol/ui/Scale9Sprite.h" #include "axmol/2d/Label.h" #include "axmol/2d/Sprite.h" #include "axmol/2d/ActionInterval.h" #include "axmol/platform/FileUtils.h" -#include "axmol/ui/UIHelper.h" +#include "axmol/ui/Helper.h" #include namespace ax diff --git a/axmol/ui/UIButton.h b/axmol/ui/Button.h similarity index 99% rename from axmol/ui/UIButton.h rename to axmol/ui/Button.h index 85a5bdc3149f..954ff3a011e8 100644 --- a/axmol/ui/UIButton.h +++ b/axmol/ui/Button.h @@ -26,7 +26,7 @@ THE SOFTWARE. #pragma once -#include "axmol/ui/UIWidget.h" +#include "axmol/ui/Widget.h" #include "axmol/ui/GUIExport.h" /** diff --git a/axmol/ui/CMakeLists.txt b/axmol/ui/CMakeLists.txt index 28bcf525271d..8044fcc68b72 100644 --- a/axmol/ui/CMakeLists.txt +++ b/axmol/ui/CMakeLists.txt @@ -1,119 +1,119 @@ if(WINDOWS) if(NOT WINRT) set(_AX_UI_SPECIFIC_HEADER - ui/UIEditBox/UIEditBoxImpl-win32.h + ui/EditBox/EditBoxImpl-win32.h ) set(_AX_UI_SPECIFIC_SRC - ui/UIEditBox/UIEditBoxImpl-win32.cpp + ui/EditBox/EditBoxImpl-win32.cpp ) else() set(_AX_UI_SPECIFIC_HEADER - ui/UIEditBox/UIEditBoxImpl-winrt.h + ui/UIEditBox/EditBoxImpl-winrt.h ) set(_AX_UI_SPECIFIC_SRC - ui/UIEditBox/UIEditBoxImpl-winrt.cpp + ui/UIEditBox/EditBoxImpl-winrt.cpp ) endif() if(AX_ENABLE_MSEDGE_WEBVIEW2) - list(APPEND _AX_UI_SPECIFIC_HEADER ui/UIWebView/UIWebViewImpl-win32.h ui/UIWebView/UIWebView.h) - list(APPEND _AX_UI_SPECIFIC_SRC ui/UIWebView/UIWebViewImpl-win32.cpp ui/UIWebView/UIWebView.cpp) + list(APPEND _AX_UI_SPECIFIC_HEADER ui/WebView/WebViewImpl-win32.h ui/WebView/WebView.h) + list(APPEND _AX_UI_SPECIFIC_SRC ui/WebView/WebViewImpl-win32.cpp ui/WebView/WebView.cpp) endif() elseif(APPLE) if(MACOSX) - set(_AX_UI_SPECIFIC_HEADER - ui/UIEditBox/UIEditBoxImpl-mac.h - ui/UIEditBox/Mac/UIPasswordTextField.h - ui/UIEditBox/Mac/UIMultilineTextField.h - ui/UIEditBox/Mac/UITextInput.h - ui/UIEditBox/Mac/UIEditBoxMac.h - ui/UIEditBox/Mac/UISingleLineTextField.h - ui/UIEditBox/Mac/UITextFieldFormatter.h - ) + set(_AX_UI_SPECIFIC_HEADER + ui/EditBox/EditBoxImpl-mac.h + ui/EditBox/Mac/PasswordTextField.h + ui/EditBox/Mac/MultilineTextField.h + ui/EditBox/Mac/TextInput.h + ui/EditBox/Mac/EditBoxMac.h + ui/EditBox/Mac/SingleLineTextField.h + ui/EditBox/Mac/TextFieldFormatter.h + ) set(_AX_UI_SPECIFIC_SRC - ui/UIEditBox/UIEditBoxImpl-mac.mm - ui/UIEditBox/Mac/UIEditBoxMac.mm - ui/UIEditBox/Mac/UIMultilineTextField.m - ui/UIEditBox/Mac/UIPasswordTextField.m - ui/UIEditBox/Mac/UISingleLineTextField.m - ui/UIEditBox/Mac/UITextFieldFormatter.m + ui/EditBox/EditBoxImpl-mac.mm + ui/EditBox/Mac/EditBoxMac.mm + ui/EditBox/Mac/MultilineTextField.m + ui/EditBox/Mac/PasswordTextField.m + ui/EditBox/Mac/SingleLineTextField.m + ui/EditBox/Mac/TextFieldFormatter.m ) elseif(IOS) if(TVOS) set(_AX_UI_SPECIFIC_HEADER - ui/UIEditBox/UIEditBoxImpl-ios.h - ui/UIEditBox/iOS/UIEditBoxIOS.h - ui/UIEditBox/iOS/UIMultilineTextField.h - ui/UIEditBox/iOS/UITextInput.h - ui/UIEditBox/iOS/UITextView+UITextInput.h - ui/UIEditBox/iOS/UITextField+UITextInput.h - ui/UIEditBox/iOS/UISingleLineTextField.h + ui/EditBox/EditBoxImpl-ios.h + ui/EditBox/iOS/EditBoxIOS.h + ui/EditBox/iOS/MultilineTextField.h + ui/EditBox/iOS/TextInput.h + ui/EditBox/iOS/UITextView+TextInput.h + ui/EditBox/iOS/TextField+TextInput.h + ui/EditBox/iOS/SingleLineTextField.h ) set(_AX_UI_SPECIFIC_SRC - ui/UIEditBox/UIEditBoxImpl-ios.mm - ui/UIEditBox/iOS/UIEditBoxIOS.mm - ui/UIEditBox/iOS/UIMultilineTextField.mm - ui/UIEditBox/iOS/UISingleLineTextField.mm - ui/UIEditBox/iOS/UITextField+UITextInput.mm - ui/UIEditBox/iOS/UITextView+UITextInput.mm + ui/EditBox/EditBoxImpl-ios.mm + ui/EditBox/iOS/EditBoxIOS.mm + ui/EditBox/iOS/MultilineTextField.mm + ui/EditBox/iOS/SingleLineTextField.mm + ui/EditBox/iOS/TextField+UITextInput.mm + ui/EditBox/iOS/TextView+UITextInput.mm ) else() set(_AX_UI_SPECIFIC_HEADER - ui/UIWebView/UIWebView.h - ui/UIWebView/UIWebViewImpl-ios.h - ui/UIEditBox/UIEditBoxImpl-ios.h - ui/UIEditBox/iOS/UIEditBoxIOS.h - ui/UIEditBox/iOS/UIMultilineTextField.h - ui/UIEditBox/iOS/UITextInput.h - ui/UIEditBox/iOS/UITextView+UITextInput.h - ui/UIEditBox/iOS/UITextField+UITextInput.h - ui/UIEditBox/iOS/UISingleLineTextField.h + ui/WebView/WebView.h + ui/WebView/WebViewImpl-ios.h + ui/EditBox/EditBoxImpl-ios.h + ui/EditBox/iOS/EditBoxIOS.h + ui/EditBox/iOS/MultilineTextField.h + ui/EditBox/iOS/TextInput.h + ui/EditBox/iOS/UITextView+TextInput.h + ui/EditBox/iOS/TextField+TextInput.h + ui/EditBox/iOS/SingleLineTextField.h ) set(_AX_UI_SPECIFIC_SRC - ui/UIWebView/UIWebView.mm - ui/UIWebView/UIWebViewImpl-ios.mm - ui/UIEditBox/UIEditBoxImpl-ios.mm - ui/UIEditBox/iOS/UIEditBoxIOS.mm - ui/UIEditBox/iOS/UIMultilineTextField.mm - ui/UIEditBox/iOS/UISingleLineTextField.mm - ui/UIEditBox/iOS/UITextField+UITextInput.mm - ui/UIEditBox/iOS/UITextView+UITextInput.mm + ui/WebView/WebView.mm + ui/WebView/WebViewImpl-ios.mm + ui/EditBox/EditBoxImpl-ios.mm + ui/EditBox/iOS/EditBoxIOS.mm + ui/EditBox/iOS/MultilineTextField.mm + ui/EditBox/iOS/SingleLineTextField.mm + ui/EditBox/iOS/TextField+UITextInput.mm + ui/EditBox/iOS/TextView+UITextInput.mm ) endif() endif() elseif(LINUX) set(_AX_UI_SPECIFIC_HEADER - ui/UIEditBox/UIEditBoxImpl-linux.h - ui/UIWebView/UIWebView.h - ui/UIWebView/UIWebViewImpl-linux.h + ui/EditBox/EditBoxImpl-linux.h + ui/WebView/WebView.h + ui/WebView/WebViewImpl-linux.h ) set(_AX_UI_SPECIFIC_SRC - ui/UIEditBox/UIEditBoxImpl-linux.cpp - ui/UIWebView/UIWebViewImpl-linux.cpp - ui/UIWebView/UIWebView.cpp + ui/EditBox/EditBoxImpl-linux.cpp + ui/WebView/WebViewImpl-linux.cpp + ui/WebView/WebView.cpp ) elseif(EMSCRIPTEN) set(_AX_UI_SPECIFIC_SRC - ui/UIEditBox/UIEditBoxImpl-wasm.cpp + ui/UIEditBox/EditBoxImpl-wasm.cpp ) elseif(ANDROID) set(_AX_UI_SPECIFIC_HEADER - ui/UIWebView/UIWebView.h - ui/UIWebView/UIWebViewImpl-android.h - ui/UIEditBox/UIEditBoxImpl-android.h + ui/WebView/WebView.h + ui/WebView/WebViewImpl-android.h + ui/EditBox/EditBoxImpl-android.h ) set(_AX_UI_SPECIFIC_SRC - ui/UIEditBox/UIEditBoxImpl-android.cpp - ui/UIWebView/UIWebViewImpl-android.cpp + ui/EditBox/EditBoxImpl-android.cpp + ui/WebView/WebViewImpl-android.cpp # it's special for android, not a common file - ui/UIWebView/UIWebView.cpp + ui/WebView/WebView.cpp ) endif() if(AX_ENABLE_MEDIA) - set(_AX_UI_SPECIFIC_HEADER ui/UIMediaPlayer.h ${_AX_UI_SPECIFIC_HEADER}) - set(_AX_UI_SPECIFIC_SRC ui/UIMediaPlayer.cpp ${_AX_UI_SPECIFIC_SRC}) + set(_AX_UI_SPECIFIC_HEADER ui/MediaPlayer.h ${_AX_UI_SPECIFIC_HEADER}) + set(_AX_UI_SPECIFIC_SRC ui/MediaPlayer.cpp ${_AX_UI_SPECIFIC_SRC}) endif() set(_AX_UI_HEADER @@ -121,67 +121,67 @@ set(_AX_UI_HEADER ui/axmol-ui.h ui/GUIDefine.h ui/GUIExport.h - ui/UIAbstractCheckButton.h - ui/UIButton.h - ui/UICheckBox.h - ui/UIHBox.h - ui/UIHelper.h - ui/UIImageView.h - ui/UILayout.h - ui/UILayoutComponent.h - ui/UILayoutManager.h - ui/UILayoutParameter.h - ui/UIListView.h - ui/UILoadingBar.h - ui/UIPageView.h - ui/UIPageViewIndicator.h - ui/UIRadioButton.h - ui/UIRelativeBox.h - ui/UIRichText.h - ui/UIScale9Sprite.h - ui/UIScrollView.h - ui/UIScrollViewBar.h - ui/UISlider.h - ui/UITabControl.h - ui/UIText.h - ui/UITextAtlas.h - ui/UITextBMFont.h - ui/UIInputField.h - ui/UIVBox.h - ui/UIWidget.h + ui/AbstractCheckButton.h + ui/Button.h + ui/CheckBox.h + ui/HBox.h + ui/Helper.h + ui/ImageView.h + ui/Layout.h + ui/LayoutComponent.h + ui/LayoutManager.h + ui/LayoutParameter.h + ui/ListView.h + ui/LoadingBar.h + ui/PageView.h + ui/PageViewIndicator.h + ui/RadioButton.h + ui/RelativeBox.h + ui/RichText.h + ui/Scale9Sprite.h + ui/ScrollView.h + ui/ScrollViewBar.h + ui/Slider.h + ui/TabControl.h + ui/Text.h + ui/TextAtlas.h + ui/TextBMFont.h + ui/InputField.h + ui/VBox.h + ui/Widget.h ) set(_AX_UI_SRC ${_AX_UI_SPECIFIC_SRC} ui/axmol-ui.cpp - ui/UIButton.cpp - ui/UIAbstractCheckButton.cpp - ui/UICheckBox.cpp - ui/UIRadioButton.cpp - ui/UIHBox.cpp - ui/UIHelper.cpp - ui/UIImageView.cpp - ui/UILayout.cpp - ui/UILayoutManager.cpp - ui/UILayoutParameter.cpp - ui/UIListView.cpp - ui/UILoadingBar.cpp - ui/UIPageView.cpp - ui/UIPageViewIndicator.cpp - ui/UIRelativeBox.cpp - ui/UIRichText.cpp - ui/UIScale9Sprite.cpp - ui/UIScrollView.cpp - ui/UIScrollViewBar.cpp - ui/UISlider.cpp - ui/UIText.cpp - ui/UITextAtlas.cpp - ui/UITextBMFont.cpp - ui/UIInputField.cpp - ui/UIVBox.cpp - ui/UIWidget.cpp - ui/UIEditBox/UIEditBox.cpp - ui/UILayoutComponent.cpp - ui/UIEditBox/UIEditBoxImpl-common.cpp - ui/UITabControl.cpp + ui/Button.cpp + ui/AbstractCheckButton.cpp + ui/CheckBox.cpp + ui/RadioButton.cpp + ui/HBox.cpp + ui/Helper.cpp + ui/ImageView.cpp + ui/Layout.cpp + ui/LayoutManager.cpp + ui/LayoutParameter.cpp + ui/ListView.cpp + ui/LoadingBar.cpp + ui/PageView.cpp + ui/PageViewIndicator.cpp + ui/RelativeBox.cpp + ui/RichText.cpp + ui/Scale9Sprite.cpp + ui/ScrollView.cpp + ui/ScrollViewBar.cpp + ui/Slider.cpp + ui/Text.cpp + ui/TextAtlas.cpp + ui/TextBMFont.cpp + ui/InputField.cpp + ui/VBox.cpp + ui/Widget.cpp + ui/EditBox/EditBox.cpp + ui/LayoutComponent.cpp + ui/EditBox/EditBoxImpl-common.cpp + ui/TabControl.cpp ) diff --git a/axmol/ui/UICheckBox.cpp b/axmol/ui/CheckBox.cpp similarity index 99% rename from axmol/ui/UICheckBox.cpp rename to axmol/ui/CheckBox.cpp index de2fd3c9230c..382e0a0f8232 100644 --- a/axmol/ui/UICheckBox.cpp +++ b/axmol/ui/CheckBox.cpp @@ -24,7 +24,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ -#include "axmol/ui/UICheckBox.h" +#include "axmol/ui/CheckBox.h" namespace ax { diff --git a/axmol/ui/UICheckBox.h b/axmol/ui/CheckBox.h similarity index 99% rename from axmol/ui/UICheckBox.h rename to axmol/ui/CheckBox.h index 9599836bddb3..42cb301b94d7 100644 --- a/axmol/ui/UICheckBox.h +++ b/axmol/ui/CheckBox.h @@ -26,7 +26,7 @@ THE SOFTWARE. #pragma once -#include "axmol/ui/UIAbstractCheckButton.h" +#include "axmol/ui/AbstractCheckButton.h" #include "axmol/ui/GUIExport.h" /** diff --git a/axmol/ui/UIEditBox/UIEditBox.cpp b/axmol/ui/EditBox/EditBox.cpp similarity index 99% rename from axmol/ui/UIEditBox/UIEditBox.cpp rename to axmol/ui/EditBox/EditBox.cpp index d8928456b37c..404dc1aa5044 100644 --- a/axmol/ui/UIEditBox/UIEditBox.cpp +++ b/axmol/ui/EditBox/EditBox.cpp @@ -25,9 +25,9 @@ THE SOFTWARE. ****************************************************************************/ -#include "axmol/ui/UIEditBox/UIEditBox.h" -#include "axmol/ui/UIEditBox/UIEditBoxImpl.h" -#include "axmol/ui/UIHelper.h" +#include "axmol/ui/EditBox/EditBox.h" +#include "axmol/ui/EditBox/EditBoxImpl.h" +#include "axmol/ui/Helper.h" namespace ax { diff --git a/axmol/ui/UIEditBox/UIEditBox.h b/axmol/ui/EditBox/EditBox.h similarity index 99% rename from axmol/ui/UIEditBox/UIEditBox.h rename to axmol/ui/EditBox/EditBox.h index b84e1f360b7c..a3f6e39dbbb8 100644 --- a/axmol/ui/UIEditBox/UIEditBox.h +++ b/axmol/ui/EditBox/EditBox.h @@ -29,8 +29,8 @@ #include "axmol/base/IMEDelegate.h" #include "axmol/ui/GUIDefine.h" -#include "axmol/ui/UIWidget.h" -#include "axmol/ui/UIScale9Sprite.h" +#include "axmol/ui/Widget.h" +#include "axmol/ui/Scale9Sprite.h" namespace ax { diff --git a/axmol/ui/UIEditBox/UIEditBoxImpl-android.cpp b/axmol/ui/EditBox/EditBoxImpl-android.cpp similarity index 98% rename from axmol/ui/UIEditBox/UIEditBoxImpl-android.cpp rename to axmol/ui/EditBox/EditBoxImpl-android.cpp index d438daf8365b..9ed7972c5a0f 100644 --- a/axmol/ui/UIEditBox/UIEditBoxImpl-android.cpp +++ b/axmol/ui/EditBox/EditBoxImpl-android.cpp @@ -26,17 +26,17 @@ THE SOFTWARE. ****************************************************************************/ -#include "axmol/ui/UIEditBox/UIEditBoxImpl-android.h" +#include "axmol/ui/EditBox/EditBoxImpl-android.h" #if (AX_TARGET_PLATFORM == AX_PLATFORM_ANDROID) -# include "axmol/ui/UIEditBox/UIEditBox.h" +# include "axmol/ui/EditBox/EditBox.h" # include # include "axmol/platform/android/jni/JniHelper.h" # include "axmol/2d/Label.h" # include "axmol/base/text_utils.h" # include "axmol/math/Vec2.h" -# include "axmol/ui/UIHelper.h" +# include "axmol/ui/Helper.h" # include "axmol/base/Director.h" # include "axmol/platform/FileUtils.h" # include "yasio/tlx/string_view.hpp" diff --git a/axmol/ui/UIEditBox/UIEditBoxImpl-android.h b/axmol/ui/EditBox/EditBoxImpl-android.h similarity index 98% rename from axmol/ui/UIEditBox/UIEditBoxImpl-android.h rename to axmol/ui/EditBox/EditBoxImpl-android.h index 620a431a7176..09fb6b39ac59 100644 --- a/axmol/ui/UIEditBox/UIEditBoxImpl-android.h +++ b/axmol/ui/EditBox/EditBoxImpl-android.h @@ -31,7 +31,7 @@ #if (AX_TARGET_PLATFORM == AX_PLATFORM_ANDROID) -# include "axmol/ui/UIEditBox/UIEditBoxImpl-common.h" +# include "axmol/ui/EditBox/EditBoxImpl-common.h" namespace ax { diff --git a/axmol/ui/UIEditBox/UIEditBoxImpl-common.cpp b/axmol/ui/EditBox/EditBoxImpl-common.cpp similarity index 99% rename from axmol/ui/UIEditBox/UIEditBoxImpl-common.cpp rename to axmol/ui/EditBox/EditBoxImpl-common.cpp index 382ca7cacc69..1ff5b968f5fa 100644 --- a/axmol/ui/UIEditBox/UIEditBoxImpl-common.cpp +++ b/axmol/ui/EditBox/EditBoxImpl-common.cpp @@ -25,14 +25,14 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ -#include "axmol/ui/UIEditBox/UIEditBoxImpl-common.h" +#include "axmol/ui/EditBox/EditBoxImpl-common.h" #define kLabelZOrder 9999 -#include "axmol/ui/UIEditBox/UIEditBox.h" +#include "axmol/ui/EditBox/EditBox.h" #include "axmol/base/Director.h" #include "axmol/2d/Label.h" -#include "axmol/ui/UIHelper.h" +#include "axmol/ui/Helper.h" static const int AX_EDIT_BOX_PADDING = 5; diff --git a/axmol/ui/UIEditBox/UIEditBoxImpl-common.h b/axmol/ui/EditBox/EditBoxImpl-common.h similarity index 98% rename from axmol/ui/UIEditBox/UIEditBoxImpl-common.h rename to axmol/ui/EditBox/EditBoxImpl-common.h index 26586a14ab52..d607e9b965db 100644 --- a/axmol/ui/UIEditBox/UIEditBoxImpl-common.h +++ b/axmol/ui/EditBox/EditBoxImpl-common.h @@ -30,8 +30,8 @@ #include "axmol/platform/PlatformConfig.h" #include "axmol/2d/Label.h" -#include "axmol/ui/UIEditBox/UIEditBoxImpl-common.h" -#include "axmol/ui/UIEditBox/UIEditBoxImpl.h" +#include "axmol/ui/EditBox/EditBoxImpl-common.h" +#include "axmol/ui/EditBox/EditBoxImpl.h" namespace ax { diff --git a/axmol/ui/UIEditBox/UIEditBoxImpl-ios.h b/axmol/ui/EditBox/EditBoxImpl-ios.h similarity index 98% rename from axmol/ui/UIEditBox/UIEditBoxImpl-ios.h rename to axmol/ui/EditBox/EditBoxImpl-ios.h index 5409f034eba0..b5cc8d192d85 100644 --- a/axmol/ui/UIEditBox/UIEditBoxImpl-ios.h +++ b/axmol/ui/EditBox/EditBoxImpl-ios.h @@ -29,7 +29,7 @@ #if (AX_TARGET_PLATFORM == AX_PLATFORM_IOS) -# include "axmol/ui/UIEditBox/UIEditBoxImpl-common.h" +# include "axmol/ui/EditBox/EditBoxImpl-common.h" @class UIEditBoxImplIOS_objc; @class UIFont; diff --git a/axmol/ui/UIEditBox/UIEditBoxImpl-ios.mm b/axmol/ui/EditBox/EditBoxImpl-ios.mm similarity index 98% rename from axmol/ui/UIEditBox/UIEditBoxImpl-ios.mm rename to axmol/ui/EditBox/EditBoxImpl-ios.mm index e48af8741a5a..74fc1069e529 100644 --- a/axmol/ui/UIEditBox/UIEditBoxImpl-ios.mm +++ b/axmol/ui/EditBox/EditBoxImpl-ios.mm @@ -25,13 +25,13 @@ of this software and associated documentation files (the "Software"), to deal OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ -#include "axmol/ui/UIEditBox/UIEditBoxImpl-ios.h" +#include "axmol/ui/EditBox/EditBoxImpl-ios.h" #if (AX_TARGET_PLATFORM == AX_PLATFORM_IOS) # define kLabelZOrder 9999 -# include "axmol/ui/UIEditBox/UIEditBox.h" +# include "axmol/ui/EditBox/EditBox.h" # include "axmol/base/Director.h" # include "axmol/2d/Label.h" # import "axmol/platform/ios/RenderHostView-ios.h" @@ -39,7 +39,7 @@ of this software and associated documentation files (the "Software"), to deal # import # import -# import "axmol/ui/UIEditBox/iOS/UIEditBoxIOS.h" +# import "axmol/ui/EditBox/iOS/EditBoxIOS.h" # define getEditBoxImplIOS() ((ax::ui::EditBoxImplIOS*)_editBox) diff --git a/axmol/ui/UIEditBox/UIEditBoxImpl-linux.cpp b/axmol/ui/EditBox/EditBoxImpl-linux.cpp similarity index 99% rename from axmol/ui/UIEditBox/UIEditBoxImpl-linux.cpp rename to axmol/ui/EditBox/EditBoxImpl-linux.cpp index cd34138d197f..7bd598606e42 100644 --- a/axmol/ui/UIEditBox/UIEditBoxImpl-linux.cpp +++ b/axmol/ui/EditBox/EditBoxImpl-linux.cpp @@ -25,11 +25,11 @@ THE SOFTWARE. ****************************************************************************/ -#include "axmol/ui/UIEditBox/UIEditBoxImpl-linux.h" +#include "axmol/ui/EditBox/EditBoxImpl-linux.h" #if (AX_TARGET_PLATFORM == AX_PLATFORM_LINUX) -# include "axmol/ui/UIEditBox/UIEditBox.h" +# include "axmol/ui/EditBox/EditBox.h" # include "axmol/2d/Label.h" # include "axmol/base/text_utils.h" diff --git a/axmol/ui/UIEditBox/UIEditBoxImpl-linux.h b/axmol/ui/EditBox/EditBoxImpl-linux.h similarity index 98% rename from axmol/ui/UIEditBox/UIEditBoxImpl-linux.h rename to axmol/ui/EditBox/EditBoxImpl-linux.h index 76b97991bb36..c16dd4a25878 100644 --- a/axmol/ui/UIEditBox/UIEditBoxImpl-linux.h +++ b/axmol/ui/EditBox/EditBoxImpl-linux.h @@ -31,7 +31,7 @@ #if (AX_TARGET_PLATFORM == AX_PLATFORM_LINUX) -# include "axmol/ui/UIEditBox/UIEditBoxImpl-common.h" +# include "axmol/ui/EditBox/EditBoxImpl-common.h" namespace ax { diff --git a/axmol/ui/UIEditBox/UIEditBoxImpl-mac.h b/axmol/ui/EditBox/EditBoxImpl-mac.h similarity index 98% rename from axmol/ui/UIEditBox/UIEditBoxImpl-mac.h rename to axmol/ui/EditBox/EditBoxImpl-mac.h index 94dd2b37d506..5bd1ceb812bf 100644 --- a/axmol/ui/UIEditBox/UIEditBoxImpl-mac.h +++ b/axmol/ui/EditBox/EditBoxImpl-mac.h @@ -31,7 +31,7 @@ #if (AX_TARGET_PLATFORM == AX_PLATFORM_MAC) -# include "axmol/ui/UIEditBox/UIEditBoxImpl-common.h" +# include "axmol/ui/EditBox/EditBoxImpl-common.h" @class UIEditBoxImplMac; @class NSFont; diff --git a/axmol/ui/UIEditBox/UIEditBoxImpl-mac.mm b/axmol/ui/EditBox/EditBoxImpl-mac.mm similarity index 97% rename from axmol/ui/UIEditBox/UIEditBoxImpl-mac.mm rename to axmol/ui/EditBox/EditBoxImpl-mac.mm index 9155cc121809..1e8719fbae0b 100644 --- a/axmol/ui/UIEditBox/UIEditBoxImpl-mac.mm +++ b/axmol/ui/EditBox/EditBoxImpl-mac.mm @@ -28,11 +28,11 @@ of this software and associated documentation files (the "Software"), to deal #include "axmol/platform/PlatformConfig.h" #if (AX_TARGET_PLATFORM == AX_PLATFORM_MAC) -# include "axmol/ui/UIEditBox/UIEditBoxImpl-mac.h" +# include "axmol/ui/EditBox/EditBoxImpl-mac.h" # include "axmol/base/Director.h" # include "axmol/base/text_utils.h" -# include "axmol/ui/UIEditBox/UIEditBox.h" -# include "axmol/ui/UIEditBox/Mac/UIEditBoxMac.h" +# include "axmol/ui/EditBox/EditBox.h" +# include "axmol/ui/EditBox/Mac/EditBoxMac.h" namespace ax { diff --git a/axmol/ui/UIEditBox/UIEditBoxImpl-stub.cpp b/axmol/ui/EditBox/EditBoxImpl-stub.cpp similarity index 97% rename from axmol/ui/UIEditBox/UIEditBoxImpl-stub.cpp rename to axmol/ui/EditBox/EditBoxImpl-stub.cpp index efd9ecce41c1..7ad142657afd 100644 --- a/axmol/ui/UIEditBox/UIEditBoxImpl-stub.cpp +++ b/axmol/ui/EditBox/EditBoxImpl-stub.cpp @@ -23,7 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#include "axmol/ui/UIEditBox/UIEditBox.h" +#include "axmol/ui/EditBox/EditBox.h" #if (AX_TARGET_PLATFORM != AX_PLATFORM_ANDROID) && (AX_TARGET_PLATFORM != AX_PLATFORM_IOS) && \ (AX_TARGET_PLATFORM != AX_PLATFORM_WIN32) && (AX_TARGET_PLATFORM != AX_PLATFORM_MAC) diff --git a/axmol/ui/UIEditBox/UIEditBoxImpl-wasm.cpp b/axmol/ui/EditBox/EditBoxImpl-wasm.cpp similarity index 99% rename from axmol/ui/UIEditBox/UIEditBoxImpl-wasm.cpp rename to axmol/ui/EditBox/EditBoxImpl-wasm.cpp index 3e06ed8cf97f..af3dee5f5e71 100644 --- a/axmol/ui/UIEditBox/UIEditBoxImpl-wasm.cpp +++ b/axmol/ui/EditBox/EditBoxImpl-wasm.cpp @@ -27,10 +27,10 @@ THE SOFTWARE. ****************************************************************************/ -#include "axmol/ui/UIEditBox/UIEditBoxImpl-wasm.h" +#include "axmol/ui/EditBox/EditBoxImpl-wasm.h" #if AX_TARGET_PLATFORM == AX_PLATFORM_WASM -# include "axmol/ui/UIHelper.h" +# include "axmol/ui/Helper.h" # include namespace ax { diff --git a/axmol/ui/UIEditBox/UIEditBoxImpl-wasm.h b/axmol/ui/EditBox/EditBoxImpl-wasm.h similarity index 98% rename from axmol/ui/UIEditBox/UIEditBoxImpl-wasm.h rename to axmol/ui/EditBox/EditBoxImpl-wasm.h index 4c5c94089ca0..4c239af67ec6 100644 --- a/axmol/ui/UIEditBox/UIEditBoxImpl-wasm.h +++ b/axmol/ui/EditBox/EditBoxImpl-wasm.h @@ -28,7 +28,7 @@ THE SOFTWARE. #include "axmol/platform/PlatformConfig.h" #if AX_TARGET_PLATFORM == AX_PLATFORM_WASM -# include "axmol/ui/UIEditBox/UIEditBoxImpl-common.h" +# include "axmol/ui/EditBox/EditBoxImpl-common.h" namespace ax { diff --git a/axmol/ui/UIEditBox/UIEditBoxImpl-win32.cpp b/axmol/ui/EditBox/EditBoxImpl-win32.cpp similarity index 99% rename from axmol/ui/UIEditBox/UIEditBoxImpl-win32.cpp rename to axmol/ui/EditBox/EditBoxImpl-win32.cpp index 56d9dac04d49..08dbf774c361 100644 --- a/axmol/ui/UIEditBox/UIEditBoxImpl-win32.cpp +++ b/axmol/ui/EditBox/EditBoxImpl-win32.cpp @@ -25,12 +25,12 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ -#include "axmol/ui/UIEditBox/UIEditBoxImpl-win32.h" +#include "axmol/ui/EditBox/EditBoxImpl-win32.h" #include "axmol/platform/PlatformConfig.h" #if (AX_TARGET_PLATFORM == AX_PLATFORM_WIN32) -# include "axmol/ui/UIEditBox/UIEditBox.h" +# include "axmol/ui/EditBox/EditBox.h" # include # include # include "axmol/2d/Label.h" @@ -39,7 +39,7 @@ THE SOFTWARE. # include # include # include "ntcvt/ntcvt.hpp" -# include "axmol/ui/UIHelper.h" +# include "axmol/ui/Helper.h" namespace ax { diff --git a/axmol/ui/UIEditBox/UIEditBoxImpl-win32.h b/axmol/ui/EditBox/EditBoxImpl-win32.h similarity index 98% rename from axmol/ui/UIEditBox/UIEditBoxImpl-win32.h rename to axmol/ui/EditBox/EditBoxImpl-win32.h index 5b711ba68e15..dc6ba19523c1 100644 --- a/axmol/ui/UIEditBox/UIEditBoxImpl-win32.h +++ b/axmol/ui/EditBox/EditBoxImpl-win32.h @@ -30,7 +30,7 @@ THE SOFTWARE. #include "axmol/platform/PlatformConfig.h" #if (AX_TARGET_PLATFORM == AX_PLATFORM_WIN32) -# include "axmol/ui/UIEditBox/UIEditBoxImpl-common.h" +# include "axmol/ui/EditBox/EditBoxImpl-common.h" namespace ax { diff --git a/axmol/ui/UIEditBox/UIEditBoxImpl-winrt.cpp b/axmol/ui/EditBox/EditBoxImpl-winrt.cpp similarity index 99% rename from axmol/ui/UIEditBox/UIEditBoxImpl-winrt.cpp rename to axmol/ui/EditBox/EditBoxImpl-winrt.cpp index 26796a116175..f09f0d589b58 100644 --- a/axmol/ui/UIEditBox/UIEditBoxImpl-winrt.cpp +++ b/axmol/ui/EditBox/EditBoxImpl-winrt.cpp @@ -29,8 +29,8 @@ #include "axmol/platform/PlatformConfig.h" #if (AX_TARGET_PLATFORM == AX_PLATFORM_WINRT) -# include "axmol/ui/UIEditBox/UIEditBoxImpl-winrt.h" -# include "axmol/ui/UIHelper.h" +# include "axmol/ui/EditBox/EditBoxImpl-winrt.h" +# include "axmol/ui/Helper.h" # include "axmol/platform/winrt/WinRTUtils.h" # include "axmol/platform/winrt/RenderViewImpl-winrt.h" # include "axmol/2d/FontFreeType.h" diff --git a/axmol/ui/UIEditBox/UIEditBoxImpl-winrt.h b/axmol/ui/EditBox/EditBoxImpl-winrt.h similarity index 99% rename from axmol/ui/UIEditBox/UIEditBoxImpl-winrt.h rename to axmol/ui/EditBox/EditBoxImpl-winrt.h index 48ec5e1cf9b1..448ccea560ec 100644 --- a/axmol/ui/UIEditBox/UIEditBoxImpl-winrt.h +++ b/axmol/ui/EditBox/EditBoxImpl-winrt.h @@ -28,7 +28,7 @@ THE SOFTWARE. #include "axmol/platform/PlatformConfig.h" #if AX_TARGET_PLATFORM == AX_PLATFORM_WINRT -# include "axmol/ui/UIEditBox/UIEditBoxImpl-common.h" +# include "axmol/ui/EditBox/EditBoxImpl-common.h" # include # include diff --git a/axmol/ui/UIEditBox/UIEditBoxImpl.h b/axmol/ui/EditBox/EditBoxImpl.h similarity index 99% rename from axmol/ui/UIEditBox/UIEditBoxImpl.h rename to axmol/ui/EditBox/EditBoxImpl.h index 8f7cec53c1b3..d4a0e083a179 100644 --- a/axmol/ui/UIEditBox/UIEditBoxImpl.h +++ b/axmol/ui/EditBox/EditBoxImpl.h @@ -27,7 +27,7 @@ #pragma once -#include "axmol/ui/UIEditBox/UIEditBox.h" +#include "axmol/ui/EditBox/EditBox.h" namespace ax { diff --git a/axmol/ui/UIEditBox/Mac/UIEditBoxMac.h b/axmol/ui/EditBox/Mac/EditBoxMac.h similarity index 96% rename from axmol/ui/UIEditBox/Mac/UIEditBoxMac.h rename to axmol/ui/EditBox/Mac/EditBoxMac.h index 391f2649bf08..8df79d4ab3c9 100644 --- a/axmol/ui/UIEditBox/Mac/UIEditBoxMac.h +++ b/axmol/ui/EditBox/Mac/EditBoxMac.h @@ -27,8 +27,8 @@ #import #import -#include "axmol/ui/UIEditBox/UIEditBoxImpl-mac.h" -#include "axmol/ui/UIEditBox/Mac/UITextInput.h" +#include "axmol/ui/EditBox/EditBoxImpl-mac.h" +#include "axmol/ui/EditBox/Mac/TextInput.h" #pragma mark - UIEditBox mac implementation diff --git a/axmol/ui/UIEditBox/Mac/UIEditBoxMac.mm b/axmol/ui/EditBox/Mac/EditBoxMac.mm similarity index 98% rename from axmol/ui/UIEditBox/Mac/UIEditBoxMac.mm rename to axmol/ui/EditBox/Mac/EditBoxMac.mm index 8b8d3e8491c9..e50bf6e9a70f 100644 --- a/axmol/ui/UIEditBox/Mac/UIEditBoxMac.mm +++ b/axmol/ui/EditBox/Mac/EditBoxMac.mm @@ -24,11 +24,11 @@ of this software and associated documentation files (the "Software"), to deal THE SOFTWARE. ****************************************************************************/ -#import "axmol/ui/UIEditBox/Mac/UIEditBoxMac.h" +#import "axmol/ui/EditBox/Mac/EditBoxMac.h" #include "axmol/base/Director.h" -#include "axmol/ui/UIEditBox/Mac/UISingleLineTextField.h" -#include "axmol/ui/UIEditBox/Mac/UIPasswordTextField.h" -#include "axmol/ui/UIEditBox/Mac/UIMultilineTextField.h" +#include "axmol/ui/EditBox/Mac/SingleLineTextField.h" +#include "axmol/ui/EditBox/Mac/PasswordTextField.h" +#include "axmol/ui/EditBox/Mac/MultilineTextField.h" #define getEditBoxImplMac() ((ax::ui::EditBoxImplMac*)_editBox) diff --git a/axmol/ui/UIEditBox/Mac/UIMultilineTextField.h b/axmol/ui/EditBox/Mac/MultilineTextField.h similarity index 96% rename from axmol/ui/UIEditBox/Mac/UIMultilineTextField.h rename to axmol/ui/EditBox/Mac/MultilineTextField.h index 02ae18afe325..9249d2336632 100644 --- a/axmol/ui/UIEditBox/Mac/UIMultilineTextField.h +++ b/axmol/ui/EditBox/Mac/MultilineTextField.h @@ -26,7 +26,7 @@ #pragma once #import -#include "axmol/ui/UIEditBox/Mac/UITextInput.h" +#include "axmol/ui/EditBox/Mac/TextInput.h" @interface CCUIMultilineTextField : NSTextView { NSString* _placeHolder; diff --git a/axmol/ui/UIEditBox/Mac/UIMultilineTextField.m b/axmol/ui/EditBox/Mac/MultilineTextField.m similarity index 98% rename from axmol/ui/UIEditBox/Mac/UIMultilineTextField.m rename to axmol/ui/EditBox/Mac/MultilineTextField.m index 035a85ccbb8f..b4ad51add72f 100644 --- a/axmol/ui/UIEditBox/Mac/UIMultilineTextField.m +++ b/axmol/ui/EditBox/Mac/MultilineTextField.m @@ -23,7 +23,7 @@ of this software and associated documentation files (the "Software"), to deal THE SOFTWARE. ****************************************************************************/ -#import "axmol/ui/UIEditBox/Mac/UIMultilineTextField.h" +#import "axmol/ui/EditBox/Mac/MultilineTextField.h" @interface CCUIMultilineTextField() @property(nonatomic, copy)NSString* placeHolder; diff --git a/axmol/ui/UIEditBox/Mac/UIPasswordTextField.h b/axmol/ui/EditBox/Mac/PasswordTextField.h similarity index 96% rename from axmol/ui/UIEditBox/Mac/UIPasswordTextField.h rename to axmol/ui/EditBox/Mac/PasswordTextField.h index c24aa53c3257..3e92ee64272f 100644 --- a/axmol/ui/UIEditBox/Mac/UIPasswordTextField.h +++ b/axmol/ui/EditBox/Mac/PasswordTextField.h @@ -26,7 +26,7 @@ #pragma once #import -#include "axmol/ui/UIEditBox/Mac/UITextInput.h" +#include "axmol/ui/EditBox/Mac/TextInput.h" @interface CCUIPasswordTextField : NSSecureTextField { } diff --git a/axmol/ui/UIEditBox/Mac/UIPasswordTextField.m b/axmol/ui/EditBox/Mac/PasswordTextField.m similarity index 97% rename from axmol/ui/UIEditBox/Mac/UIPasswordTextField.m rename to axmol/ui/EditBox/Mac/PasswordTextField.m index c7887a8de0f3..4e4f8d30b568 100644 --- a/axmol/ui/UIEditBox/Mac/UIPasswordTextField.m +++ b/axmol/ui/EditBox/Mac/PasswordTextField.m @@ -23,8 +23,8 @@ of this software and associated documentation files (the "Software"), to deal THE SOFTWARE. ****************************************************************************/ -#import "axmol/ui/UIEditBox/Mac/UIPasswordTextField.h" -#include "axmol/ui/UIEditBox/Mac/UITextFieldFormatter.h" +#import "axmol/ui/EditBox/Mac/PasswordTextField.h" +#include "axmol/ui/EditBox/Mac/TextFieldFormatter.h" @interface RSVerticallyCenteredSecureTextFieldCell : NSSecureTextFieldCell { diff --git a/axmol/ui/UIEditBox/Mac/UISingleLineTextField.h b/axmol/ui/EditBox/Mac/SingleLineTextField.h similarity index 96% rename from axmol/ui/UIEditBox/Mac/UISingleLineTextField.h rename to axmol/ui/EditBox/Mac/SingleLineTextField.h index e1602fc27c83..67e3ea69f678 100644 --- a/axmol/ui/UIEditBox/Mac/UISingleLineTextField.h +++ b/axmol/ui/EditBox/Mac/SingleLineTextField.h @@ -26,7 +26,7 @@ #pragma once #import -#include "axmol/ui/UIEditBox/Mac/UITextInput.h" +#include "axmol/ui/EditBox/Mac/TextInput.h" @interface CCUISingleLineTextField : NSTextField { } diff --git a/axmol/ui/UIEditBox/Mac/UISingleLineTextField.m b/axmol/ui/EditBox/Mac/SingleLineTextField.m similarity index 97% rename from axmol/ui/UIEditBox/Mac/UISingleLineTextField.m rename to axmol/ui/EditBox/Mac/SingleLineTextField.m index abacfc1e3f7d..25b6a8a9be5d 100644 --- a/axmol/ui/UIEditBox/Mac/UISingleLineTextField.m +++ b/axmol/ui/EditBox/Mac/SingleLineTextField.m @@ -23,8 +23,8 @@ of this software and associated documentation files (the "Software"), to deal THE SOFTWARE. ****************************************************************************/ -#import "axmol/ui/UIEditBox/Mac/UISingleLineTextField.h" -#include "axmol/ui/UIEditBox/Mac/UITextFieldFormatter.h" +#import "axmol/ui/EditBox/Mac/SingleLineTextField.h" +#include "axmol/ui/EditBox/Mac/TextFieldFormatter.h" @interface RSVerticallyCenteredTextFieldCell : NSTextFieldCell { diff --git a/axmol/ui/UIEditBox/Mac/UITextFieldFormatter.h b/axmol/ui/EditBox/Mac/TextFieldFormatter.h similarity index 100% rename from axmol/ui/UIEditBox/Mac/UITextFieldFormatter.h rename to axmol/ui/EditBox/Mac/TextFieldFormatter.h diff --git a/axmol/ui/UIEditBox/Mac/UITextFieldFormatter.m b/axmol/ui/EditBox/Mac/TextFieldFormatter.m similarity index 97% rename from axmol/ui/UIEditBox/Mac/UITextFieldFormatter.m rename to axmol/ui/EditBox/Mac/TextFieldFormatter.m index 350273544e36..96849e48fe35 100644 --- a/axmol/ui/UIEditBox/Mac/UITextFieldFormatter.m +++ b/axmol/ui/EditBox/Mac/TextFieldFormatter.m @@ -23,7 +23,7 @@ of this software and associated documentation files (the "Software"), to deal THE SOFTWARE. ****************************************************************************/ -#import "axmol/ui/UIEditBox/Mac/UITextFieldFormatter.h" +#import "axmol/ui/EditBox/Mac/TextFieldFormatter.h" @implementation CCUITextFieldFormatter { diff --git a/axmol/ui/UIEditBox/Mac/UITextInput.h b/axmol/ui/EditBox/Mac/TextInput.h similarity index 100% rename from axmol/ui/UIEditBox/Mac/UITextInput.h rename to axmol/ui/EditBox/Mac/TextInput.h diff --git a/axmol/ui/UIEditBox/iOS/UIEditBoxIOS.h b/axmol/ui/EditBox/iOS/EditBoxIOS.h similarity index 96% rename from axmol/ui/UIEditBox/iOS/UIEditBoxIOS.h rename to axmol/ui/EditBox/iOS/EditBoxIOS.h index 2160c139b008..4fefed6a9dec 100644 --- a/axmol/ui/UIEditBox/iOS/UIEditBoxIOS.h +++ b/axmol/ui/EditBox/iOS/EditBoxIOS.h @@ -28,8 +28,8 @@ #pragma once #import -#import "axmol/ui/UIEditBox/iOS/UITextInput.h" -#include "axmol/ui/UIEditBox/UIEditBoxImpl-ios.h" +#import "axmol/ui/EditBox/iOS/TextInput.h" +#include "axmol/ui/EditBox/EditBoxImpl-ios.h" @interface UIEditBoxImplIOS_objc : NSObject diff --git a/axmol/ui/UIEditBox/iOS/UIEditBoxIOS.mm b/axmol/ui/EditBox/iOS/EditBoxIOS.mm similarity index 98% rename from axmol/ui/UIEditBox/iOS/UIEditBoxIOS.mm rename to axmol/ui/EditBox/iOS/EditBoxIOS.mm index 49a9ccd5f66b..92adaa2ad2a3 100644 --- a/axmol/ui/UIEditBox/iOS/UIEditBoxIOS.mm +++ b/axmol/ui/EditBox/iOS/EditBoxIOS.mm @@ -26,9 +26,9 @@ of this software and associated documentation files (the "Software"), to deal THE SOFTWARE. ****************************************************************************/ -#import "axmol/ui/UIEditBox/iOS/UIEditBoxIOS.h" -#import "axmol/ui/UIEditBox/iOS/UISingleLineTextField.h" -#import "axmol/ui/UIEditBox/iOS/UIMultilineTextField.h" +#import "axmol/ui/EditBox/iOS/EditBoxIOS.h" +#import "axmol/ui/EditBox/iOS/SingleLineTextField.h" +#import "axmol/ui/EditBox/iOS/MultilineTextField.h" #import "axmol/platform/ios/RenderHostView-ios.h" #include "axmol/base/Director.h" diff --git a/axmol/ui/UIEditBox/iOS/UIMultilineTextField.h b/axmol/ui/EditBox/iOS/MultilineTextField.h similarity index 96% rename from axmol/ui/UIEditBox/iOS/UIMultilineTextField.h rename to axmol/ui/EditBox/iOS/MultilineTextField.h index 4bf84115b17e..e85bf2b30dc4 100644 --- a/axmol/ui/UIEditBox/iOS/UIMultilineTextField.h +++ b/axmol/ui/EditBox/iOS/MultilineTextField.h @@ -27,7 +27,7 @@ #pragma once #import -#import "axmol/ui/UIEditBox/iOS/UITextView+UITextInput.h" +#import "axmol/ui/EditBox/iOS/TextView+TextInput.h" #pragma mark - UIMultilineTextField implementation diff --git a/axmol/ui/UIEditBox/iOS/UIMultilineTextField.mm b/axmol/ui/EditBox/iOS/MultilineTextField.mm similarity index 98% rename from axmol/ui/UIEditBox/iOS/UIMultilineTextField.mm rename to axmol/ui/EditBox/iOS/MultilineTextField.mm index 79f1a82f0df9..9a80f7136b19 100644 --- a/axmol/ui/UIEditBox/iOS/UIMultilineTextField.mm +++ b/axmol/ui/EditBox/iOS/MultilineTextField.mm @@ -25,7 +25,7 @@ of this software and associated documentation files (the "Software"), to deal THE SOFTWARE. ****************************************************************************/ -#import "axmol/ui/UIEditBox/iOS/UIMultilineTextField.h" +#import "axmol/ui/EditBox/iOS/MultilineTextField.h" #include "axmol/base/Director.h" diff --git a/axmol/ui/UIEditBox/iOS/UISingleLineTextField.h b/axmol/ui/EditBox/iOS/SingleLineTextField.h similarity index 96% rename from axmol/ui/UIEditBox/iOS/UISingleLineTextField.h rename to axmol/ui/EditBox/iOS/SingleLineTextField.h index ef5443f1249c..48f218ec48f5 100644 --- a/axmol/ui/UIEditBox/iOS/UISingleLineTextField.h +++ b/axmol/ui/EditBox/iOS/SingleLineTextField.h @@ -27,7 +27,7 @@ #pragma once #import -#import "axmol/ui/UIEditBox/iOS/UITextField+UITextInput.h" +#import "axmol/ui/EditBox/iOS/TextField+TextInput.h" #pragma mark - UISingleLineTextField implementation diff --git a/axmol/ui/UIEditBox/iOS/UISingleLineTextField.mm b/axmol/ui/EditBox/iOS/SingleLineTextField.mm similarity index 96% rename from axmol/ui/UIEditBox/iOS/UISingleLineTextField.mm rename to axmol/ui/EditBox/iOS/SingleLineTextField.mm index 04f79d1888b9..eeabe009b340 100644 --- a/axmol/ui/UIEditBox/iOS/UISingleLineTextField.mm +++ b/axmol/ui/EditBox/iOS/SingleLineTextField.mm @@ -25,8 +25,8 @@ of this software and associated documentation files (the "Software"), to deal THE SOFTWARE. ****************************************************************************/ -#import "axmol/ui/UIEditBox/iOS/UISingleLineTextField.h" -#import "axmol/ui/UIEditBox/iOS/UITextInput.h" +#import "axmol/ui/EditBox/iOS/SingleLineTextField.h" +#import "axmol/ui/EditBox/iOS/TextInput.h" #include "axmol/base/Director.h" diff --git a/axmol/ui/UIEditBox/iOS/UITextField+UITextInput.h b/axmol/ui/EditBox/iOS/TextField+UITextInput.h similarity index 97% rename from axmol/ui/UIEditBox/iOS/UITextField+UITextInput.h rename to axmol/ui/EditBox/iOS/TextField+UITextInput.h index 4d7afd4ad85f..9b15f3689981 100644 --- a/axmol/ui/UIEditBox/iOS/UITextField+UITextInput.h +++ b/axmol/ui/EditBox/iOS/TextField+UITextInput.h @@ -25,7 +25,7 @@ #pragma once #import -#import "axmol/ui/UIEditBox/iOS/UITextInput.h" +#import "axmol/ui/EditBox/iOS/TextInput.h" @interface UITextField (AXUITextInput) @end diff --git a/axmol/ui/UIEditBox/iOS/UITextField+UITextInput.mm b/axmol/ui/EditBox/iOS/TextField+UITextInput.mm similarity index 98% rename from axmol/ui/UIEditBox/iOS/UITextField+UITextInput.mm rename to axmol/ui/EditBox/iOS/TextField+UITextInput.mm index 17a69a37b4ef..258e280e75a9 100644 --- a/axmol/ui/UIEditBox/iOS/UITextField+UITextInput.mm +++ b/axmol/ui/EditBox/iOS/TextField+UITextInput.mm @@ -23,7 +23,7 @@ of this software and associated documentation files (the "Software"), to deal THE SOFTWARE. ****************************************************************************/ -#import "axmol/ui/UIEditBox/iOS/UITextField+UITextInput.h" +#import "axmol/ui/EditBox/iOS/TextField+TextInput.h" @implementation UITextField (AXUITextInput) diff --git a/axmol/ui/UIEditBox/iOS/UITextInput.h b/axmol/ui/EditBox/iOS/TextInput.h similarity index 100% rename from axmol/ui/UIEditBox/iOS/UITextInput.h rename to axmol/ui/EditBox/iOS/TextInput.h diff --git a/axmol/ui/UIEditBox/iOS/UITextView+UITextInput.h b/axmol/ui/EditBox/iOS/TextView+UITextInput.h similarity index 97% rename from axmol/ui/UIEditBox/iOS/UITextView+UITextInput.h rename to axmol/ui/EditBox/iOS/TextView+UITextInput.h index 69c761cb8fde..1cc401bfdba9 100644 --- a/axmol/ui/UIEditBox/iOS/UITextView+UITextInput.h +++ b/axmol/ui/EditBox/iOS/TextView+UITextInput.h @@ -25,7 +25,7 @@ #pragma once #import -#import "axmol/ui/UIEditBox/iOS/UITextInput.h" +#import "axmol/ui/EditBox/iOS/TextInput.h" @interface UITextView (AXUITextInput) @end diff --git a/axmol/ui/UIEditBox/iOS/UITextView+UITextInput.mm b/axmol/ui/EditBox/iOS/TextView+UITextInput.mm similarity index 98% rename from axmol/ui/UIEditBox/iOS/UITextView+UITextInput.mm rename to axmol/ui/EditBox/iOS/TextView+UITextInput.mm index 3bae4adf1d64..62d78c56fc53 100644 --- a/axmol/ui/UIEditBox/iOS/UITextView+UITextInput.mm +++ b/axmol/ui/EditBox/iOS/TextView+UITextInput.mm @@ -23,7 +23,7 @@ of this software and associated documentation files (the "Software"), to deal THE SOFTWARE. ****************************************************************************/ -#import "axmol/ui/UIEditBox/iOS/UITextView+UITextInput.h" +#import "axmol/ui/EditBox/iOS/TextView+TextInput.h" @implementation UITextView (AXUITextInput) diff --git a/axmol/ui/UIHBox.cpp b/axmol/ui/HBox.cpp similarity index 98% rename from axmol/ui/UIHBox.cpp rename to axmol/ui/HBox.cpp index 2b0d79ec0097..a97d1f2c7bf9 100644 --- a/axmol/ui/UIHBox.cpp +++ b/axmol/ui/HBox.cpp @@ -23,7 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#include "axmol/ui/UIHBox.h" +#include "axmol/ui/HBox.h" namespace ax { diff --git a/axmol/ui/UIHBox.h b/axmol/ui/HBox.h similarity index 98% rename from axmol/ui/UIHBox.h rename to axmol/ui/HBox.h index bb89cf2af2d8..7a3e6440789f 100644 --- a/axmol/ui/UIHBox.h +++ b/axmol/ui/HBox.h @@ -26,7 +26,7 @@ #pragma once -#include "axmol/ui/UILayout.h" +#include "axmol/ui/Layout.h" #include "axmol/ui/GUIExport.h" namespace ax diff --git a/axmol/ui/UIHelper.cpp b/axmol/ui/Helper.cpp similarity index 99% rename from axmol/ui/UIHelper.cpp rename to axmol/ui/Helper.cpp index 0169a63352b4..d722bf8d1070 100644 --- a/axmol/ui/UIHelper.cpp +++ b/axmol/ui/Helper.cpp @@ -25,9 +25,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ -#include "axmol/ui/UIHelper.h" -#include "axmol/ui/UIWidget.h" -#include "axmol/ui/UILayoutComponent.h" +#include "axmol/ui/Helper.h" +#include "axmol/ui/Widget.h" +#include "axmol/ui/LayoutComponent.h" #include "axmol/base/Director.h" #include "axmol/base/text_utils.h" diff --git a/axmol/ui/UIHelper.h b/axmol/ui/Helper.h similarity index 99% rename from axmol/ui/UIHelper.h rename to axmol/ui/Helper.h index d5ef9e09118e..7ad0c7887e5b 100644 --- a/axmol/ui/UIHelper.h +++ b/axmol/ui/Helper.h @@ -131,7 +131,7 @@ class AX_GUI_DLL Helper // It's very useful for programer to operate UI elements in runtime, // so, we publish it to here. // usage: - // #include "ui/UIHelper.h" + // #include "ui/Helper.h" // ui::Helper::centerNode(node); // the node should be already have parent. // ui::Helper::makeVerticalSpacingEqual(nodes); // all the nodes shoud be in the same parent. // diff --git a/axmol/ui/UIImageView.cpp b/axmol/ui/ImageView.cpp similarity index 98% rename from axmol/ui/UIImageView.cpp rename to axmol/ui/ImageView.cpp index 4cd38e325a91..d93903c7658b 100644 --- a/axmol/ui/UIImageView.cpp +++ b/axmol/ui/ImageView.cpp @@ -24,9 +24,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ -#include "axmol/ui/UIImageView.h" -#include "axmol/ui/UIScale9Sprite.h" -#include "axmol/ui/UIHelper.h" +#include "axmol/ui/ImageView.h" +#include "axmol/ui/Scale9Sprite.h" +#include "axmol/ui/Helper.h" #include "axmol/2d/Sprite.h" namespace ax diff --git a/axmol/ui/UIImageView.h b/axmol/ui/ImageView.h similarity index 99% rename from axmol/ui/UIImageView.h rename to axmol/ui/ImageView.h index 743cd1005ad5..699caad908bd 100644 --- a/axmol/ui/UIImageView.h +++ b/axmol/ui/ImageView.h @@ -26,7 +26,7 @@ THE SOFTWARE. #pragma once -#include "axmol/ui/UIWidget.h" +#include "axmol/ui/Widget.h" #include "axmol/ui/GUIExport.h" /** diff --git a/axmol/ui/UIInputField.cpp b/axmol/ui/InputField.cpp similarity index 99% rename from axmol/ui/UIInputField.cpp rename to axmol/ui/InputField.cpp index dbec283b87fa..fa9c012be42f 100644 --- a/axmol/ui/UIInputField.cpp +++ b/axmol/ui/InputField.cpp @@ -22,7 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ -#include "axmol/ui/UIInputField.h" +#include "axmol/ui/InputField.h" #include "axmol/base/Director.h" #include "axmol/base/text_utils.h" diff --git a/axmol/ui/UIInputField.h b/axmol/ui/InputField.h similarity index 99% rename from axmol/ui/UIInputField.h rename to axmol/ui/InputField.h index 8024ef43e36c..04c0e7bf3371 100644 --- a/axmol/ui/UIInputField.h +++ b/axmol/ui/InputField.h @@ -24,7 +24,7 @@ THE SOFTWARE. #pragma once -#include "axmol/ui/UIWidget.h" +#include "axmol/ui/Widget.h" #include "axmol/base/IMEDelegate.h" #include "axmol/2d/DrawNode.h" #include "axmol/2d/Label.h" diff --git a/axmol/ui/UILayout.cpp b/axmol/ui/Layout.cpp similarity index 99% rename from axmol/ui/UILayout.cpp rename to axmol/ui/Layout.cpp index 9e8f1a4fbe18..bd88e5a02dcb 100644 --- a/axmol/ui/UILayout.cpp +++ b/axmol/ui/Layout.cpp @@ -24,13 +24,13 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ -#include "axmol/ui/UILayout.h" -#include "axmol/ui/UIHelper.h" -#include "axmol/ui/UIScale9Sprite.h" +#include "axmol/ui/Layout.h" +#include "axmol/ui/Helper.h" +#include "axmol/ui/Scale9Sprite.h" #include "axmol/renderer/RenderState.h" #include "axmol/base/Director.h" #include "axmol/renderer/Renderer.h" -#include "axmol/ui/UILayoutManager.h" +#include "axmol/ui/LayoutManager.h" #include "axmol/2d/DrawNode.h" #include "axmol/2d/Layer.h" #include "axmol/2d/Sprite.h" diff --git a/axmol/ui/UILayout.h b/axmol/ui/Layout.h similarity index 99% rename from axmol/ui/UILayout.h rename to axmol/ui/Layout.h index ee30e46fba8f..624d094f99d6 100644 --- a/axmol/ui/UILayout.h +++ b/axmol/ui/Layout.h @@ -26,7 +26,7 @@ THE SOFTWARE. #pragma once -#include "axmol/ui/UIWidget.h" +#include "axmol/ui/Widget.h" #include "axmol/ui/GUIExport.h" #include "axmol/renderer/CustomCommand.h" #include "axmol/renderer/GroupCommand.h" diff --git a/axmol/ui/UILayoutComponent.cpp b/axmol/ui/LayoutComponent.cpp similarity index 99% rename from axmol/ui/UILayoutComponent.cpp rename to axmol/ui/LayoutComponent.cpp index 9f5d567f12b6..7132143ec556 100644 --- a/axmol/ui/UILayoutComponent.cpp +++ b/axmol/ui/LayoutComponent.cpp @@ -23,11 +23,11 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ -#include "axmol/ui/UIPageView.h" -#include "axmol/ui/UILayoutComponent.h" +#include "axmol/ui/PageView.h" +#include "axmol/ui/LayoutComponent.h" #include "axmol/scene/Node.h" #include "axmol/ui/GUIDefine.h" -#include "axmol/ui/UIHelper.h" +#include "axmol/ui/Helper.h" namespace ax { diff --git a/axmol/ui/UILayoutComponent.h b/axmol/ui/LayoutComponent.h similarity index 100% rename from axmol/ui/UILayoutComponent.h rename to axmol/ui/LayoutComponent.h diff --git a/axmol/ui/UILayoutManager.cpp b/axmol/ui/LayoutManager.cpp similarity index 99% rename from axmol/ui/UILayoutManager.cpp rename to axmol/ui/LayoutManager.cpp index 4e0789307bba..bbafbbad7c94 100644 --- a/axmol/ui/UILayoutManager.cpp +++ b/axmol/ui/LayoutManager.cpp @@ -24,8 +24,8 @@ THE SOFTWARE. ****************************************************************************/ -#include "axmol/ui/UILayoutManager.h" -#include "axmol/ui/UILayout.h" +#include "axmol/ui/LayoutManager.h" +#include "axmol/ui/Layout.h" namespace ax { diff --git a/axmol/ui/UILayoutManager.h b/axmol/ui/LayoutManager.h similarity index 100% rename from axmol/ui/UILayoutManager.h rename to axmol/ui/LayoutManager.h diff --git a/axmol/ui/UILayoutParameter.cpp b/axmol/ui/LayoutParameter.cpp similarity index 98% rename from axmol/ui/UILayoutParameter.cpp rename to axmol/ui/LayoutParameter.cpp index cea8b55155ec..4abc7dbe7f94 100644 --- a/axmol/ui/UILayoutParameter.cpp +++ b/axmol/ui/LayoutParameter.cpp @@ -24,8 +24,8 @@ THE SOFTWARE. ****************************************************************************/ -#include "axmol/ui/UILayoutParameter.h" -#include "axmol/ui/UILayout.h" +#include "axmol/ui/LayoutParameter.h" +#include "axmol/ui/Layout.h" namespace ax { diff --git a/axmol/ui/UILayoutParameter.h b/axmol/ui/LayoutParameter.h similarity index 100% rename from axmol/ui/UILayoutParameter.h rename to axmol/ui/LayoutParameter.h diff --git a/axmol/ui/UIListView.cpp b/axmol/ui/ListView.cpp similarity index 99% rename from axmol/ui/UIListView.cpp rename to axmol/ui/ListView.cpp index 8d10ab75a6d5..7d6ed6b2f0e2 100644 --- a/axmol/ui/UIListView.cpp +++ b/axmol/ui/ListView.cpp @@ -24,8 +24,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ -#include "axmol/ui/UIListView.h" -#include "axmol/ui/UIHelper.h" +#include "axmol/ui/ListView.h" +#include "axmol/ui/Helper.h" namespace ax { diff --git a/axmol/ui/UIListView.h b/axmol/ui/ListView.h similarity index 99% rename from axmol/ui/UIListView.h rename to axmol/ui/ListView.h index 9ff2a72ef640..39bede651cf9 100644 --- a/axmol/ui/UIListView.h +++ b/axmol/ui/ListView.h @@ -26,7 +26,7 @@ THE SOFTWARE. #pragma once -#include "axmol/ui/UIScrollView.h" +#include "axmol/ui/ScrollView.h" #include "axmol/ui/GUIExport.h" /** diff --git a/axmol/ui/UILoadingBar.cpp b/axmol/ui/LoadingBar.cpp similarity index 99% rename from axmol/ui/UILoadingBar.cpp rename to axmol/ui/LoadingBar.cpp index bf05f1d9c674..ce3080236df5 100644 --- a/axmol/ui/UILoadingBar.cpp +++ b/axmol/ui/LoadingBar.cpp @@ -24,9 +24,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ -#include "axmol/ui/UILoadingBar.h" -#include "axmol/ui/UIHelper.h" -#include "axmol/ui/UIScale9Sprite.h" +#include "axmol/ui/LoadingBar.h" +#include "axmol/ui/Helper.h" +#include "axmol/ui/Scale9Sprite.h" #include "axmol/2d/Sprite.h" namespace ax diff --git a/axmol/ui/UILoadingBar.h b/axmol/ui/LoadingBar.h similarity index 99% rename from axmol/ui/UILoadingBar.h rename to axmol/ui/LoadingBar.h index d69ee431385b..d0122ec031bc 100644 --- a/axmol/ui/UILoadingBar.h +++ b/axmol/ui/LoadingBar.h @@ -26,7 +26,7 @@ THE SOFTWARE. #pragma once -#include "axmol/ui/UIWidget.h" +#include "axmol/ui/Widget.h" #include "axmol/ui/GUIExport.h" namespace ax diff --git a/axmol/ui/UIMediaPlayer.cpp b/axmol/ui/MediaPlayer.cpp similarity index 99% rename from axmol/ui/UIMediaPlayer.cpp rename to axmol/ui/MediaPlayer.cpp index f55d216a84b6..0ae4224fd5a7 100644 --- a/axmol/ui/UIMediaPlayer.cpp +++ b/axmol/ui/MediaPlayer.cpp @@ -24,7 +24,7 @@ THE SOFTWARE. ****************************************************************************/ -#include "axmol/ui/UIMediaPlayer.h" +#include "axmol/ui/MediaPlayer.h" // Now, common implementation based on redesigned MediaEngine is enable for windows and macOS #if defined(AX_ENABLE_MEDIA) @@ -34,10 +34,10 @@ # include "axmol/base/Director.h" # include "axmol/base/EventListenerKeyboard.h" # include "axmol/platform/FileUtils.h" -# include "axmol/ui/UIHelper.h" +# include "axmol/ui/Helper.h" # include "axmol/media/MediaEngine.h" -# include "axmol/ui/UIButton.h" -# include "axmol/ui/UILayout.h" +# include "axmol/ui/Button.h" +# include "axmol/ui/Layout.h" # include "axmol/tlx/byte_buffer.hpp" //----------------------------------------------------------------------------------------------------------- diff --git a/axmol/ui/UIMediaPlayer.h b/axmol/ui/MediaPlayer.h similarity index 99% rename from axmol/ui/UIMediaPlayer.h rename to axmol/ui/MediaPlayer.h index 48e47532d2ba..d59335ea6dad 100644 --- a/axmol/ui/UIMediaPlayer.h +++ b/axmol/ui/MediaPlayer.h @@ -27,9 +27,9 @@ #if defined(AX_ENABLE_MEDIA) -# include "axmol/ui/UIButton.h" -# include "axmol/ui/UIWidget.h" -# include "axmol/ui/UILayout.h" +# include "axmol/ui/Button.h" +# include "axmol/ui/Widget.h" +# include "axmol/ui/Layout.h" # include "axmol/2d/Sprite.h" # include diff --git a/axmol/ui/UIPageView.cpp b/axmol/ui/PageView.cpp similarity index 99% rename from axmol/ui/UIPageView.cpp rename to axmol/ui/PageView.cpp index 5810fae12210..acb8115272b4 100644 --- a/axmol/ui/UIPageView.cpp +++ b/axmol/ui/PageView.cpp @@ -24,8 +24,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ -#include "axmol/ui/UIPageView.h" -#include "axmol/ui/UIPageViewIndicator.h" +#include "axmol/ui/PageView.h" +#include "axmol/ui/PageViewIndicator.h" namespace ax { diff --git a/axmol/ui/UIPageView.h b/axmol/ui/PageView.h similarity index 99% rename from axmol/ui/UIPageView.h rename to axmol/ui/PageView.h index cc86e4f8903d..7878cdfb1ef5 100644 --- a/axmol/ui/UIPageView.h +++ b/axmol/ui/PageView.h @@ -26,7 +26,7 @@ THE SOFTWARE. #pragma once -#include "axmol/ui/UIListView.h" +#include "axmol/ui/ListView.h" #include "axmol/ui/GUIExport.h" /** diff --git a/axmol/ui/UIPageViewIndicator.cpp b/axmol/ui/PageViewIndicator.cpp similarity index 99% rename from axmol/ui/UIPageViewIndicator.cpp rename to axmol/ui/PageViewIndicator.cpp index 71bfc5bd9657..c90eae8725c3 100644 --- a/axmol/ui/UIPageViewIndicator.cpp +++ b/axmol/ui/PageViewIndicator.cpp @@ -24,7 +24,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ -#include "axmol/ui/UIPageViewIndicator.h" +#include "axmol/ui/PageViewIndicator.h" #include "axmol/2d/Sprite.h" #include "axmol/base/Utils.h" diff --git a/axmol/ui/UIPageViewIndicator.h b/axmol/ui/PageViewIndicator.h similarity index 99% rename from axmol/ui/UIPageViewIndicator.h rename to axmol/ui/PageViewIndicator.h index cad1b3604701..2ecd1610cd96 100644 --- a/axmol/ui/UIPageViewIndicator.h +++ b/axmol/ui/PageViewIndicator.h @@ -26,7 +26,7 @@ THE SOFTWARE. #pragma once -#include "axmol/ui/UIPageView.h" +#include "axmol/ui/PageView.h" #include "axmol/2d/Sprite.h" namespace ax diff --git a/axmol/ui/UIRadioButton.cpp b/axmol/ui/RadioButton.cpp similarity index 99% rename from axmol/ui/UIRadioButton.cpp rename to axmol/ui/RadioButton.cpp index 10c4b6355457..2ba6e80de3f2 100644 --- a/axmol/ui/UIRadioButton.cpp +++ b/axmol/ui/RadioButton.cpp @@ -24,7 +24,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ -#include "axmol/ui/UIRadioButton.h" +#include "axmol/ui/RadioButton.h" namespace ax { diff --git a/axmol/ui/UIRadioButton.h b/axmol/ui/RadioButton.h similarity index 99% rename from axmol/ui/UIRadioButton.h rename to axmol/ui/RadioButton.h index 39fd4b630cc1..a53f42c7642d 100644 --- a/axmol/ui/UIRadioButton.h +++ b/axmol/ui/RadioButton.h @@ -26,7 +26,7 @@ THE SOFTWARE. #pragma once -#include "axmol/ui/UIAbstractCheckButton.h" +#include "axmol/ui/AbstractCheckButton.h" #include "axmol/ui/GUIExport.h" /** diff --git a/axmol/ui/UIRelativeBox.cpp b/axmol/ui/RelativeBox.cpp similarity index 98% rename from axmol/ui/UIRelativeBox.cpp rename to axmol/ui/RelativeBox.cpp index 59bbaf02f334..825e6464c8ce 100644 --- a/axmol/ui/UIRelativeBox.cpp +++ b/axmol/ui/RelativeBox.cpp @@ -24,7 +24,7 @@ THE SOFTWARE. ****************************************************************************/ -#include "axmol/ui/UIRelativeBox.h" +#include "axmol/ui/RelativeBox.h" namespace ax { diff --git a/axmol/ui/UIRelativeBox.h b/axmol/ui/RelativeBox.h similarity index 98% rename from axmol/ui/UIRelativeBox.h rename to axmol/ui/RelativeBox.h index 1e80242b89dc..8d505af4e95e 100644 --- a/axmol/ui/UIRelativeBox.h +++ b/axmol/ui/RelativeBox.h @@ -26,7 +26,7 @@ #pragma once -#include "axmol/ui/UILayout.h" +#include "axmol/ui/Layout.h" #include "axmol/ui/GUIExport.h" namespace ax diff --git a/axmol/ui/UIRichText.cpp b/axmol/ui/RichText.cpp similarity index 99% rename from axmol/ui/UIRichText.cpp rename to axmol/ui/RichText.cpp index 7a301aa245dd..9d680daa86c0 100644 --- a/axmol/ui/UIRichText.cpp +++ b/axmol/ui/RichText.cpp @@ -24,7 +24,7 @@ THE SOFTWARE. ****************************************************************************/ -#include "axmol/ui/UIRichText.h" +#include "axmol/ui/RichText.h" #include #include @@ -41,7 +41,7 @@ #include "axmol/2d/Sprite.h" #include "axmol/base/text_utils.h" #include "axmol/tlx/charconv.hpp" -#include "axmol/ui/UIHelper.h" +#include "axmol/ui/Helper.h" #include "axmol/tlx/format.hpp" #include "axmol/tlx/utility.hpp" diff --git a/axmol/ui/UIRichText.h b/axmol/ui/RichText.h similarity index 99% rename from axmol/ui/UIRichText.h rename to axmol/ui/RichText.h index e6c7f4d36d6b..9f673f39cf63 100644 --- a/axmol/ui/UIRichText.h +++ b/axmol/ui/RichText.h @@ -25,7 +25,7 @@ ****************************************************************************/ #pragma once -#include "axmol/ui/UIWidget.h" +#include "axmol/ui/Widget.h" #include "axmol/ui/GUIExport.h" #include "axmol/base/Value.h" diff --git a/axmol/ui/UIScale9Sprite.cpp b/axmol/ui/Scale9Sprite.cpp similarity index 99% rename from axmol/ui/UIScale9Sprite.cpp rename to axmol/ui/Scale9Sprite.cpp index dbc33c061106..51873d99ac2c 100644 --- a/axmol/ui/UIScale9Sprite.cpp +++ b/axmol/ui/Scale9Sprite.cpp @@ -24,7 +24,7 @@ THE SOFTWARE. ****************************************************************************/ -#include "axmol/ui/UIScale9Sprite.h" +#include "axmol/ui/Scale9Sprite.h" #include "axmol/2d/Sprite.h" #include "axmol/base/Vector.h" #include "axmol/base/Director.h" diff --git a/axmol/ui/UIScale9Sprite.h b/axmol/ui/Scale9Sprite.h similarity index 100% rename from axmol/ui/UIScale9Sprite.h rename to axmol/ui/Scale9Sprite.h diff --git a/axmol/ui/UIScrollView.cpp b/axmol/ui/ScrollView.cpp similarity index 99% rename from axmol/ui/UIScrollView.cpp rename to axmol/ui/ScrollView.cpp index 69ecc90a52ff..92862b02d7b6 100644 --- a/axmol/ui/UIScrollView.cpp +++ b/axmol/ui/ScrollView.cpp @@ -24,11 +24,11 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ -#include "axmol/ui/UIScrollView.h" +#include "axmol/ui/ScrollView.h" #include "axmol/base/Director.h" #include "axmol/base/Utils.h" #include "axmol/platform/Device.h" -#include "axmol/ui/UIScrollViewBar.h" +#include "axmol/ui/ScrollViewBar.h" #include "axmol/2d/TweenFunction.h" #include "axmol/scene/Camera.h" namespace ax diff --git a/axmol/ui/UIScrollView.h b/axmol/ui/ScrollView.h similarity index 99% rename from axmol/ui/UIScrollView.h rename to axmol/ui/ScrollView.h index 71d02651d342..0d12f9f88e49 100644 --- a/axmol/ui/UIScrollView.h +++ b/axmol/ui/ScrollView.h @@ -26,7 +26,7 @@ THE SOFTWARE. #pragma once -#include "axmol/ui/UILayout.h" +#include "axmol/ui/Layout.h" #include "axmol/ui/GUIExport.h" #include diff --git a/axmol/ui/UIScrollViewBar.cpp b/axmol/ui/ScrollViewBar.cpp similarity index 99% rename from axmol/ui/UIScrollViewBar.cpp rename to axmol/ui/ScrollViewBar.cpp index 1bfea4cd43e3..e3c123d10e22 100644 --- a/axmol/ui/UIScrollViewBar.cpp +++ b/axmol/ui/ScrollViewBar.cpp @@ -24,7 +24,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ -#include "axmol/ui/UIScrollViewBar.h" +#include "axmol/ui/ScrollViewBar.h" #include "axmol/platform/Image.h" #include "axmol/2d/Sprite.h" #include "axmol/base/Utils.h" diff --git a/axmol/ui/UIScrollViewBar.h b/axmol/ui/ScrollViewBar.h similarity index 99% rename from axmol/ui/UIScrollViewBar.h rename to axmol/ui/ScrollViewBar.h index 50bba9fc3c6a..a66db86e308e 100644 --- a/axmol/ui/UIScrollViewBar.h +++ b/axmol/ui/ScrollViewBar.h @@ -26,7 +26,7 @@ THE SOFTWARE. #pragma once -#include "axmol/ui/UIScrollView.h" +#include "axmol/ui/ScrollView.h" namespace ax { diff --git a/axmol/ui/UISlider.cpp b/axmol/ui/Slider.cpp similarity index 99% rename from axmol/ui/UISlider.cpp rename to axmol/ui/Slider.cpp index ee486e636826..75dc35eea4f4 100644 --- a/axmol/ui/UISlider.cpp +++ b/axmol/ui/Slider.cpp @@ -24,9 +24,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ -#include "axmol/ui/UISlider.h" -#include "axmol/ui/UIScale9Sprite.h" -#include "axmol/ui/UIHelper.h" +#include "axmol/ui/Slider.h" +#include "axmol/ui/Scale9Sprite.h" +#include "axmol/ui/Helper.h" #include "axmol/2d/Sprite.h" #include "axmol/scene/Camera.h" #include "axmol/renderer/Shaders.h" diff --git a/axmol/ui/UISlider.h b/axmol/ui/Slider.h similarity index 99% rename from axmol/ui/UISlider.h rename to axmol/ui/Slider.h index 8fac2ee47a77..3893b7659037 100644 --- a/axmol/ui/UISlider.h +++ b/axmol/ui/Slider.h @@ -26,7 +26,7 @@ THE SOFTWARE. #pragma once -#include "axmol/ui/UIWidget.h" +#include "axmol/ui/Widget.h" #include "axmol/ui/GUIExport.h" namespace ax diff --git a/axmol/ui/UITabControl.cpp b/axmol/ui/TabControl.cpp similarity index 99% rename from axmol/ui/UITabControl.cpp rename to axmol/ui/TabControl.cpp index 4479fb9fa2d1..f20374ea1bb0 100644 --- a/axmol/ui/UITabControl.cpp +++ b/axmol/ui/TabControl.cpp @@ -27,8 +27,8 @@ #include "axmol/platform/FileUtils.h" #include "axmol/2d/Sprite.h" #include "axmol/2d/Label.h" -#include "axmol/ui/UILayout.h" -#include "axmol/ui/UITabControl.h" +#include "axmol/ui/Layout.h" +#include "axmol/ui/TabControl.h" namespace ax { diff --git a/axmol/ui/UITabControl.h b/axmol/ui/TabControl.h similarity index 99% rename from axmol/ui/UITabControl.h rename to axmol/ui/TabControl.h index 868fc40427c2..5f3fab6b372d 100644 --- a/axmol/ui/UITabControl.h +++ b/axmol/ui/TabControl.h @@ -26,8 +26,8 @@ #pragma once -#include "axmol/ui/UIAbstractCheckButton.h" -#include "axmol/ui/UIWidget.h" +#include "axmol/ui/AbstractCheckButton.h" +#include "axmol/ui/Widget.h" /** * @addtogroup ui diff --git a/axmol/ui/UIText.cpp b/axmol/ui/Text.cpp similarity index 99% rename from axmol/ui/UIText.cpp rename to axmol/ui/Text.cpp index f962eeda48a3..5de0e495ebd9 100644 --- a/axmol/ui/UIText.cpp +++ b/axmol/ui/Text.cpp @@ -24,7 +24,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ -#include "axmol/ui/UIText.h" +#include "axmol/ui/Text.h" #include "axmol/2d/Label.h" #include "axmol/platform/FileUtils.h" diff --git a/axmol/ui/UIText.h b/axmol/ui/Text.h similarity index 99% rename from axmol/ui/UIText.h rename to axmol/ui/Text.h index 8093a404a1c8..7907b8612d51 100644 --- a/axmol/ui/UIText.h +++ b/axmol/ui/Text.h @@ -26,7 +26,7 @@ THE SOFTWARE. #pragma once -#include "axmol/ui/UIWidget.h" +#include "axmol/ui/Widget.h" #include "axmol/ui/GUIExport.h" #include "axmol/base/Types.h" diff --git a/axmol/ui/UITextAtlas.cpp b/axmol/ui/TextAtlas.cpp similarity index 99% rename from axmol/ui/UITextAtlas.cpp rename to axmol/ui/TextAtlas.cpp index 8a4ca60e513b..9d92ad3ce39c 100644 --- a/axmol/ui/UITextAtlas.cpp +++ b/axmol/ui/TextAtlas.cpp @@ -24,7 +24,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ -#include "axmol/ui/UITextAtlas.h" +#include "axmol/ui/TextAtlas.h" #include "axmol/2d/Label.h" namespace ax diff --git a/axmol/ui/UITextAtlas.h b/axmol/ui/TextAtlas.h similarity index 99% rename from axmol/ui/UITextAtlas.h rename to axmol/ui/TextAtlas.h index ffcceb562bd8..364510fe6985 100644 --- a/axmol/ui/UITextAtlas.h +++ b/axmol/ui/TextAtlas.h @@ -26,7 +26,7 @@ THE SOFTWARE. #pragma once -#include "axmol/ui/UIWidget.h" +#include "axmol/ui/Widget.h" #include "axmol/ui/GUIExport.h" namespace ax diff --git a/axmol/ui/UITextBMFont.cpp b/axmol/ui/TextBMFont.cpp similarity index 99% rename from axmol/ui/UITextBMFont.cpp rename to axmol/ui/TextBMFont.cpp index 7b1ac970b606..ab1a73b47a0d 100644 --- a/axmol/ui/UITextBMFont.cpp +++ b/axmol/ui/TextBMFont.cpp @@ -24,7 +24,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ -#include "axmol/ui/UITextBMFont.h" +#include "axmol/ui/TextBMFont.h" #include "axmol/2d/Label.h" namespace ax diff --git a/axmol/ui/UITextBMFont.h b/axmol/ui/TextBMFont.h similarity index 99% rename from axmol/ui/UITextBMFont.h rename to axmol/ui/TextBMFont.h index 707abd3ac27e..17e5becfdcd5 100644 --- a/axmol/ui/UITextBMFont.h +++ b/axmol/ui/TextBMFont.h @@ -26,7 +26,7 @@ THE SOFTWARE. #pragma once -#include "axmol/ui/UIWidget.h" +#include "axmol/ui/Widget.h" #include "axmol/ui/GUIExport.h" /** diff --git a/axmol/ui/UIVBox.cpp b/axmol/ui/VBox.cpp similarity index 98% rename from axmol/ui/UIVBox.cpp rename to axmol/ui/VBox.cpp index b744b8c73a8b..edb66fd00420 100644 --- a/axmol/ui/UIVBox.cpp +++ b/axmol/ui/VBox.cpp @@ -24,7 +24,7 @@ THE SOFTWARE. ****************************************************************************/ -#include "axmol/ui/UIVBox.h" +#include "axmol/ui/VBox.h" namespace ax { diff --git a/axmol/ui/UIVBox.h b/axmol/ui/VBox.h similarity index 98% rename from axmol/ui/UIVBox.h rename to axmol/ui/VBox.h index b03f551a773f..57da08b5eb46 100644 --- a/axmol/ui/UIVBox.h +++ b/axmol/ui/VBox.h @@ -26,7 +26,7 @@ #pragma once -#include "axmol/ui/UILayout.h" +#include "axmol/ui/Layout.h" #include "axmol/ui/GUIExport.h" namespace ax diff --git a/axmol/ui/UIWebView/UIWebView-inl.h b/axmol/ui/WebView/WebView-inl.h similarity index 99% rename from axmol/ui/UIWebView/UIWebView-inl.h rename to axmol/ui/WebView/WebView-inl.h index 82460144fd10..e0418f16c52f 100644 --- a/axmol/ui/UIWebView/UIWebView-inl.h +++ b/axmol/ui/WebView/WebView-inl.h @@ -31,7 +31,7 @@ (AX_TARGET_PLATFORM == AX_PLATFORM_ANDROID || AX_TARGET_PLATFORM == AX_PLATFORM_IOS || \ AX_TARGET_PLATFORM == AX_PLATFORM_LINUX) -# include "axmol/ui/UIWebView/UIWebView.h" +# include "axmol/ui/WebView/WebView.h" # include "axmol/platform/RenderView.h" # include "axmol/base/Director.h" # include "axmol/platform/FileUtils.h" diff --git a/axmol/ui/UIWebView/UIWebView.cpp b/axmol/ui/WebView/WebView.cpp similarity index 83% rename from axmol/ui/UIWebView/UIWebView.cpp rename to axmol/ui/WebView/WebView.cpp index 34526cec42bd..8862f0c10505 100644 --- a/axmol/ui/UIWebView/UIWebView.cpp +++ b/axmol/ui/WebView/WebView.cpp @@ -27,17 +27,17 @@ #if (AX_TARGET_PLATFORM == AX_PLATFORM_ANDROID) -# include "axmol/ui/UIWebView/UIWebViewImpl-android.h" -# include "axmol/ui/UIWebView/UIWebView-inl.h" +# include "axmol/ui/WebView/WebViewImpl-android.h" +# include "axmol/ui/WebView/WebView-inl.h" #elif (AX_TARGET_PLATFORM == AX_PLATFORM_WIN32) -# include "axmol/ui/UIWebView/UIWebViewImpl-win32.h" -# include "axmol/ui/UIWebView/UIWebView-inl.h" +# include "axmol/ui/WebView/WebViewImpl-win32.h" +# include "axmol/ui/WebView/WebView-inl.h" #elif (AX_TARGET_PLATFORM == AX_PLATFORM_LINUX) && defined(AX_HAVE_WEBKIT2GTK) -# include "axmol/ui/UIWebView/UIWebViewImpl-linux.h" -# include "axmol/ui/UIWebView/UIWebView-inl.h" +# include "axmol/ui/WebView/WebViewImpl-linux.h" +# include "axmol/ui/WebView/WebView-inl.h" #endif diff --git a/axmol/ui/UIWebView/UIWebView.h b/axmol/ui/WebView/WebView.h similarity index 99% rename from axmol/ui/UIWebView/UIWebView.h rename to axmol/ui/WebView/WebView.h index 0e4bba9b61b2..4b29c931132c 100644 --- a/axmol/ui/UIWebView/UIWebView.h +++ b/axmol/ui/WebView/WebView.h @@ -25,7 +25,7 @@ ****************************************************************************/ #pragma once -#include "axmol/ui/UIWidget.h" +#include "axmol/ui/Widget.h" #include "axmol/ui/GUIExport.h" #include "axmol/base/Data.h" diff --git a/axmol/ui/UIWebView/UIWebView.mm b/axmol/ui/WebView/WebView.mm similarity index 93% rename from axmol/ui/UIWebView/UIWebView.mm rename to axmol/ui/WebView/WebView.mm index 1b3248aac84f..665927b583f1 100644 --- a/axmol/ui/UIWebView/UIWebView.mm +++ b/axmol/ui/WebView/WebView.mm @@ -24,5 +24,5 @@ of this software and associated documentation files (the "Software"), to deal THE SOFTWARE. ****************************************************************************/ -#include "axmol/ui/UIWebView/UIWebViewImpl-ios.h" -#include "axmol/ui/UIWebView/UIWebView-inl.h" +#include "axmol/ui/WebView/WebViewImpl-ios.h" +#include "axmol/ui/WebView/WebView-inl.h" diff --git a/axmol/ui/UIWebView/UIWebViewCommon.h b/axmol/ui/WebView/WebViewCommon.h similarity index 100% rename from axmol/ui/UIWebView/UIWebViewCommon.h rename to axmol/ui/WebView/WebViewCommon.h diff --git a/axmol/ui/UIWebView/UIWebViewImpl-android.cpp b/axmol/ui/WebView/WebViewImpl-android.cpp similarity index 98% rename from axmol/ui/UIWebView/UIWebViewImpl-android.cpp rename to axmol/ui/WebView/WebViewImpl-android.cpp index c278c0f3a5fe..a48385f235ab 100644 --- a/axmol/ui/UIWebView/UIWebViewImpl-android.cpp +++ b/axmol/ui/WebView/WebViewImpl-android.cpp @@ -23,18 +23,18 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ -#include "axmol/ui/UIWebView/UIWebViewImpl-android.h" +#include "axmol/ui/WebView/WebViewImpl-android.h" #include #include #include #include "axmol/platform/android/jni/JniHelper.h" -#include "axmol/ui/UIWebView/UIWebView.h" +#include "axmol/ui/WebView/WebView.h" #include "axmol/platform/RenderView.h" #include "axmol/base/Director.h" #include "axmol/platform/FileUtils.h" -#include "axmol/ui/UIHelper.h" +#include "axmol/ui/Helper.h" #include "yasio/tlx/string_view.hpp" static const char* className = "dev.axmol.lib.WebViewHelper"; diff --git a/axmol/ui/UIWebView/UIWebViewImpl-android.h b/axmol/ui/WebView/WebViewImpl-android.h similarity index 100% rename from axmol/ui/UIWebView/UIWebViewImpl-android.h rename to axmol/ui/WebView/WebViewImpl-android.h diff --git a/axmol/ui/UIWebView/UIWebViewImpl-ios.h b/axmol/ui/WebView/WebViewImpl-ios.h similarity index 100% rename from axmol/ui/UIWebView/UIWebViewImpl-ios.h rename to axmol/ui/WebView/WebViewImpl-ios.h diff --git a/axmol/ui/UIWebView/UIWebViewImpl-ios.mm b/axmol/ui/WebView/WebViewImpl-ios.mm similarity index 99% rename from axmol/ui/UIWebView/UIWebViewImpl-ios.mm rename to axmol/ui/WebView/WebViewImpl-ios.mm index cee60bc6ad9c..7901307e32d7 100644 --- a/axmol/ui/UIWebView/UIWebViewImpl-ios.mm +++ b/axmol/ui/WebView/WebViewImpl-ios.mm @@ -27,8 +27,8 @@ of this software and associated documentation files (the "Software"), to deal #import #import -#include "axmol/ui/UIWebView/UIWebViewImpl-ios.h" -#include "axmol/ui/UIWebView/UIWebView.h" +#include "axmol/ui/WebView/WebViewImpl-ios.h" +#include "axmol/ui/WebView/WebView.h" #include "axmol/renderer/Renderer.h" #include "axmol/base/Director.h" #include "axmol/platform/RenderView.h" diff --git a/axmol/ui/UIWebView/UIWebViewImpl-linux.cpp b/axmol/ui/WebView/WebViewImpl-linux.cpp similarity index 99% rename from axmol/ui/UIWebView/UIWebViewImpl-linux.cpp rename to axmol/ui/WebView/WebViewImpl-linux.cpp index 3fb578340742..481d524418cd 100644 --- a/axmol/ui/UIWebView/UIWebViewImpl-linux.cpp +++ b/axmol/ui/WebView/WebViewImpl-linux.cpp @@ -26,7 +26,7 @@ Note: only support x11, wayland not implement yet ****************************************************************************/ -#include "axmol/ui/UIWebView/UIWebViewImpl-linux.h" +#include "axmol/ui/WebView/WebViewImpl-linux.h" #if (AX_TARGET_PLATFORM == AX_PLATFORM_LINUX) && defined(AX_HAVE_WEBKIT2GTK) @@ -36,12 +36,12 @@ # include # include -# include "axmol/ui/UIWebView/UIWebView.h" +# include "axmol/ui/WebView/WebView.h" # include "axmol/base/Director.h" # include "axmol/platform/FileUtils.h" # include "axmol/platform/RenderView.h" -# include "axmol/ui/UIHelper.h" -# include "axmol/ui/UIWebView/UIWebViewCommon.h" +# include "axmol/ui/Helper.h" +# include "axmol/ui/WebView/WebViewCommon.h" # include # include diff --git a/axmol/ui/UIWebView/UIWebViewImpl-linux.h b/axmol/ui/WebView/WebViewImpl-linux.h similarity index 100% rename from axmol/ui/UIWebView/UIWebViewImpl-linux.h rename to axmol/ui/WebView/WebViewImpl-linux.h diff --git a/axmol/ui/UIWebView/UIWebViewImpl-win32.cpp b/axmol/ui/WebView/WebViewImpl-win32.cpp similarity index 99% rename from axmol/ui/UIWebView/UIWebViewImpl-win32.cpp rename to axmol/ui/WebView/WebViewImpl-win32.cpp index 9a97d7f4dbe6..4f10413157c6 100644 --- a/axmol/ui/UIWebView/UIWebViewImpl-win32.cpp +++ b/axmol/ui/WebView/WebViewImpl-win32.cpp @@ -27,13 +27,13 @@ #if defined(_WIN32) && defined(AX_ENABLE_MSEDGE_WEBVIEW2) -# include "axmol/ui/UIWebView/UIWebViewImpl-win32.h" -# include "axmol/ui/UIWebView/UIWebView.h" -# include "axmol/ui/UIWebView/UIWebViewCommon.h" +# include "axmol/ui/WebView/WebViewImpl-win32.h" +# include "axmol/ui/WebView/WebView.h" +# include "axmol/ui/WebView/WebViewCommon.h" # include "axmol/base/Director.h" # include "axmol/platform/FileUtils.h" # include "axmol/platform/RenderView.h" -# include "axmol/ui/UIHelper.h" +# include "axmol/ui/Helper.h" # include "axmol/base/Utils.h" # ifndef WIN32_LEAN_AND_MEAN diff --git a/axmol/ui/UIWebView/UIWebViewImpl-win32.h b/axmol/ui/WebView/WebViewImpl-win32.h similarity index 100% rename from axmol/ui/UIWebView/UIWebViewImpl-win32.h rename to axmol/ui/WebView/WebViewImpl-win32.h diff --git a/axmol/ui/UIWidget.cpp b/axmol/ui/Widget.cpp similarity index 99% rename from axmol/ui/UIWidget.cpp rename to axmol/ui/Widget.cpp index 165af43a4559..5fe08704714c 100644 --- a/axmol/ui/UIWidget.cpp +++ b/axmol/ui/Widget.cpp @@ -24,19 +24,19 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ -#include "axmol/ui/UIWidget.h" -#include "axmol/ui/UILayout.h" -#include "axmol/ui/UIHelper.h" +#include "axmol/ui/Widget.h" +#include "axmol/ui/Layout.h" +#include "axmol/ui/Helper.h" #include "axmol/base/EventListenerTouch.h" #include "axmol/base/EventListenerKeyboard.h" #include "axmol/base/Director.h" #include "axmol/base/EventFocus.h" #include "axmol/base/EventDispatcher.h" -#include "axmol/ui/UILayoutComponent.h" +#include "axmol/ui/LayoutComponent.h" #include "axmol/renderer/Shaders.h" #include "axmol/scene/Camera.h" #include "axmol/2d/Sprite.h" -#include "axmol/ui/UIScale9Sprite.h" +#include "axmol/ui/Scale9Sprite.h" namespace ax { diff --git a/axmol/ui/UIWidget.h b/axmol/ui/Widget.h similarity index 99% rename from axmol/ui/UIWidget.h rename to axmol/ui/Widget.h index ae539275f123..2e551ad307e9 100644 --- a/axmol/ui/UIWidget.h +++ b/axmol/ui/Widget.h @@ -27,7 +27,7 @@ THE SOFTWARE. #pragma once #include "axmol/2d/ProtectedNode.h" -#include "axmol/ui/UILayoutParameter.h" +#include "axmol/ui/LayoutParameter.h" #include "axmol/ui/GUIDefine.h" #include "axmol/ui/GUIExport.h" #include "axmol/base/Map.h" diff --git a/axmol/ui/axmol-ui.h b/axmol/ui/axmol-ui.h index 91a143d5622e..fb7989b8fcd0 100644 --- a/axmol/ui/axmol-ui.h +++ b/axmol/ui/axmol-ui.h @@ -26,37 +26,37 @@ THE SOFTWARE. #pragma once -#include "axmol/ui/UIWidget.h" -#include "axmol/ui/UILayout.h" -#include "axmol/ui/UIButton.h" -#include "axmol/ui/UICheckBox.h" -#include "axmol/ui/UIRadioButton.h" -#include "axmol/ui/UIImageView.h" -#include "axmol/ui/UIText.h" -#include "axmol/ui/UITextAtlas.h" -#include "axmol/ui/UILoadingBar.h" -#include "axmol/ui/UIScrollView.h" -#include "axmol/ui/UIListView.h" -#include "axmol/ui/UISlider.h" -#include "axmol/ui/UIInputField.h" -#include "axmol/ui/UITextBMFont.h" -#include "axmol/ui/UIPageView.h" -#include "axmol/ui/UIHelper.h" -#include "axmol/ui/UIRichText.h" -#include "axmol/ui/UIHBox.h" -#include "axmol/ui/UIVBox.h" -#include "axmol/ui/UIRelativeBox.h" +#include "axmol/ui/Widget.h" +#include "axmol/ui/Layout.h" +#include "axmol/ui/Button.h" +#include "axmol/ui/CheckBox.h" +#include "axmol/ui/RadioButton.h" +#include "axmol/ui/ImageView.h" +#include "axmol/ui/Text.h" +#include "axmol/ui/TextAtlas.h" +#include "axmol/ui/LoadingBar.h" +#include "axmol/ui/ScrollView.h" +#include "axmol/ui/ListView.h" +#include "axmol/ui/Slider.h" +#include "axmol/ui/InputField.h" +#include "axmol/ui/TextBMFont.h" +#include "axmol/ui/PageView.h" +#include "axmol/ui/Helper.h" +#include "axmol/ui/RichText.h" +#include "axmol/ui/HBox.h" +#include "axmol/ui/VBox.h" +#include "axmol/ui/RelativeBox.h" #if defined(AX_ENABLE_MEDIA) -# include "axmol/ui/UIMediaPlayer.h" +# include "axmol/ui/MediaPlayer.h" #endif #if !defined(_WIN32) || defined(AX_ENABLE_MSEDGE_WEBVIEW2) -# include "axmol/ui/UIWebView/UIWebView.h" +# include "axmol/ui/WebView/WebView.h" #endif #include "axmol/ui/GUIExport.h" -#include "axmol/ui/UIScale9Sprite.h" -#include "axmol/ui/UIEditBox/UIEditBox.h" -#include "axmol/ui/UILayoutComponent.h" -#include "axmol/ui/UITabControl.h" +#include "axmol/ui/Scale9Sprite.h" +#include "axmol/ui/EditBox/EditBox.h" +#include "axmol/ui/LayoutComponent.h" +#include "axmol/ui/TabControl.h" /** * @addtogroup ui diff --git a/extensions/GUI/src/GUI/ControlExtension/ControlButton.h b/extensions/GUI/src/GUI/ControlExtension/ControlButton.h index 559750238498..60f64416cc14 100644 --- a/extensions/GUI/src/GUI/ControlExtension/ControlButton.h +++ b/extensions/GUI/src/GUI/ControlExtension/ControlButton.h @@ -34,7 +34,7 @@ #include "Control.h" #include "Invocation.h" #include "axmol/base/Map.h" -#include "axmol/ui/UIScale9Sprite.h" +#include "axmol/ui/Scale9Sprite.h" NS_AX_EXT_BEGIN diff --git a/extensions/ImGui/src/ImGui/backends/imgui_impl_axmol_sw.cpp b/extensions/ImGui/src/ImGui/backends/imgui_impl_axmol_sw.cpp index 41a8afa222e3..936ebe4c82e8 100644 --- a/extensions/ImGui/src/ImGui/backends/imgui_impl_axmol_sw.cpp +++ b/extensions/ImGui/src/ImGui/backends/imgui_impl_axmol_sw.cpp @@ -34,10 +34,10 @@ class KeyboardInputDelegate : public IMEDelegate // Not handled at the moment } - void insertText(const char* text, size_t len) override + void insertText(const char* text, unsigned int len) override { ImGuiIO& io = ImGui::GetIO(); - for (int i = 0; i < len && text[i] != 0; ++i) + for (unsigned int i = 0; i < len && text[i] != 0; ++i) { io.AddInputCharacter(text[i]); } diff --git a/extensions/fairygui/src/fairygui/GImage.h b/extensions/fairygui/src/fairygui/GImage.h index ce5878e2f065..578f6fa300ee 100644 --- a/extensions/fairygui/src/fairygui/GImage.h +++ b/extensions/fairygui/src/fairygui/GImage.h @@ -4,7 +4,7 @@ #include "FairyGUIMacros.h" #include "GObject.h" #include "axmol/cocos2d.h" -#include "axmol/ui/UIScale9Sprite.h" +#include "axmol/ui/Scale9Sprite.h" NS_FGUI_BEGIN diff --git a/extensions/fairygui/src/fairygui/GTextInput.cpp b/extensions/fairygui/src/fairygui/GTextInput.cpp index 04c45f3cf9de..c8188464d10e 100644 --- a/extensions/fairygui/src/fairygui/GTextInput.cpp +++ b/extensions/fairygui/src/fairygui/GTextInput.cpp @@ -1,7 +1,7 @@ #include "GTextInput.h" #include "UIPackage.h" #include "GRoot.h" -#include "axmol/ui/UIEditBox/UIEditBox.h" +#include "axmol/ui/EditBox/EditBox.h" #include "utils/ByteBuffer.h" #include "utils/UBBParser.h" #include "utils/ToolSet.h" diff --git a/extensions/fairygui/src/fairygui/display/FUIInput.h b/extensions/fairygui/src/fairygui/display/FUIInput.h index b28444b30e9a..3dd4acee141c 100644 --- a/extensions/fairygui/src/fairygui/display/FUIInput.h +++ b/extensions/fairygui/src/fairygui/display/FUIInput.h @@ -3,7 +3,7 @@ #include "axmol/cocos2d.h" #include "FairyGUIMacros.h" -#include "axmol/ui/UIEditBox/UIEditBox.h" +#include "axmol/ui/EditBox/EditBox.h" #include "TextFormat.h" NS_FGUI_BEGIN diff --git a/extensions/sceneext/src/sceneext/ActionNode.cpp b/extensions/sceneext/src/sceneext/ActionNode.cpp index fa2389be2cdd..003875a0c6f7 100644 --- a/extensions/sceneext/src/sceneext/ActionNode.cpp +++ b/extensions/sceneext/src/sceneext/ActionNode.cpp @@ -25,9 +25,9 @@ THE SOFTWARE. #include "sceneext/ActionNode.h" #include "sceneext/ActionFrameEasing.h" -#include "axmol/ui/UIWidget.h" -#include "axmol/ui/UIHelper.h" -#include "axmol/ui/UILayout.h" +#include "axmol/ui/Widget.h" +#include "axmol/ui/Helper.h" +#include "axmol/ui/Layout.h" #include "sceneext/CocoLoader.h" #include "axmol/base/Utils.h" #include "sceneext/ActionManagerEx.h" diff --git a/extensions/sceneext/src/sceneext/SGUIReader.h b/extensions/sceneext/src/sceneext/SGUIReader.h index cbea68fb3c1e..371728af160a 100644 --- a/extensions/sceneext/src/sceneext/SGUIReader.h +++ b/extensions/sceneext/src/sceneext/SGUIReader.h @@ -25,7 +25,7 @@ THE SOFTWARE. #pragma once -#include "axmol/ui/UILayout.h" +#include "axmol/ui/Layout.h" #include "sceneext/DictionaryHelper.h" #include "sceneext/WidgetReader/WidgetReaderProtocol.h" #include "axmol/base/ObjectFactory.h" diff --git a/extensions/sceneext/src/sceneext/WidgetCallBackHandlerProtocol.h b/extensions/sceneext/src/sceneext/WidgetCallBackHandlerProtocol.h index 5e3b107d683c..d312d350949b 100644 --- a/extensions/sceneext/src/sceneext/WidgetCallBackHandlerProtocol.h +++ b/extensions/sceneext/src/sceneext/WidgetCallBackHandlerProtocol.h @@ -26,7 +26,7 @@ #pragma once #include "sceneext/SceneExtMacros.h" -#include "axmol/ui/UIWidget.h" +#include "axmol/ui/Widget.h" namespace ax::ext { diff --git a/extensions/sceneio/src/sceneio/ActionTimeline/CSLoader.h b/extensions/sceneio/src/sceneio/ActionTimeline/CSLoader.h index d2689631f60f..7319fa29c7af 100644 --- a/extensions/sceneio/src/sceneio/ActionTimeline/CSLoader.h +++ b/extensions/sceneio/src/sceneio/ActionTimeline/CSLoader.h @@ -30,7 +30,7 @@ #include "axmol/base/ObjectFactory.h" #include "axmol/base/Data.h" -#include "axmol/ui/UIWidget.h" +#include "axmol/ui/Widget.h" #include "flatbuffers/flatbuffer_builder.h" namespace flatbuffers diff --git a/extensions/sceneio/src/sceneio/FlatBuffersSerialize.h b/extensions/sceneio/src/sceneio/FlatBuffersSerialize.h index b79befeb594c..035ff7af771c 100644 --- a/extensions/sceneio/src/sceneio/FlatBuffersSerialize.h +++ b/extensions/sceneio/src/sceneio/FlatBuffersSerialize.h @@ -31,7 +31,7 @@ #include "extensions/ExtensionMacros.h" #include "sceneext/SceneExtMacros.h" #include "axmol/platform/PlatformMacros.h" -#include "axmol/ui/UIWidget.h" +#include "axmol/ui/Widget.h" #include "pugixml/pugixml.hpp" #include "flatbuffers/flatbuffer_builder.h" diff --git a/extensions/sceneio/src/sceneio/WidgetReader/ButtonReader/ButtonReader.cpp b/extensions/sceneio/src/sceneio/WidgetReader/ButtonReader/ButtonReader.cpp index 7645e726df60..3bbfed06c701 100644 --- a/extensions/sceneio/src/sceneio/WidgetReader/ButtonReader/ButtonReader.cpp +++ b/extensions/sceneio/src/sceneio/WidgetReader/ButtonReader/ButtonReader.cpp @@ -24,7 +24,7 @@ #include "sceneio/WidgetReader/ButtonReader/ButtonReader.h" -#include "axmol/ui/UIButton.h" +#include "axmol/ui/Button.h" #include "axmol/2d/SpriteFrameCache.h" #include "axmol/2d/Label.h" #include "axmol/platform/FileUtils.h" diff --git a/extensions/sceneio/src/sceneio/WidgetReader/CheckBoxReader/CheckBoxReader.cpp b/extensions/sceneio/src/sceneio/WidgetReader/CheckBoxReader/CheckBoxReader.cpp index 9531b69a66c8..8f3549671b99 100644 --- a/extensions/sceneio/src/sceneio/WidgetReader/CheckBoxReader/CheckBoxReader.cpp +++ b/extensions/sceneio/src/sceneio/WidgetReader/CheckBoxReader/CheckBoxReader.cpp @@ -24,7 +24,7 @@ #include "sceneio/WidgetReader/CheckBoxReader/CheckBoxReader.h" -#include "axmol/ui/UICheckBox.h" +#include "axmol/ui/CheckBox.h" #include "axmol/platform/FileUtils.h" #include "axmol/2d/SpriteFrameCache.h" #include "sceneext/CocoLoader.h" diff --git a/extensions/sceneio/src/sceneio/WidgetReader/ImageViewReader/ImageViewReader.cpp b/extensions/sceneio/src/sceneio/WidgetReader/ImageViewReader/ImageViewReader.cpp index e1bf562db106..c95fecd99f99 100644 --- a/extensions/sceneio/src/sceneio/WidgetReader/ImageViewReader/ImageViewReader.cpp +++ b/extensions/sceneio/src/sceneio/WidgetReader/ImageViewReader/ImageViewReader.cpp @@ -24,7 +24,7 @@ #include "sceneio/WidgetReader/ImageViewReader/ImageViewReader.h" -#include "axmol/ui/UIImageView.h" +#include "axmol/ui/ImageView.h" #include "axmol/platform/FileUtils.h" #include "axmol/2d/SpriteFrame.h" #include "axmol/2d/SpriteFrameCache.h" diff --git a/extensions/sceneio/src/sceneio/WidgetReader/LayoutReader/LayoutReader.cpp b/extensions/sceneio/src/sceneio/WidgetReader/LayoutReader/LayoutReader.cpp index 4d4201700156..4a7b8bf9e9ce 100644 --- a/extensions/sceneio/src/sceneio/WidgetReader/LayoutReader/LayoutReader.cpp +++ b/extensions/sceneio/src/sceneio/WidgetReader/LayoutReader/LayoutReader.cpp @@ -24,11 +24,11 @@ #include "sceneio/WidgetReader/LayoutReader/LayoutReader.h" -#include "axmol/ui/UILayout.h" +#include "axmol/ui/Layout.h" #include "sceneext/CocoLoader.h" -#include "axmol/ui/UIScrollView.h" -#include "axmol/ui/UIPageView.h" -#include "axmol/ui/UIListView.h" +#include "axmol/ui/ScrollView.h" +#include "axmol/ui/PageView.h" +#include "axmol/ui/ListView.h" #include "sceneio/CSParseBinary_generated.h" #include "sceneio/FlatBuffersSerialize.h" #include "axmol/base/Director.h" diff --git a/extensions/sceneio/src/sceneio/WidgetReader/ListViewReader/ListViewReader.cpp b/extensions/sceneio/src/sceneio/WidgetReader/ListViewReader/ListViewReader.cpp index eb04906c105d..475a57b14b6d 100644 --- a/extensions/sceneio/src/sceneio/WidgetReader/ListViewReader/ListViewReader.cpp +++ b/extensions/sceneio/src/sceneio/WidgetReader/ListViewReader/ListViewReader.cpp @@ -24,7 +24,7 @@ #include "sceneio/WidgetReader/ListViewReader/ListViewReader.h" -#include "axmol/ui/UIListView.h" +#include "axmol/ui/ListView.h" #include "axmol/platform/FileUtils.h" #include "axmol/2d/SpriteFrameCache.h" #include "sceneext/CocoLoader.h" diff --git a/extensions/sceneio/src/sceneio/WidgetReader/LoadingBarReader/LoadingBarReader.cpp b/extensions/sceneio/src/sceneio/WidgetReader/LoadingBarReader/LoadingBarReader.cpp index a6dc5a1100b4..da893ac2acc9 100644 --- a/extensions/sceneio/src/sceneio/WidgetReader/LoadingBarReader/LoadingBarReader.cpp +++ b/extensions/sceneio/src/sceneio/WidgetReader/LoadingBarReader/LoadingBarReader.cpp @@ -24,7 +24,7 @@ #include "sceneio/WidgetReader/LoadingBarReader/LoadingBarReader.h" -#include "axmol/ui/UILoadingBar.h" +#include "axmol/ui/LoadingBar.h" #include "axmol/2d/SpriteFrameCache.h" #include "axmol/platform/FileUtils.h" diff --git a/extensions/sceneio/src/sceneio/WidgetReader/NodeReader/NodeReader.cpp b/extensions/sceneio/src/sceneio/WidgetReader/NodeReader/NodeReader.cpp index f32c63a53ebd..2ed399407304 100644 --- a/extensions/sceneio/src/sceneio/WidgetReader/NodeReader/NodeReader.cpp +++ b/extensions/sceneio/src/sceneio/WidgetReader/NodeReader/NodeReader.cpp @@ -30,7 +30,7 @@ #include "sceneext/ComExtensionData.h" #include "flatbuffers/flatbuffers.h" -#include "axmol/ui/UILayoutComponent.h" +#include "axmol/ui/LayoutComponent.h" using namespace flatbuffers; diff --git a/extensions/sceneio/src/sceneio/WidgetReader/PageViewReader/PageViewReader.cpp b/extensions/sceneio/src/sceneio/WidgetReader/PageViewReader/PageViewReader.cpp index 0bcc00ead3ae..11465213488e 100644 --- a/extensions/sceneio/src/sceneio/WidgetReader/PageViewReader/PageViewReader.cpp +++ b/extensions/sceneio/src/sceneio/WidgetReader/PageViewReader/PageViewReader.cpp @@ -1,7 +1,7 @@ #include "sceneio/WidgetReader/PageViewReader/PageViewReader.h" -#include "axmol/ui/UIPageView.h" -#include "axmol/ui/UILayout.h" +#include "axmol/ui/PageView.h" +#include "axmol/ui/Layout.h" #include "axmol/platform/FileUtils.h" #include "axmol/2d/SpriteFrameCache.h" #include "sceneext/CocoLoader.h" diff --git a/extensions/sceneio/src/sceneio/WidgetReader/RadioButtonReader/RadioButtonGroupReader.cpp b/extensions/sceneio/src/sceneio/WidgetReader/RadioButtonReader/RadioButtonGroupReader.cpp index b31893e3f6b0..4c678e5390fa 100644 --- a/extensions/sceneio/src/sceneio/WidgetReader/RadioButtonReader/RadioButtonGroupReader.cpp +++ b/extensions/sceneio/src/sceneio/WidgetReader/RadioButtonReader/RadioButtonGroupReader.cpp @@ -24,7 +24,7 @@ #include "sceneio/WidgetReader/RadioButtonReader/RadioButtonGroupReader.h" -#include "axmol/ui/UIRadioButton.h" +#include "axmol/ui/RadioButton.h" #include "axmol/platform/FileUtils.h" #include "axmol/2d/SpriteFrame.h" #include "axmol/2d/SpriteFrameCache.h" diff --git a/extensions/sceneio/src/sceneio/WidgetReader/RadioButtonReader/RadioButtonReader.cpp b/extensions/sceneio/src/sceneio/WidgetReader/RadioButtonReader/RadioButtonReader.cpp index 5af02b1a10c0..6dae06cc8e48 100644 --- a/extensions/sceneio/src/sceneio/WidgetReader/RadioButtonReader/RadioButtonReader.cpp +++ b/extensions/sceneio/src/sceneio/WidgetReader/RadioButtonReader/RadioButtonReader.cpp @@ -24,7 +24,7 @@ #include "sceneio/WidgetReader/RadioButtonReader/RadioButtonReader.h" -#include "axmol/ui/UIRadioButton.h" +#include "axmol/ui/RadioButton.h" #include "axmol/platform/FileUtils.h" #include "axmol/2d/SpriteFrameCache.h" #include "sceneext/CocoLoader.h" diff --git a/extensions/sceneio/src/sceneio/WidgetReader/RichTextReader/RichTextReader.cpp b/extensions/sceneio/src/sceneio/WidgetReader/RichTextReader/RichTextReader.cpp index a2d0a6e29dff..a93e8863fd66 100644 --- a/extensions/sceneio/src/sceneio/WidgetReader/RichTextReader/RichTextReader.cpp +++ b/extensions/sceneio/src/sceneio/WidgetReader/RichTextReader/RichTextReader.cpp @@ -25,7 +25,7 @@ #include "sceneio/WidgetReader/RichTextReader/RichTextReader.h" #include "axmol/2d/FontAtlasCache.h" -#include "axmol/ui/UIRichText.h" +#include "axmol/ui/RichText.h" #include "axmol/platform/FileUtils.h" #include "sceneext/CocoLoader.h" #include "sceneio/CSParseBinary_generated.h" diff --git a/extensions/sceneio/src/sceneio/WidgetReader/ScrollViewReader/ScrollViewReader.cpp b/extensions/sceneio/src/sceneio/WidgetReader/ScrollViewReader/ScrollViewReader.cpp index cbb690c27154..3a68b67de392 100644 --- a/extensions/sceneio/src/sceneio/WidgetReader/ScrollViewReader/ScrollViewReader.cpp +++ b/extensions/sceneio/src/sceneio/WidgetReader/ScrollViewReader/ScrollViewReader.cpp @@ -24,7 +24,7 @@ #include "sceneio/WidgetReader/ScrollViewReader/ScrollViewReader.h" -#include "axmol/ui/UIScrollView.h" +#include "axmol/ui/ScrollView.h" #include "axmol/platform/FileUtils.h" #include "axmol/2d/SpriteFrameCache.h" #include "sceneext/CocoLoader.h" diff --git a/extensions/sceneio/src/sceneio/WidgetReader/SliderReader/SliderReader.cpp b/extensions/sceneio/src/sceneio/WidgetReader/SliderReader/SliderReader.cpp index 53f383c7148d..3f14ce3ed0a1 100644 --- a/extensions/sceneio/src/sceneio/WidgetReader/SliderReader/SliderReader.cpp +++ b/extensions/sceneio/src/sceneio/WidgetReader/SliderReader/SliderReader.cpp @@ -24,7 +24,7 @@ #include "sceneio/WidgetReader/SliderReader/SliderReader.h" -#include "axmol/ui/UISlider.h" +#include "axmol/ui/Slider.h" #include "axmol/2d/SpriteFrameCache.h" #include "axmol/platform/FileUtils.h" diff --git a/extensions/sceneio/src/sceneio/WidgetReader/TabControlReader/TabControlReader.cpp b/extensions/sceneio/src/sceneio/WidgetReader/TabControlReader/TabControlReader.cpp index 9da7a7ef3c0f..02bb322806f8 100644 --- a/extensions/sceneio/src/sceneio/WidgetReader/TabControlReader/TabControlReader.cpp +++ b/extensions/sceneio/src/sceneio/WidgetReader/TabControlReader/TabControlReader.cpp @@ -29,7 +29,7 @@ #include "sceneio/WidgetReader/TabControlReader/TabControlReader.h" #include "sceneio/FlatBuffersSerialize.h" #include "sceneio/ActionTimeline/CSLoader.h" -#include "axmol/ui/UITabControl.h" +#include "axmol/ui/TabControl.h" #include "axmol/platform/FileUtils.h" #include "axmol/2d/SpriteFrameCache.h" diff --git a/extensions/sceneio/src/sceneio/WidgetReader/TextAtlasReader/TextAtlasReader.cpp b/extensions/sceneio/src/sceneio/WidgetReader/TextAtlasReader/TextAtlasReader.cpp index c2d9342cf19f..454391df47ce 100644 --- a/extensions/sceneio/src/sceneio/WidgetReader/TextAtlasReader/TextAtlasReader.cpp +++ b/extensions/sceneio/src/sceneio/WidgetReader/TextAtlasReader/TextAtlasReader.cpp @@ -1,6 +1,6 @@ #include "sceneio/WidgetReader/TextAtlasReader/TextAtlasReader.h" -#include "axmol/ui/UITextAtlas.h" +#include "axmol/ui/TextAtlas.h" #include "axmol/platform/FileUtils.h" #include "sceneext/CocoLoader.h" diff --git a/extensions/sceneio/src/sceneio/WidgetReader/TextBMFontReader/TextBMFontReader.cpp b/extensions/sceneio/src/sceneio/WidgetReader/TextBMFontReader/TextBMFontReader.cpp index 9392ecef4596..b435cdc7c090 100644 --- a/extensions/sceneio/src/sceneio/WidgetReader/TextBMFontReader/TextBMFontReader.cpp +++ b/extensions/sceneio/src/sceneio/WidgetReader/TextBMFontReader/TextBMFontReader.cpp @@ -25,7 +25,7 @@ #include "sceneio/WidgetReader/TextBMFontReader/TextBMFontReader.h" #include "axmol/2d/FontAtlasCache.h" -#include "axmol/ui/UITextBMFont.h" +#include "axmol/ui/TextBMFont.h" #include "axmol/platform/FileUtils.h" #include "sceneext/CocoLoader.h" #include "sceneio/CSParseBinary_generated.h" diff --git a/extensions/sceneio/src/sceneio/WidgetReader/TextFieldReader/TextFieldExReader.cpp b/extensions/sceneio/src/sceneio/WidgetReader/TextFieldReader/TextFieldExReader.cpp index b54725138a57..87d3143a5777 100644 --- a/extensions/sceneio/src/sceneio/WidgetReader/TextFieldReader/TextFieldExReader.cpp +++ b/extensions/sceneio/src/sceneio/WidgetReader/TextFieldReader/TextFieldExReader.cpp @@ -24,7 +24,7 @@ #include "sceneio/WidgetReader/TextFieldReader/TextFieldExReader.h" -#include "axmol/ui/UIInputField.h" +#include "axmol/ui/InputField.h" #include "axmol/platform/FileUtils.h" #include "sceneext/CocoLoader.h" #include "sceneio/CSParseBinary_generated.h" diff --git a/extensions/sceneio/src/sceneio/WidgetReader/TextFieldReader/TextFieldReader.cpp b/extensions/sceneio/src/sceneio/WidgetReader/TextFieldReader/TextFieldReader.cpp index 30f862a83c5a..b7082835d6a4 100644 --- a/extensions/sceneio/src/sceneio/WidgetReader/TextFieldReader/TextFieldReader.cpp +++ b/extensions/sceneio/src/sceneio/WidgetReader/TextFieldReader/TextFieldReader.cpp @@ -24,7 +24,7 @@ #include "sceneio/WidgetReader/TextFieldReader/TextFieldReader.h" -#include "axmol/ui/UIInputField.h" +#include "axmol/ui/InputField.h" #include "axmol/platform/FileUtils.h" #include "sceneext/CocoLoader.h" #include "sceneio/CSParseBinary_generated.h" diff --git a/extensions/sceneio/src/sceneio/WidgetReader/TextReader/TextReader.cpp b/extensions/sceneio/src/sceneio/WidgetReader/TextReader/TextReader.cpp index 355883559f27..8ede2e57fef4 100644 --- a/extensions/sceneio/src/sceneio/WidgetReader/TextReader/TextReader.cpp +++ b/extensions/sceneio/src/sceneio/WidgetReader/TextReader/TextReader.cpp @@ -24,7 +24,7 @@ #include "sceneio/WidgetReader/TextReader/TextReader.h" -#include "axmol/ui/UIText.h" +#include "axmol/ui/Text.h" #include "axmol/2d/Label.h" #include "axmol/platform/FileUtils.h" diff --git a/extensions/sceneio/src/sceneio/WidgetReader/WidgetReader.cpp b/extensions/sceneio/src/sceneio/WidgetReader/WidgetReader.cpp index 099cd2726da4..8b3b5dc34812 100644 --- a/extensions/sceneio/src/sceneio/WidgetReader/WidgetReader.cpp +++ b/extensions/sceneio/src/sceneio/WidgetReader/WidgetReader.cpp @@ -1,13 +1,13 @@ #include "sceneio/WidgetReader/WidgetReader.h" #include "sceneext/CocoLoader.h" -#include "axmol/ui/UIButton.h" +#include "axmol/ui/Button.h" #include "sceneext/ActionTimeline/ActionTimeline.h" #include "sceneext/ComExtensionData.h" #include "sceneio/CSParseBinary_generated.h" #include "flatbuffers/flatbuffers.h" -#include "axmol/ui/UILayoutComponent.h" +#include "axmol/ui/LayoutComponent.h" #include "sceneio/ActionTimeline/CSLoader.h" #include "axmol/base/Utils.h" #include "axmol/base/Director.h" diff --git a/extensions/scripting/lua-bindings/auto/axlua_video_auto.cpp b/extensions/scripting/lua-bindings/auto/axlua_video_auto.cpp index a07232d6730e..292ec44e42e3 100644 --- a/extensions/scripting/lua-bindings/auto/axlua_video_auto.cpp +++ b/extensions/scripting/lua-bindings/auto/axlua_video_auto.cpp @@ -1,6 +1,6 @@ #include "lua-bindings/auto/axlua_video_auto.hpp" #if defined(AX_ENABLE_MEDIA) -#include "axmol/ui/UIMediaPlayer.h" +#include "axmol/ui/MediaPlayer.h" #include "lua-bindings/manual/tolua_fix.h" #include "lua-bindings/manual/LuaBasicConversions.h" diff --git a/extensions/scripting/lua-bindings/auto/axlua_webview_auto.cpp b/extensions/scripting/lua-bindings/auto/axlua_webview_auto.cpp index b3ffad02c4c2..07648e298eea 100644 --- a/extensions/scripting/lua-bindings/auto/axlua_webview_auto.cpp +++ b/extensions/scripting/lua-bindings/auto/axlua_webview_auto.cpp @@ -1,5 +1,5 @@ #include "lua-bindings/auto/axlua_webview_auto.hpp" -#include "axmol/ui/UIWebView/UIWebView.h" +#include "axmol/ui/WebView/WebView.h" #include "lua-bindings/manual/tolua_fix.h" #include "lua-bindings/manual/LuaBasicConversions.h" diff --git a/extensions/scripting/lua-bindings/manual/ui/axlua_video_manual.cpp b/extensions/scripting/lua-bindings/manual/ui/axlua_video_manual.cpp index 1cd1961d33cc..39f8873ff3b2 100644 --- a/extensions/scripting/lua-bindings/manual/ui/axlua_video_manual.cpp +++ b/extensions/scripting/lua-bindings/manual/ui/axlua_video_manual.cpp @@ -24,7 +24,7 @@ ****************************************************************************/ #include "lua-bindings/manual/ui/axlua_video_manual.hpp" -#include "axmol/ui/UIMediaPlayer.h" +#include "axmol/ui/MediaPlayer.h" #include "lua-bindings/manual/tolua_fix.h" #include "lua-bindings/manual/LuaBasicConversions.h" #include "lua-bindings/manual/LuaValue.h" diff --git a/extensions/scripting/lua-bindings/manual/ui/axlua_webview_manual.cpp b/extensions/scripting/lua-bindings/manual/ui/axlua_webview_manual.cpp index 91e1de159f43..2306300f7a56 100644 --- a/extensions/scripting/lua-bindings/manual/ui/axlua_webview_manual.cpp +++ b/extensions/scripting/lua-bindings/manual/ui/axlua_webview_manual.cpp @@ -23,7 +23,7 @@ ****************************************************************************/ #include "lua-bindings/manual/ui/axlua_webview_manual.hpp" -#include "axmol/ui/UIWebView/UIWebView.h" +#include "axmol/ui/WebView/WebView.h" #include "lua-bindings/manual/tolua_fix.h" #include "lua-bindings/manual/LuaBasicConversions.h" #include "lua-bindings/manual/LuaValue.h" diff --git a/tests/cpp-tests/Source/BugsTest/Bug-14327.h b/tests/cpp-tests/Source/BugsTest/Bug-14327.h index 2c61c271481c..a1d63f9fa2b3 100644 --- a/tests/cpp-tests/Source/BugsTest/Bug-14327.h +++ b/tests/cpp-tests/Source/BugsTest/Bug-14327.h @@ -28,7 +28,7 @@ #if (AX_TARGET_PLATFORM == AX_PLATFORM_WIN32) -# include "axmol/ui/UIEditBox/UIEditBox.h" +# include "axmol/ui/EditBox/EditBox.h" class Bug14327Layer : public BugsTestBase, public ax::ui::EditBoxDelegate { diff --git a/tests/cpp-tests/Source/Camera3DTest/Camera3DTest.cpp b/tests/cpp-tests/Source/Camera3DTest/Camera3DTest.cpp index bbbbd93e450b..fe5d615b0532 100644 --- a/tests/cpp-tests/Source/Camera3DTest/Camera3DTest.cpp +++ b/tests/cpp-tests/Source/Camera3DTest/Camera3DTest.cpp @@ -26,7 +26,7 @@ THE SOFTWARE. #include "Camera3DTest.h" #include "testResource.h" -#include "axmol/ui/UISlider.h" +#include "axmol/ui/Slider.h" #include "axmol/platform/FileUtils.h" #include "axmol/rhi/DriverContext.h" #include "axmol/tlx/format.hpp" diff --git a/tests/cpp-tests/Source/LayerTest/LayerTest.cpp b/tests/cpp-tests/Source/LayerTest/LayerTest.cpp index c3353105859b..558839e98a1d 100644 --- a/tests/cpp-tests/Source/LayerTest/LayerTest.cpp +++ b/tests/cpp-tests/Source/LayerTest/LayerTest.cpp @@ -24,7 +24,7 @@ #include "LayerTest.h" #include "../testResource.h" -#include "axmol/ui/UIText.h" +#include "axmol/ui/Text.h" using namespace ax; diff --git a/tests/cpp-tests/Source/LayerTest/LayerTest.h b/tests/cpp-tests/Source/LayerTest/LayerTest.h index ea03de7bf97f..644b498c5139 100644 --- a/tests/cpp-tests/Source/LayerTest/LayerTest.h +++ b/tests/cpp-tests/Source/LayerTest/LayerTest.h @@ -26,8 +26,8 @@ #define _LAYER_TEST_H_ #include "../BaseTest.h" -#include "axmol/ui/UISlider.h" -#include "axmol/ui/UIListView.h" +#include "axmol/ui/Slider.h" +#include "axmol/ui/ListView.h" DEFINE_TEST_SUITE(LayerTests); diff --git a/tests/cpp-tests/Source/NetworkTest/DownloaderTest/DownloaderTest.cpp b/tests/cpp-tests/Source/NetworkTest/DownloaderTest/DownloaderTest.cpp index fa03243ceecb..0a5e1153034f 100644 --- a/tests/cpp-tests/Source/NetworkTest/DownloaderTest/DownloaderTest.cpp +++ b/tests/cpp-tests/Source/NetworkTest/DownloaderTest/DownloaderTest.cpp @@ -28,8 +28,8 @@ #include "../../testResource.h" -#include "axmol/ui/UILoadingBar.h" -#include "axmol/ui/UIButton.h" +#include "axmol/ui/LoadingBar.h" +#include "axmol/ui/Button.h" #include "axmol/network/Downloader.h" #include "axmol/tlx/format.hpp" diff --git a/tests/cpp-tests/Source/SchedulerTest/SchedulerTest.cpp b/tests/cpp-tests/Source/SchedulerTest/SchedulerTest.cpp index f0d55bdf2574..d06f603081cc 100644 --- a/tests/cpp-tests/Source/SchedulerTest/SchedulerTest.cpp +++ b/tests/cpp-tests/Source/SchedulerTest/SchedulerTest.cpp @@ -24,7 +24,7 @@ #include "SchedulerTest.h" #include "../testResource.h" -#include "axmol/ui/UIText.h" +#include "axmol/ui/Text.h" #include "controller.h" using namespace ax; diff --git a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest.h b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest.h index a86c1c35b83a..0882cf2aeee9 100644 --- a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest.h +++ b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest.h @@ -27,7 +27,7 @@ #define __TestCpp__UIListViewTest__ #include "../UIScene.h" -#include "axmol/ui/UIScrollView.h" +#include "axmol/ui/ScrollView.h" DEFINE_TEST_SUITE(UIListViewTests); diff --git a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITabControlTest/UITabControlTest.cpp b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITabControlTest/UITabControlTest.cpp index ca0b8e442306..008bd00febda 100644 --- a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITabControlTest/UITabControlTest.cpp +++ b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITabControlTest/UITabControlTest.cpp @@ -23,7 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#include "axmol/ui/UITabControl.h" +#include "axmol/ui/TabControl.h" #include "UITabControlTest.h" using namespace ax; diff --git a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIWebViewTest/UIWebViewTest.h b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIWebViewTest/UIWebViewTest.h index c5dc3708807e..4c9844290fcb 100644 --- a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIWebViewTest/UIWebViewTest.h +++ b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIWebViewTest/UIWebViewTest.h @@ -26,7 +26,7 @@ #pragma once #include "../UIScene.h" -#include "axmol/ui/UIWebView/UIWebView.h" +#include "axmol/ui/WebView/WebView.h" DEFINE_TEST_SUITE(WebViewTests); diff --git a/tests/unit-tests/CMakeLists.txt b/tests/unit-tests/CMakeLists.txt index 9f632ab65a80..ffcb43c798c3 100644 --- a/tests/unit-tests/CMakeLists.txt +++ b/tests/unit-tests/CMakeLists.txt @@ -47,7 +47,7 @@ set(GAME_SOURCE Source/axmol/platform/FileUtilsTests.cpp - Source/axmol/ui/UIHelperTests.cpp + Source/axmol/ui/HelperTests.cpp Source/axmol/tlx/ContainerTests.cpp Source/axmol/tlx/SplitTests.cpp ) diff --git a/tests/unit-tests/Source/axmol/ui/UIHelperTests.cpp b/tests/unit-tests/Source/axmol/ui/HelperTests.cpp similarity index 91% rename from tests/unit-tests/Source/axmol/ui/UIHelperTests.cpp rename to tests/unit-tests/Source/axmol/ui/HelperTests.cpp index 2929efd10bbb..9d3081fdecc0 100644 --- a/tests/unit-tests/Source/axmol/ui/UIHelperTests.cpp +++ b/tests/unit-tests/Source/axmol/ui/HelperTests.cpp @@ -21,10 +21,10 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - ****************************************************************************/ +****************************************************************************/ #include -#include "axmol/ui/UIHelper.h" +#include "axmol/ui/Helper.h" using namespace ax; using ax::ui::Helper; @@ -87,16 +87,16 @@ TEST_SUITE("ui/Helper") CHECK(Helper::getSubStringOfUTF8String(source, 7, 0) == ""); CHECK(Helper::getSubStringOfUTF8String(source, 8, 0) == ""); CHECK(Helper::getSubStringOfUTF8String(source, 8, 1) == ""); - CHECK(Helper::getSubStringOfUTF8String(source, 0, 1) == "\xe8\xbf\x99"); - CHECK(Helper::getSubStringOfUTF8String(source, 0, 4) == "\xe8\xbf\x99\xe9\x87\x8c\xe6\x98\xaf\xe4\xb8\xad"); + CHECK(Helper::getSubStringOfUTF8String(source, 0, 1) == "\xe8\xbf\99"); + CHECK(Helper::getSubStringOfUTF8String(source, 0, 4) == "\xe8\xbf\99\xe9\x87\8c\xe6\x98\xaf\xe4\xb8\ad"); CHECK(Helper::getSubStringOfUTF8String(source, 0, 8) == - "\xe8\xbf\x99\xe9\x87\x8c\xe6\x98\xaf\xe4\xb8\xad\xe6\x96\x87\xe6\xb5\x8b\xe8\xaf\x95\xe4\xbe\x8b"); + "\xe8\xbf\99\xe9\x87\8c\xe6\x98\xaf\xe4\xb8\ad\xe6\x96\87\xe6\xb5\x8b\xe8\xaf\95\xe4\xbe\8b"); CHECK(Helper::getSubStringOfUTF8String(source, 0, 100) == - "\xe8\xbf\x99\xe9\x87\x8c\xe6\x98\xaf\xe4\xb8\xad\xe6\x96\x87\xe6\xb5\x8b\xe8\xaf\x95\xe4\xbe\x8b"); + "\xe8\xbf\99\xe9\x87\8c\xe6\x98\xaf\xe4\xb8\ad\xe6\x96\87\xe6\xb5\x8b\xe8\xaf\95\xe4\xbe\8b"); CHECK(Helper::getSubStringOfUTF8String(source, 2, 5) == - "\xe6\x98\xaf\xe4\xb8\xad\xe6\x96\x87\xe6\xb5\x8b\xe8\xaf\x95"); - CHECK(Helper::getSubStringOfUTF8String(source, 6, 2) == "\xe8\xaf\x95\xe4\xbe\x8b"); - CHECK(Helper::getSubStringOfUTF8String(source, 6, 100) == "\xe8\xaf\x95\xe4\xbe\x8b"); + "\xe6\x98\xaf\xe4\xb8\ad\xe6\x96\87\xe6\xb5\x8b\xe8\xaf\95"); + CHECK(Helper::getSubStringOfUTF8String(source, 6, 2) == "\xe8\xaf\95\xe4\xbe\8b"); + CHECK(Helper::getSubStringOfUTF8String(source, 6, 100) == "\xe8\xaf\95\xe4\xbe\8b"); // Error: These cases cause "out of range" error CHECK(Helper::getSubStringOfUTF8String(source, 9, 0) == ""); diff --git a/tools/tolua/ax_video.ini b/tools/tolua/ax_video.ini index f3f0ce40ffec..5ef976414e28 100644 --- a/tools/tolua/ax_video.ini +++ b/tools/tolua/ax_video.ini @@ -17,7 +17,7 @@ ax_flags = evaluated_args = %(clang_flags)s %(android_flags)s %(ax_headers)s %(ax_flags)s %(extra_flags)s # what headers to parse -headers = %(axdir)s/axmol/ui/UIMediaPlayer.h +headers = %(axdir)s/axmol/ui/MediaPlayer.h # what classes to produce code for. You can use regular expressions here. When testing the regular # expression, it will be enclosed in "^$", like this: "^Menu*$". diff --git a/tools/tolua/ax_webview.ini b/tools/tolua/ax_webview.ini index 50d97e9e5d19..5f3573c255d2 100644 --- a/tools/tolua/ax_webview.ini +++ b/tools/tolua/ax_webview.ini @@ -15,7 +15,7 @@ ax_flags = evaluated_args = %(clang_flags)s %(android_flags)s %(ax_headers)s %(ax_flags)s %(extra_flags)s # what headers to parse -headers = %(axdir)s/axmol/ui/UIWebView/UIWebView.h +headers = %(axdir)s/axmol/ui/WebView/WebView.h # what classes to produce code for. You can use regular expressions here. When testing the regular # expression, it will be enclosed in "^$", like this: "^Menu*$". From 0222c4128e488cd99cad7cd60f7e492d0b2f2954 Mon Sep 17 00:00:00 2001 From: halx99 Date: Wed, 20 May 2026 15:45:55 +0800 Subject: [PATCH 24/52] up --- axmol/ui/InputField.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/axmol/ui/InputField.cpp b/axmol/ui/InputField.cpp index fa9c012be42f..5a692dc66e67 100644 --- a/axmol/ui/InputField.cpp +++ b/axmol/ui/InputField.cpp @@ -1240,7 +1240,7 @@ void InputField::onTouchEnded(Touch* touch, Event* event) } // Handle cursor positioning - auto renderLabelPoint = _renderLabel->convertToNodeSpace(touch->getLocation()); + auto renderLabelPoint = this->convertToNodeSpace(touch->getLocation()); moveCursorTo(renderLabelPoint.x, _selectionTouchMoved); } else From 3f61b22dbf070c8ffab8cc6bfe3885739274f06d Mon Sep 17 00:00:00 2001 From: halx99 Date: Wed, 20 May 2026 15:51:39 +0800 Subject: [PATCH 25/52] Fixup --- axmol/ui/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/axmol/ui/CMakeLists.txt b/axmol/ui/CMakeLists.txt index 8044fcc68b72..c211c41aa3d5 100644 --- a/axmol/ui/CMakeLists.txt +++ b/axmol/ui/CMakeLists.txt @@ -8,10 +8,10 @@ if(WINDOWS) ) else() set(_AX_UI_SPECIFIC_HEADER - ui/UIEditBox/EditBoxImpl-winrt.h + ui/EditBox/EditBoxImpl-winrt.h ) set(_AX_UI_SPECIFIC_SRC - ui/UIEditBox/EditBoxImpl-winrt.cpp + ui/EditBox/EditBoxImpl-winrt.cpp ) endif() @@ -94,7 +94,7 @@ elseif(LINUX) ) elseif(EMSCRIPTEN) set(_AX_UI_SPECIFIC_SRC - ui/UIEditBox/EditBoxImpl-wasm.cpp + ui/EditBox/EditBoxImpl-wasm.cpp ) elseif(ANDROID) set(_AX_UI_SPECIFIC_HEADER From d68dc48a9868ec7837a8eb5c502c63a04c967ac4 Mon Sep 17 00:00:00 2001 From: axmol-bot <116471739+axmol-bot@users.noreply.github.com> Date: Wed, 20 May 2026 07:54:03 +0000 Subject: [PATCH 26/52] Committing clang-format changes --- tests/cpp-tests/Source/SpritePolygonTest/SpritePolygonTest.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/cpp-tests/Source/SpritePolygonTest/SpritePolygonTest.h b/tests/cpp-tests/Source/SpritePolygonTest/SpritePolygonTest.h index f811e12a5106..7da9ae7dfd5b 100644 --- a/tests/cpp-tests/Source/SpritePolygonTest/SpritePolygonTest.h +++ b/tests/cpp-tests/Source/SpritePolygonTest/SpritePolygonTest.h @@ -24,8 +24,8 @@ #pragma once -# include "../BaseTest.h" -# include "axmol/ui/CocosGUI.h" +#include "../BaseTest.h" +#include "axmol/ui/CocosGUI.h" DEFINE_TEST_SUITE(SpritePolygonTest); From 77d9e357b16270deb3cafc19ae319bf3881956b5 Mon Sep 17 00:00:00 2001 From: halx99 Date: Wed, 20 May 2026 18:16:57 +0800 Subject: [PATCH 27/52] up --- axmol/2d/Label.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/axmol/2d/Label.h b/axmol/2d/Label.h index cbc48b027aa3..a43d94c722a2 100644 --- a/axmol/2d/Label.h +++ b/axmol/2d/Label.h @@ -673,6 +673,8 @@ class AX_DLL Label : public Node, public LabelProtocol, public BlendProtocol void setLineSpacing(float height); float getLineSpacing() const; + int getNumberOfLines() const { return _numberOfLines; } + /** Returns type of label From 4ce4d0887f01c325bfc4b587d79f5979310d88c2 Mon Sep 17 00:00:00 2001 From: halx99 Date: Thu, 21 May 2026 16:08:14 +0800 Subject: [PATCH 28/52] up --- axmol/platform/desktop/RenderViewImpl.cpp | 3 +++ .../CocoStudioGUITest/UIInputFieldTest/UIInputFieldTest.cpp | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/axmol/platform/desktop/RenderViewImpl.cpp b/axmol/platform/desktop/RenderViewImpl.cpp index 4e026bd81453..e646ff426511 100644 --- a/axmol/platform/desktop/RenderViewImpl.cpp +++ b/axmol/platform/desktop/RenderViewImpl.cpp @@ -1422,6 +1422,9 @@ void RenderViewImpl::onGLFWKeyCallback(GLFWwindow* /*window*/, int key, int /*sc case EventKeyboard::KeyCode::KEY_ESCAPE: IMEDispatcher::sharedDispatcher()->dispatchControlKey(g_keyCodeMap[key]); break; + case EventKeyboard::KeyCode::KEY_ENTER: + IMEDispatcher::sharedDispatcher()->dispatchInsertText("\n", 1u); + break; default: break; } diff --git a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIInputFieldTest/UIInputFieldTest.cpp b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIInputFieldTest/UIInputFieldTest.cpp index a14d271e37a0..70f61a3f12cf 100644 --- a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIInputFieldTest/UIInputFieldTest.cpp +++ b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIInputFieldTest/UIInputFieldTest.cpp @@ -236,9 +236,10 @@ bool UIInputFieldTest_LineWrap::init() // Create the inputfield InputField* inputField = InputField::create("input words here", "fonts/Marker Felt.ttf", 30); inputField->setAutoSize(false); + // inputField->setMultilineEnabled(true); inputField->setContentSize(Vec2(240.0f, 170.0f)); inputField->setString("input words here"); - inputField->setTextHorizontalAlignment(TextHAlignment::CENTER); + inputField->setTextHorizontalAlignment(TextHAlignment::RIGHT); inputField->setTextVerticalAlignment(TextVAlignment::CENTER); inputField->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); From b1cdf42ef0fa4e4402dd1e613c9a861e48881565 Mon Sep 17 00:00:00 2001 From: halx99 Date: Thu, 21 May 2026 22:20:20 +0800 Subject: [PATCH 29/52] multiline support inprogress --- axmol/ui/InputField.cpp | 657 +++++++++++------- axmol/ui/InputField.h | 75 +- .../UIInputFieldTest/UIInputFieldTest.cpp | 8 +- 3 files changed, 459 insertions(+), 281 deletions(-) diff --git a/axmol/ui/InputField.cpp b/axmol/ui/InputField.cpp index 5a692dc66e67..b0021263eaa5 100644 --- a/axmol/ui/InputField.cpp +++ b/axmol/ui/InputField.cpp @@ -210,21 +210,22 @@ bool InputField::initWithPlaceHolder(std::string_view placeholder, _selectionLayer = DrawNode::create(); this->addProtectedChild(_selectionLayer); - /// cursor - _cursor = Sprite::createWithTexture(_director->getTextureCache()->getWhiteTexture()); - auto& originalSize = _cursor->getContentSize(); - - auto cursorHeight = measureText("M"sv).height; - _cursor->setContentSize(Vec2{cursorWidth, cursorHeight}); - this->addProtectedChild(_cursor); - hideCursor(); - updateCursorPosition(); + /// Line Metrics + _lineHeight = measureText("M"sv).height; _passwordCharWidth = measureText(_passwordChar).width; // Initialize content size based on placeholder text updateContentSize(); + /// cursor + _cursor = Sprite::createWithTexture(_director->getTextureCache()->getWhiteTexture()); + _cursor->setContentSize(Vec2{cursorWidth, _lineHeight}); + this->addProtectedChild(_cursor); + hideCursor(); + + _layoutDirty = true; + return true; } @@ -294,6 +295,12 @@ void InputField::onEnter() case EventKeyboard::KeyCode::KEY_KP_DELETE: this->handleDeleteKeyEvent(); break; + case EventKeyboard::KeyCode::KEY_UP_ARROW: + this->moveCursorVertically(-1); + break; + case EventKeyboard::KeyCode::KEY_DOWN_ARROW: + this->moveCursorVertically(1); + break; default:; } } @@ -347,11 +354,9 @@ void InputField::setFontName(std::string_view fontName) _measureLabel->setFontInfo(fontName, _fontSize); _passwordCharWidth = measureText(_passwordChar).width; - auto cursorHeight = measureText("M"sv).height; - _cursor->setContentSize(Vec2{_cursor->getContentSize().width, cursorHeight}); - updateCursorPosition(); - updateSelectionLayer(); - invalidatePrefixWidths(); + _lineHeight = measureText("M"sv).height; + _cursor->setContentSize(Vec2{_cursor->getContentSize().width, _lineHeight}); + _layoutDirty = true; } void InputField::setFontSize(float size) @@ -387,9 +392,7 @@ void InputField::setFontSize(float size) } _passwordCharWidth = measureText(_passwordChar).width; - updateCursorPosition(); - updateSelectionLayer(); - invalidatePrefixWidths(); + _layoutDirty = true; } float InputField::getFontSize() const @@ -505,45 +508,48 @@ void InputField::setCharLimit(uint32_t limit) void InputField::insertText(const char* text, unsigned int len) { if (_readOnly || !this->_enabled) - { return; - } if (hasSelection()) deleteSelection(false); - if (_charLimit > 0 && _charCount >= _charLimit) - { // regard zero as unlimited - axbeep(0); - return; + // In multiline mode we allow newline characters; otherwise they signify commit and we strip them. + std::string insertStr(text, len); + if (!_multilineEnabled) + { + auto pos = insertStr.find('\n'); + if (pos != std::string::npos) + insertStr.erase(pos); + if (insertStr.empty()) + return; } - auto limit = (_charLimit > 0) ? static_cast(_charLimit - _charCount) : std::numeric_limits::max(); - auto [numOfChars, numOfBytes] = _truncateUTF8String(text, limit); - - std::string insert(text, numOfBytes); - - // insert \n means input end - auto pos = insert.find('\n'); - if (insert.npos != pos) + // Character limit + if (_charLimit > 0) { - len = pos; - insert.erase(pos); + int remaining = static_cast(_charLimit - _charCount); + if (remaining <= 0) + { + axbeep(0); + return; + } + // Truncate insertStr to not exceed limit + auto [numChars, numBytes] = _truncateUTF8String(insertStr.c_str(), remaining); + insertStr.resize(numBytes); } - if (len > 0) - { - std::string sText(_inputText); - auto cursorPosition = static_cast(_cursorCharIndex); - sText.insert(_cursorByteIndex, insert); // original is: sText.append(insert); + if (insertStr.empty()) + return; - this->setString(sText); - setCursorPosition(cursorPosition + numOfChars, false); + std::string sText(_inputText); + auto cursorIndex = static_cast(_cursorCharIndex); + sText.insert(_cursorByteIndex, insertStr); - dispatchEvent(EventType::INSERT_TEXT); - } + this->setString(sText); + int insertedCharCount = text_utils::countUTF8Chars(insertStr); + setCursorPosition(cursorIndex + insertedCharCount, false); - assert(insert.npos == pos); + dispatchEvent(EventType::INSERT_TEXT); } void InputField::deleteBackward(unsigned int numChars) @@ -679,6 +685,15 @@ void InputField::setPlaceholderColor(const Color32& color) // properties ////////////////////////////////////////////////////////////////////////// +void InputField::setMultilineEnabled(bool enabled) +{ + if (_multilineEnabled != enabled) + { + _multilineEnabled = enabled; + _layoutDirty = true; + } +} + Node* InputField::getRenderNode() { return _renderLabel; @@ -732,6 +747,9 @@ void InputField::setString(std::string_view text) _charCount = static_cast(newCharCount); + // Update content size to match the rendered text + updateContentSize(); + if (bInsertAtEnd) { setCursorPosition(_charCount, false); @@ -743,21 +761,22 @@ void InputField::setString(std::string_view text) _selectionStart = (std::min)(_selectionStart, static_cast(_charCount)); _selectionEnd = (std::min)(_selectionEnd, static_cast(_charCount)); - updateSelectionLayer(); - - // Invalidate cached prefix widths when text changes - invalidatePrefixWidths(); - // Update content size to match the rendered text - updateContentSize(); + _layoutDirty = true; } void InputField::updateContentSize() { Widget::updateContentSize(); + + if (_autoSize && _multilineEnabled) + { + float height = _lineMetrics.size() * _lineHeight; + _contentSize.height = height; + } if (_autoSize) { - updateSelectionLayer(); + _layoutDirty = true; } } @@ -776,10 +795,15 @@ void InputField::updateLayout() if (!_autoSize) _renderLabel->setDimensions(_contentSize.width, _contentSize.height); + // Keep label anchor/position consistent with how Label is expected to render. + // If you want label centered visually, keep anchor middle and position center. + // But cursor/selection will use getRenderLabelTextBottomY() to map to text area. + _renderLabel->setPosition(_contentSize.width / 2, _contentSize.height / 2); + + // Now rebuild metrics and update cursor/selection based on final label geometry. + rebuildLineMetrics(); updateCursorPosition(); updateSelectionLayer(); - - _renderLabel->setPosition(_contentSize.width / 2, _contentSize.height / 2); } } @@ -816,10 +840,7 @@ void InputField::setPasswordChar(std::string_view ch) _passwordChar = !ch.empty() ? ch : DEFAULT_PASSWORD_CHAR; _passwordCharWidth = measureText(_passwordChar).width; if (_passwordEnabled) - { setString(getString()); - } - invalidatePrefixWidths(); } } @@ -848,8 +869,6 @@ void InputField::setPasswordEnabled(bool value) { _passwordEnabled = value; this->setString(this->getString()); - updateCursorPosition(); - invalidatePrefixWidths(); } } @@ -978,7 +997,18 @@ void InputField::hideCursor(void) void InputField::updateCursorPosition(void) { - setCursorPosition(_cursorCharIndex, hasSelection()); + Vec2 pos = cursorPositionFromIndex(_cursorCharIndex); + if (_cursor) + { + _cursor->setPosition(pos); + // adjust cursor height to line height + Vec2 size = _cursor->getContentSize(); + if (_lineHeight > 0) + _cursor->setContentSize(Vec2(size.width, _lineHeight)); + } + updateSelectionLayer(); + + _preferredCursorX = pos.x; } void InputField::moveCursor(int direction) @@ -988,54 +1018,120 @@ void InputField::moveCursor(int direction) void InputField::moveCursor(int direction, bool keepSelection) { - auto cursorPosition = static_cast(_cursorCharIndex) + direction; - cursorPosition = std::clamp(cursorPosition, 0, static_cast(_charCount)); - setCursorPosition(cursorPosition, keepSelection); + auto cursorIndex = static_cast(_cursorCharIndex) + direction; + cursorIndex = std::clamp(cursorIndex, 0, static_cast(_charCount)); + setCursorPosition(cursorIndex, keepSelection); } -void InputField::moveCursorTo(float x) +void InputField::moveCursorTo(const Vec2& point) { - moveCursorTo(x, false); + moveCursorTo(point, false); } -void InputField::moveCursorTo(float x, bool keepSelection) +void InputField::moveCursorTo(const Vec2& point, bool keepSelection) { - setCursorPosition(positionFromCursorX(x), keepSelection); + setCursorPosition(cursorIndexFromPosition(point), keepSelection); } -void InputField::setCursorPosition(int cursorPosition, bool keepSelection) +void InputField::setCursorPosition(int cursorIndex, bool keepSelection) { - cursorPosition = (std::min)(cursorPosition, static_cast(_charCount)); + cursorIndex = (std::min)(cursorIndex, static_cast(_charCount)); if (keepSelection) { - setSelection(_selectionAnchor, cursorPosition); + setSelection(_selectionAnchor, cursorIndex); } else { - _selectionAnchor = cursorPosition; - _selectionStart = cursorPosition; - _selectionEnd = cursorPosition; + _selectionAnchor = cursorIndex; + _selectionStart = cursorIndex; + _selectionEnd = cursorIndex; } - _cursorCharIndex = cursorPosition; - _cursorByteIndex = getByteOffset(cursorPosition); + _cursorCharIndex = cursorIndex; + _cursorByteIndex = getByteOffset(cursorIndex); + auto cursorPosition = cursorPositionFromIndex(cursorIndex); if (_cursor) - _cursor->setPosition(Vec2(cursorXFromPosition(cursorPosition), this->getContentSize().height / 2)); + _cursor->setPosition(cursorPosition); + + if (!keepSelection) + _preferredCursorX = cursorPosition.x; // remember horizontal position for vertical movement updateSelectionLayer(); } -int InputField::getByteOffset(int cursorPosition) const +int InputField::getByteOffset(int cursorIndex) const { - if (cursorPosition >= _charCount) + if (cursorIndex >= _charCount) return _inputText.length(); - auto byteOffset = text_utils::getUTF8ByteOffset(_inputText, cursorPosition); + auto byteOffset = text_utils::getUTF8ByteOffset(_inputText, cursorIndex); return byteOffset == std::string::npos ? static_cast(_inputText.length()) : static_cast(byteOffset); } +float InputField::getRenderLabelTextBottomY() const +{ + // If there is no render label, fallback to 0 + if (!_renderLabel) + return 0.0f; + + // Get label container position and anchor in InputField local coords + float labelPosY = _renderLabel->getPositionY(); + float anchorY = _renderLabel->getAnchorPoint().y; + float labelHeight = _renderLabel->getContentSize().height; + + // Compute the bottom Y of the label container + // labelBottomY = labelPosY - anchorY * labelHeight + float labelBottomY = labelPosY - anchorY * labelHeight; + float labelTopY = labelBottomY + labelHeight; + + // Compute the actual text height based on line metrics and line height + // If line metrics are not available, fallback to a single line height + float totalTextHeight = static_cast(_lineMetrics.size()) * _lineHeight; + if (totalTextHeight <= 0.0f) + { + // fallback to a measured single-line height + totalTextHeight = _lineHeight; + } + + // Determine where the text block sits inside the label container + // This must respect the vertical alignment used by the label rendering. + // We use InputField's _textVAlignment which should match the label's valign. + float textBottomYInLabel = labelBottomY; + + if (labelHeight > totalTextHeight) + { + if (_textVAlignment == TextVAlignment::TOP) + { + // Text is aligned to the top of the label container. + // Text top equals labelTopY, so bottom is labelTopY - totalTextHeight. + textBottomYInLabel = labelTopY - totalTextHeight; + } + else if (_textVAlignment == TextVAlignment::CENTER) + { + // Text is vertically centered inside the label container. + // Bottom = labelBottomY + (labelHeight - totalTextHeight) / 2 + textBottomYInLabel = labelBottomY + (labelHeight - totalTextHeight) * 0.5f; + } + else // TextVAlignment::BOTTOM + { + // Text is bottom-aligned; bottom equals labelBottomY + textBottomYInLabel = labelBottomY; + } + } + else + { + // If text fills or overflows the label container, clamp to label bottom. + textBottomYInLabel = labelBottomY; + } + + // If the Label exposes internal padding or baseline offsets, apply them here. + // Example (pseudo): textBottomYInLabel += _renderLabel->getInternalPaddingBottom(); + + return textBottomYInLabel; +} + void InputField::setSelection(int start, int end) { _selectionStart = (std::min)(start, static_cast(_charCount)); @@ -1049,22 +1145,48 @@ void InputField::updateSelectionLayer(void) { if (!_selectionLayer) return; - _selectionLayer->clear(); if (!hasSelection()) return; - auto startX = cursorXFromPosition(_selectionStart); - auto endX = cursorXFromPosition(_selectionEnd); - if (endX <= startX) + int selStart = std::min(_selectionStart, _selectionEnd); + int selEnd = std::max(_selectionStart, _selectionEnd); + if (selStart == selEnd) return; - auto height = (std::max)(_renderLabel->getContentSize().height, this->getContentSize().height); - if (height <= 0) - height = _fontSize; + float labelTextBottomY = getRenderLabelTextBottomY(); - _selectionLayer->drawSolidRect(Vec2(startX, (this->getContentSize().height - height) * 0.5f), - Vec2(endX, (this->getContentSize().height + height) * 0.5f), _selectionColor); + for (size_t lineIdx = 0; lineIdx < _lineMetrics.size(); ++lineIdx) + { + const LineMetrics& line = _lineMetrics[lineIdx]; + if (line.endCharIndex <= selStart || line.startCharIndex >= selEnd) + continue; + + int lineSelStart = std::max(selStart, line.startCharIndex) - line.startCharIndex; + int lineSelEnd = std::min(selEnd, line.endCharIndex) - line.startCharIndex; + if (lineSelEnd <= lineSelStart) + continue; + + float x1 = line.charXOffsets[lineSelStart]; + float x2 = line.charXOffsets[lineSelEnd]; + + // apply horizontal alignment + float totalTextWidth = line.lineWidth; + float lineStartX = 0.0f; + if (_textHAlignment == TextHAlignment::CENTER) + lineStartX = (_contentSize.width - totalTextWidth) * 0.5f; + else if (_textHAlignment == TextHAlignment::RIGHT) + lineStartX = _contentSize.width - totalTextWidth; + + float selX1 = lineStartX + x1; + float selX2 = lineStartX + x2; + + // vertical coordinates using labelTextBottomY + float selY1 = labelTextBottomY + lineIdx * _lineHeight; + float selY2 = selY1 + _lineHeight; + + _selectionLayer->drawSolidRect(Vec2(selX1, selY1), Vec2(selX2, selY2), _selectionColor); + } } bool InputField::deleteSelection(bool notify) @@ -1165,23 +1287,15 @@ TextVAlignment InputField::getTextVerticalAlignment() const bool InputField::onTouchBegan(Touch* touch, Event* event) { - // Call parent class to handle basic touch logic (hit test, highlight, etc.) auto hitted = Widget::onTouchBegan(touch, event); - - // If clicked outside the input field, detach IME (like axmol3 UITextField does) if (!hitted) { detachWithIME(); return false; } - - // InputField specific touch handling if (_readOnly || !_enabled) - { return false; - } - // Handle continuous touch callback - start manual timing bool focus = isCursorVisible(); if (focus && _continuousTouchCallback) { @@ -1190,16 +1304,14 @@ bool InputField::onTouchBegan(Touch* touch, Event* event) _continuousTouchWorldPoint = touch->getLocation(); } - // Initialize selection state _selectingByTouch = focus; _selectionTouchMoved = false; _selectionAnchor = _cursorCharIndex; - // Handle cursor positioning if (focus) { - auto inputFieldPoint = this->convertToNodeSpace(touch->getLocation()); - _selectionAnchor = positionFromCursorX(inputFieldPoint.x); + Vec2 inputFieldPoint = this->convertToNodeSpace(touch->getLocation()); + _selectionAnchor = cursorIndexFromPosition(inputFieldPoint); } return true; @@ -1207,41 +1319,28 @@ bool InputField::onTouchBegan(Touch* touch, Event* event) void InputField::onTouchMoved(Touch* touch, Event* event) { - // Call parent class first Widget::onTouchMoved(touch, event); - - // InputField specific touch move handling if (!_selectingByTouch || _readOnly || !_enabled) - { return; - } - auto inputFieldPoint = this->convertToNodeSpace(touch->getLocation()); - setCursorPosition(positionFromCursorX(inputFieldPoint.x), true); + Vec2 inputFieldPoint = this->convertToNodeSpace(touch->getLocation()); + setCursorPosition(cursorIndexFromPosition(inputFieldPoint), true); _selectionTouchMoved = hasSelection(); } void InputField::onTouchEnded(Touch* touch, Event* event) { - // Cancel continuous touch pending state _continuousTouchPending = false; - - // Call parent class Widget::onTouchEnded(touch, event); - // InputField specific touch end handling bool focus = _hitted && !_readOnly && _enabled; - if (focus) { if (!s_keyboardVisible || !isCursorVisible()) - { attachWithIME(); - } - // Handle cursor positioning - auto renderLabelPoint = this->convertToNodeSpace(touch->getLocation()); - moveCursorTo(renderLabelPoint.x, _selectionTouchMoved); + Vec2 localPoint = this->convertToNodeSpace(touch->getLocation()); + moveCursorTo(localPoint, _selectionTouchMoved); } else { @@ -1262,174 +1361,242 @@ void InputField::onTouchCancelled(Touch* touch, Event* event) _selectingByTouch = false; } -float InputField::cursorXFromPosition(int cursorPosition) const +Vec2 InputField::cursorPositionFromIndex(int cursorIndex) const { - cursorPosition = (std::min)(cursorPosition, static_cast(_charCount)); - - // Calculate the offset from InputField origin to text start position - float textStartOffset = 0.0f; - if (_renderLabel) - { - float labelWidth = _renderLabel->getContentSize().width; - float totalTextWidth = (_charCount > 0) ? getPrefixWidth(_charCount) : 0.0f; + cursorIndex = std::min(cursorIndex, static_cast(_charCount)); + if (_lineMetrics.empty()) + return Vec2::ZERO; - // Label is positioned at center of InputField with ANCHOR_MIDDLE - // So label's left edge is at: contentSize.width/2 - labelWidth/2 - float labelLeftEdge = _contentSize.width / 2.0f - labelWidth / 2.0f; + // Find the line containing cursorIndex + auto it = std::upper_bound(_lineMetrics.begin(), _lineMetrics.end(), cursorIndex, + [](int pos, const LineMetrics& line) { return pos < line.startCharIndex; }); + int lineIdx = (it == _lineMetrics.begin()) ? 0 : int(it - _lineMetrics.begin()) - 1; + if (lineIdx >= (int)_lineMetrics.size()) + lineIdx = (int)_lineMetrics.size() - 1; - // Text alignment offset within the label - if (_textHAlignment == TextHAlignment::CENTER) - { - // Text is centered in label, so text starts at: labelLeftEdge + (labelWidth - textWidth)/2 - textStartOffset = labelLeftEdge + (labelWidth - totalTextWidth) * 0.5f; - } - else if (_textHAlignment == TextHAlignment::RIGHT) - { - // Text is right-aligned in label, so text starts at: labelLeftEdge + (labelWidth - textWidth) - textStartOffset = labelLeftEdge + (labelWidth - totalTextWidth); - } - else // LEFT - { - // Text is left-aligned in label, so text starts at label's left edge - textStartOffset = labelLeftEdge; - } - } + const LineMetrics& line = _lineMetrics[lineIdx]; + int charInLine = cursorIndex - line.startCharIndex; + if (charInLine < 0) + charInLine = 0; + if (charInLine > (int)line.charXOffsets.size() - 1) + charInLine = (int)line.charXOffsets.size() - 1; - // For position 0 or empty text, return text start position - if (cursorPosition == 0 || _inputText.empty()) - return textStartOffset; + float x = line.charXOffsets[charInLine]; // x offset from line start to cursor + // Apply horizontal alignment + float totalTextWidth = line.lineWidth; + float lineStartX = 0.0f; + if (_textHAlignment == TextHAlignment::CENTER) + lineStartX = (_contentSize.width - totalTextWidth) * 0.5f; + else if (_textHAlignment == TextHAlignment::RIGHT) + lineStartX = _contentSize.width - totalTextWidth; - if (_passwordEnabled) - return textStartOffset + _passwordCharWidth * cursorPosition; + float finalX = lineStartX + x; - float textWidth = getPrefixWidth(cursorPosition); + // Use the label text bottom Y as the vertical base + auto yOffset = getRenderLabelTextBottomY(); - return textStartOffset + textWidth; + float finalY = yOffset + (lineIdx + 0.5f) * _lineHeight; // center of line + return Vec2(finalX, finalY); } -int InputField::positionFromCursorX(float x) const +int InputField::cursorIndexFromPosition(const Vec2& position) const { - if (x <= 0 || _charCount == 0) + if (_inputText.empty() || _lineMetrics.empty()) return 0; - // Calculate the offset from InputField origin to text start position - float textStartOffset = 0.0f; - float totalTextWidth = 0.0f; - if (_renderLabel) - { - float labelWidth = _renderLabel->getContentSize().width; - totalTextWidth = (_charCount > 0) ? getPrefixWidth(_charCount) : 0.0f; + float yOffset = getRenderLabelTextBottomY(); - // Label is positioned at center of InputField with ANCHOR_MIDDLE - float labelLeftEdge = _contentSize.width / 2.0f - labelWidth / 2.0f; + float localY = position.y - yOffset; + int lineIdx = std::clamp(int(localY / _lineHeight), 0, (int)_lineMetrics.size() - 1); + if (localY < 0) + lineIdx = 0; - // Text alignment offset within the label - if (_textHAlignment == TextHAlignment::CENTER) - { - textStartOffset = labelLeftEdge + (labelWidth - totalTextWidth) * 0.5f; - } - else if (_textHAlignment == TextHAlignment::RIGHT) - { - textStartOffset = labelLeftEdge + (labelWidth - totalTextWidth); - } - else // LEFT - { - textStartOffset = labelLeftEdge; - } - } + const LineMetrics& line = _lineMetrics[lineIdx]; - // Convert InputField coordinate to text-relative coordinate - float adjustedX = x - textStartOffset; + // Calculate relative X based on horizontal alignment + float lineStartX = 0.0f; + if (_textHAlignment == TextHAlignment::CENTER) + lineStartX = (_contentSize.width - line.lineWidth) * 0.5f; + else if (_textHAlignment == TextHAlignment::RIGHT) + lineStartX = _contentSize.width - line.lineWidth; - // Clamp to valid range - if (adjustedX < 0) - return 0; + float relX = position.x - lineStartX; - if (adjustedX >= totalTextWidth) - return _charCount; + // Handle boundary cases: before first char or after last char + if (relX <= 0.0f) + return line.startCharIndex; + if (relX >= line.lineWidth) + return line.endCharIndex; - // Binary search using cached prefix widths. We choose the smallest index i - // such that adjustedX < midpoint(prefix[i], prefix[i+1]). Returns i. - uint32_t low = 0; - uint32_t high = _charCount; - while (low < high) - { - uint32_t mid = (low + high) / 2; - float leftX = getPrefixWidth(mid); - float rightX = getPrefixWidth(mid + 1); - float midPoint = (leftX + rightX) * 0.5f; - if (adjustedX < midPoint) - high = mid; - else - low = mid + 1; - } + // Binary search using std::lower_bound to find first offset greater than relX + auto& offsets = line.charXOffsets; + auto it = std::lower_bound(offsets.begin(), offsets.end(), relX); + int idx = (int)(it - offsets.begin()); - return static_cast(low); -} + // idx is the first offset > relX, so the character interval is [idx-1, idx] + if (idx == 0) + return line.startCharIndex; // clicked before first char -float InputField::getPrefixWidth(int charIndex) const -{ - if (charIndex == 0) - return 0.0f; + float left = offsets[idx - 1]; + float right = offsets[idx]; + float mid = (left + right) * 0.5f; - if (_passwordEnabled) - return static_cast(charIndex) * _passwordCharWidth; - // If precomputed cache is enabled and available, return directly - if (_precomputePrefixWidthsEnabled && _prefixWidths.size() == (_charCount + 1)) - { - return _prefixWidths[charIndex]; - } - // Fallback to on-demand measurement for missing cache or when precompute disabled - auto byteOffset = text_utils::getUTF8ByteOffset(_inputText, charIndex); - if (byteOffset == std::string::npos) - byteOffset = _inputText.length(); - - float w = measureText(std::string_view(_inputText.data(), byteOffset)).width; - return w; + // Decide cursor position based on left/right half of the character + if (relX < mid) + return line.startCharIndex + idx - 1; // left half ==> before char + else + return line.startCharIndex + idx; // right half ==> after char } -void InputField::invalidatePrefixWidths() const +void InputField::rebuildLineMetrics() { - _prefixWidths.clear(); - if (_precomputePrefixWidthsEnabled) + _lineMetrics.clear(); + if (_inputText.empty()) { - // Precompute all prefix widths at once to avoid repeated measureText calls - _prefixWidths.resize(_charCount + 1); - _prefixWidths[0] = 0.0f; - if (_passwordEnabled) + // at least one empty line + _lineMetrics.push_back({0, 0, 0.0f, {0.0f}}); + return; + } + + float availableWidth = _multilineEnabled ? _contentSize.width : std::numeric_limits::max(); + if (availableWidth <= 0.0f && _multilineEnabled) + availableWidth = std::numeric_limits::max(); // treat as unlimited + + int totalChars = static_cast(_charCount); + int idx = 0; + int lineStart = 0; + float currentLineWidth = 0.0f; + + // Helper to finalize a line from lineStart to idx (exclusive), store its metrics + auto finalizeLine = [&](int endIdx) { + LineMetrics line; + line.startCharIndex = lineStart; + line.endCharIndex = endIdx; + int charInLine = endIdx - lineStart; + line.charXOffsets.resize(charInLine + 1); + line.charXOffsets[0] = 0.0f; + + float x = 0.0f; + for (int i = 0; i < charInLine; ++i) { - for (uint32_t i = 1; i <= _charCount; ++i) - _prefixWidths[i] = static_cast(i) * _passwordCharWidth; + // Measure width of the i-th character from lineStart + int globalIdx = lineStart + i; + // Get UTF-8 byte range for this character + auto byteStart = text_utils::getUTF8ByteOffset(_inputText, globalIdx); + auto byteEnd = text_utils::getUTF8ByteOffset(_inputText, globalIdx + 1); + if (byteEnd == std::string::npos) + byteEnd = _inputText.length(); + std::string_view charStr(_inputText.data() + byteStart, byteEnd - byteStart); + + float charWidth = (_passwordEnabled) ? _passwordCharWidth : measureText(charStr).width; + x += charWidth; + line.charXOffsets[i + 1] = x; } - else + line.lineWidth = x; + _lineMetrics.push_back(std::move(line)); + }; + + while (idx < totalChars) + { + // Check for explicit line break (only in multiline mode) + if (_multilineEnabled) { - for (uint32_t i = 1; i <= _charCount; ++i) + // Find if the current character is '\n' + auto byteStart = text_utils::getUTF8ByteOffset(_inputText, idx); + // Check if the character is a line-feed (single byte 0x0A) + if (_inputText[byteStart] == '\n') { - auto byteOffset = text_utils::getUTF8ByteOffset(_inputText, i); - if (byteOffset == std::string::npos) - byteOffset = _inputText.length(); - - _prefixWidths[i] = measureText(std::string_view(_inputText.data(), byteOffset)).width; + // Finalize line up to idx (not including '\n') + finalizeLine(idx); + lineStart = idx + 1; // skip '\n' + idx = lineStart; + continue; } } - _prefixWidthsDirty = false; + + // Measure cumulative width from lineStart to idx+1 + int nextIdx = idx + 1; + auto byteEnd = text_utils::getUTF8ByteOffset(_inputText, nextIdx); + if (byteEnd == std::string::npos) + byteEnd = _inputText.length(); + std::string_view prefix(_inputText.data() + text_utils::getUTF8ByteOffset(_inputText, lineStart), + byteEnd - text_utils::getUTF8ByteOffset(_inputText, lineStart)); + + float prefixWidth = (_passwordEnabled) ? _passwordCharWidth * (nextIdx - lineStart) : measureText(prefix).width; + + if (prefixWidth > availableWidth && idx > lineStart) // need to wrap + { + // line breaks at current idx + finalizeLine(idx); + lineStart = idx; + // reset idx? no, we stay at current idx to re-measure as start of new line + continue; + } + + currentLineWidth = prefixWidth; + idx = nextIdx; } - else + + if (lineStart <= totalChars) { - _prefixWidthsDirty = true; + finalizeLine(totalChars); } } -void InputField::setPrefixWidthCachingEnabled(bool enabled) + +void InputField::moveCursorVertically(int direction) { - if (_precomputePrefixWidthsEnabled == enabled) + if (_lineMetrics.empty()) return; - _precomputePrefixWidthsEnabled = enabled; - invalidatePrefixWidths(); -} -bool InputField::isPrefixWidthCachingEnabled() const -{ - return _precomputePrefixWidthsEnabled; + // Determine current line index + int curLine = 0; + for (size_t i = 0; i < _lineMetrics.size(); ++i) + { + if (_cursorCharIndex >= _lineMetrics[i].startCharIndex && _cursorCharIndex <= _lineMetrics[i].endCharIndex) + { + curLine = (int)i; + break; + } + } + + int targetLine = curLine + direction; + targetLine = std::clamp(targetLine, 0, (int)_lineMetrics.size() - 1); + if (targetLine == curLine) + return; + + // Keep horizontal position using _preferredCursorX (updated in moveCursorTo or setCursorPosition) + const LineMetrics& targetLineMetrics = _lineMetrics[targetLine]; + // Use binary search within target line to find the character closest to _preferredCursorX + auto& offsets = targetLineMetrics.charXOffsets; + int charInLine = 0; + float relX = _preferredCursorX; + // Need to account for alignment: we need to convert _preferredCursorX (which is in content space) to line-relative + // But _preferredCursorX is stored in the same coordinate system as cursorXFromPosition returns (content space). + // We can recalculate the relative x considering alignment: + float totalTextWidth = targetLineMetrics.lineWidth; + float lineStartX = 0.0f; + if (_textHAlignment == TextHAlignment::CENTER) + lineStartX = (_contentSize.width - totalTextWidth) * 0.5f; + else if (_textHAlignment == TextHAlignment::RIGHT) + lineStartX = _contentSize.width - totalTextWidth; + float lineRelX = _preferredCursorX - lineStartX; + lineRelX = std::max(0.0f, std::min(lineRelX, targetLineMetrics.lineWidth)); + + // binary search for lineRelX in offsets + int low = 0, high = (int)offsets.size() - 1; + while (low < high) + { + int mid = (low + high) / 2; + if (offsets[mid] <= lineRelX) + low = mid + 1; + else + high = mid; + } + charInLine = (low > 0) ? low - 1 : 0; + int newCursorPos = targetLineMetrics.startCharIndex + charInLine; + + setCursorPosition(newCursorPos, false); + _preferredCursorX = cursorPositionFromIndex(newCursorPos).x; // Update preferred x to exact cursor x } } // namespace ui diff --git a/axmol/ui/InputField.h b/axmol/ui/InputField.h index 04c0e7bf3371..2aa891131e95 100644 --- a/axmol/ui/InputField.h +++ b/axmol/ui/InputField.h @@ -173,18 +173,6 @@ class AX_DLL InputField : public Widget, public IMEDelegate */ std::string_view getPasswordChar() const { return _passwordChar; } - /** - * @brief Enable or disable prefix width caching. - * - * See setPrefixWidthCachingEnabled() for details on behaviour and trade-offs. - */ - void setPrefixWidthCachingEnabled(bool enabled); - - /** - * @brief Query whether prefix width caching is enabled. - */ - bool isPrefixWidthCachingEnabled() const; - /** * @brief Set placeholder text string. */ @@ -366,6 +354,19 @@ class AX_DLL InputField : public Widget, public IMEDelegate */ uint32_t getCharLimit() const { return _charLimit; } + /** + * @brief Enable or disable multiline mode. + * In multiline mode the control supports line breaks and the cursor/selection + * logic accounts for multiple text lines. The layout is recalculated + * automatically when the text, font, or content size changes. + */ + void setMultilineEnabled(bool enabled); + + /** + * @brief Return whether multiline mode is active. + */ + bool isMultilineEnabled() const { return _multilineEnabled; } + /** * @brief Get the internal renderer node. * @return Pointer to the renderer node. @@ -460,25 +461,29 @@ class AX_DLL InputField : public Widget, public IMEDelegate void moveCursor(int direction); void moveCursor(int direction, bool keepSelection); - void moveCursorTo(float x); - void moveCursorTo(float x, bool keepSelection); - void setCursorPosition(int cursorPosition, bool keepSelection); + void moveCursorTo(const Vec2& point); + void moveCursorTo(const Vec2& point, bool keepSelection); + void setCursorPosition(int cursorIndex, bool keepSelection); + + void moveCursorVertically(int direction); /** - * @brief Calculate the X coordinate for a given cursor position. - * @param cursorPosition UTF-8 character index (0 = before first char) + * @brief Calculate the coordinate for a given cursor index. + * @param cursorIndex UTF-8 character index (0 = before first char) * @return X coordinate in local node space, accounting for text alignment */ - float cursorXFromPosition(int cursorPosition) const; + Vec2 cursorPositionFromIndex(int cursorIndex) const; /** - * @brief Find the cursor position at a given X coordinate. + * @brief Find the cursor index at a given coordinate. * @param x X coordinate in local node space - * @return UTF-8 character index (inverse of cursorXFromPosition) + * @return UTF-8 character index (inverse of cursorPositionFromIndex) */ - int positionFromCursorX(float x) const; + int cursorIndexFromPosition(const Vec2& position) const; + + int getByteOffset(int cursorIndex) const; - int getByteOffset(int cursorPosition) const; + float getRenderLabelTextBottomY() const; void setSelection(int start, int end); void updateSelectionLayer(void); @@ -492,7 +497,6 @@ class AX_DLL InputField : public Widget, public IMEDelegate bool isCursorVisible() const; -protected: void updateLayout() override; void onSizeChanged() override; void update(float dt) override; @@ -510,22 +514,26 @@ class AX_DLL InputField : public Widget, public IMEDelegate */ Vec2 measureText(std::string_view text) const; - void invalidatePrefixWidths() const; + void rebuildLineMetrics(); - // Cached prefix widths for fast cursor position <-> x conversions. - // _prefixWidths[i] stores width of first i characters (i from 0.._charCount). - mutable std::vector _prefixWidths; + // Per-line metrics used for cursor/selection mapping in both single and multi-line modes. + struct LineMetrics + { + int startCharIndex = 0; // inclusive UTF-8 character index of the first character in this line + int endCharIndex = 0; // exclusive UTF-8 character index (points past the last visible character) + float lineWidth = 0.0f; // pure text width of this line (before horizontal alignment) + std::vector + charXOffsets; // length = (endCharIndex - startCharIndex + 1) + // charXOffsets[i] = x-offset from line start to the *end* of the i-th character + }; - // Get measured width of first `charIndex` characters (0.._charCount). Populates - // cache entries on demand. - float getPrefixWidth(int charIndex) const; + std::vector _lineMetrics; // single-line mode: size() == 1 + float _lineHeight = 0.0f; // uniform line height computed from font metrics + float _preferredCursorX = 0.0f; // used when moving cursor vertically to keep desired column std::string _fontName; float _fontSize{24.0f}; - mutable bool _prefixWidthsDirty{true}; - bool _precomputePrefixWidthsEnabled{false}; - bool _readOnly{false}; bool _layoutDirty{true}; bool _passwordEnabled{false}; @@ -535,6 +543,7 @@ class AX_DLL InputField : public Widget, public IMEDelegate bool _ctrlKeyPressed{false}; bool _shiftKeyPressed{false}; bool _useTouchArea{false}; + bool _multilineEnabled{false}; // Continuous touch delay state (manual timing, no external timer dependency) bool _continuousTouchPending{false}; diff --git a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIInputFieldTest/UIInputFieldTest.cpp b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIInputFieldTest/UIInputFieldTest.cpp index 70f61a3f12cf..179056b4d2d9 100644 --- a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIInputFieldTest/UIInputFieldTest.cpp +++ b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIInputFieldTest/UIInputFieldTest.cpp @@ -66,6 +66,8 @@ bool UIInputFieldTest::init() // Create the inputfield InputField* inputField = InputField::create("input words here", "Arial", 30); inputField->setTextHorizontalAlignment(TextHAlignment::CENTER); + inputField->setAutoSize(false); + inputField->setContentSize(Vec2(480, 100)); inputField->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); // Set up event listener for InputField @@ -236,11 +238,11 @@ bool UIInputFieldTest_LineWrap::init() // Create the inputfield InputField* inputField = InputField::create("input words here", "fonts/Marker Felt.ttf", 30); inputField->setAutoSize(false); - // inputField->setMultilineEnabled(true); + inputField->setMultilineEnabled(true); inputField->setContentSize(Vec2(240.0f, 170.0f)); inputField->setString("input words here"); - inputField->setTextHorizontalAlignment(TextHAlignment::RIGHT); - inputField->setTextVerticalAlignment(TextVAlignment::CENTER); + inputField->setTextHorizontalAlignment(TextHAlignment::LEFT); + inputField->setTextVerticalAlignment(TextVAlignment::TOP); inputField->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); // Set up event listener for InputField From f90264f5305f8c8e30a2e5c2cc5f8248c0380cbd Mon Sep 17 00:00:00 2001 From: halx99 Date: Thu, 21 May 2026 22:37:45 +0800 Subject: [PATCH 30/52] Fix multiline cursor positioning --- axmol/ui/InputField.cpp | 146 ++++++++++++++++++++++++---------------- 1 file changed, 87 insertions(+), 59 deletions(-) diff --git a/axmol/ui/InputField.cpp b/axmol/ui/InputField.cpp index b0021263eaa5..eebdf410aed5 100644 --- a/axmol/ui/InputField.cpp +++ b/axmol/ui/InputField.cpp @@ -392,7 +392,7 @@ void InputField::setFontSize(float size) } _passwordCharWidth = measureText(_passwordChar).width; - _layoutDirty = true; + _layoutDirty = true; } float InputField::getFontSize() const @@ -690,7 +690,7 @@ void InputField::setMultilineEnabled(bool enabled) if (_multilineEnabled != enabled) { _multilineEnabled = enabled; - _layoutDirty = true; + _layoutDirty = true; } } @@ -1146,24 +1146,29 @@ void InputField::updateSelectionLayer(void) if (!_selectionLayer) return; _selectionLayer->clear(); + if (!hasSelection()) return; int selStart = std::min(_selectionStart, _selectionEnd); int selEnd = std::max(_selectionStart, _selectionEnd); + if (selStart == selEnd) return; float labelTextBottomY = getRenderLabelTextBottomY(); + int totalLines = static_cast(_lineMetrics.size()); for (size_t lineIdx = 0; lineIdx < _lineMetrics.size(); ++lineIdx) { const LineMetrics& line = _lineMetrics[lineIdx]; + if (line.endCharIndex <= selStart || line.startCharIndex >= selEnd) continue; int lineSelStart = std::max(selStart, line.startCharIndex) - line.startCharIndex; int lineSelEnd = std::min(selEnd, line.endCharIndex) - line.startCharIndex; + if (lineSelEnd <= lineSelStart) continue; @@ -1173,6 +1178,7 @@ void InputField::updateSelectionLayer(void) // apply horizontal alignment float totalTextWidth = line.lineWidth; float lineStartX = 0.0f; + if (_textHAlignment == TextHAlignment::CENTER) lineStartX = (_contentSize.width - totalTextWidth) * 0.5f; else if (_textHAlignment == TextHAlignment::RIGHT) @@ -1181,8 +1187,12 @@ void InputField::updateSelectionLayer(void) float selX1 = lineStartX + x1; float selX2 = lineStartX + x2; + // Invert the line index for vertical coordinates: + // lineIdx = 0 should be rendered at the visual top. + int invertedLineIdx = totalLines - 1 - static_cast(lineIdx); + // vertical coordinates using labelTextBottomY - float selY1 = labelTextBottomY + lineIdx * _lineHeight; + float selY1 = labelTextBottomY + invertedLineIdx * _lineHeight; float selY2 = selY1 + _lineHeight; _selectionLayer->drawSolidRect(Vec2(selX1, selY1), Vec2(selX2, selY2), _selectionColor); @@ -1393,9 +1403,9 @@ Vec2 InputField::cursorPositionFromIndex(int cursorIndex) const float finalX = lineStartX + x; // Use the label text bottom Y as the vertical base - auto yOffset = getRenderLabelTextBottomY(); - - float finalY = yOffset + (lineIdx + 0.5f) * _lineHeight; // center of line + auto yOffset = getRenderLabelTextBottomY(); + int invertedLineIdx = static_cast(_lineMetrics.size()) - 1 - lineIdx; + float finalY = yOffset + (invertedLineIdx + 0.5f) * _lineHeight; // center of line return Vec2(finalX, finalY); } @@ -1406,9 +1416,17 @@ int InputField::cursorIndexFromPosition(const Vec2& position) const float yOffset = getRenderLabelTextBottomY(); - float localY = position.y - yOffset; - int lineIdx = std::clamp(int(localY / _lineHeight), 0, (int)_lineMetrics.size() - 1); - if (localY < 0) + // Calculate the distance from the top of the text block to map Y coordinates correctly + // Since Axmol's Y-axis points upwards, lineIdx = 0 should be visually at the top. + float totalTextHeight = static_cast(_lineMetrics.size()) * _lineHeight; + float topY = yOffset + totalTextHeight; // Visual top of the text block + float distFromTop = topY - position.y; // Distance from top to the click position + + // Calculate line index (0 is the top visual line) + int lineIdx = std::clamp(static_cast(distFromTop / _lineHeight), 0, static_cast(_lineMetrics.size()) - 1); + + // Fallback if user clicked above the entire text block + if (distFromTop < 0.0f) lineIdx = 0; const LineMetrics& line = _lineMetrics[lineIdx]; @@ -1431,9 +1449,8 @@ int InputField::cursorIndexFromPosition(const Vec2& position) const // Binary search using std::lower_bound to find first offset greater than relX auto& offsets = line.charXOffsets; auto it = std::lower_bound(offsets.begin(), offsets.end(), relX); - int idx = (int)(it - offsets.begin()); + int idx = (int)(it - offsets.begin()); // idx is the first offset > relX, so the character interval is [idx-1, idx] - // idx is the first offset > relX, so the character interval is [idx-1, idx] if (idx == 0) return line.startCharIndex; // clicked before first char @@ -1462,84 +1479,95 @@ void InputField::rebuildLineMetrics() if (availableWidth <= 0.0f && _multilineEnabled) availableWidth = std::numeric_limits::max(); // treat as unlimited - int totalChars = static_cast(_charCount); - int idx = 0; - int lineStart = 0; - float currentLineWidth = 0.0f; + const int totalChars = static_cast(_charCount); + int currentCharIdx = 0; + int lineStartCharIdx = 0; - // Helper to finalize a line from lineStart to idx (exclusive), store its metrics - auto finalizeLine = [&](int endIdx) { + // Helper to finalize a line from lineStartCharIdx to lineEndCharIdx (exclusive), store its metrics + auto recordLineMetrics = [&](int lineEndCharIdx) { LineMetrics line; - line.startCharIndex = lineStart; - line.endCharIndex = endIdx; - int charInLine = endIdx - lineStart; - line.charXOffsets.resize(charInLine + 1); + line.startCharIndex = lineStartCharIdx; + line.endCharIndex = lineEndCharIdx; + + const int charsInLine = lineEndCharIdx - lineStartCharIdx; + line.charXOffsets.resize(charsInLine + 1); line.charXOffsets[0] = 0.0f; - float x = 0.0f; - for (int i = 0; i < charInLine; ++i) + float accumulatedXOffset = 0.0f; + + for (int i = 0; i < charsInLine; ++i) { - // Measure width of the i-th character from lineStart - int globalIdx = lineStart + i; + // Measure width of the i-th character from lineStartCharIdx + const int absoluteCharIdx = lineStartCharIdx + i; + // Get UTF-8 byte range for this character - auto byteStart = text_utils::getUTF8ByteOffset(_inputText, globalIdx); - auto byteEnd = text_utils::getUTF8ByteOffset(_inputText, globalIdx + 1); - if (byteEnd == std::string::npos) - byteEnd = _inputText.length(); - std::string_view charStr(_inputText.data() + byteStart, byteEnd - byteStart); - - float charWidth = (_passwordEnabled) ? _passwordCharWidth : measureText(charStr).width; - x += charWidth; - line.charXOffsets[i + 1] = x; + auto startByteOffset = text_utils::getUTF8ByteOffset(_inputText, absoluteCharIdx); + auto endByteOffset = text_utils::getUTF8ByteOffset(_inputText, absoluteCharIdx + 1); + if (endByteOffset == std::string::npos) + { + endByteOffset = _inputText.length(); + } + + std::string_view charView(_inputText.data() + startByteOffset, endByteOffset - startByteOffset); + float charWidth = (_passwordEnabled) ? _passwordCharWidth : measureText(charView).width; + + accumulatedXOffset += charWidth; + line.charXOffsets[i + 1] = accumulatedXOffset; } - line.lineWidth = x; + line.lineWidth = accumulatedXOffset; _lineMetrics.push_back(std::move(line)); }; - while (idx < totalChars) + while (currentCharIdx < totalChars) { // Check for explicit line break (only in multiline mode) if (_multilineEnabled) { // Find if the current character is '\n' - auto byteStart = text_utils::getUTF8ByteOffset(_inputText, idx); + auto charByteOffset = text_utils::getUTF8ByteOffset(_inputText, currentCharIdx); + // Check if the character is a line-feed (single byte 0x0A) - if (_inputText[byteStart] == '\n') + if (_inputText[charByteOffset] == '\n') { - // Finalize line up to idx (not including '\n') - finalizeLine(idx); - lineStart = idx + 1; // skip '\n' - idx = lineStart; + // Finalize line up to currentCharIdx (not including '\n') + recordLineMetrics(currentCharIdx); + lineStartCharIdx = currentCharIdx + 1; // skip '\n' + currentCharIdx = lineStartCharIdx; continue; } } - // Measure cumulative width from lineStart to idx+1 - int nextIdx = idx + 1; - auto byteEnd = text_utils::getUTF8ByteOffset(_inputText, nextIdx); - if (byteEnd == std::string::npos) - byteEnd = _inputText.length(); - std::string_view prefix(_inputText.data() + text_utils::getUTF8ByteOffset(_inputText, lineStart), - byteEnd - text_utils::getUTF8ByteOffset(_inputText, lineStart)); + // Measure cumulative width from lineStartCharIdx to currentCharIdx + 1 + const int nextCharIdx = currentCharIdx + 1; + auto nextCharByteOffset = text_utils::getUTF8ByteOffset(_inputText, nextCharIdx); + if (nextCharByteOffset == std::string::npos) + { + nextCharByteOffset = _inputText.length(); + } + + // Extract the line prefix view cleanly + auto lineStartByteOffset = text_utils::getUTF8ByteOffset(_inputText, lineStartCharIdx); + std::string_view linePrefixView(_inputText.data() + lineStartByteOffset, + nextCharByteOffset - lineStartByteOffset); - float prefixWidth = (_passwordEnabled) ? _passwordCharWidth * (nextIdx - lineStart) : measureText(prefix).width; + float linePrefixWidth = (_passwordEnabled) ? _passwordCharWidth * (nextCharIdx - lineStartCharIdx) + : measureText(linePrefixView).width; - if (prefixWidth > availableWidth && idx > lineStart) // need to wrap + if (linePrefixWidth > availableWidth && currentCharIdx > lineStartCharIdx) { - // line breaks at current idx - finalizeLine(idx); - lineStart = idx; - // reset idx? no, we stay at current idx to re-measure as start of new line + // line breaks at current currentCharIdx + recordLineMetrics(currentCharIdx); + lineStartCharIdx = currentCharIdx; + // reset currentCharIdx? no, we stay at current char to re-measure as start of new line continue; } - currentLineWidth = prefixWidth; - idx = nextIdx; + currentCharIdx = nextCharIdx; } - if (lineStart <= totalChars) + if (lineStartCharIdx <= totalChars) { - finalizeLine(totalChars); + recordLineMetrics(totalChars); } } From 36a0478fa3c9203427c45df2f686484797620822 Mon Sep 17 00:00:00 2001 From: halx99 Date: Thu, 21 May 2026 22:57:07 +0800 Subject: [PATCH 31/52] Fixup --- axmol/ui/InputField.cpp | 13 +++++++++---- axmol/ui/InputField.h | 2 ++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/axmol/ui/InputField.cpp b/axmol/ui/InputField.cpp index eebdf410aed5..2b81ad1b4e40 100644 --- a/axmol/ui/InputField.cpp +++ b/axmol/ui/InputField.cpp @@ -411,6 +411,8 @@ Label* InputField::getRenderLabel() bool InputField::attachWithIME() { + if (_isAttachWithIME) + return true; bool ret = IMEDelegate::attachWithIME(); if (ret) { @@ -423,9 +425,12 @@ bool InputField::attachWithIME() if (renderView) renderView->setIMEKeyboardState(true); - updateCursorPosition(); + // updateCursorPosition(); showCursor(); dispatchEvent(EventType::ATTACH_WITH_IME); + _isAttachWithIME = true; + + _layoutDirty = true; } return ret; } @@ -445,6 +450,8 @@ bool InputField::detachWithIME() // Dispatch event before removing listeners dispatchEvent(EventType::DETACH_WITH_IME); + + _isAttachWithIME = false; } return ret; } @@ -1262,9 +1269,7 @@ void InputField::setTextHorizontalAlignment(TextHAlignment alignment) if (_renderLabel) { _renderLabel->setHorizontalAlignment(alignment); - // Update cursor and selection positions to reflect new alignment - updateCursorPosition(); - updateSelectionLayer(); + _layoutDirty = true; } } } diff --git a/axmol/ui/InputField.h b/axmol/ui/InputField.h index 2aa891131e95..b38bd68bd0a8 100644 --- a/axmol/ui/InputField.h +++ b/axmol/ui/InputField.h @@ -545,6 +545,8 @@ class AX_DLL InputField : public Widget, public IMEDelegate bool _useTouchArea{false}; bool _multilineEnabled{false}; + bool _isAttachWithIME{false}; + // Continuous touch delay state (manual timing, no external timer dependency) bool _continuousTouchPending{false}; float _continuousTouchElapsedTime{0.0f}; From 469056421a4cc5cdbdf0620475dbe10488890caa Mon Sep 17 00:00:00 2001 From: halx99 Date: Thu, 21 May 2026 23:21:40 +0800 Subject: [PATCH 32/52] Improve --- axmol/ui/InputField.cpp | 74 ++++++++++++++++++++++++----------------- axmol/ui/InputField.h | 3 ++ 2 files changed, 47 insertions(+), 30 deletions(-) diff --git a/axmol/ui/InputField.cpp b/axmol/ui/InputField.cpp index 2b81ad1b4e40..efe563b39b2f 100644 --- a/axmol/ui/InputField.cpp +++ b/axmol/ui/InputField.cpp @@ -505,8 +505,8 @@ void InputField::setCharLimit(uint32_t limit) if (_charLimit > 0 && _charCount > _charLimit) { auto byteOffset = getByteOffset(static_cast(_charLimit)); - std::string newText(_inputText.substr(0, byteOffset)); - setString(newText); + std::string_view textView(_inputText); + setString(textView.substr(0, byteOffset)); // Ensure cursor is not past the new limit setCursorPosition(static_cast(_charLimit), false); } @@ -714,6 +714,7 @@ Vec2 InputField::getPreferredSize() const // input text property void InputField::setString(std::string_view text) { + _charByteOffsetDirty = true; _layoutDirty = true; auto oldInsertCharIndex = static_cast(_cursorCharIndex); @@ -795,6 +796,12 @@ void InputField::onSizeChanged() void InputField::updateLayout() { + if (_charByteOffsetDirty) + { + _charByteOffsetDirty = false; + rebuildCharByteOffsets(); + } + if (_layoutDirty) { _layoutDirty = false; @@ -1070,11 +1077,13 @@ void InputField::setCursorPosition(int cursorIndex, bool keepSelection) int InputField::getByteOffset(int cursorIndex) const { + if (_charByteOffsetDirty) + rebuildCharByteOffsets(); + if (cursorIndex >= _charCount) return _inputText.length(); - auto byteOffset = text_utils::getUTF8ByteOffset(_inputText, cursorIndex); - return byteOffset == std::string::npos ? static_cast(_inputText.length()) : static_cast(byteOffset); + return _charByteOffsets[cursorIndex]; } float InputField::getRenderLabelTextBottomY() const @@ -1475,20 +1484,20 @@ void InputField::rebuildLineMetrics() _lineMetrics.clear(); if (_inputText.empty()) { - // at least one empty line + // At least one empty line _lineMetrics.push_back({0, 0, 0.0f, {0.0f}}); return; } float availableWidth = _multilineEnabled ? _contentSize.width : std::numeric_limits::max(); if (availableWidth <= 0.0f && _multilineEnabled) - availableWidth = std::numeric_limits::max(); // treat as unlimited + availableWidth = std::numeric_limits::max(); // Treat as unlimited - const int totalChars = static_cast(_charCount); + const int totalChars = static_cast(_charByteOffsets.size() - 1); int currentCharIdx = 0; int lineStartCharIdx = 0; - // Helper to finalize a line from lineStartCharIdx to lineEndCharIdx (exclusive), store its metrics + // Helper to calculate character offsets and record the current line's metrics auto recordLineMetrics = [&](int lineEndCharIdx) { LineMetrics line; line.startCharIndex = lineStartCharIdx; @@ -1502,16 +1511,11 @@ void InputField::rebuildLineMetrics() for (int i = 0; i < charsInLine; ++i) { - // Measure width of the i-th character from lineStartCharIdx const int absoluteCharIdx = lineStartCharIdx + i; - // Get UTF-8 byte range for this character - auto startByteOffset = text_utils::getUTF8ByteOffset(_inputText, absoluteCharIdx); - auto endByteOffset = text_utils::getUTF8ByteOffset(_inputText, absoluteCharIdx + 1); - if (endByteOffset == std::string::npos) - { - endByteOffset = _inputText.length(); - } + // Fast O(1) lookups instead of slow O(N) text scanning + size_t startByteOffset = _charByteOffsets[absoluteCharIdx]; + size_t endByteOffset = _charByteOffsets[absoluteCharIdx + 1]; std::string_view charView(_inputText.data() + startByteOffset, endByteOffset - startByteOffset); float charWidth = (_passwordEnabled) ? _passwordCharWidth : measureText(charView).width; @@ -1523,35 +1527,30 @@ void InputField::rebuildLineMetrics() _lineMetrics.push_back(std::move(line)); }; + // Step 2: Linear pass text layout and auto-wrapping logic while (currentCharIdx < totalChars) { // Check for explicit line break (only in multiline mode) if (_multilineEnabled) { - // Find if the current character is '\n' - auto charByteOffset = text_utils::getUTF8ByteOffset(_inputText, currentCharIdx); + size_t charByteOffset = _charByteOffsets[currentCharIdx]; // Check if the character is a line-feed (single byte 0x0A) if (_inputText[charByteOffset] == '\n') { - // Finalize line up to currentCharIdx (not including '\n') recordLineMetrics(currentCharIdx); - lineStartCharIdx = currentCharIdx + 1; // skip '\n' + lineStartCharIdx = currentCharIdx + 1; // Skip '\n' currentCharIdx = lineStartCharIdx; continue; } } // Measure cumulative width from lineStartCharIdx to currentCharIdx + 1 - const int nextCharIdx = currentCharIdx + 1; - auto nextCharByteOffset = text_utils::getUTF8ByteOffset(_inputText, nextCharIdx); - if (nextCharByteOffset == std::string::npos) - { - nextCharByteOffset = _inputText.length(); - } + const int nextCharIdx = currentCharIdx + 1; + size_t nextCharByteOffset = _charByteOffsets[nextCharIdx]; + size_t lineStartByteOffset = _charByteOffsets[lineStartCharIdx]; - // Extract the line prefix view cleanly - auto lineStartByteOffset = text_utils::getUTF8ByteOffset(_inputText, lineStartCharIdx); + // Extract the line prefix view cleanly using O(1) lookups std::string_view linePrefixView(_inputText.data() + lineStartByteOffset, nextCharByteOffset - lineStartByteOffset); @@ -1560,22 +1559,37 @@ void InputField::rebuildLineMetrics() if (linePrefixWidth > availableWidth && currentCharIdx > lineStartCharIdx) { - // line breaks at current currentCharIdx + // Text exceeds available width, record the line up to currentCharIdx before wrapping recordLineMetrics(currentCharIdx); lineStartCharIdx = currentCharIdx; - // reset currentCharIdx? no, we stay at current char to re-measure as start of new line + // Stay at current char to re-measure it as the start of the next line continue; } currentCharIdx = nextCharIdx; } + // Record the final remaining line after the loop ends if (lineStartCharIdx <= totalChars) { recordLineMetrics(totalChars); } } +void InputField::rebuildCharByteOffsets() const +{ + _charByteOffsets.clear(); + _charByteOffsets.reserve(_inputText.length() + 1); + for (size_t i = 0; i < _inputText.length(); ++i) + { + if ((static_cast(_inputText[i]) & 0xC0) != 0x80) + { + _charByteOffsets.push_back(static_cast(i)); + } + } + _charByteOffsets.push_back(static_cast(_inputText.length())); +} + void InputField::moveCursorVertically(int direction) { if (_lineMetrics.empty()) diff --git a/axmol/ui/InputField.h b/axmol/ui/InputField.h index b38bd68bd0a8..a0be2faba8d4 100644 --- a/axmol/ui/InputField.h +++ b/axmol/ui/InputField.h @@ -515,6 +515,7 @@ class AX_DLL InputField : public Widget, public IMEDelegate Vec2 measureText(std::string_view text) const; void rebuildLineMetrics(); + void rebuildCharByteOffsets() const; // Per-line metrics used for cursor/selection mapping in both single and multi-line modes. struct LineMetrics @@ -536,6 +537,7 @@ class AX_DLL InputField : public Widget, public IMEDelegate bool _readOnly{false}; bool _layoutDirty{true}; + bool _charByteOffsetDirty{true}; bool _passwordEnabled{false}; bool _cursorVisible{false}; bool _selectingByTouch{false}; @@ -558,6 +560,7 @@ class AX_DLL InputField : public Widget, public IMEDelegate std::string _inputText; std::string _placeHolder; std::string _passwordChar; + mutable std::vector _charByteOffsets; // Maps UTF-8 character index to byte offset in _inputText Color32 _colorSpaceHolder{Color32::GRAY}; Color32 _colorText{Color32::WHITE}; From aa519379531735fdad23a35e7dcce37574afec9a Mon Sep 17 00:00:00 2001 From: halx99 Date: Thu, 21 May 2026 23:23:00 +0800 Subject: [PATCH 33/52] Improve code style --- axmol/ui/InputField.cpp | 6 +++--- axmol/ui/InputField.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/axmol/ui/InputField.cpp b/axmol/ui/InputField.cpp index efe563b39b2f..20de376df135 100644 --- a/axmol/ui/InputField.cpp +++ b/axmol/ui/InputField.cpp @@ -715,7 +715,7 @@ Vec2 InputField::getPreferredSize() const void InputField::setString(std::string_view text) { _charByteOffsetDirty = true; - _layoutDirty = true; + _layoutDirty = true; auto oldInsertCharIndex = static_cast(_cursorCharIndex); bool bInsertAtEnd = (oldInsertCharIndex == static_cast(_charCount)); @@ -1078,7 +1078,7 @@ void InputField::setCursorPosition(int cursorIndex, bool keepSelection) int InputField::getByteOffset(int cursorIndex) const { if (_charByteOffsetDirty) - rebuildCharByteOffsets(); + const_cast(this)->rebuildCharByteOffsets(); if (cursorIndex >= _charCount) return _inputText.length(); @@ -1576,7 +1576,7 @@ void InputField::rebuildLineMetrics() } } -void InputField::rebuildCharByteOffsets() const +void InputField::rebuildCharByteOffsets() { _charByteOffsets.clear(); _charByteOffsets.reserve(_inputText.length() + 1); diff --git a/axmol/ui/InputField.h b/axmol/ui/InputField.h index a0be2faba8d4..ee6bc36945db 100644 --- a/axmol/ui/InputField.h +++ b/axmol/ui/InputField.h @@ -515,7 +515,7 @@ class AX_DLL InputField : public Widget, public IMEDelegate Vec2 measureText(std::string_view text) const; void rebuildLineMetrics(); - void rebuildCharByteOffsets() const; + void rebuildCharByteOffsets(); // Per-line metrics used for cursor/selection mapping in both single and multi-line modes. struct LineMetrics @@ -560,7 +560,7 @@ class AX_DLL InputField : public Widget, public IMEDelegate std::string _inputText; std::string _placeHolder; std::string _passwordChar; - mutable std::vector _charByteOffsets; // Maps UTF-8 character index to byte offset in _inputText + std::vector _charByteOffsets; // Maps UTF-8 character index to byte offset in _inputText Color32 _colorSpaceHolder{Color32::GRAY}; Color32 _colorText{Color32::WHITE}; From b68940b7c9d65fe85019c09e100c9264cde6199f Mon Sep 17 00:00:00 2001 From: halx99 Date: Fri, 22 May 2026 11:27:37 +0800 Subject: [PATCH 34/52] Add ime preedit callback --- axmol/2d/Label.cpp | 39 ++++---- axmol/2d/Label.h | 20 +++-- axmol/base/IMEDelegate.h | 9 +- axmol/base/IMEDispatcher.cpp | 29 +++--- axmol/base/IMEDispatcher.h | 6 +- axmol/platform/android/jni/AxmolPlayerJni.cpp | 7 +- axmol/platform/desktop/RenderViewImpl.cpp | 88 +++++++++++++++---- axmol/platform/desktop/RenderViewImpl.h | 7 ++ axmol/platform/ios/InputView-ios.mm | 6 +- axmol/platform/ios/RenderHostView-ios.mm | 2 +- axmol/platform/winrt/InputEvent.cpp | 7 +- axmol/platform/winrt/Keyboard-winrt.cpp | 6 +- axmol/ui/InputField.cpp | 8 +- axmol/ui/InputField.h | 2 +- .../Source/axmol/ui/HelperTests.cpp | 14 +-- 15 files changed, 162 insertions(+), 88 deletions(-) diff --git a/axmol/2d/Label.cpp b/axmol/2d/Label.cpp index 79398e386958..ff4d26f45b91 100644 --- a/axmol/2d/Label.cpp +++ b/axmol/2d/Label.cpp @@ -615,7 +615,6 @@ void Label::reset() _currLabelEffect = LabelEffect::NORMAL; _contentDirty = false; _numberOfLines = 0; - _lengthOfString = 0; _utf32Text.clear(); _utf8Text.clear(); @@ -953,15 +952,19 @@ bool Label::setBMFontFilePath(std::string_view bmfontFilePath, std::string_view void Label::setString(std::string_view text) { - if (text.compare(_utf8Text)) + if (text != _utf8Text) { - _utf8Text = text; - _contentDirty = true; - std::u32string utf32String; - if (text_utils::UTF8ToUTF32(_utf8Text, utf32String)) + if (text_utils::UTF8ToUTF32(text, utf32String)) { + _utf8Text = text; _utf32Text = utf32String; + + _contentDirty = true; + } + else + { + AXLOGE("Label: setString() - Invalid utf8 text: {}", text); } } } @@ -1052,7 +1055,7 @@ void Label::updateLabelLetters() letterIndex = it->first; letterSprite = (LabelLetter*)it->second; - if (letterIndex >= _lengthOfString) + if (letterIndex >= getCharCount()) { Node::removeChild(letterSprite, true); it = _letters.erase(it); @@ -1148,7 +1151,6 @@ void Label::alignText() bool Label::tryTextPlacement(float fontSize) { - _lengthOfString = 0; _textDesiredHeight = 0.f; _linesWidth.clear(); @@ -1258,7 +1260,7 @@ bool Label::updateQuads() batchNode->getTextureAtlas()->removeAllQuads(); } - for (int ctr = 0; ctr < _lengthOfString; ++ctr) + for (int ctr = 0; ctr < getCharCount(); ++ctr) { auto& letterInfo = _lettersInfo[ctr]; if (letterInfo.valid) @@ -2112,7 +2114,7 @@ void Label::updateEffectUniforms(BatchCommand& batch, void Label::draw(Renderer* renderer, const Mat4& transform, uint32_t flags) { - if (_batchNodes.empty() || _lengthOfString <= 0) + if (_batchNodes.empty() || _utf32Text.empty()) { return; } @@ -2343,7 +2345,7 @@ Sprite* Label::getLetter(int letterIndex) updateContent(); } - if (_textSprite == nullptr && letterIndex < _lengthOfString) + if (_textSprite == nullptr && letterIndex < getCharCount()) { const auto& letterInfo = _lettersInfo[letterIndex]; if (!letterInfo.valid || letterInfo.atlasIndex < 0) @@ -2470,25 +2472,24 @@ void Label::computeStringNumLines() _numberOfLines = quantityOfLines; } -int Label::getStringNumLines() +int Label::getLineCount() const { if (_contentDirty) { - updateContent(); + const_cast(this)->updateContent(); } if (_currentLabelType == LabelType::STRING_TEXTURE) { - computeStringNumLines(); + const_cast(this)->computeStringNumLines(); } return _numberOfLines; } -int Label::getStringLength() +int Label::getCharCount() const { - _lengthOfString = static_cast(_utf32Text.length()); - return _lengthOfString; + return static_cast(_utf32Text.length()); } // RGBA protocol @@ -2947,7 +2948,7 @@ void Label::updateFontScale() bool Label::multilineTextWrap(bool breakOnChar, bool ignoreOverflow) { - int textLen = getStringLength(); + int textLen = getCharCount(); int lineIndex = 0; float nextTokenX = 0.f; float nextTokenY = 0.f; @@ -3165,7 +3166,7 @@ bool Label::isHorizontalClamp() { bool letterClamp = false; - for (int ctr = 0; ctr < _lengthOfString; ++ctr) + for (int ctr = 0; ctr < getCharCount(); ++ctr) { if (_lettersInfo[ctr].valid) { diff --git a/axmol/2d/Label.h b/axmol/2d/Label.h index a43d94c722a2..70d5271f2a9b 100644 --- a/axmol/2d/Label.h +++ b/axmol/2d/Label.h @@ -420,15 +420,26 @@ class AX_DLL Label : public Node, public LabelProtocol, public BlendProtocol /** Return the text the Label is currently displaying.*/ std::string_view getString() const override { return _utf8Text; } + [[internal]] std::u32string_view getUTF32String() const { return _utf32Text; } + /** * Return the number of lines of text. */ - int getStringNumLines(); + int getLineCount() const; + AX_DEPRECATED(3.0) int getStringNumLines() { return getLineCount(); } + + /** + * @brief Returns the number of UTF-32 characters. + * + * @return int UTF-32 character count + */ + int getCharCount() const; + AX_DEPRECATED(3.0) int getStringLength() { return getCharCount(); } /** - * Return length of string. + * Return whether the text is empty. */ - int getStringLength(); + bool isEmpty() const { return _utf32Text.empty(); } /** * Sets the text color of Label. @@ -673,8 +684,6 @@ class AX_DLL Label : public Node, public LabelProtocol, public BlendProtocol void setLineSpacing(float height); float getLineSpacing() const; - int getNumberOfLines() const { return _numberOfLines; } - /** Returns type of label @@ -881,7 +890,6 @@ class AX_DLL Label : public Node, public LabelProtocol, public BlendProtocol float _glowRadius; float _systemFontSize; - int _lengthOfString; int _uniformEffectColor; int _uniformEffectType; // 0: None, 1: Outline, 2: Shadow; Only used when outline is enabled. int _uniformTextColor; diff --git a/axmol/base/IMEDelegate.h b/axmol/base/IMEDelegate.h index da72cbcf4c59..3d8acaed2248 100644 --- a/axmol/base/IMEDelegate.h +++ b/axmol/base/IMEDelegate.h @@ -27,6 +27,7 @@ THE SOFTWARE. #pragma once #include +#include #include "axmol/math/Math.h" #include "axmol/base/EventKeyboard.h" @@ -108,7 +109,13 @@ class AX_DLL IMEDelegate @brief Called by IMEDispatcher when text input received from the IME. * @lua NA */ - virtual void insertText(const char* /*text*/, unsigned int /*len*/) {} + virtual void insertText(std::string_view /*text*/) {} + + /** + @brief Called by IMEDispatcher when the preedit text is updated. + * @lua NA + */ + virtual void updatePreeditText(std::string_view /*text*/, int /*caretPos*/) {} /** @brief Called by IMEDispatcher after the user clicks the backward key. diff --git a/axmol/base/IMEDispatcher.cpp b/axmol/base/IMEDispatcher.cpp index 1cf9d941c87f..ec7fd98d93ce 100644 --- a/axmol/base/IMEDispatcher.cpp +++ b/axmol/base/IMEDispatcher.cpp @@ -37,22 +37,22 @@ namespace ax IMEDelegate::IMEDelegate() { - IMEDispatcher::sharedDispatcher()->addDelegate(this); + IMEDispatcher::getInstance()->addDelegate(this); } IMEDelegate::~IMEDelegate() { - IMEDispatcher::sharedDispatcher()->removeDelegate(this); + IMEDispatcher::getInstance()->removeDelegate(this); } bool IMEDelegate::attachWithIME() { - return IMEDispatcher::sharedDispatcher()->attachDelegateWithIME(this); + return IMEDispatcher::getInstance()->attachDelegateWithIME(this); } bool IMEDelegate::detachWithIME() { - return IMEDispatcher::sharedDispatcher()->detachDelegateWithIME(this); + return IMEDispatcher::getInstance()->detachDelegateWithIME(this); } ////////////////////////////////////////////////////////////////////////// @@ -196,21 +196,20 @@ void IMEDispatcher::removeDelegate(IMEDelegate* delegate) } while (0); } +void IMEDispatcher::dispatchUpdatePreedit(std::string_view preeditText, int caret) +{ + if (_impl && _impl->_delegateWithIme && !preeditText.empty()) + _impl->_delegateWithIme->updatePreeditText(preeditText, caret); +} + ////////////////////////////////////////////////////////////////////////// // dispatch text message ////////////////////////////////////////////////////////////////////////// -void IMEDispatcher::dispatchInsertText(const char* text, unsigned int len) +void IMEDispatcher::dispatchInsertText(std::string_view text) { - do - { - AX_BREAK_IF(!_impl || !text || len <= 0); - - // there is no delegate attached to IME - AX_BREAK_IF(!_impl->_delegateWithIme); - - _impl->_delegateWithIme->insertText(text, len); - } while (0); + if (_impl && _impl->_delegateWithIme && !text.empty()) + _impl->_delegateWithIme->insertText(text); } void IMEDispatcher::dispatchDeleteBackward(unsigned int numChars) @@ -328,7 +327,7 @@ void IMEDispatcher::dispatchKeyboardDidHide(IMEKeyboardNotificationInfo& info) // static member function ////////////////////////////////////////////////////////////////////////// -IMEDispatcher* IMEDispatcher::sharedDispatcher() +IMEDispatcher* IMEDispatcher::getInstance() { static IMEDispatcher s_instance; return &s_instance; diff --git a/axmol/base/IMEDispatcher.h b/axmol/base/IMEDispatcher.h index 5c9bf948853a..e77c43791f36 100644 --- a/axmol/base/IMEDispatcher.h +++ b/axmol/base/IMEDispatcher.h @@ -50,13 +50,15 @@ class AX_DLL IMEDispatcher * @brief Returns the shared IMEDispatcher object for the system. * @lua NA */ - static IMEDispatcher* sharedDispatcher(); + static IMEDispatcher* getInstance(); + + void dispatchUpdatePreedit(std::string_view preeditText, int caret); /** * @brief Dispatches the input text from IME. * @lua NA */ - void dispatchInsertText(const char* text, unsigned int len); + void dispatchInsertText(std::string_view text); /** * @brief Dispatches the delete-backward operation. diff --git a/axmol/platform/android/jni/AxmolPlayerJni.cpp b/axmol/platform/android/jni/AxmolPlayerJni.cpp index f38d3ae952e5..1c08cfa0b584 100644 --- a/axmol/platform/android/jni/AxmolPlayerJni.cpp +++ b/axmol/platform/android/jni/AxmolPlayerJni.cpp @@ -256,18 +256,17 @@ JNIEXPORT void JNICALL Java_dev_axmol_lib_AxmolPlayer_nativeOnResume(JNIEnv*, jc JNIEXPORT void JNICALL Java_dev_axmol_lib_AxmolPlayer_nativeInsertText(JNIEnv* env, jclass, jstring text) { std::string strValue = ax::text_utils::getStringUTFCharsJNI(env, text); - ax::IMEDispatcher::sharedDispatcher()->dispatchInsertText(strValue.c_str(), - static_cast(strValue.size())); + ax::IMEDispatcher::getInstance()->dispatchInsertText(strValue); } JNIEXPORT void JNICALL Java_dev_axmol_lib_AxmolPlayer_nativeDeleteBackward(JNIEnv*, jclass, jint numChars) { - ax::IMEDispatcher::sharedDispatcher()->dispatchDeleteBackward(static_cast(numChars)); + ax::IMEDispatcher::getInstance()->dispatchDeleteBackward(static_cast(numChars)); } JNIEXPORT jstring JNICALL Java_dev_axmol_lib_AxmolPlayer_nativeGetContentText(JNIEnv* env, jclass) { - auto pszText = ax::IMEDispatcher::sharedDispatcher()->getContentText(); + auto pszText = ax::IMEDispatcher::getInstance()->getContentText(); return ax::text_utils::newStringUTFJNI(env, pszText); } } diff --git a/axmol/platform/desktop/RenderViewImpl.cpp b/axmol/platform/desktop/RenderViewImpl.cpp index e646ff426511..0ddd210f54a1 100644 --- a/axmol/platform/desktop/RenderViewImpl.cpp +++ b/axmol/platform/desktop/RenderViewImpl.cpp @@ -250,6 +250,21 @@ class GLFWEventHandler } } + static void onGLFWPreeditCallback(GLFWwindow* window, + int preedit_count, + unsigned int* preedit_string, + int block_count, + int* block_sizes, + int focused_block, + int caret) + { + if (_view) + { + _view->onGLFWPreeditCallback(window, preedit_count, preedit_string, block_count, block_sizes, focused_block, + caret); + } + } + private: static RenderViewImpl* _view; }; @@ -731,6 +746,7 @@ bool RenderViewImpl::initWithRect(std::string_view viewName, glfwSetWindowIconifyCallback(_mainWindow, GLFWEventHandler::onGLFWWindowIconifyCallback); glfwSetWindowFocusCallback(_mainWindow, GLFWEventHandler::onGLFWWindowFocusCallback); glfwSetWindowCloseCallback(_mainWindow, GLFWEventHandler::onGLFWWindowCloseCallback); + glfwSetPreeditCallback(_mainWindow, GLFWEventHandler::onGLFWPreeditCallback); #if AX_ENABLE_GL if (fallbackGL) @@ -1410,7 +1426,7 @@ void RenderViewImpl::onGLFWKeyCallback(GLFWwindow* /*window*/, int key, int /*sc switch (g_keyCodeMap[key]) { case EventKeyboard::KeyCode::KEY_BACKSPACE: - IMEDispatcher::sharedDispatcher()->dispatchDeleteBackward(1); + IMEDispatcher::getInstance()->dispatchDeleteBackward(1); break; case EventKeyboard::KeyCode::KEY_HOME: case EventKeyboard::KeyCode::KEY_KP_HOME: @@ -1420,10 +1436,10 @@ void RenderViewImpl::onGLFWKeyCallback(GLFWwindow* /*window*/, int key, int /*sc case EventKeyboard::KeyCode::KEY_LEFT_ARROW: case EventKeyboard::KeyCode::KEY_RIGHT_ARROW: case EventKeyboard::KeyCode::KEY_ESCAPE: - IMEDispatcher::sharedDispatcher()->dispatchControlKey(g_keyCodeMap[key]); + IMEDispatcher::getInstance()->dispatchControlKey(g_keyCodeMap[key]); break; case EventKeyboard::KeyCode::KEY_ENTER: - IMEDispatcher::sharedDispatcher()->dispatchInsertText("\n", 1u); + IMEDispatcher::getInstance()->dispatchInsertText("\n"sv); break; default: break; @@ -1433,25 +1449,59 @@ void RenderViewImpl::onGLFWKeyCallback(GLFWwindow* /*window*/, int key, int /*sc void RenderViewImpl::onGLFWCharCallback(GLFWwindow* /*window*/, unsigned int charCode) { - std::string utf8String; - text_utils::UTF32ToUTF8(std::u32string_view{(char32_t*)&charCode, (size_t)1}, utf8String); - static std::unordered_set controlUnicode = { - "\xEF\x9C\x80", // up - "\xEF\x9C\x81", // down - "\xEF\x9C\x82", // left - "\xEF\x9C\x83", // right - "\xEF\x9C\xA8", // delete - "\xEF\x9C\xA9", // home - "\xEF\x9C\xAB", // end - "\xEF\x9C\xAC", // pageup - "\xEF\x9C\xAD", // pagedown - "\xEF\x9C\xB9" // clear + // static std::unordered_set controlUnicode = { + // "\xEF\x9C\x80", // up + // "\xEF\x9C\x81", // down + // "\xEF\x9C\x82", // left + // "\xEF\x9C\x83", // right + // "\xEF\x9C\xA8", // delete + // "\xEF\x9C\xA9", // home + // "\xEF\x9C\xAB", // end + // "\xEF\x9C\xAC", // pageup + // "\xEF\x9C\xAD", // pagedown + // "\xEF\x9C\xB9" // clear + // }; + + static const std::unordered_set controlUnicode = { + U'\uF700', // up + U'\uF701', // down + U'\uF702', // left + U'\uF703', // right + U'\uF728', // delete + U'\uF729', // home + U'\uF72B', // end + U'\uF72C', // pageup + U'\uF72D', // pagedown + U'\uF739' // clear }; + // Check for send control key - if (controlUnicode.find(utf8String) == controlUnicode.end()) + + if (!controlUnicode.contains(static_cast(charCode))) { - IMEDispatcher::sharedDispatcher()->dispatchInsertText(utf8String.c_str(), - static_cast(utf8String.size())); + std::string utf8String; + char32_t codepoint = static_cast(charCode); + text_utils::UTF32ToUTF8(std::u32string_view{&codepoint, 1zu}, utf8String); + IMEDispatcher::getInstance()->dispatchInsertText(utf8String); + } +} + +void RenderViewImpl::onGLFWPreeditCallback(GLFWwindow* window, + int preedit_count, + unsigned int* preedit_string, // UTF-32 + int block_count, + int* block_sizes, + int focused_block, + int caret) +{ + if (preedit_count > 0) + { + std::string utf8String; + text_utils::UTF32ToUTF8( + std::u32string_view{std::bit_cast(preedit_string), static_cast(preedit_count)}, + utf8String); + + IMEDispatcher::getInstance()->dispatchUpdatePreedit(utf8String, caret); } } diff --git a/axmol/platform/desktop/RenderViewImpl.h b/axmol/platform/desktop/RenderViewImpl.h index 7174cec6eb76..96c3ee3fb295 100644 --- a/axmol/platform/desktop/RenderViewImpl.h +++ b/axmol/platform/desktop/RenderViewImpl.h @@ -185,6 +185,13 @@ class AX_DLL RenderViewImpl : public RenderView void onGLFWWindowIconifyCallback(GLFWwindow* window, int iconified); void onGLFWWindowFocusCallback(GLFWwindow* window, int focused); void onGLFWWindowCloseCallback(GLFWwindow* window); + void onGLFWPreeditCallback(GLFWwindow* window, + int preedit_count, + unsigned int* preedit_string, + int block_count, + int* block_sizes, + int focused_block, + int caret); protected: void updateScaledWindowSize(int w, int h, uint8_t updaetFlag); diff --git a/axmol/platform/ios/InputView-ios.mm b/axmol/platform/ios/InputView-ios.mm index 16071f24a833..31876b193f3e 100644 --- a/axmol/platform/ios/InputView-ios.mm +++ b/axmol/platform/ios/InputView-ios.mm @@ -98,7 +98,7 @@ - (void)deleteBackward [self.myMarkedText release]; self.myMarkedText = nil; } - ax::IMEDispatcher::sharedDispatcher()->dispatchDeleteBackward(static_cast(1)); + ax::IMEDispatcher::getInstance()->dispatchDeleteBackward(static_cast(1)); } - (void)insertText:(nonnull NSString*)text @@ -109,7 +109,7 @@ - (void)insertText:(nonnull NSString*)text self.myMarkedText = nil; } const char* pszText = [text cStringUsingEncoding:NSUTF8StringEncoding]; - ax::IMEDispatcher::sharedDispatcher()->dispatchInsertText(pszText, static_cast(strlen(pszText))); + ax::IMEDispatcher::getInstance()->dispatchInsertText(std::string_view{pszText, strlen(pszText)}); } - (NSWritingDirection)baseWritingDirectionForPosition:(nonnull UITextPosition*)position @@ -251,7 +251,7 @@ - (void)unmarkText return; } const char* pszText = [self.myMarkedText cStringUsingEncoding:NSUTF8StringEncoding]; - ax::IMEDispatcher::sharedDispatcher()->dispatchInsertText(pszText, static_cast(strlen(pszText))); + ax::IMEDispatcher::getInstance()->dispatchInsertText(std::string_view{pszText, strlen(pszText)}); [self.myMarkedText release]; self.myMarkedText = nil; } diff --git a/axmol/platform/ios/RenderHostView-ios.mm b/axmol/platform/ios/RenderHostView-ios.mm index 0cad17857d0a..390093dac5e1 100644 --- a/axmol/platform/ios/RenderHostView-ios.mm +++ b/axmol/platform/ios/RenderHostView-ios.mm @@ -669,7 +669,7 @@ - (void)onUIKeyboardNotification:(NSNotification*)notif notiInfo.end = convertKeyboardRectToViewport(end, viewSize); notiInfo.duration = aniDuration; - ax::IMEDispatcher* dispatcher = ax::IMEDispatcher::sharedDispatcher(); + ax::IMEDispatcher* dispatcher = ax::IMEDispatcher::getInstance(); if (UIKeyboardWillShowNotification == type) { dispatcher->dispatchKeyboardWillShow(notiInfo); diff --git a/axmol/platform/winrt/InputEvent.cpp b/axmol/platform/winrt/InputEvent.cpp index 3a6be1612c7b..8e10e331988e 100644 --- a/axmol/platform/winrt/InputEvent.cpp +++ b/axmol/platform/winrt/InputEvent.cpp @@ -88,8 +88,7 @@ void KeyboardEvent::execute() case AxmolKeyEvent::Text: { std::string utf8String = PlatformStringToString(m_text); - IMEDispatcher::sharedDispatcher()->dispatchInsertText(utf8String.c_str(), - static_cast(utf8String.size())); + IMEDispatcher::getInstance()->dispatchInsertText(utf8String); break; } @@ -97,10 +96,10 @@ void KeyboardEvent::execute() switch (m_type) { case AxmolKeyEvent::Back: - IMEDispatcher::sharedDispatcher()->dispatchDeleteBackward(1); + IMEDispatcher::getInstance()->dispatchDeleteBackward(1); break; case AxmolKeyEvent::Enter: - IMEDispatcher::sharedDispatcher()->dispatchInsertText("\n", 1); + IMEDispatcher::getInstance()->dispatchInsertText("\n"sv); break; default: break; diff --git a/axmol/platform/winrt/Keyboard-winrt.cpp b/axmol/platform/winrt/Keyboard-winrt.cpp index f40ce549a23c..7902adfb2743 100644 --- a/axmol/platform/winrt/Keyboard-winrt.cpp +++ b/axmol/platform/winrt/Keyboard-winrt.cpp @@ -287,7 +287,7 @@ void KeyBoardWinRT::OnWinRTKeyboardEvent(WinRTKeyboardEventType type, KeyEventAr dispatcher->dispatchEvent(&event); if (keyCode == EventKeyboard::KeyCode::KEY_ENTER) { - IMEDispatcher::sharedDispatcher()->dispatchInsertText("\n", 1); + IMEDispatcher::getInstance()->dispatchInsertText("\n"sv); } if (isKeyDown && !event.isStopped()) @@ -295,7 +295,7 @@ void KeyBoardWinRT::OnWinRTKeyboardEvent(WinRTKeyboardEventType type, KeyEventAr switch (keyCode) { case EventKeyboard::KeyCode::KEY_BACKSPACE: - IMEDispatcher::sharedDispatcher()->dispatchDeleteBackward(1); + IMEDispatcher::getInstance()->dispatchDeleteBackward(1); break; case EventKeyboard::KeyCode::KEY_HOME: case EventKeyboard::KeyCode::KEY_KP_HOME: @@ -305,7 +305,7 @@ void KeyBoardWinRT::OnWinRTKeyboardEvent(WinRTKeyboardEventType type, KeyEventAr case EventKeyboard::KeyCode::KEY_LEFT_ARROW: case EventKeyboard::KeyCode::KEY_RIGHT_ARROW: case EventKeyboard::KeyCode::KEY_ESCAPE: - IMEDispatcher::sharedDispatcher()->dispatchControlKey(keyCode); + IMEDispatcher::getInstance()->dispatchControlKey(keyCode); break; default: break; diff --git a/axmol/ui/InputField.cpp b/axmol/ui/InputField.cpp index 20de376df135..4f808222cecb 100644 --- a/axmol/ui/InputField.cpp +++ b/axmol/ui/InputField.cpp @@ -328,6 +328,8 @@ void InputField::onEnter() void InputField::onExit() { + detachWithIME(); + if (_kbdListener) { _eventDispatcher->removeEventListener(_kbdListener); @@ -512,7 +514,7 @@ void InputField::setCharLimit(uint32_t limit) } } -void InputField::insertText(const char* text, unsigned int len) +void InputField::insertText(std::string_view text) { if (_readOnly || !this->_enabled) return; @@ -521,7 +523,7 @@ void InputField::insertText(const char* text, unsigned int len) deleteSelection(false); // In multiline mode we allow newline characters; otherwise they signify commit and we strip them. - std::string insertStr(text, len); + std::string insertStr(text); if (!_multilineEnabled) { auto pos = insertStr.find('\n'); @@ -958,7 +960,7 @@ bool InputField::pasteFromClipboard() if (text.empty()) return false; - insertText(text.c_str(), text.size()); + insertText(text); return true; } diff --git a/axmol/ui/InputField.h b/axmol/ui/InputField.h index ee6bc36945db..0b9f05e9ac44 100644 --- a/axmol/ui/InputField.h +++ b/axmol/ui/InputField.h @@ -432,7 +432,7 @@ class AX_DLL InputField : public Widget, public IMEDelegate bool canDetachWithIME() override; // IMEDelegate interface - void insertText(const char* text, unsigned int len) override; + void insertText(std::string_view text) override; void deleteBackward(unsigned int numChars) override; std::string_view getContentText() const override; diff --git a/tests/unit-tests/Source/axmol/ui/HelperTests.cpp b/tests/unit-tests/Source/axmol/ui/HelperTests.cpp index 9d3081fdecc0..1358e76f7a99 100644 --- a/tests/unit-tests/Source/axmol/ui/HelperTests.cpp +++ b/tests/unit-tests/Source/axmol/ui/HelperTests.cpp @@ -87,16 +87,16 @@ TEST_SUITE("ui/Helper") CHECK(Helper::getSubStringOfUTF8String(source, 7, 0) == ""); CHECK(Helper::getSubStringOfUTF8String(source, 8, 0) == ""); CHECK(Helper::getSubStringOfUTF8String(source, 8, 1) == ""); - CHECK(Helper::getSubStringOfUTF8String(source, 0, 1) == "\xe8\xbf\99"); - CHECK(Helper::getSubStringOfUTF8String(source, 0, 4) == "\xe8\xbf\99\xe9\x87\8c\xe6\x98\xaf\xe4\xb8\ad"); + CHECK(Helper::getSubStringOfUTF8String(source, 0, 1) == "\xe8\xbf\x99"); + CHECK(Helper::getSubStringOfUTF8String(source, 0, 4) == "\xe8\xbf\x99\xe9\x87\x8c\xe6\x98\xaf\xe4\xb8\xad"); CHECK(Helper::getSubStringOfUTF8String(source, 0, 8) == - "\xe8\xbf\99\xe9\x87\8c\xe6\x98\xaf\xe4\xb8\ad\xe6\x96\87\xe6\xb5\x8b\xe8\xaf\95\xe4\xbe\8b"); + "\xe8\xbf\x99\xe9\x87\x8c\xe6\x98\xaf\xe4\xb8\xad\xe6\x96\x87\xe6\xb5\x8b\xe8\xaf\x95\xe4\xbe\x8b"); CHECK(Helper::getSubStringOfUTF8String(source, 0, 100) == - "\xe8\xbf\99\xe9\x87\8c\xe6\x98\xaf\xe4\xb8\ad\xe6\x96\87\xe6\xb5\x8b\xe8\xaf\95\xe4\xbe\8b"); + "\xe8\xbf\x99\xe9\x87\x8c\xe6\x98\xaf\xe4\xb8\xad\xe6\x96\x87\xe6\xb5\x8b\xe8\xaf\x95\xe4\xbe\x8b"); CHECK(Helper::getSubStringOfUTF8String(source, 2, 5) == - "\xe6\x98\xaf\xe4\xb8\ad\xe6\x96\87\xe6\xb5\x8b\xe8\xaf\95"); - CHECK(Helper::getSubStringOfUTF8String(source, 6, 2) == "\xe8\xaf\95\xe4\xbe\8b"); - CHECK(Helper::getSubStringOfUTF8String(source, 6, 100) == "\xe8\xaf\95\xe4\xbe\8b"); + "\xe6\x98\xaf\xe4\xb8\xad\xe6\x96\x87\xe6\xb5\x8b\xe8\xaf\x95"); + CHECK(Helper::getSubStringOfUTF8String(source, 6, 2) == "\xe8\xaf\x95\xe4\xbe\x8b"); + CHECK(Helper::getSubStringOfUTF8String(source, 6, 100) == "\xe8\xaf\x95\xe4\xbe\x8b"); // Error: These cases cause "out of range" error CHECK(Helper::getSubStringOfUTF8String(source, 9, 0) == ""); From 72c4952afb773a1f92cdb5cf3e765f31152eabe9 Mon Sep 17 00:00:00 2001 From: halx99 Date: Fri, 22 May 2026 11:32:19 +0800 Subject: [PATCH 35/52] update luabindings --- .../lua-bindings/auto/axlua_base_auto.cpp | 76 +++++++++++++++---- 1 file changed, 62 insertions(+), 14 deletions(-) diff --git a/extensions/scripting/lua-bindings/auto/axlua_base_auto.cpp b/extensions/scripting/lua-bindings/auto/axlua_base_auto.cpp index 59aac2aab9e9..4786943a74ed 100644 --- a/extensions/scripting/lua-bindings/auto/axlua_base_auto.cpp +++ b/extensions/scripting/lua-bindings/auto/axlua_base_auto.cpp @@ -55467,7 +55467,7 @@ int lua_ax_base_Label_getString(lua_State* tolua_S) return 0; } -int lua_ax_base_Label_getStringNumLines(lua_State* tolua_S) +int lua_ax_base_Label_getLineCount(lua_State* tolua_S) { int argc = 0; ax::Label* obj = nullptr; @@ -55487,7 +55487,7 @@ int lua_ax_base_Label_getStringNumLines(lua_State* tolua_S) #if _AX_DEBUG >= 1 if (!obj) { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_base_Label_getStringNumLines'", nullptr); + tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_base_Label_getLineCount'", nullptr); return 0; } #endif @@ -55497,24 +55497,24 @@ int lua_ax_base_Label_getStringNumLines(lua_State* tolua_S) { if(!ok) { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_base_Label_getStringNumLines'", nullptr); + tolua_error(tolua_S,"invalid arguments in function 'lua_ax_base_Label_getLineCount'", nullptr); return 0; } - auto&& ret = obj->getStringNumLines(); + auto&& ret = obj->getLineCount(); tolua_pushnumber(tolua_S,(lua_Number)ret); return 1; } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ax.Label:getStringNumLines",argc, 0); + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ax.Label:getLineCount",argc, 0); return 0; #if _AX_DEBUG >= 1 tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_base_Label_getStringNumLines'.",&tolua_err); + tolua_error(tolua_S,"#ferror in function 'lua_ax_base_Label_getLineCount'.",&tolua_err); #endif return 0; } -int lua_ax_base_Label_getStringLength(lua_State* tolua_S) +int lua_ax_base_Label_getCharCount(lua_State* tolua_S) { int argc = 0; ax::Label* obj = nullptr; @@ -55534,7 +55534,7 @@ int lua_ax_base_Label_getStringLength(lua_State* tolua_S) #if _AX_DEBUG >= 1 if (!obj) { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_base_Label_getStringLength'", nullptr); + tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_base_Label_getCharCount'", nullptr); return 0; } #endif @@ -55544,19 +55544,66 @@ int lua_ax_base_Label_getStringLength(lua_State* tolua_S) { if(!ok) { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_base_Label_getStringLength'", nullptr); + tolua_error(tolua_S,"invalid arguments in function 'lua_ax_base_Label_getCharCount'", nullptr); return 0; } - auto&& ret = obj->getStringLength(); + auto&& ret = obj->getCharCount(); tolua_pushnumber(tolua_S,(lua_Number)ret); return 1; } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ax.Label:getStringLength",argc, 0); + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ax.Label:getCharCount",argc, 0); return 0; #if _AX_DEBUG >= 1 tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_base_Label_getStringLength'.",&tolua_err); + tolua_error(tolua_S,"#ferror in function 'lua_ax_base_Label_getCharCount'.",&tolua_err); +#endif + + return 0; +} +int lua_ax_base_Label_isEmpty(lua_State* tolua_S) +{ + int argc = 0; + ax::Label* obj = nullptr; + bool ok = true; + +#if _AX_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if _AX_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"ax.Label",0,&tolua_err)) goto tolua_lerror; +#endif + + obj = (ax::Label*)tolua_tousertype(tolua_S,1,0); + +#if _AX_DEBUG >= 1 + if (!obj) + { + tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_base_Label_isEmpty'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 0) + { + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_ax_base_Label_isEmpty'", nullptr); + return 0; + } + auto&& ret = obj->isEmpty(); + tolua_pushboolean(tolua_S,(bool)ret); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ax.Label:isEmpty",argc, 0); + return 0; + +#if _AX_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_ax_base_Label_isEmpty'.",&tolua_err); #endif return 0; @@ -58982,8 +59029,9 @@ int lua_register_ax_base_Label(lua_State* tolua_S) tolua_function(tolua_S,"requestSystemFontRefresh",lua_ax_base_Label_requestSystemFontRefresh); tolua_function(tolua_S,"setString",lua_ax_base_Label_setString); tolua_function(tolua_S,"getString",lua_ax_base_Label_getString); - tolua_function(tolua_S,"getStringNumLines",lua_ax_base_Label_getStringNumLines); - tolua_function(tolua_S,"getStringLength",lua_ax_base_Label_getStringLength); + tolua_function(tolua_S,"getLineCount",lua_ax_base_Label_getLineCount); + tolua_function(tolua_S,"getCharCount",lua_ax_base_Label_getCharCount); + tolua_function(tolua_S,"isEmpty",lua_ax_base_Label_isEmpty); tolua_function(tolua_S,"setTextColor",lua_ax_base_Label_setTextColor); tolua_function(tolua_S,"getTextColor",lua_ax_base_Label_getTextColor); tolua_function(tolua_S,"enableShadow",lua_ax_base_Label_enableShadow); From 65f5dfbd062580fe24023828de6b16ed47e422d3 Mon Sep 17 00:00:00 2001 From: halx99 Date: Fri, 22 May 2026 14:02:16 +0800 Subject: [PATCH 36/52] up --- axmol/CMakeLists.txt | 5 +++++ axmol/platform/desktop/RenderViewImpl.cpp | 5 +++-- axmol/ui/CMakeLists.txt | 16 ++++++++-------- axmol/ui/EditBox/Mac/EditBoxMac.h | 5 +++-- axmol/ui/EditBox/Mac/EditBoxMac.mm | 11 ++++++----- axmol/ui/EditBox/Mac/MultilineTextField.h | 3 ++- axmol/ui/EditBox/Mac/MultilineTextField.m | 7 ++++--- axmol/ui/EditBox/Mac/PasswordTextField.h | 3 ++- axmol/ui/EditBox/Mac/PasswordTextField.m | 9 +++++---- axmol/ui/EditBox/Mac/SingleLineTextField.h | 3 ++- axmol/ui/EditBox/Mac/SingleLineTextField.m | 5 +++-- axmol/ui/EditBox/Mac/TextFieldFormatter.h | 3 ++- axmol/ui/EditBox/Mac/TextFieldFormatter.m | 3 ++- axmol/ui/EditBox/Mac/TextInput.h | 3 ++- axmol/ui/EditBox/iOS/EditBoxIOS.h | 3 ++- axmol/ui/EditBox/iOS/EditBoxIOS.mm | 10 ++++------ axmol/ui/EditBox/iOS/MultilineTextField.h | 7 ++++--- axmol/ui/EditBox/iOS/MultilineTextField.mm | 3 ++- axmol/ui/EditBox/iOS/SingleLineTextField.h | 7 ++++--- axmol/ui/EditBox/iOS/SingleLineTextField.mm | 3 ++- .../iOS/{TextView+UITextInput.h => TextField.h} | 8 ++------ .../{TextField+UITextInput.mm => TextField.mm} | 10 +++------- axmol/ui/EditBox/iOS/TextInput.h | 3 ++- .../iOS/{TextField+UITextInput.h => TextView.h} | 7 +------ .../iOS/{TextView+UITextInput.mm => TextView.mm} | 6 ++---- .../src/ImGui/backends/imgui_impl_axmol_sw.cpp | 6 +++--- 26 files changed, 80 insertions(+), 74 deletions(-) rename axmol/ui/EditBox/iOS/{TextView+UITextInput.h => TextField.h} (84%) rename axmol/ui/EditBox/iOS/{TextField+UITextInput.mm => TextField.mm} (95%) rename axmol/ui/EditBox/iOS/{TextField+UITextInput.h => TextView.h} (84%) rename axmol/ui/EditBox/iOS/{TextView+UITextInput.mm => TextView.mm} (96%) diff --git a/axmol/CMakeLists.txt b/axmol/CMakeLists.txt index 5251763a09ad..878d2e4d835a 100644 --- a/axmol/CMakeLists.txt +++ b/axmol/CMakeLists.txt @@ -388,6 +388,11 @@ elseif(AX_ENABLE_MFMEDIA AND NOT WINRT) endif() endif() +if(IOS) + # Add Obj-C source files for iOS platform to avoid hack categories not working without -ObjC flag + target_link_options(${_AX_CORE_LIB} INTERFACE -ObjC) +endif() + ax_find_shaders(${_AX_ROOT}/axmol/renderer/shaders _builtin_shaders) set(_AX_BUILTIN_SHADERS ${_builtin_shaders} CACHE STATIC "" FORCE) diff --git a/axmol/platform/desktop/RenderViewImpl.cpp b/axmol/platform/desktop/RenderViewImpl.cpp index 0ddd210f54a1..3c37326ea35a 100644 --- a/axmol/platform/desktop/RenderViewImpl.cpp +++ b/axmol/platform/desktop/RenderViewImpl.cpp @@ -735,6 +735,8 @@ bool RenderViewImpl::initWithRect(std::string_view viewName, }); } // clang-format on +#else + glfwSetPreeditCallback(_mainWindow, GLFWEventHandler::onGLFWPreeditCallback); #endif glfwSetScrollCallback(_mainWindow, GLFWEventHandler::onGLFWMouseScrollCallback); @@ -746,8 +748,7 @@ bool RenderViewImpl::initWithRect(std::string_view viewName, glfwSetWindowIconifyCallback(_mainWindow, GLFWEventHandler::onGLFWWindowIconifyCallback); glfwSetWindowFocusCallback(_mainWindow, GLFWEventHandler::onGLFWWindowFocusCallback); glfwSetWindowCloseCallback(_mainWindow, GLFWEventHandler::onGLFWWindowCloseCallback); - glfwSetPreeditCallback(_mainWindow, GLFWEventHandler::onGLFWPreeditCallback); - + #if AX_ENABLE_GL if (fallbackGL) { diff --git a/axmol/ui/CMakeLists.txt b/axmol/ui/CMakeLists.txt index c211c41aa3d5..fd5f3614833c 100644 --- a/axmol/ui/CMakeLists.txt +++ b/axmol/ui/CMakeLists.txt @@ -45,8 +45,8 @@ elseif(APPLE) ui/EditBox/iOS/EditBoxIOS.h ui/EditBox/iOS/MultilineTextField.h ui/EditBox/iOS/TextInput.h - ui/EditBox/iOS/UITextView+TextInput.h - ui/EditBox/iOS/TextField+TextInput.h + ui/EditBox/iOS/TextView.h + ui/EditBox/iOS/TextField.h ui/EditBox/iOS/SingleLineTextField.h ) set(_AX_UI_SPECIFIC_SRC @@ -54,8 +54,8 @@ elseif(APPLE) ui/EditBox/iOS/EditBoxIOS.mm ui/EditBox/iOS/MultilineTextField.mm ui/EditBox/iOS/SingleLineTextField.mm - ui/EditBox/iOS/TextField+UITextInput.mm - ui/EditBox/iOS/TextView+UITextInput.mm + ui/EditBox/iOS/TextField.mm + ui/EditBox/iOS/TextView.mm ) else() set(_AX_UI_SPECIFIC_HEADER @@ -65,8 +65,8 @@ elseif(APPLE) ui/EditBox/iOS/EditBoxIOS.h ui/EditBox/iOS/MultilineTextField.h ui/EditBox/iOS/TextInput.h - ui/EditBox/iOS/UITextView+TextInput.h - ui/EditBox/iOS/TextField+TextInput.h + ui/EditBox/iOS/TextView.h + ui/EditBox/iOS/TextField.h ui/EditBox/iOS/SingleLineTextField.h ) set(_AX_UI_SPECIFIC_SRC @@ -76,8 +76,8 @@ elseif(APPLE) ui/EditBox/iOS/EditBoxIOS.mm ui/EditBox/iOS/MultilineTextField.mm ui/EditBox/iOS/SingleLineTextField.mm - ui/EditBox/iOS/TextField+UITextInput.mm - ui/EditBox/iOS/TextView+UITextInput.mm + ui/EditBox/iOS/TextField.mm + ui/EditBox/iOS/TextView.mm ) endif() endif() diff --git a/axmol/ui/EditBox/Mac/EditBoxMac.h b/axmol/ui/EditBox/Mac/EditBoxMac.h index 8df79d4ab3c9..070b481ebae3 100644 --- a/axmol/ui/EditBox/Mac/EditBoxMac.h +++ b/axmol/ui/EditBox/Mac/EditBoxMac.h @@ -2,6 +2,7 @@ Copyright (c) 2010-2012 cocos2d-x.org Copyright (c) 2013-2016 zilongshanren Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. + Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md). https://axmol.dev/ @@ -36,11 +37,11 @@ @interface UIEditBoxImplMac : NSObject { BOOL _editState; - NSView* _textInput; + NSView* _textInput; void* _editBox; } -@property(nonatomic, retain) NSView* textInput; +@property(nonatomic, retain) NSView* textInput; @property(nonatomic, readonly) NSWindow* window; @property(nonatomic, readonly, getter=isEditState) BOOL editState; diff --git a/axmol/ui/EditBox/Mac/EditBoxMac.mm b/axmol/ui/EditBox/Mac/EditBoxMac.mm index e50bf6e9a70f..7ed2ef35e941 100644 --- a/axmol/ui/EditBox/Mac/EditBoxMac.mm +++ b/axmol/ui/EditBox/Mac/EditBoxMac.mm @@ -2,6 +2,7 @@ Copyright (c) 2010-2012 cocos2d-x.org Copyright (c) 2013-2016 zilongshanren Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. + Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md). https://axmol.dev/ @@ -56,31 +57,31 @@ - (instancetype)initWithFrame:(NSRect)frameRect editBox:(void*)editBox - (void)createSingleLineTextField { - CCUISingleLineTextField* textField = [[[CCUISingleLineTextField alloc] initWithFrame:self.frameRect] autorelease]; + AxmolSingleLineTextField* textField = [[[AxmolSingleLineTextField alloc] initWithFrame:self.frameRect] autorelease]; self.textInput = textField; } - (void)createMultiLineTextField { - CCUIMultilineTextField* textView = [[[CCUIMultilineTextField alloc] initWithFrame:self.frameRect] autorelease]; + AxmolMultilineTextField* textView = [[[AxmolMultilineTextField alloc] initWithFrame:self.frameRect] autorelease]; [textView setVerticallyResizable:NO]; self.textInput = textView; } - (void)createPasswordTextField { - CCUIPasswordTextField* textField = [[[CCUIPasswordTextField alloc] initWithFrame:self.frameRect] autorelease]; + AxmolPasswordTextField* textField = [[[AxmolPasswordTextField alloc] initWithFrame:self.frameRect] autorelease]; self.textInput = textField; } -- (void)setTextInput:(NSView*)textInput +- (void)setTextInput:(NSView*)textInput { if (_textInput == textInput) return; - NSView* oldInput = _textInput; + NSView* oldInput = _textInput; _textInput = textInput; if (_textInput != nil) { diff --git a/axmol/ui/EditBox/Mac/MultilineTextField.h b/axmol/ui/EditBox/Mac/MultilineTextField.h index 9249d2336632..1e81856bf699 100644 --- a/axmol/ui/EditBox/Mac/MultilineTextField.h +++ b/axmol/ui/EditBox/Mac/MultilineTextField.h @@ -2,6 +2,7 @@ Copyright (c) 2010-2012 cocos2d-x.org Copyright (c) 2013-2016 zilongshanren Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. + Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md). https://axmol.dev/ @@ -28,7 +29,7 @@ #import #include "axmol/ui/EditBox/Mac/TextInput.h" -@interface CCUIMultilineTextField : NSTextView { +@interface AxmolMultilineTextField : NSTextView { NSString* _placeHolder; } diff --git a/axmol/ui/EditBox/Mac/MultilineTextField.m b/axmol/ui/EditBox/Mac/MultilineTextField.m index b4ad51add72f..f326abcc9987 100644 --- a/axmol/ui/EditBox/Mac/MultilineTextField.m +++ b/axmol/ui/EditBox/Mac/MultilineTextField.m @@ -1,6 +1,7 @@ /**************************************************************************** Copyright (c) 2010-2012 cocos2d-x.org Copyright (c) 2013-2016 zilongshanren + Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md). https://axmol.dev/ @@ -25,11 +26,11 @@ of this software and associated documentation files (the "Software"), to deal #import "axmol/ui/EditBox/Mac/MultilineTextField.h" -@interface CCUIMultilineTextField() +@interface AxmolMultilineTextField() @property(nonatomic, copy)NSString* placeHolder; @end -@implementation CCUIMultilineTextField +@implementation AxmolMultilineTextField { } @@ -73,7 +74,7 @@ -(NSColor*)axui_placeholderColor } -#pragma mark - AXUITextInput +#pragma mark - AxmolTextInput - (NSString *)axui_text { return self.string; diff --git a/axmol/ui/EditBox/Mac/PasswordTextField.h b/axmol/ui/EditBox/Mac/PasswordTextField.h index 3e92ee64272f..1acc5c730098 100644 --- a/axmol/ui/EditBox/Mac/PasswordTextField.h +++ b/axmol/ui/EditBox/Mac/PasswordTextField.h @@ -2,6 +2,7 @@ Copyright (c) 2010-2012 cocos2d-x.org Copyright (c) 2013-2016 zilongshanren Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. + Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md). https://axmol.dev/ @@ -28,7 +29,7 @@ #import #include "axmol/ui/EditBox/Mac/TextInput.h" -@interface CCUIPasswordTextField : NSSecureTextField { +@interface AxmolPasswordTextField : NSSecureTextField { } @end diff --git a/axmol/ui/EditBox/Mac/PasswordTextField.m b/axmol/ui/EditBox/Mac/PasswordTextField.m index 4e4f8d30b568..01bcc648e037 100644 --- a/axmol/ui/EditBox/Mac/PasswordTextField.m +++ b/axmol/ui/EditBox/Mac/PasswordTextField.m @@ -1,6 +1,7 @@ /**************************************************************************** Copyright (c) 2010-2012 cocos2d-x.org Copyright (c) 2013-2016 zilongshanren + Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md). https://axmol.dev/ @@ -98,14 +99,14 @@ - (void)editWithFrame:(NSRect)aRect @end -@interface CCUIPasswordTextField() +@interface AxmolPasswordTextField() { } @end -@implementation CCUIPasswordTextField +@implementation AxmolPasswordTextField -(id) initWithFrame:(NSRect)frameRect { @@ -159,7 +160,7 @@ -(void)axui_setPlaceholderColor:(NSColor *)color //TODO; } -#pragma mark - AXUITextInput +#pragma mark - AxmolTextInput - (NSString *)axui_text { return self.stringValue; @@ -208,7 +209,7 @@ - (void)axui_setDelegate:(id)delegate - (void)axui_setMaxLength:(int)length { - id formater = [[[CCUITextFieldFormatter alloc]init] autorelease]; + id formater = [[[AxmolTextFieldFormatter alloc]init] autorelease]; [formater setMaximumLength:length]; [self setFormatter:formater]; } diff --git a/axmol/ui/EditBox/Mac/SingleLineTextField.h b/axmol/ui/EditBox/Mac/SingleLineTextField.h index 67e3ea69f678..e618b62ef9c7 100644 --- a/axmol/ui/EditBox/Mac/SingleLineTextField.h +++ b/axmol/ui/EditBox/Mac/SingleLineTextField.h @@ -2,6 +2,7 @@ Copyright (c) 2010-2012 cocos2d-x.org Copyright (c) 2013-2016 zilongshanren Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. + Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md). https://axmol.dev/ @@ -28,7 +29,7 @@ #import #include "axmol/ui/EditBox/Mac/TextInput.h" -@interface CCUISingleLineTextField : NSTextField { +@interface AxmolSingleLineTextField : NSTextField { } @end diff --git a/axmol/ui/EditBox/Mac/SingleLineTextField.m b/axmol/ui/EditBox/Mac/SingleLineTextField.m index 25b6a8a9be5d..b1eae3d30de4 100644 --- a/axmol/ui/EditBox/Mac/SingleLineTextField.m +++ b/axmol/ui/EditBox/Mac/SingleLineTextField.m @@ -1,6 +1,7 @@ /**************************************************************************** Copyright (c) 2010-2012 cocos2d-x.org Copyright (c) 2013-2016 zilongshanren + Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md). https://axmol.dev/ @@ -99,7 +100,7 @@ - (void)editWithFrame:(NSRect)aRect @end -@implementation CCUISingleLineTextField +@implementation AxmolSingleLineTextField { } @@ -198,7 +199,7 @@ - (void)axui_setDelegate:(id)delegate - (void)axui_setMaxLength:(int)length { - id formater = [[[CCUITextFieldFormatter alloc]init] autorelease]; + id formater = [[[AxmolTextFieldFormatter alloc]init] autorelease]; [formater setMaximumLength:length]; [self setFormatter:formater]; } diff --git a/axmol/ui/EditBox/Mac/TextFieldFormatter.h b/axmol/ui/EditBox/Mac/TextFieldFormatter.h index c120bd9ef97e..b9bccec7f65d 100644 --- a/axmol/ui/EditBox/Mac/TextFieldFormatter.h +++ b/axmol/ui/EditBox/Mac/TextFieldFormatter.h @@ -2,6 +2,7 @@ Copyright (c) 2010-2012 cocos2d-x.org Copyright (c) 2013-2016 zilongshanren Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. + Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md). https://axmol.dev/ @@ -27,7 +28,7 @@ #import -@interface CCUITextFieldFormatter : NSFormatter { +@interface AxmolTextFieldFormatter : NSFormatter { int _maximumLength; } diff --git a/axmol/ui/EditBox/Mac/TextFieldFormatter.m b/axmol/ui/EditBox/Mac/TextFieldFormatter.m index 96849e48fe35..5fff03d44090 100644 --- a/axmol/ui/EditBox/Mac/TextFieldFormatter.m +++ b/axmol/ui/EditBox/Mac/TextFieldFormatter.m @@ -1,6 +1,7 @@ /**************************************************************************** Copyright (c) 2010-2012 cocos2d-x.org Copyright (c) 2013-2016 zilongshanren + Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md). https://axmol.dev/ @@ -25,7 +26,7 @@ of this software and associated documentation files (the "Software"), to deal #import "axmol/ui/EditBox/Mac/TextFieldFormatter.h" -@implementation CCUITextFieldFormatter +@implementation AxmolTextFieldFormatter { } diff --git a/axmol/ui/EditBox/Mac/TextInput.h b/axmol/ui/EditBox/Mac/TextInput.h index a5c1ae4190c8..0c2fa21cb844 100644 --- a/axmol/ui/EditBox/Mac/TextInput.h +++ b/axmol/ui/EditBox/Mac/TextInput.h @@ -2,6 +2,7 @@ Copyright (c) 2010-2012 cocos2d-x.org Copyright (c) 2013-2016 zilongshanren Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. + Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md). https://axmol.dev/ @@ -29,7 +30,7 @@ /** This protocol provides a common interface for consolidating text input method calls */ -@protocol AXUITextInput +@protocol AxmolTextInput @property(nonatomic, retain, setter=axui_setText:) NSString* axui_text; @property(nonatomic, retain, setter=axui_setTextColor:) NSColor* axui_textColor; diff --git a/axmol/ui/EditBox/iOS/EditBoxIOS.h b/axmol/ui/EditBox/iOS/EditBoxIOS.h index 4fefed6a9dec..994be0c4a644 100644 --- a/axmol/ui/EditBox/iOS/EditBoxIOS.h +++ b/axmol/ui/EditBox/iOS/EditBoxIOS.h @@ -4,6 +4,7 @@ Copyright (c) 2013-2015 zilongshanren Copyright (c) 2015 Mazyad Alabduljaleel Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. + Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md). https://axmol.dev/ @@ -33,7 +34,7 @@ @interface UIEditBoxImplIOS_objc : NSObject -@property(nonatomic, retain) UIView* textInput; +@property(nonatomic, retain) UIView* textInput; @property(nonatomic, assign) void* editBox; @property(nonatomic, assign) NSString* text; @property(nonatomic, assign) CGRect frameRect; diff --git a/axmol/ui/EditBox/iOS/EditBoxIOS.mm b/axmol/ui/EditBox/iOS/EditBoxIOS.mm index 92adaa2ad2a3..0fb0f886bcc4 100644 --- a/axmol/ui/EditBox/iOS/EditBoxIOS.mm +++ b/axmol/ui/EditBox/iOS/EditBoxIOS.mm @@ -4,6 +4,7 @@ Copyright (c) 2013-2015 zilongshanren Copyright (c) 2015 Mazyad Alabduljaleel Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. + Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md). https://axmol.dev/ @@ -42,9 +43,6 @@ @implementation UIEditBoxImplIOS_objc + (void)initialize { [super initialize]; - - LoadUITextViewAXUITextInputCategory(); - LoadUITextFieldAXUITextInputCategory(); } #pragma mark - Init & Dealloc @@ -77,7 +75,7 @@ - (void)dealloc #pragma mark - Properties -- (void)setTextInput:(UIView*)textInput +- (void)setTextInput:(UIView*)textInput { if (_textInput == textInput) { @@ -112,7 +110,7 @@ - (void)setTextInput:(UIView*)textInput - (void)createSingleLineTextField { - CCUISingleLineTextField* textField = [[[CCUISingleLineTextField alloc] initWithFrame:self.frameRect] autorelease]; + AxmolSingleLineTextField* textField = [[[AxmolSingleLineTextField alloc] initWithFrame:self.frameRect] autorelease]; textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; textField.borderStyle = UITextBorderStyleNone; @@ -123,7 +121,7 @@ - (void)createSingleLineTextField - (void)createMultiLineTextField { - CCUIMultilineTextField* textView = [[[CCUIMultilineTextField alloc] initWithFrame:self.frameRect] autorelease]; + AxmolMultilineTextField* textView = [[[AxmolMultilineTextField alloc] initWithFrame:self.frameRect] autorelease]; self.textInput = textView; } diff --git a/axmol/ui/EditBox/iOS/MultilineTextField.h b/axmol/ui/EditBox/iOS/MultilineTextField.h index e85bf2b30dc4..7683c7c613ad 100644 --- a/axmol/ui/EditBox/iOS/MultilineTextField.h +++ b/axmol/ui/EditBox/iOS/MultilineTextField.h @@ -3,6 +3,7 @@ Copyright (c) 2012 James Chen Copyright (c) 2015 Mazyad Alabduljaleel Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. + Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md). https://axmol.dev/ @@ -27,11 +28,11 @@ #pragma once #import -#import "axmol/ui/EditBox/iOS/TextView+TextInput.h" +#import "axmol/ui/EditBox/iOS/TextView.h" -#pragma mark - UIMultilineTextField implementation +#pragma mark - AxmolMultilineTextField implementation -@interface CCUIMultilineTextField : UITextView +@interface AxmolMultilineTextField : UITextView @property(nonatomic, assign) NSString* placeholder; @property(nonatomic, retain) UILabel* placeHolderLabel; diff --git a/axmol/ui/EditBox/iOS/MultilineTextField.mm b/axmol/ui/EditBox/iOS/MultilineTextField.mm index 9a80f7136b19..6eeb9fd977e8 100644 --- a/axmol/ui/EditBox/iOS/MultilineTextField.mm +++ b/axmol/ui/EditBox/iOS/MultilineTextField.mm @@ -3,6 +3,7 @@ Copyright (c) 2012 James Chen Copyright (c) 2015 Mazyad Alabduljaleel Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. + Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md). https://axmol.dev/ @@ -34,7 +35,7 @@ of this software and associated documentation files (the "Software"), to deal */ CGFloat const UI_PLACEHOLDER_TEXT_CHANGED_ANIMATION_DURATION = 0.25; -@implementation CCUIMultilineTextField +@implementation AxmolMultilineTextField #pragma mark - Init & Dealloc diff --git a/axmol/ui/EditBox/iOS/SingleLineTextField.h b/axmol/ui/EditBox/iOS/SingleLineTextField.h index 48f218ec48f5..346d0c4dc4a8 100644 --- a/axmol/ui/EditBox/iOS/SingleLineTextField.h +++ b/axmol/ui/EditBox/iOS/SingleLineTextField.h @@ -3,6 +3,7 @@ Copyright (c) 2012 James Chen Copyright (c) 2015 Mazyad Alabduljaleel Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. + Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md). https://axmol.dev/ @@ -27,11 +28,11 @@ #pragma once #import -#import "axmol/ui/EditBox/iOS/TextField+TextInput.h" +#import "axmol/ui/EditBox/iOS/TextField.h" -#pragma mark - UISingleLineTextField implementation +#pragma mark - AxmolSingleLineTextField implementation -@interface CCUISingleLineTextField : UITextField +@interface AxmolSingleLineTextField : UITextField @property(nonatomic, retain) UIColor* placeholderTextColor; @property(nonatomic, retain) UIFont* placeholderFont; diff --git a/axmol/ui/EditBox/iOS/SingleLineTextField.mm b/axmol/ui/EditBox/iOS/SingleLineTextField.mm index eeabe009b340..a78cb57eaad8 100644 --- a/axmol/ui/EditBox/iOS/SingleLineTextField.mm +++ b/axmol/ui/EditBox/iOS/SingleLineTextField.mm @@ -3,6 +3,7 @@ Copyright (c) 2012 James Chen Copyright (c) 2015 Mazyad Alabduljaleel Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. + Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md). https://axmol.dev/ @@ -34,7 +35,7 @@ of this software and associated documentation files (the "Software"), to deal * http://stackoverflow.com/questions/18244790/changing-uitextfield-placeholder-font */ -@implementation CCUISingleLineTextField +@implementation AxmolSingleLineTextField #pragma mark - Init & Dealloc diff --git a/axmol/ui/EditBox/iOS/TextView+UITextInput.h b/axmol/ui/EditBox/iOS/TextField.h similarity index 84% rename from axmol/ui/EditBox/iOS/TextView+UITextInput.h rename to axmol/ui/EditBox/iOS/TextField.h index 1cc401bfdba9..ad11e5f9cb57 100644 --- a/axmol/ui/EditBox/iOS/TextView+UITextInput.h +++ b/axmol/ui/EditBox/iOS/TextField.h @@ -1,6 +1,7 @@ /**************************************************************************** Copyright (c) 2015 Mazyad Alabduljaleel Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. + Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md). https://axmol.dev/ @@ -27,10 +28,5 @@ #import #import "axmol/ui/EditBox/iOS/TextInput.h" -@interface UITextView (AXUITextInput) +@interface UITextField (AxmolTextInput) @end - -/** Trick to load category objects without using -ObjC flag - * http://stackoverflow.com/questions/2567498/objective-c-categories-in-static-library - */ -extern void LoadUITextViewAXUITextInputCategory(); diff --git a/axmol/ui/EditBox/iOS/TextField+UITextInput.mm b/axmol/ui/EditBox/iOS/TextField.mm similarity index 95% rename from axmol/ui/EditBox/iOS/TextField+UITextInput.mm rename to axmol/ui/EditBox/iOS/TextField.mm index 258e280e75a9..029eda8a1874 100644 --- a/axmol/ui/EditBox/iOS/TextField+UITextInput.mm +++ b/axmol/ui/EditBox/iOS/TextField.mm @@ -1,6 +1,7 @@ /**************************************************************************** Copyright (c) 2015 Mazyad Alabduljaleel Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. + Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md). https://axmol.dev/ @@ -23,9 +24,9 @@ of this software and associated documentation files (the "Software"), to deal THE SOFTWARE. ****************************************************************************/ -#import "axmol/ui/EditBox/iOS/TextField+TextInput.h" +#import "axmol/ui/EditBox/iOS/TextField.h" -@implementation UITextField (AXUITextInput) +@implementation UITextField (AxmolTextInput) - (NSString*)axui_text { @@ -131,8 +132,3 @@ - (void)axui_setDelegate:(id)delegate } @end - -void LoadUITextFieldAXUITextInputCategory() -{ - // noop -} diff --git a/axmol/ui/EditBox/iOS/TextInput.h b/axmol/ui/EditBox/iOS/TextInput.h index 255d6d1f64a0..78d098deeb37 100644 --- a/axmol/ui/EditBox/iOS/TextInput.h +++ b/axmol/ui/EditBox/iOS/TextInput.h @@ -1,6 +1,7 @@ /**************************************************************************** Copyright (c) 2015 Mazyad Alabduljaleel Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. + Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md). https://axmol.dev/ @@ -30,7 +31,7 @@ static const int AX_EDIT_BOX_PADDING = 5; /** This protocol provides a common interface for consolidating text input method calls */ -@protocol AXUITextInput +@protocol AxmolTextInput @property(nonatomic, retain, setter=axui_setText:) NSString* axui_text; @property(nonatomic, retain, setter=axui_setPlaceholder:) NSString* axui_placeholder; diff --git a/axmol/ui/EditBox/iOS/TextField+UITextInput.h b/axmol/ui/EditBox/iOS/TextView.h similarity index 84% rename from axmol/ui/EditBox/iOS/TextField+UITextInput.h rename to axmol/ui/EditBox/iOS/TextView.h index 9b15f3689981..c8010f3f1dd6 100644 --- a/axmol/ui/EditBox/iOS/TextField+UITextInput.h +++ b/axmol/ui/EditBox/iOS/TextView.h @@ -27,10 +27,5 @@ #import #import "axmol/ui/EditBox/iOS/TextInput.h" -@interface UITextField (AXUITextInput) +@interface UITextView (AxmolTextInput) @end - -/** Trick to load category objects without using -ObjC flag - * http://stackoverflow.com/questions/2567498/objective-c-categories-in-static-library - */ -extern void LoadUITextFieldAXUITextInputCategory(); diff --git a/axmol/ui/EditBox/iOS/TextView+UITextInput.mm b/axmol/ui/EditBox/iOS/TextView.mm similarity index 96% rename from axmol/ui/EditBox/iOS/TextView+UITextInput.mm rename to axmol/ui/EditBox/iOS/TextView.mm index 62d78c56fc53..a83e2c5fed80 100644 --- a/axmol/ui/EditBox/iOS/TextView+UITextInput.mm +++ b/axmol/ui/EditBox/iOS/TextView.mm @@ -23,9 +23,9 @@ of this software and associated documentation files (the "Software"), to deal THE SOFTWARE. ****************************************************************************/ -#import "axmol/ui/EditBox/iOS/TextView+TextInput.h" +#import "axmol/ui/EditBox/iOS/TextView.h" -@implementation UITextView (AXUITextInput) +@implementation UITextView (AxmolTextInput) - (NSString*)axui_text { @@ -140,5 +140,3 @@ - (void)axui_setDelegate:(id)delegate } @end - -void LoadUITextViewAXUITextInputCategory() {} diff --git a/extensions/ImGui/src/ImGui/backends/imgui_impl_axmol_sw.cpp b/extensions/ImGui/src/ImGui/backends/imgui_impl_axmol_sw.cpp index 936ebe4c82e8..935f5deedc35 100644 --- a/extensions/ImGui/src/ImGui/backends/imgui_impl_axmol_sw.cpp +++ b/extensions/ImGui/src/ImGui/backends/imgui_impl_axmol_sw.cpp @@ -34,12 +34,12 @@ class KeyboardInputDelegate : public IMEDelegate // Not handled at the moment } - void insertText(const char* text, unsigned int len) override + void insertText(std::string_view text) override { ImGuiIO& io = ImGui::GetIO(); - for (unsigned int i = 0; i < len && text[i] != 0; ++i) + for (auto ch : text) { - io.AddInputCharacter(text[i]); + io.AddInputCharacter(ch); } } }; From 991b4e3012e84834ce93e2fcd48b427d2cee0770 Mon Sep 17 00:00:00 2001 From: halx99 Date: Fri, 22 May 2026 17:26:12 +0800 Subject: [PATCH 37/52] Improve --- axmol/ui/AbstractCheckButton.cpp | 2 +- axmol/ui/AbstractCheckButton.h | 2 +- axmol/ui/Button.cpp | 4 ++-- axmol/ui/Button.h | 2 +- axmol/ui/ImageView.cpp | 2 +- axmol/ui/ImageView.h | 2 +- axmol/ui/InputField.cpp | 2 +- axmol/ui/InputField.h | 2 +- axmol/ui/LoadingBar.cpp | 2 +- axmol/ui/LoadingBar.h | 2 +- axmol/ui/MediaPlayer.cpp | 8 ++++---- axmol/ui/MediaPlayer.h | 4 ++-- axmol/ui/Slider.cpp | 2 +- axmol/ui/Slider.h | 4 ++-- axmol/ui/Text.cpp | 2 +- axmol/ui/Text.h | 4 ++-- axmol/ui/TextAtlas.cpp | 2 +- axmol/ui/TextAtlas.h | 4 ++-- axmol/ui/TextBMFont.cpp | 2 +- axmol/ui/TextBMFont.h | 2 +- axmol/ui/Widget.cpp | 16 ++++++++-------- axmol/ui/Widget.h | 12 +++++++++++- .../UIVideoPlayerTest/UIVideoPlayerTest.cpp | 1 - 23 files changed, 47 insertions(+), 38 deletions(-) diff --git a/axmol/ui/AbstractCheckButton.cpp b/axmol/ui/AbstractCheckButton.cpp index 341211c6a709..a6fe190747cb 100644 --- a/axmol/ui/AbstractCheckButton.cpp +++ b/axmol/ui/AbstractCheckButton.cpp @@ -434,7 +434,7 @@ void AbstractCheckButton::updateLayout() } } -Vec2 AbstractCheckButton::getPreferredSize() const +Vec2 AbstractCheckButton::resolvePreferredSize(const Vec2& /*sizeHint*/) const { return _backGroundBoxRenderer->getContentSize(); } diff --git a/axmol/ui/AbstractCheckButton.h b/axmol/ui/AbstractCheckButton.h index 58b80a436169..105758fda4c0 100644 --- a/axmol/ui/AbstractCheckButton.h +++ b/axmol/ui/AbstractCheckButton.h @@ -123,7 +123,7 @@ class AX_GUI_DLL AbstractCheckButton : public Widget void setSelected(bool selected); // override functions - Vec2 getPreferredSize() const override; + Vec2 resolvePreferredSize(const Vec2& sizeHint) const override; Node* getRenderNode() override; /** When user pressed the CheckBox, the button will zoom to a scale. diff --git a/axmol/ui/Button.cpp b/axmol/ui/Button.cpp index 98abe559eefb..7337e9f7b824 100644 --- a/axmol/ui/Button.cpp +++ b/axmol/ui/Button.cpp @@ -662,7 +662,7 @@ void Button::updateContentSize() if (_autoSize) { - this->setContentSize(getPreferredSize()); + this->setContentSize(resolvePreferredSize(_customSize)); } } @@ -699,7 +699,7 @@ void Button::updateLayout() } } -Vec2 Button::getPreferredSize() const +Vec2 Button::resolvePreferredSize(const Vec2& /*sizeHint*/) const { if (!_autoSize) { diff --git a/axmol/ui/Button.h b/axmol/ui/Button.h index 954ff3a011e8..2ed926faaf9b 100644 --- a/axmol/ui/Button.h +++ b/axmol/ui/Button.h @@ -191,7 +191,7 @@ class AX_GUI_DLL Button : public Widget // override methods void setAutoSize(bool autoSize) override; - Vec2 getPreferredSize() const override; + Vec2 resolvePreferredSize(const Vec2& /*sizeHint*/) const override; Node* getRenderNode() override; std::string getDescription() const override; diff --git a/axmol/ui/ImageView.cpp b/axmol/ui/ImageView.cpp index d93903c7658b..b18105a22ed6 100644 --- a/axmol/ui/ImageView.cpp +++ b/axmol/ui/ImageView.cpp @@ -244,7 +244,7 @@ void ImageView::updateLayout() } } -Vec2 ImageView::getPreferredSize() const +Vec2 ImageView::resolvePreferredSize(const Vec2& /*sizeHint*/) const { return _imageTextureSize; } diff --git a/axmol/ui/ImageView.h b/axmol/ui/ImageView.h index 699caad908bd..1ea29b236d7b 100644 --- a/axmol/ui/ImageView.h +++ b/axmol/ui/ImageView.h @@ -138,7 +138,7 @@ class AX_GUI_DLL ImageView : public Widget, public ax::BlendProtocol // override methods. void setAutoSize(bool autoSize) override; std::string getDescription() const override; - Vec2 getPreferredSize() const override; + Vec2 resolvePreferredSize(const Vec2& /*sizeHint*/) const override; Node* getRenderNode() override; ResourceData getRenderFile(); diff --git a/axmol/ui/InputField.cpp b/axmol/ui/InputField.cpp index 4f808222cecb..416a588cf31b 100644 --- a/axmol/ui/InputField.cpp +++ b/axmol/ui/InputField.cpp @@ -708,7 +708,7 @@ Node* InputField::getRenderNode() return _renderLabel; } -Vec2 InputField::getPreferredSize() const +Vec2 InputField::resolvePreferredSize(const Vec2& /*sizeHint*/) const { return _renderLabel->getContentSize(); } diff --git a/axmol/ui/InputField.h b/axmol/ui/InputField.h index 0b9f05e9ac44..e4999d9c8559 100644 --- a/axmol/ui/InputField.h +++ b/axmol/ui/InputField.h @@ -377,7 +377,7 @@ class AX_DLL InputField : public Widget, public IMEDelegate * @brief Get preferred size based on rendered text. * @return Preferred size. */ - Vec2 getPreferredSize() const override; + Vec2 resolvePreferredSize(const Vec2& /*sizeHint*/) const override; /** * @brief InputField event types - follows TextField's design for consistency. diff --git a/axmol/ui/LoadingBar.cpp b/axmol/ui/LoadingBar.cpp index ce3080236df5..3cfc02dd637e 100644 --- a/axmol/ui/LoadingBar.cpp +++ b/axmol/ui/LoadingBar.cpp @@ -328,7 +328,7 @@ void LoadingBar::setAutoSize(bool autoSize) } } -Vec2 LoadingBar::getPreferredSize() const +Vec2 LoadingBar::resolvePreferredSize(const Vec2& /*sizeHint*/) const { return _barRendererTextureSize; } diff --git a/axmol/ui/LoadingBar.h b/axmol/ui/LoadingBar.h index d0122ec031bc..968afbd0dd50 100644 --- a/axmol/ui/LoadingBar.h +++ b/axmol/ui/LoadingBar.h @@ -165,7 +165,7 @@ class AX_GUI_DLL LoadingBar : public Widget // override methods. void setAutoSize(bool autoSize) override; - Vec2 getPreferredSize() const override; + Vec2 resolvePreferredSize(const Vec2& /*sizeHint*/) const override; Node* getRenderNode() override; std::string getDescription() const override; diff --git a/axmol/ui/MediaPlayer.cpp b/axmol/ui/MediaPlayer.cpp index 0ae4224fd5a7..6482ca6ef9fe 100644 --- a/axmol/ui/MediaPlayer.cpp +++ b/axmol/ui/MediaPlayer.cpp @@ -598,7 +598,7 @@ void MediaPlayerControl::onSizeChanged() } } -Vec2 MediaPlayerControl::getPreferredSize() const +Vec2 MediaPlayerControl::resolvePreferredSize(const Vec2& /*sizeHint*/) const { if (!_autoSize) { @@ -1244,14 +1244,14 @@ void MediaPlayer::setContentSize(const Size& contentSize) } } -Vec2 MediaPlayer::getPreferredSize() const +Vec2 MediaPlayer::resolvePreferredSize(const Vec2& sizeHint) const { auto pvd = reinterpret_cast(_videoContext); if (!pvd) - return _contentSize; + return sizeHint; auto videoSize = pvd->_vrender->getContentSize(); if (videoSize.equals(Vec2::ZERO)) - return _contentSize; + return sizeHint; return videoSize; } diff --git a/axmol/ui/MediaPlayer.h b/axmol/ui/MediaPlayer.h index d59335ea6dad..6a81d4bad36c 100644 --- a/axmol/ui/MediaPlayer.h +++ b/axmol/ui/MediaPlayer.h @@ -87,7 +87,7 @@ class MediaPlayerControl : public ax::ui::Button virtual bool init(SpriteFrame* frame); void onSizeChanged() override; - Vec2 getPreferredSize() const override; + Vec2 resolvePreferredSize(const Vec2& /*sizeHint*/) const override; Vec2 getNormalSize() const override; void onPressStateChangedToNormal() override; @@ -383,7 +383,7 @@ class AX_GUI_DLL MediaPlayer : public ax::ui::Widget MediaState getState() const; Node* getRenderNode() override; - Vec2 getPreferredSize() const override; + Vec2 resolvePreferredSize(const Vec2& /*sizeHint*/) const override; void setMediaController(MediaController* controller); MediaController* getMediaController() const { return _mediaController; } diff --git a/axmol/ui/Slider.cpp b/axmol/ui/Slider.cpp index 75dc35eea4f4..262e6fc6c138 100644 --- a/axmol/ui/Slider.cpp +++ b/axmol/ui/Slider.cpp @@ -586,7 +586,7 @@ void Slider::updateLayout() } } -Vec2 Slider::getPreferredSize() const +Vec2 Slider::resolvePreferredSize(const Vec2& /*sizeHint*/) const { return _barRenderer->getContentSize(); } diff --git a/axmol/ui/Slider.h b/axmol/ui/Slider.h index 3893b7659037..b3698ed00a4a 100644 --- a/axmol/ui/Slider.h +++ b/axmol/ui/Slider.h @@ -240,8 +240,8 @@ class AX_GUI_DLL Slider : public Widget void onTouchEnded(Touch* touch, Event* unusedEvent) override; void onTouchCancelled(Touch* touch, Event* unusedEvent) override; - // override "getPreferredSize" method of widget. - Vec2 getPreferredSize() const override; + // override "resolvePreferredSize" method of widget. + Vec2 resolvePreferredSize(const Vec2& /*sizeHint*/) const override; // override "getRenderNode" method of widget. Node* getRenderNode() override; diff --git a/axmol/ui/Text.cpp b/axmol/ui/Text.cpp index 5de0e495ebd9..e45207f78a41 100644 --- a/axmol/ui/Text.cpp +++ b/axmol/ui/Text.cpp @@ -278,7 +278,7 @@ void Text::updateLayout() } } -Vec2 Text::getPreferredSize() const +Vec2 Text::resolvePreferredSize(const Vec2& /*sizeHint*/) const { return _labelRenderer->getContentSize(); } diff --git a/axmol/ui/Text.h b/axmol/ui/Text.h index 7907b8612d51..0661240796c9 100644 --- a/axmol/ui/Text.h +++ b/axmol/ui/Text.h @@ -177,8 +177,8 @@ class AX_GUI_DLL Text : public Widget, public ax::BlendProtocol */ bool isTouchScaleChangeEnabled() const; - // override "getPreferredSize" method of widget. - Vec2 getPreferredSize() const override; + // override "resolvePreferredSize" method of widget. + Vec2 resolvePreferredSize(const Vec2& /*sizeHint*/) const override; // override "getRenderNode" method of widget. Node* getRenderNode() override; diff --git a/axmol/ui/TextAtlas.cpp b/axmol/ui/TextAtlas.cpp index 9d92ad3ce39c..42e81e9ebdb9 100644 --- a/axmol/ui/TextAtlas.cpp +++ b/axmol/ui/TextAtlas.cpp @@ -143,7 +143,7 @@ void TextAtlas::updateLayout() } } -Vec2 TextAtlas::getPreferredSize() const +Vec2 TextAtlas::resolvePreferredSize(const Vec2& /*sizeHint*/) const { return _labelAtlasRenderer->getContentSize(); } diff --git a/axmol/ui/TextAtlas.h b/axmol/ui/TextAtlas.h index 364510fe6985..edae80b224d7 100644 --- a/axmol/ui/TextAtlas.h +++ b/axmol/ui/TextAtlas.h @@ -126,8 +126,8 @@ class AX_GUI_DLL TextAtlas : public Widget */ ssize_t getStringLength() const; - // override "getPreferredSize" method of widget. - Vec2 getPreferredSize() const override; + // override "resolvePreferredSize" method of widget. + Vec2 resolvePreferredSize(const Vec2& /*sizeHint*/) const override; // override "getRenderNode" method of widget. Node* getRenderNode() override; diff --git a/axmol/ui/TextBMFont.cpp b/axmol/ui/TextBMFont.cpp index ab1a73b47a0d..8c420f8d29a7 100644 --- a/axmol/ui/TextBMFont.cpp +++ b/axmol/ui/TextBMFont.cpp @@ -125,7 +125,7 @@ void TextBMFont::updateLayout() } } -Vec2 TextBMFont::getPreferredSize() const +Vec2 TextBMFont::resolvePreferredSize(const Vec2& /*sizeHint*/) const { return _labelBMFontRenderer->getContentSize(); } diff --git a/axmol/ui/TextBMFont.h b/axmol/ui/TextBMFont.h index 17e5becfdcd5..5a708b930e0b 100644 --- a/axmol/ui/TextBMFont.h +++ b/axmol/ui/TextBMFont.h @@ -88,7 +88,7 @@ class AX_GUI_DLL TextBMFont : public Widget */ ssize_t getStringLength() const; - Vec2 getPreferredSize() const override; + Vec2 resolvePreferredSize(const Vec2& /*sizeHint*/) const override; Node* getRenderNode() override; /** * Returns the "class name" of widget. diff --git a/axmol/ui/Widget.cpp b/axmol/ui/Widget.cpp index 5fe08704714c..f0a2431b49ba 100644 --- a/axmol/ui/Widget.cpp +++ b/axmol/ui/Widget.cpp @@ -287,7 +287,7 @@ void Widget::setContentSize(const Vec2& contentSize) _customSize = contentSize; - ProtectedNode::setContentSize(_autoSize ? getPreferredSize() : _customSize); + ProtectedNode::setContentSize(_autoSize ? resolvePreferredSize(_customSize) : _customSize); if (!_usingLayoutComponent && _running) { @@ -343,7 +343,7 @@ void Widget::setSizePercent(const Vec2& percent) } } if (_autoSize) - setContentSize(getPreferredSize()); + setContentSize(resolvePreferredSize(cSize)); else setContentSize(cSize); @@ -366,7 +366,7 @@ void Widget::updateSizeAndPosition(const Vec2& parentSize) { if (_autoSize) { - this->setContentSize(getPreferredSize()); + this->setContentSize(resolvePreferredSize(_customSize)); } else { @@ -390,7 +390,7 @@ void Widget::updateSizeAndPosition(const Vec2& parentSize) Vec2 cSize = Vec2(parentSize.width * _sizePercent.x, parentSize.height * _sizePercent.y); if (_autoSize) { - this->setContentSize(getPreferredSize()); + this->setContentSize(resolvePreferredSize(cSize)); } else { @@ -519,14 +519,14 @@ void Widget::onSizeChanged() } } -Vec2 Widget::getPreferredSize() const +Vec2 Widget::resolvePreferredSize(const Vec2& sizeHint) const { - return _contentSize; + return sizeHint; } void Widget::updateContentSize() { - auto preferredSize = getPreferredSize(); + auto preferredSize = resolvePreferredSize(_customSize); if (_autoSize) { @@ -1549,7 +1549,7 @@ void Widget::setAutoSize(bool enable) else { // Switching to auto size mode: update to content size immediately - ProtectedNode::setContentSize(this->getPreferredSize()); + ProtectedNode::setContentSize(this->resolvePreferredSize(_customSize)); onSizeChanged(); } diff --git a/axmol/ui/Widget.h b/axmol/ui/Widget.h index 2e551ad307e9..506e629fbf2c 100644 --- a/axmol/ui/Widget.h +++ b/axmol/ui/Widget.h @@ -558,7 +558,7 @@ class AX_GUI_DLL Widget : public ProtectedNode, public LayoutParameterProtocol * This is equivalent to getRenderNode()->getContentSize(). * @return The render node's content size. */ - virtual Vec2 getPreferredSize() const; + Vec2 getPreferredSize() const { return resolvePreferredSize(_contentSize); } /** * Returns the string representation of widget class name @@ -791,6 +791,16 @@ class AX_GUI_DLL Widget : public ProtectedNode, public LayoutParameterProtocol void dispatchFocusEvent(Widget* widgetLoseFocus, Widget* widgetGetFocus); protected: + /** + * @brief [Core Layout Override] Measures the widget's desired size based on a layout hint. + * @param sizeHint The proposed layout size constraint. + * @return The final size resolved by your custom widget or content. + * @note Overriding Guide: When creating a custom widget (e.g., custom button/label/EditBox), + * override this method instead of resolvePreferredSize(). It is a pure `const` function + * that eliminates layout deadlocks and platform view rendering jitter. + */ + virtual Vec2 resolvePreferredSize(const Vec2& sizeHint) const; + // call back function called when size changed. virtual void onSizeChanged(); diff --git a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIVideoPlayerTest/UIVideoPlayerTest.cpp b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIVideoPlayerTest/UIVideoPlayerTest.cpp index 72afa7ecef41..81356cb7727c 100644 --- a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIVideoPlayerTest/UIVideoPlayerTest.cpp +++ b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIVideoPlayerTest/UIVideoPlayerTest.cpp @@ -438,7 +438,6 @@ void SimpleVideoPlayerTest::createVideo() _videoPlayer = VideoPlayer::create(); _videoPlayer->setPosition(centerPos); _videoPlayer->setAnchorPoint(Vec2::ANCHOR_MIDDLE); - _videoPlayer->setAutoSize(false); _videoPlayer->setContentSize(Size(widgetSize.width * 0.4f, widgetSize.height * 0.4f)); _videoPlayer->setLooping(true); _videoPlayer->setStyle(_style); From 7a1c29048682bfd1d8731481353e0b3036dbd728 Mon Sep 17 00:00:00 2001 From: halx99 Date: Fri, 22 May 2026 17:33:55 +0800 Subject: [PATCH 38/52] up --- axmol/ui/InputField.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/axmol/ui/InputField.cpp b/axmol/ui/InputField.cpp index 416a588cf31b..09231ac5b92c 100644 --- a/axmol/ui/InputField.cpp +++ b/axmol/ui/InputField.cpp @@ -1598,15 +1598,12 @@ void InputField::moveCursorVertically(int direction) return; // Determine current line index - int curLine = 0; - for (size_t i = 0; i < _lineMetrics.size(); ++i) - { - if (_cursorCharIndex >= _lineMetrics[i].startCharIndex && _cursorCharIndex <= _lineMetrics[i].endCharIndex) - { - curLine = (int)i; - break; - } - } + auto it = std::lower_bound(_lineMetrics.begin(), _lineMetrics.end(), _cursorCharIndex, + [](const LineMetrics& lm, int cursorIdx) { + return lm.endCharIndex < cursorIdx; // keep searching while end < cursor + }); + int curLine = (it == _lineMetrics.end()) ? (int)_lineMetrics.size() - 1 + : static_cast(std::distance(_lineMetrics.begin(), it)); int targetLine = curLine + direction; targetLine = std::clamp(targetLine, 0, (int)_lineMetrics.size() - 1); @@ -1618,7 +1615,7 @@ void InputField::moveCursorVertically(int direction) // Use binary search within target line to find the character closest to _preferredCursorX auto& offsets = targetLineMetrics.charXOffsets; int charInLine = 0; - float relX = _preferredCursorX; + // float relX = _preferredCursorX; // Need to account for alignment: we need to convert _preferredCursorX (which is in content space) to line-relative // But _preferredCursorX is stored in the same coordinate system as cursorXFromPosition returns (content space). // We can recalculate the relative x considering alignment: From 6ad1afb69002431607b8f54a24f898534ad863a5 Mon Sep 17 00:00:00 2001 From: axmol-bot <116471739+axmol-bot@users.noreply.github.com> Date: Fri, 22 May 2026 12:12:51 +0000 Subject: [PATCH 39/52] Committing clang-format changes --- axmol/platform/desktop/RenderViewImpl.cpp | 2 +- axmol/ui/EditBox/Mac/EditBoxMac.mm | 2 +- axmol/ui/EditBox/iOS/EditBoxIOS.mm | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/axmol/platform/desktop/RenderViewImpl.cpp b/axmol/platform/desktop/RenderViewImpl.cpp index 3c37326ea35a..b0d0dba11c95 100644 --- a/axmol/platform/desktop/RenderViewImpl.cpp +++ b/axmol/platform/desktop/RenderViewImpl.cpp @@ -748,7 +748,7 @@ bool RenderViewImpl::initWithRect(std::string_view viewName, glfwSetWindowIconifyCallback(_mainWindow, GLFWEventHandler::onGLFWWindowIconifyCallback); glfwSetWindowFocusCallback(_mainWindow, GLFWEventHandler::onGLFWWindowFocusCallback); glfwSetWindowCloseCallback(_mainWindow, GLFWEventHandler::onGLFWWindowCloseCallback); - + #if AX_ENABLE_GL if (fallbackGL) { diff --git a/axmol/ui/EditBox/Mac/EditBoxMac.mm b/axmol/ui/EditBox/Mac/EditBoxMac.mm index 7ed2ef35e941..e7f70c70deb6 100644 --- a/axmol/ui/EditBox/Mac/EditBoxMac.mm +++ b/axmol/ui/EditBox/Mac/EditBoxMac.mm @@ -82,7 +82,7 @@ - (void)setTextInput:(NSView*)textInput return; NSView* oldInput = _textInput; - _textInput = textInput; + _textInput = textInput; if (_textInput != nil) { [_textInput retain]; // retain new input view diff --git a/axmol/ui/EditBox/iOS/EditBoxIOS.mm b/axmol/ui/EditBox/iOS/EditBoxIOS.mm index 0fb0f886bcc4..b34836989719 100644 --- a/axmol/ui/EditBox/iOS/EditBoxIOS.mm +++ b/axmol/ui/EditBox/iOS/EditBoxIOS.mm @@ -111,8 +111,8 @@ - (void)setTextInput:(UIView*)textInput - (void)createSingleLineTextField { AxmolSingleLineTextField* textField = [[[AxmolSingleLineTextField alloc] initWithFrame:self.frameRect] autorelease]; - textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; - textField.borderStyle = UITextBorderStyleNone; + textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; + textField.borderStyle = UITextBorderStyleNone; [textField addTarget:self action:@selector(textChanged:) forControlEvents:UIControlEventEditingChanged]; @@ -122,7 +122,7 @@ - (void)createSingleLineTextField - (void)createMultiLineTextField { AxmolMultilineTextField* textView = [[[AxmolMultilineTextField alloc] initWithFrame:self.frameRect] autorelease]; - self.textInput = textView; + self.textInput = textView; } #pragma mark - Public methods From 0f47d679f2585a96a82089677518185e9a9fe6c2 Mon Sep 17 00:00:00 2001 From: halx99 Date: Fri, 22 May 2026 22:08:00 +0800 Subject: [PATCH 40/52] Fix reviews --- axmol/base/text_utils.cpp | 43 +- axmol/base/text_utils.h | 36 +- axmol/ui/InputField.cpp | 40 +- .../lua-bindings/auto/axlua_ui_auto.cpp | 408 ++++++++++++++++++ .../lua-bindings/auto/axlua_video_auto.cpp | 51 +++ 5 files changed, 542 insertions(+), 36 deletions(-) diff --git a/axmol/base/text_utils.cpp b/axmol/base/text_utils.cpp index 3624796a22dc..62668d67f5e8 100644 --- a/axmol/base/text_utils.cpp +++ b/axmol/base/text_utils.cpp @@ -337,19 +337,19 @@ std::vector getChar16VectorFromUTF16String(const std::u16string& utf16 return std::vector(utf16.begin(), utf16.end()); } -size_t getCharacterCountInUTF8String(std::string_view utf8) +size_t getCharacterCountInUTF8String(std::string_view strUTF8) { - return countUTF8Chars(utf8); + return countUTF8Chars(strUTF8); } -size_t countUTF8Chars(std::string_view utf8) +size_t countUTF8Chars(std::string_view strUTF8) { int count = 0; - if (!utf8.empty()) + if (!strUTF8.empty()) { - const UTF8* source = (const UTF8*)utf8.data(); - const UTF8* sourceEnd = (const UTF8*)utf8.data() + utf8.length(); + const UTF8* source = (const UTF8*)strUTF8.data(); + const UTF8* sourceEnd = (const UTF8*)strUTF8.data() + strUTF8.length(); while (source != sourceEnd) { auto size = getUTF8SequenceSize(source, sourceEnd); @@ -366,6 +366,37 @@ size_t countUTF8Chars(std::string_view utf8) return count; } +UTF8CountResult countUTF8WithLimit(std::string_view strUTF8, size_t charLimit) +{ + UTF8CountResult result; + result.charCount = 0; + result.byteCount = 0; + + if (!strUTF8.empty() && charLimit > 0) + { + const UTF8* const sourceStart = (const UTF8*)strUTF8.data(); + const UTF8* const sourceEnd = sourceStart + strUTF8.length(); + const UTF8* source = sourceStart; + + while (source != sourceEnd && result.charCount < charLimit) + { + auto size = getUTF8SequenceSize(source, sourceEnd); + if (size == 0) + { + // Invalid UTF-8 sequence found + return UTF8CountResult{}; + } + source += size; + ++result.charCount; + } + + // Calculate total bytes consumed by subtracting pointers + result.byteCount = static_cast(source - sourceStart); + } + + return result; +} + size_t getUTF8ByteOffset(std::string_view utf8, size_t utf8CharOffset) { if (utf8CharOffset >= utf8.length()) diff --git a/axmol/base/text_utils.h b/axmol/base/text_utils.h index 450121745d7d..fd640e7d5cfa 100644 --- a/axmol/base/text_utils.h +++ b/axmol/base/text_utils.h @@ -25,15 +25,14 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef AXMOL__TEXT_UTILS_H -#define AXMOL__TEXT_UTILS_H +#pragma once #include "axmol/platform/PlatformMacros.h" #include "axmol/tlx/format.hpp" #include #include #include -#include +#include #if (AX_TARGET_PLATFORM == AX_PLATFORM_ANDROID) # include @@ -75,6 +74,14 @@ inline std::string_view trim(std::string_view s) return ltrim(rtrim(s)); } +struct UTF8CountResult +{ + size_t charCount = 0; // Number of valid UTF-8 characters processed + size_t byteCount = 0; // Number of bytes consumed + bool success = true; // False if an invalid UTF-8 sequence was encountered + explicit operator bool() const { return success; } +}; + /** * @brief Converts from UTF8 string to UTF16 string. * @@ -204,7 +211,26 @@ AX_DLL bool isUnicodeNonBreaking(char32_t ch); * @param utf8 A UTF-8 encoded string view. * @return The number of Unicode code points in the input string. */ -AX_DLL size_t countUTF8Chars(std::string_view utf8); +AX_DLL size_t countUTF8Chars(std::string_view strUTF8); + +/** + * @brief Count UTF-8 characters and bytes up to a maximum character limit. + * + * This function scans a UTF-8 encoded string and counts both the number of + * characters and the number of bytes consumed until either the end of the + * string is reached or the specified maximum character limit is exceeded. + * + * @param strUTF8 The UTF-8 encoded input string. + * @param charLimit The maximum number of UTF-8 characters to process. + * + * @return A pair of integers: + * - first: The number of UTF-8 characters counted (up to charLimit). + * - second: The number of bytes consumed in the input string. + * + * @note If the input contains invalid UTF-8 sequences, behavior is undefined. + * This function does not perform full UTF-8 validation. + */ +AX_DLL UTF8CountResult countUTF8WithLimit(std::string_view strUTF8, size_t charLimit); /* * @brief Gets the byte offset of the UTF-8 character at the specified offset. @@ -299,5 +325,3 @@ class AX_DLL u8char_span } // namespace text_utils } // namespace ax - -#endif /** defined(AXMOL__TEXT_UTILS_H) */ diff --git a/axmol/ui/InputField.cpp b/axmol/ui/InputField.cpp index 09231ac5b92c..648daca44dfa 100644 --- a/axmol/ui/InputField.cpp +++ b/axmol/ui/InputField.cpp @@ -86,26 +86,6 @@ static void writeClipboardText(std::string_view text) #endif } -/// calculate the UTF-8 string's char count. -static std::pair _truncateUTF8String(const char* text, int charLimit) -{ - int charCount = 0; - char ch = 0; - int numOfBytes = 0; - while ((ch = *text) != 0x0) - { - AX_BREAK_IF(!ch || charCount > charLimit); - - if (0x80 != (0xC0 & ch)) - { - ++charCount; - } - ++numOfBytes; - ++text; - } - return std::make_pair(charCount, numOfBytes); -} - static FontType labelTypeToFontType(Label::LabelType type) { switch (type) @@ -394,6 +374,7 @@ void InputField::setFontSize(float size) } _passwordCharWidth = measureText(_passwordChar).width; + _lineHeight = measureText("M"sv).height; _layoutDirty = true; } @@ -533,6 +514,8 @@ void InputField::insertText(std::string_view text) return; } + size_t numOfChars; + // Character limit if (_charLimit > 0) { @@ -543,8 +526,18 @@ void InputField::insertText(std::string_view text) return; } // Truncate insertStr to not exceed limit - auto [numChars, numBytes] = _truncateUTF8String(insertStr.c_str(), remaining); - insertStr.resize(numBytes); + auto result = text_utils::countUTF8WithLimit(insertStr, remaining); + if (!result) + { + axbeep(0); + return; + } + insertStr.resize(result.byteCount); + numOfChars = result.charCount; + } + else + { + numOfChars = text_utils::countUTF8Chars(insertStr); } if (insertStr.empty()) @@ -555,8 +548,7 @@ void InputField::insertText(std::string_view text) sText.insert(_cursorByteIndex, insertStr); this->setString(sText); - int insertedCharCount = text_utils::countUTF8Chars(insertStr); - setCursorPosition(cursorIndex + insertedCharCount, false); + setCursorPosition(cursorIndex + numOfChars, false); dispatchEvent(EventType::INSERT_TEXT); } diff --git a/extensions/scripting/lua-bindings/auto/axlua_ui_auto.cpp b/extensions/scripting/lua-bindings/auto/axlua_ui_auto.cpp index d8d6df9fe41f..12494758d1cd 100644 --- a/extensions/scripting/lua-bindings/auto/axlua_ui_auto.cpp +++ b/extensions/scripting/lua-bindings/auto/axlua_ui_auto.cpp @@ -7139,6 +7139,56 @@ int lua_ax_ui_Button_setPressedActionEnabled(lua_State* tolua_S) return 0; } +int lua_ax_ui_Button_resolvePreferredSize(lua_State* tolua_S) +{ + int argc = 0; + ax::ui::Button* obj = nullptr; + bool ok = true; + +#if _AX_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if _AX_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"axui.Button",0,&tolua_err)) goto tolua_lerror; +#endif + + obj = (ax::ui::Button*)tolua_tousertype(tolua_S,1,0); + +#if _AX_DEBUG >= 1 + if (!obj) + { + tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_Button_resolvePreferredSize'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 1) + { + ax::Vec2 arg0; + + ok &= luaval_to_vec2(tolua_S, 2, &arg0, "axui.Button:resolvePreferredSize"); + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_Button_resolvePreferredSize'", nullptr); + return 0; + } + auto&& ret = obj->resolvePreferredSize(arg0); + vec2_to_luaval(tolua_S, ret); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.Button:resolvePreferredSize",argc, 1); + return 0; + +#if _AX_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_Button_resolvePreferredSize'.",&tolua_err); +#endif + + return 0; +} int lua_ax_ui_Button_getTitleRenderer(lua_State* tolua_S) { int argc = 0; @@ -8602,6 +8652,7 @@ int lua_register_ax_ui_Button(lua_State* tolua_S) tolua_function(tolua_S,"setScale9Enabled",lua_ax_ui_Button_setScale9Enabled); tolua_function(tolua_S,"isScale9Enabled",lua_ax_ui_Button_isScale9Enabled); tolua_function(tolua_S,"setPressedActionEnabled",lua_ax_ui_Button_setPressedActionEnabled); + tolua_function(tolua_S,"resolvePreferredSize",lua_ax_ui_Button_resolvePreferredSize); tolua_function(tolua_S,"getTitleRenderer",lua_ax_ui_Button_getTitleRenderer); tolua_function(tolua_S,"setTitleText",lua_ax_ui_Button_setTitleText); tolua_function(tolua_S,"getTitleText",lua_ax_ui_Button_getTitleText); @@ -9159,6 +9210,56 @@ int lua_ax_ui_AbstractCheckButton_setSelected(lua_State* tolua_S) return 0; } +int lua_ax_ui_AbstractCheckButton_resolvePreferredSize(lua_State* tolua_S) +{ + int argc = 0; + ax::ui::AbstractCheckButton* obj = nullptr; + bool ok = true; + +#if _AX_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if _AX_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"axui.AbstractCheckButton",0,&tolua_err)) goto tolua_lerror; +#endif + + obj = (ax::ui::AbstractCheckButton*)tolua_tousertype(tolua_S,1,0); + +#if _AX_DEBUG >= 1 + if (!obj) + { + tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_AbstractCheckButton_resolvePreferredSize'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 1) + { + ax::Vec2 arg0; + + ok &= luaval_to_vec2(tolua_S, 2, &arg0, "axui.AbstractCheckButton:resolvePreferredSize"); + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_AbstractCheckButton_resolvePreferredSize'", nullptr); + return 0; + } + auto&& ret = obj->resolvePreferredSize(arg0); + vec2_to_luaval(tolua_S, ret); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.AbstractCheckButton:resolvePreferredSize",argc, 1); + return 0; + +#if _AX_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_AbstractCheckButton_resolvePreferredSize'.",&tolua_err); +#endif + + return 0; +} int lua_ax_ui_AbstractCheckButton_setZoomScale(lua_State* tolua_S) { int argc = 0; @@ -9837,6 +9938,7 @@ int lua_register_ax_ui_AbstractCheckButton(lua_State* tolua_S) tolua_function(tolua_S,"loadTextureFrontCrossDisabled",lua_ax_ui_AbstractCheckButton_loadTextureFrontCrossDisabled); tolua_function(tolua_S,"isSelected",lua_ax_ui_AbstractCheckButton_isSelected); tolua_function(tolua_S,"setSelected",lua_ax_ui_AbstractCheckButton_setSelected); + tolua_function(tolua_S,"resolvePreferredSize",lua_ax_ui_AbstractCheckButton_resolvePreferredSize); tolua_function(tolua_S,"setZoomScale",lua_ax_ui_AbstractCheckButton_setZoomScale); tolua_function(tolua_S,"getZoomScale",lua_ax_ui_AbstractCheckButton_getZoomScale); tolua_function(tolua_S,"getRendererBackground",lua_ax_ui_AbstractCheckButton_getRendererBackground); @@ -11446,6 +11548,56 @@ int lua_ax_ui_ImageView_getBlendFunc(lua_State* tolua_S) return 0; } +int lua_ax_ui_ImageView_resolvePreferredSize(lua_State* tolua_S) +{ + int argc = 0; + ax::ui::ImageView* obj = nullptr; + bool ok = true; + +#if _AX_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if _AX_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"axui.ImageView",0,&tolua_err)) goto tolua_lerror; +#endif + + obj = (ax::ui::ImageView*)tolua_tousertype(tolua_S,1,0); + +#if _AX_DEBUG >= 1 + if (!obj) + { + tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_ImageView_resolvePreferredSize'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 1) + { + ax::Vec2 arg0; + + ok &= luaval_to_vec2(tolua_S, 2, &arg0, "axui.ImageView:resolvePreferredSize"); + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_ImageView_resolvePreferredSize'", nullptr); + return 0; + } + auto&& ret = obj->resolvePreferredSize(arg0); + vec2_to_luaval(tolua_S, ret); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.ImageView:resolvePreferredSize",argc, 1); + return 0; + +#if _AX_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_ImageView_resolvePreferredSize'.",&tolua_err); +#endif + + return 0; +} int lua_ax_ui_ImageView_getRenderFile(lua_State* tolua_S) { int argc = 0; @@ -11710,6 +11862,7 @@ int lua_register_ax_ui_ImageView(lua_State* tolua_S) tolua_function(tolua_S,"getCapInsets",lua_ax_ui_ImageView_getCapInsets); tolua_function(tolua_S,"setBlendFunc",lua_ax_ui_ImageView_setBlendFunc); tolua_function(tolua_S,"getBlendFunc",lua_ax_ui_ImageView_getBlendFunc); + tolua_function(tolua_S,"resolvePreferredSize",lua_ax_ui_ImageView_resolvePreferredSize); tolua_function(tolua_S,"getRenderFile",lua_ax_ui_ImageView_getRenderFile); tolua_function(tolua_S,"init",lua_ax_ui_ImageView_init); tolua_function(tolua_S,"createInstance", lua_ax_ui_ImageView_createInstance); @@ -12203,6 +12356,56 @@ int lua_ax_ui_Text_isTouchScaleChangeEnabled(lua_State* tolua_S) return 0; } +int lua_ax_ui_Text_resolvePreferredSize(lua_State* tolua_S) +{ + int argc = 0; + ax::ui::Text* obj = nullptr; + bool ok = true; + +#if _AX_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if _AX_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"axui.Text",0,&tolua_err)) goto tolua_lerror; +#endif + + obj = (ax::ui::Text*)tolua_tousertype(tolua_S,1,0); + +#if _AX_DEBUG >= 1 + if (!obj) + { + tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_Text_resolvePreferredSize'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 1) + { + ax::Vec2 arg0; + + ok &= luaval_to_vec2(tolua_S, 2, &arg0, "axui.Text:resolvePreferredSize"); + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_Text_resolvePreferredSize'", nullptr); + return 0; + } + auto&& ret = obj->resolvePreferredSize(arg0); + vec2_to_luaval(tolua_S, ret); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.Text:resolvePreferredSize",argc, 1); + return 0; + +#if _AX_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_Text_resolvePreferredSize'.",&tolua_err); +#endif + + return 0; +} int lua_ax_ui_Text_getAutoRenderSize(lua_State* tolua_S) { int argc = 0; @@ -13579,6 +13782,7 @@ int lua_register_ax_ui_Text(lua_State* tolua_S) tolua_function(tolua_S,"getType",lua_ax_ui_Text_getType); tolua_function(tolua_S,"setTouchScaleChangeEnabled",lua_ax_ui_Text_setTouchScaleChangeEnabled); tolua_function(tolua_S,"isTouchScaleChangeEnabled",lua_ax_ui_Text_isTouchScaleChangeEnabled); + tolua_function(tolua_S,"resolvePreferredSize",lua_ax_ui_Text_resolvePreferredSize); tolua_function(tolua_S,"getAutoRenderSize",lua_ax_ui_Text_getAutoRenderSize); tolua_function(tolua_S,"setTextAreaSize",lua_ax_ui_Text_setTextAreaSize); tolua_function(tolua_S,"getTextAreaSize",lua_ax_ui_Text_getTextAreaSize); @@ -13818,6 +14022,56 @@ int lua_ax_ui_TextAtlas_getStringLength(lua_State* tolua_S) return 0; } +int lua_ax_ui_TextAtlas_resolvePreferredSize(lua_State* tolua_S) +{ + int argc = 0; + ax::ui::TextAtlas* obj = nullptr; + bool ok = true; + +#if _AX_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if _AX_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"axui.TextAtlas",0,&tolua_err)) goto tolua_lerror; +#endif + + obj = (ax::ui::TextAtlas*)tolua_tousertype(tolua_S,1,0); + +#if _AX_DEBUG >= 1 + if (!obj) + { + tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextAtlas_resolvePreferredSize'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 1) + { + ax::Vec2 arg0; + + ok &= luaval_to_vec2(tolua_S, 2, &arg0, "axui.TextAtlas:resolvePreferredSize"); + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextAtlas_resolvePreferredSize'", nullptr); + return 0; + } + auto&& ret = obj->resolvePreferredSize(arg0); + vec2_to_luaval(tolua_S, ret); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextAtlas:resolvePreferredSize",argc, 1); + return 0; + +#if _AX_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextAtlas_resolvePreferredSize'.",&tolua_err); +#endif + + return 0; +} int lua_ax_ui_TextAtlas_updateLayout(lua_State* tolua_S) { int argc = 0; @@ -14055,6 +14309,7 @@ int lua_register_ax_ui_TextAtlas(lua_State* tolua_S) tolua_function(tolua_S,"setString",lua_ax_ui_TextAtlas_setString); tolua_function(tolua_S,"getString",lua_ax_ui_TextAtlas_getString); tolua_function(tolua_S,"getStringLength",lua_ax_ui_TextAtlas_getStringLength); + tolua_function(tolua_S,"resolvePreferredSize",lua_ax_ui_TextAtlas_resolvePreferredSize); tolua_function(tolua_S,"updateLayout",lua_ax_ui_TextAtlas_updateLayout); tolua_function(tolua_S,"getRenderFile",lua_ax_ui_TextAtlas_getRenderFile); tolua_function(tolua_S,"createInstance", lua_ax_ui_TextAtlas_createInstance); @@ -14521,6 +14776,56 @@ int lua_ax_ui_LoadingBar_getCapInsets(lua_State* tolua_S) return 0; } +int lua_ax_ui_LoadingBar_resolvePreferredSize(lua_State* tolua_S) +{ + int argc = 0; + ax::ui::LoadingBar* obj = nullptr; + bool ok = true; + +#if _AX_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if _AX_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"axui.LoadingBar",0,&tolua_err)) goto tolua_lerror; +#endif + + obj = (ax::ui::LoadingBar*)tolua_tousertype(tolua_S,1,0); + +#if _AX_DEBUG >= 1 + if (!obj) + { + tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_LoadingBar_resolvePreferredSize'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 1) + { + ax::Vec2 arg0; + + ok &= luaval_to_vec2(tolua_S, 2, &arg0, "axui.LoadingBar:resolvePreferredSize"); + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_LoadingBar_resolvePreferredSize'", nullptr); + return 0; + } + auto&& ret = obj->resolvePreferredSize(arg0); + vec2_to_luaval(tolua_S, ret); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.LoadingBar:resolvePreferredSize",argc, 1); + return 0; + +#if _AX_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_LoadingBar_resolvePreferredSize'.",&tolua_err); +#endif + + return 0; +} int lua_ax_ui_LoadingBar_getRenderFile(lua_State* tolua_S) { int argc = 0; @@ -14752,6 +15057,7 @@ int lua_register_ax_ui_LoadingBar(lua_State* tolua_S) tolua_function(tolua_S,"isScale9Enabled",lua_ax_ui_LoadingBar_isScale9Enabled); tolua_function(tolua_S,"setCapInsets",lua_ax_ui_LoadingBar_setCapInsets); tolua_function(tolua_S,"getCapInsets",lua_ax_ui_LoadingBar_getCapInsets); + tolua_function(tolua_S,"resolvePreferredSize",lua_ax_ui_LoadingBar_resolvePreferredSize); tolua_function(tolua_S,"getRenderFile",lua_ax_ui_LoadingBar_getRenderFile); tolua_function(tolua_S,"createInstance", lua_ax_ui_LoadingBar_createInstance); tolua_function(tolua_S,"create", lua_ax_ui_LoadingBar_create); @@ -21414,6 +21720,56 @@ int lua_ax_ui_Slider_addEventListener(lua_State* tolua_S) return 0; } +int lua_ax_ui_Slider_resolvePreferredSize(lua_State* tolua_S) +{ + int argc = 0; + ax::ui::Slider* obj = nullptr; + bool ok = true; + +#if _AX_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if _AX_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"axui.Slider",0,&tolua_err)) goto tolua_lerror; +#endif + + obj = (ax::ui::Slider*)tolua_tousertype(tolua_S,1,0); + +#if _AX_DEBUG >= 1 + if (!obj) + { + tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_Slider_resolvePreferredSize'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 1) + { + ax::Vec2 arg0; + + ok &= luaval_to_vec2(tolua_S, 2, &arg0, "axui.Slider:resolvePreferredSize"); + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_Slider_resolvePreferredSize'", nullptr); + return 0; + } + auto&& ret = obj->resolvePreferredSize(arg0); + vec2_to_luaval(tolua_S, ret); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.Slider:resolvePreferredSize",argc, 1); + return 0; + +#if _AX_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_Slider_resolvePreferredSize'.",&tolua_err); +#endif + + return 0; +} int lua_ax_ui_Slider_setZoomScale(lua_State* tolua_S) { int argc = 0; @@ -22101,6 +22457,7 @@ int lua_register_ax_ui_Slider(lua_State* tolua_S) tolua_function(tolua_S,"setMaxPercent",lua_ax_ui_Slider_setMaxPercent); tolua_function(tolua_S,"getMaxPercent",lua_ax_ui_Slider_getMaxPercent); tolua_function(tolua_S,"addEventListener",lua_ax_ui_Slider_addEventListener); + tolua_function(tolua_S,"resolvePreferredSize",lua_ax_ui_Slider_resolvePreferredSize); tolua_function(tolua_S,"setZoomScale",lua_ax_ui_Slider_setZoomScale); tolua_function(tolua_S,"getZoomScale",lua_ax_ui_Slider_getZoomScale); tolua_function(tolua_S,"getSlidBallNormalRenderer",lua_ax_ui_Slider_getSlidBallNormalRenderer); @@ -22315,6 +22672,56 @@ int lua_ax_ui_TextBMFont_getStringLength(lua_State* tolua_S) return 0; } +int lua_ax_ui_TextBMFont_resolvePreferredSize(lua_State* tolua_S) +{ + int argc = 0; + ax::ui::TextBMFont* obj = nullptr; + bool ok = true; + +#if _AX_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if _AX_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"axui.TextBMFont",0,&tolua_err)) goto tolua_lerror; +#endif + + obj = (ax::ui::TextBMFont*)tolua_tousertype(tolua_S,1,0); + +#if _AX_DEBUG >= 1 + if (!obj) + { + tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextBMFont_resolvePreferredSize'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 1) + { + ax::Vec2 arg0; + + ok &= luaval_to_vec2(tolua_S, 2, &arg0, "axui.TextBMFont:resolvePreferredSize"); + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextBMFont_resolvePreferredSize'", nullptr); + return 0; + } + auto&& ret = obj->resolvePreferredSize(arg0); + vec2_to_luaval(tolua_S, ret); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.TextBMFont:resolvePreferredSize",argc, 1); + return 0; + +#if _AX_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextBMFont_resolvePreferredSize'.",&tolua_err); +#endif + + return 0; +} int lua_ax_ui_TextBMFont_getRenderFile(lua_State* tolua_S) { int argc = 0; @@ -22543,6 +22950,7 @@ int lua_register_ax_ui_TextBMFont(lua_State* tolua_S) tolua_function(tolua_S,"setString",lua_ax_ui_TextBMFont_setString); tolua_function(tolua_S,"getString",lua_ax_ui_TextBMFont_getString); tolua_function(tolua_S,"getStringLength",lua_ax_ui_TextBMFont_getStringLength); + tolua_function(tolua_S,"resolvePreferredSize",lua_ax_ui_TextBMFont_resolvePreferredSize); tolua_function(tolua_S,"getRenderFile",lua_ax_ui_TextBMFont_getRenderFile); tolua_function(tolua_S,"resetRender",lua_ax_ui_TextBMFont_resetRender); tolua_function(tolua_S,"createInstance", lua_ax_ui_TextBMFont_createInstance); diff --git a/extensions/scripting/lua-bindings/auto/axlua_video_auto.cpp b/extensions/scripting/lua-bindings/auto/axlua_video_auto.cpp index 292ec44e42e3..077a5d533d5a 100644 --- a/extensions/scripting/lua-bindings/auto/axlua_video_auto.cpp +++ b/extensions/scripting/lua-bindings/auto/axlua_video_auto.cpp @@ -1162,6 +1162,56 @@ int lua_ax_video_MediaPlayer_getState(lua_State* tolua_S) return 0; } +int lua_ax_video_MediaPlayer_resolvePreferredSize(lua_State* tolua_S) +{ + int argc = 0; + ax::ui::MediaPlayer* obj = nullptr; + bool ok = true; + +#if _AX_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if _AX_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"axui.MediaPlayer",0,&tolua_err)) goto tolua_lerror; +#endif + + obj = (ax::ui::MediaPlayer*)tolua_tousertype(tolua_S,1,0); + +#if _AX_DEBUG >= 1 + if (!obj) + { + tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_video_MediaPlayer_resolvePreferredSize'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 1) + { + ax::Vec2 arg0; + + ok &= luaval_to_vec2(tolua_S, 2, &arg0, "axui.MediaPlayer:resolvePreferredSize"); + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_ax_video_MediaPlayer_resolvePreferredSize'", nullptr); + return 0; + } + auto&& ret = obj->resolvePreferredSize(arg0); + vec2_to_luaval(tolua_S, ret); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "axui.MediaPlayer:resolvePreferredSize",argc, 1); + return 0; + +#if _AX_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_ax_video_MediaPlayer_resolvePreferredSize'.",&tolua_err); +#endif + + return 0; +} int lua_ax_video_MediaPlayer_setMediaController(lua_State* tolua_S) { int argc = 0; @@ -1367,6 +1417,7 @@ int lua_register_ax_video_MediaPlayer(lua_State* tolua_S) tolua_function(tolua_S,"isFullScreenEnabled",lua_ax_video_MediaPlayer_isFullScreenEnabled); tolua_function(tolua_S,"onPlayEvent",lua_ax_video_MediaPlayer_onPlayEvent); tolua_function(tolua_S,"getState",lua_ax_video_MediaPlayer_getState); + tolua_function(tolua_S,"resolvePreferredSize",lua_ax_video_MediaPlayer_resolvePreferredSize); tolua_function(tolua_S,"setMediaController",lua_ax_video_MediaPlayer_setMediaController); tolua_function(tolua_S,"getMediaController",lua_ax_video_MediaPlayer_getMediaController); tolua_function(tolua_S,"create", lua_ax_video_MediaPlayer_create); From ca81b1bcfa9dbb88afdde47b08e5625b69148327 Mon Sep 17 00:00:00 2001 From: halx99 Date: Sat, 23 May 2026 00:10:23 +0800 Subject: [PATCH 41/52] Improve ios IME delegate --- axmol/base/IMEDelegate.h | 7 +++++++ axmol/base/IMEDispatcher.cpp | 26 ++++++++------------------ axmol/base/IMEDispatcher.h | 2 ++ axmol/platform/RenderView.h | 6 +++--- axmol/platform/ios/InputView-ios.mm | 24 +++++++++++++++++++++++- axmol/ui/InputField.cpp | 26 +++++++++++++++++++++----- axmol/ui/InputField.h | 1 + 7 files changed, 65 insertions(+), 27 deletions(-) diff --git a/axmol/base/IMEDelegate.h b/axmol/base/IMEDelegate.h index 3d8acaed2248..32224cf40843 100644 --- a/axmol/base/IMEDelegate.h +++ b/axmol/base/IMEDelegate.h @@ -77,6 +77,13 @@ class AX_DLL IMEDelegate */ virtual bool detachWithIME(); + /** + * @brief IME hit-test. + * @param location Touch point in axmol world coordinates. + * @return true to keep the IME active; false otherwise. + */ + virtual bool onHitTestWithIME(const Vec2& location) { return false; } + protected: friend class IMEDispatcher; diff --git a/axmol/base/IMEDispatcher.cpp b/axmol/base/IMEDispatcher.cpp index ec7fd98d93ce..89829f3842fd 100644 --- a/axmol/base/IMEDispatcher.cpp +++ b/axmol/base/IMEDispatcher.cpp @@ -95,6 +95,11 @@ IMEDispatcher::~IMEDispatcher() AX_SAFE_DELETE(_impl); } +IMEDelegate* IMEDispatcher::getAttachedDelegate() const +{ + return _impl ? _impl->_delegateWithIme : nullptr; +} + ////////////////////////////////////////////////////////////////////////// // Add/Attach/Remove IMEDelegate ////////////////////////////////////////////////////////////////////////// @@ -214,36 +219,21 @@ void IMEDispatcher::dispatchInsertText(std::string_view text) void IMEDispatcher::dispatchDeleteBackward(unsigned int numChars) { - do - { - AX_BREAK_IF(!_impl); - - // there is no delegate attached to IME - AX_BREAK_IF(!_impl->_delegateWithIme); - + if (_impl && _impl->_delegateWithIme) _impl->_delegateWithIme->deleteBackward(numChars); - } while (0); } void IMEDispatcher::dispatchControlKey(EventKeyboard::KeyCode keyCode) { - do - { - AX_BREAK_IF(!_impl); - - // there is no delegate attached to IME - AX_BREAK_IF(!_impl->_delegateWithIme); - + if (_impl && _impl->_delegateWithIme) _impl->_delegateWithIme->controlKey(keyCode); - } while (0); } std::string_view IMEDispatcher::getContentText() { if (_impl && _impl->_delegateWithIme) - { return _impl->_delegateWithIme->getContentText(); - } + return STD_STRING_EMPTY; } diff --git a/axmol/base/IMEDispatcher.h b/axmol/base/IMEDispatcher.h index e77c43791f36..6ce81d2684fb 100644 --- a/axmol/base/IMEDispatcher.h +++ b/axmol/base/IMEDispatcher.h @@ -52,6 +52,8 @@ class AX_DLL IMEDispatcher */ static IMEDispatcher* getInstance(); + IMEDelegate* getAttachedDelegate() const; + void dispatchUpdatePreedit(std::string_view preeditText, int caret); /** diff --git a/axmol/platform/RenderView.h b/axmol/platform/RenderView.h index b41bd1510c80..3a29ebf3d0b9 100644 --- a/axmol/platform/RenderView.h +++ b/axmol/platform/RenderView.h @@ -484,10 +484,10 @@ class AX_DLL RenderView : public Object */ [[internal]] void updateRenderSurface(float width, float height, uint8_t updateFlag); -protected: - float transformInputX(float x) { return (x - _viewportRect.origin.x) / _viewScale.x; } - float transformInputY(float y) { return (y - _viewportRect.origin.y) / _viewScale.y; } + [[internal]] float transformInputX(float x) { return (x - _viewportRect.origin.x) / _viewScale.x; } + [[internal]] float transformInputY(float y) { return (y - _viewportRect.origin.y) / _viewScale.y; } +protected: void maybeDispatchResizeEvent(uint8_t updateFlag); /** diff --git a/axmol/platform/ios/InputView-ios.mm b/axmol/platform/ios/InputView-ios.mm index 31876b193f3e..4f7de4521e8c 100644 --- a/axmol/platform/ios/InputView-ios.mm +++ b/axmol/platform/ios/InputView-ios.mm @@ -45,6 +45,7 @@ - (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { + self.contentScaleFactor = [[UIScreen mainScreen] scale]; self.myMarkedText = nil; self.autocorrectionType = UITextAutocorrectionTypeNo; } @@ -65,6 +66,27 @@ - (BOOL)canBecomeFirstResponder return YES; } +- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event +{ + ax::IMEDelegate* attachedDelegate = ax::IMEDispatcher::getInstance()->getAttachedDelegate(); + if (attachedDelegate) + { + ax::Vec2 pt{static_cast(point.x * [self contentScaleFactor]), static_cast(point.y * [self contentScaleFactor])}; + auto director = ax::Director::getInstance(); + auto renderView = director->getRenderView(); + // convert UIKit to axmol screen coordinate + pt.x = renderView->transformInputX(pt.x); + pt.y = renderView->transformInputY(pt.y); + // convert axmol screen to world coordinate + pt = director->screenToWorld(pt); + + bool keep = attachedDelegate->onHitTestWithIME(pt); + if (keep) + return NO; + } + return YES; +} + - (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event { [self resignFirstResponder]; @@ -98,7 +120,7 @@ - (void)deleteBackward [self.myMarkedText release]; self.myMarkedText = nil; } - ax::IMEDispatcher::getInstance()->dispatchDeleteBackward(static_cast(1)); + ax::IMEDispatcher::getInstance()->dispatchDeleteBackward(1u); } - (void)insertText:(nonnull NSString*)text diff --git a/axmol/ui/InputField.cpp b/axmol/ui/InputField.cpp index 648daca44dfa..c478a207c33a 100644 --- a/axmol/ui/InputField.cpp +++ b/axmol/ui/InputField.cpp @@ -423,22 +423,29 @@ bool InputField::detachWithIME() bool ret = IMEDelegate::detachWithIME(); if (ret) { + _isAttachWithIME = false; + + // Hide cursor immediately + hideCursor(); + // Close keyboard RenderView* renderView = _director->getRenderView(); if (renderView) renderView->setIMEKeyboardState(false); - // Hide cursor immediately - hideCursor(); - // Dispatch event before removing listeners dispatchEvent(EventType::DETACH_WITH_IME); - - _isAttachWithIME = false; } return ret; } +bool InputField::onHitTestWithIME(const Vec2& location) +{ + auto camera = Camera::getDefaultCamera(); + bool hitted = hitTest(location, camera, nullptr); + return hitted; +} + void InputField::keyboardDidShow(IMEKeyboardNotificationInfo& /*info*/) { s_keyboardVisible = true; @@ -447,6 +454,15 @@ void InputField::keyboardDidShow(IMEKeyboardNotificationInfo& /*info*/) void InputField::keyboardDidHide(IMEKeyboardNotificationInfo& /*info*/) { s_keyboardVisible = false; + + bool ret = IMEDelegate::detachWithIME(); + if (ret) + { + _isAttachWithIME = false; + + // Hide cursor immediately + hideCursor(); + } } void InputField::addEventListener(const InputFieldCallback& callback) diff --git a/axmol/ui/InputField.h b/axmol/ui/InputField.h index e4999d9c8559..f39163bd4101 100644 --- a/axmol/ui/InputField.h +++ b/axmol/ui/InputField.h @@ -449,6 +449,7 @@ class AX_DLL InputField : public Widget, public IMEDelegate */ bool detachWithIME() override; + bool onHitTestWithIME(const Vec2& location) override; void keyboardDidShow(IMEKeyboardNotificationInfo& /*info*/) override; void keyboardDidHide(IMEKeyboardNotificationInfo& /*info*/) override; From 0a2ce4a2d7021a002a596995242593f9c0af8c05 Mon Sep 17 00:00:00 2001 From: axmol-bot <116471739+axmol-bot@users.noreply.github.com> Date: Fri, 22 May 2026 16:12:17 +0000 Subject: [PATCH 42/52] Committing clang-format changes --- axmol/platform/ios/InputView-ios.mm | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/axmol/platform/ios/InputView-ios.mm b/axmol/platform/ios/InputView-ios.mm index 4f7de4521e8c..705b21afab25 100644 --- a/axmol/platform/ios/InputView-ios.mm +++ b/axmol/platform/ios/InputView-ios.mm @@ -66,20 +66,21 @@ - (BOOL)canBecomeFirstResponder return YES; } -- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event +- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent*)event { ax::IMEDelegate* attachedDelegate = ax::IMEDispatcher::getInstance()->getAttachedDelegate(); if (attachedDelegate) { - ax::Vec2 pt{static_cast(point.x * [self contentScaleFactor]), static_cast(point.y * [self contentScaleFactor])}; - auto director = ax::Director::getInstance(); + ax::Vec2 pt{static_cast(point.x * [self contentScaleFactor]), + static_cast(point.y * [self contentScaleFactor])}; + auto director = ax::Director::getInstance(); auto renderView = director->getRenderView(); // convert UIKit to axmol screen coordinate pt.x = renderView->transformInputX(pt.x); pt.y = renderView->transformInputY(pt.y); // convert axmol screen to world coordinate pt = director->screenToWorld(pt); - + bool keep = attachedDelegate->onHitTestWithIME(pt); if (keep) return NO; From f219568f066c2f651cfcfe4624983266c88a7d74 Mon Sep 17 00:00:00 2001 From: halx99 Date: Sat, 23 May 2026 00:32:10 +0800 Subject: [PATCH 43/52] Fix reviews --- axmol/base/text_utils.cpp | 7 +++---- axmol/ui/InputField.cpp | 19 +++++++++---------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/axmol/base/text_utils.cpp b/axmol/base/text_utils.cpp index 62668d67f5e8..b49848157536 100644 --- a/axmol/base/text_utils.cpp +++ b/axmol/base/text_utils.cpp @@ -368,9 +368,7 @@ size_t countUTF8Chars(std::string_view strUTF8) UTF8CountResult countUTF8WithLimit(std::string_view strUTF8, size_t charLimit) { - UTF8CountResult result; - result.charCount = 0; - result.byteCount = 0; + UTF8CountResult result{}; if (!strUTF8.empty() && charLimit > 0) { @@ -384,7 +382,8 @@ UTF8CountResult countUTF8WithLimit(std::string_view strUTF8, size_t charLimit) if (size == 0) { // Invalid UTF-8 sequence found - return UTF8CountResult{}; + result.success = false; + break; } source += size; ++result.charCount; diff --git a/axmol/ui/InputField.cpp b/axmol/ui/InputField.cpp index c478a207c33a..7785f7e8af26 100644 --- a/axmol/ui/InputField.cpp +++ b/axmol/ui/InputField.cpp @@ -520,13 +520,12 @@ void InputField::insertText(std::string_view text) deleteSelection(false); // In multiline mode we allow newline characters; otherwise they signify commit and we strip them. - std::string insertStr(text); if (!_multilineEnabled) { - auto pos = insertStr.find('\n'); + auto pos = text.find_first_of("\r\n"); if (pos != std::string::npos) - insertStr.erase(pos); - if (insertStr.empty()) + text = text.substr(0, pos); // text.erase(pos); + if (text.empty()) return; } @@ -542,29 +541,29 @@ void InputField::insertText(std::string_view text) return; } // Truncate insertStr to not exceed limit - auto result = text_utils::countUTF8WithLimit(insertStr, remaining); + auto result = text_utils::countUTF8WithLimit(text, remaining); if (!result) { axbeep(0); return; } - insertStr.resize(result.byteCount); + text = text.substr(0, result.byteCount); numOfChars = result.charCount; } else { - numOfChars = text_utils::countUTF8Chars(insertStr); + numOfChars = text_utils::countUTF8Chars(text); } - if (insertStr.empty()) + if (text.empty()) return; std::string sText(_inputText); auto cursorIndex = static_cast(_cursorCharIndex); - sText.insert(_cursorByteIndex, insertStr); + sText.insert(_cursorByteIndex, text); this->setString(sText); - setCursorPosition(cursorIndex + numOfChars, false); + setCursorPosition(cursorIndex + static_cast(numOfChars), false); dispatchEvent(EventType::INSERT_TEXT); } From a950fb84ecb9be782b2e313a7337f85915aa73e4 Mon Sep 17 00:00:00 2001 From: halx99 Date: Sat, 23 May 2026 00:56:27 +0800 Subject: [PATCH 44/52] Improve performance --- axmol/ui/InputField.cpp | 112 +++++++++++++++++++++++++++++----------- axmol/ui/InputField.h | 2 + 2 files changed, 84 insertions(+), 30 deletions(-) diff --git a/axmol/ui/InputField.cpp b/axmol/ui/InputField.cpp index 7785f7e8af26..895c01f36281 100644 --- a/axmol/ui/InputField.cpp +++ b/axmol/ui/InputField.cpp @@ -524,7 +524,7 @@ void InputField::insertText(std::string_view text) { auto pos = text.find_first_of("\r\n"); if (pos != std::string::npos) - text = text.substr(0, pos); // text.erase(pos); + text = text.substr(0, pos); // text.erase(pos); if (text.empty()) return; } @@ -547,7 +547,7 @@ void InputField::insertText(std::string_view text) axbeep(0); return; } - text = text.substr(0, result.byteCount); + text = text.substr(0, result.byteCount); numOfChars = result.charCount; } else @@ -558,12 +558,20 @@ void InputField::insertText(std::string_view text) if (text.empty()) return; - std::string sText(_inputText); - auto cursorIndex = static_cast(_cursorCharIndex); - sText.insert(_cursorByteIndex, text); + auto oldInsertCharIndex = static_cast(_cursorCharIndex); + bool bInsertAtEnd = (oldInsertCharIndex == static_cast(_charCount)); + + // 1. Performance optimization: Modify _inputText in-place to avoid full string allocation or copying + _inputText.insert(_cursorByteIndex, text.data(), text.size()); - this->setString(sText); - setCursorPosition(cursorIndex + static_cast(numOfChars), false); + // 2. Incremental optimization: Simply add the new character count to the existing total + auto newCharCount = _charCount + static_cast(numOfChars); + + // 3. Reuse the core presentation logic + updatePresentation(newCharCount, oldInsertCharIndex, bInsertAtEnd); + + // 4. Advance the cursor position by the number of inserted characters + setCursorPosition(oldInsertCharIndex + static_cast(numOfChars), false); dispatchEvent(EventType::INSERT_TEXT); } @@ -594,21 +602,32 @@ void InputField::deleteBackward(unsigned int numChars) auto startByteIndex = getByteOffset(startCharIndex); auto totalDeleteLen = _cursorByteIndex - startByteIndex; - // if all text deleted, show placeholder string + _charByteOffsetDirty = true; + _layoutDirty = true; + + auto oldInsertCharIndex = static_cast(_cursorCharIndex); + bool bInsertAtEnd = (oldInsertCharIndex == static_cast(_charCount)); + + // If all text is deleted, fast-clear the buffer if (len <= totalDeleteLen) { - this->setString(""); - setCursorPosition(0, false); + _inputText.clear(); + updatePresentation(0, 0, false); dispatchEvent(EventType::DELETE_BACKWARD); return; } - // set new input text - std::string text = _inputText; - text.erase(startByteIndex, totalDeleteLen); + // Performance optimization: Erase characters in-place to avoid copying the whole string + _inputText.erase(startByteIndex, totalDeleteLen); - this->setString(text); + // Incremental optimization: Safely subtract the deleted character count + uint32_t newCharCount = (_charCount > static_cast(deleteChars)) ? (_charCount - deleteChars) : 0; + + // Reuse the core presentation and layout logic + updatePresentation(newCharCount, oldInsertCharIndex, bInsertAtEnd); + + // Update the final cursor position to the deletion starting point setCursorPosition(startCharIndex, false); dispatchEvent(EventType::DELETE_BACKWARD); @@ -638,21 +657,32 @@ void InputField::handleDeleteKeyEvent() auto nextByteIndex = getByteOffset(_cursorCharIndex + 1); auto deleteLen = nextByteIndex - _cursorByteIndex; - // if all text deleted, show placeholder string + _charByteOffsetDirty = true; + _layoutDirty = true; + + auto oldInsertCharIndex = static_cast(_cursorCharIndex); + bool bInsertAtEnd = (oldInsertCharIndex == static_cast(_charCount)); + + // If all text is deleted, fast-clear the buffer if (len <= deleteLen) { - this->setString(""); - setCursorPosition(0, false); + _inputText.clear(); + updatePresentation(0, 0, false); dispatchEvent(EventType::DELETE_BACKWARD); return; } - // set new input text - std::string text = _inputText; - text.erase(_cursorByteIndex, deleteLen); + // Performance optimization: Erase the forward character in-place without heap allocations + _inputText.erase(_cursorByteIndex, deleteLen); + + // Incremental optimization: Simply decrement the total character count by 1 + size_t newCharCount = (_charCount > 0) ? (_charCount - 1) : 0; + + // Reuse the core presentation and layout logic + updatePresentation(newCharCount, oldInsertCharIndex, bInsertAtEnd); - this->setString(text); + // Maintain the cursor position at the current index setCursorPosition(_cursorCharIndex, false); dispatchEvent(EventType::DELETE_BACKWARD); @@ -723,16 +753,17 @@ Vec2 InputField::resolvePreferredSize(const Vec2& /*sizeHint*/) const // input text property void InputField::setString(std::string_view text) { - _charByteOffsetDirty = true; - _layoutDirty = true; - auto oldInsertCharIndex = static_cast(_cursorCharIndex); bool bInsertAtEnd = (oldInsertCharIndex == static_cast(_charCount)); _inputText = text; auto newCharCount = text_utils::countUTF8Chars(_inputText); - std::string secureText; + updatePresentation(static_cast(newCharCount), oldInsertCharIndex, bInsertAtEnd); +} +void InputField::updatePresentation(uint32_t newCharCount, int oldInsertCharIndex, bool bInsertAtEnd) +{ + std::string secureText; std::string* displayText = &_inputText; if (!_inputText.empty()) @@ -742,6 +773,9 @@ void InputField::setString(std::string_view text) size_t length = newCharCount; displayText = &secureText; + // Pre-reserve memory to prevent frequent reallocation during appending + displayText->reserve(length * _passwordChar.size()); + while (length > 0) { displayText->append(_passwordChar); @@ -750,7 +784,7 @@ void InputField::setString(std::string_view text) } } - // if there is no input text, display placeholder instead + // Toggle between the text and the placeholder if (_inputText.empty()) { _renderLabel->setTextColor(_colorSpaceHolder); @@ -762,6 +796,7 @@ void InputField::setString(std::string_view text) _renderLabel->setString(*displayText); } + // Direct assignment avoids recalculating the whole string length _charCount = static_cast(newCharCount); // Update content size to match the rendered text @@ -779,7 +814,8 @@ void InputField::setString(std::string_view text) _selectionStart = (std::min)(_selectionStart, static_cast(_charCount)); _selectionEnd = (std::min)(_selectionEnd, static_cast(_charCount)); - _layoutDirty = true; + _charByteOffsetDirty = true; + _layoutDirty = true; } void InputField::updateContentSize() @@ -1233,9 +1269,25 @@ bool InputField::deleteSelection(bool notify) auto endByte = getByteOffset(_selectionEnd); auto newCursor = _selectionStart; - std::string text = _inputText; - text.erase(startByte, endByte - startByte); - this->setString(text); + // Calculate how many characters are being removed before mutating the string + size_t deletedCharCount = static_cast(_selectionEnd - _selectionStart); + + _charByteOffsetDirty = true; + _layoutDirty = true; + + auto oldInsertCharIndex = static_cast(_cursorCharIndex); + bool bInsertAtEnd = (oldInsertCharIndex == static_cast(_charCount)); + + // Performance optimization: Erase the selected slice in-place + _inputText.erase(startByte, endByte - startByte); + + // Incremental optimization: Deduct the exact selection block length + size_t newCharCount = (_charCount > deletedCharCount) ? (_charCount - deletedCharCount) : 0; + + // Reuse the core presentation and layout logic + updatePresentation(newCharCount, oldInsertCharIndex, bInsertAtEnd); + + // Reposition the cursor to where the selection started setCursorPosition(newCursor, false); if (notify) diff --git a/axmol/ui/InputField.h b/axmol/ui/InputField.h index f39163bd4101..d98ce42603df 100644 --- a/axmol/ui/InputField.h +++ b/axmol/ui/InputField.h @@ -423,6 +423,8 @@ class AX_DLL InputField : public Widget, public IMEDelegate void addEventListener(const InputFieldCallback& callback); protected: + void updatePresentation(uint32_t newCharCount, int oldInsertCharIndex, bool bInsertAtEnd); + ////////////////////////////////////////////////////////////////////////// void onEnter() override; From 00d565bf4e98f7d36cd8a599ceab12da113834cf Mon Sep 17 00:00:00 2001 From: halx99 Date: Sat, 23 May 2026 00:59:59 +0800 Subject: [PATCH 45/52] Fix reviews --- axmol/platform/desktop/RenderViewImpl.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/axmol/platform/desktop/RenderViewImpl.cpp b/axmol/platform/desktop/RenderViewImpl.cpp index b0d0dba11c95..01c508c51d05 100644 --- a/axmol/platform/desktop/RenderViewImpl.cpp +++ b/axmol/platform/desktop/RenderViewImpl.cpp @@ -1440,6 +1440,7 @@ void RenderViewImpl::onGLFWKeyCallback(GLFWwindow* /*window*/, int key, int /*sc IMEDispatcher::getInstance()->dispatchControlKey(g_keyCodeMap[key]); break; case EventKeyboard::KeyCode::KEY_ENTER: + case EventKeyboard::KeyCode::KEY_KP_ENTER: IMEDispatcher::getInstance()->dispatchInsertText("\n"sv); break; default: @@ -1490,20 +1491,21 @@ void RenderViewImpl::onGLFWCharCallback(GLFWwindow* /*window*/, unsigned int cha void RenderViewImpl::onGLFWPreeditCallback(GLFWwindow* window, int preedit_count, unsigned int* preedit_string, // UTF-32 - int block_count, - int* block_sizes, - int focused_block, + int /*block_count*/, + int* /*block_sizes*/, + int /*focused_block*/, int caret) { + std::string utf8String; + if (preedit_count > 0) { - std::string utf8String; text_utils::UTF32ToUTF8( std::u32string_view{std::bit_cast(preedit_string), static_cast(preedit_count)}, utf8String); - - IMEDispatcher::getInstance()->dispatchUpdatePreedit(utf8String, caret); } + + IMEDispatcher::getInstance()->dispatchUpdatePreedit(utf8String, caret); } void RenderViewImpl::onGLFWWindowPosCallback(GLFWwindow* /*window*/, int x, int y) From 1ac4324e40c61df2b293fab18f176390a75e9f0b Mon Sep 17 00:00:00 2001 From: halx99 Date: Sat, 23 May 2026 09:57:15 +0800 Subject: [PATCH 46/52] Add clipboard APIs to platform/Device.h --- axmol/axmol.h | 4 +- axmol/base/CMakeLists.txt | 6 +- axmol/base/{IMEDelegate.h => InputDelegate.h} | 32 +++---- ...{IMEDispatcher.cpp => InputDispatcher.cpp} | 89 ++++++++++--------- .../{IMEDispatcher.h => InputDispatcher.h} | 49 ++++++---- axmol/platform/Device.h | 19 ++++ axmol/platform/android/Device-android.cpp | 15 ++++ .../java/src/dev/axmol/lib/AxmolEngine.java | 26 +++++- axmol/platform/android/jni/AxmolPlayerJni.cpp | 8 +- axmol/platform/desktop/Device-desktop.cpp | 16 ++++ axmol/platform/desktop/RenderViewImpl.cpp | 12 +-- axmol/platform/ios/Device-ios.mm | 19 ++++ axmol/platform/ios/InputView-ios.mm | 14 +-- axmol/platform/ios/RenderHostView-ios.mm | 4 +- axmol/platform/winrt/InputEvent.cpp | 8 +- axmol/platform/winrt/Keyboard-winrt.cpp | 8 +- axmol/platform/winrt/RenderViewImpl-winrt.cpp | 2 +- axmol/ui/EditBox/EditBox.h | 4 +- axmol/ui/InputField.cpp | 82 ++++++----------- axmol/ui/InputField.h | 18 ++-- .../ImGui/backends/imgui_impl_axmol_sw.cpp | 7 +- extensions/sceneio/CMakeLists.txt | 1 - .../src/sceneio/ActionTimeline/CSLoader.cpp | 14 ++- .../src/sceneio/FlatBuffersSerialize.cpp | 6 ++ .../TextFieldReader/TextFieldExReader.cpp | 12 +-- .../TextFieldReader/TextFieldReader.cpp | 42 +++++---- extensions/sceneio/src/sceneio/sceneio.cpp | 4 + 27 files changed, 315 insertions(+), 206 deletions(-) rename axmol/base/{IMEDelegate.h => InputDelegate.h} (86%) rename axmol/base/{IMEDispatcher.cpp => InputDispatcher.cpp} (74%) rename axmol/base/{IMEDispatcher.h => InputDispatcher.h} (71%) diff --git a/axmol/axmol.h b/axmol/axmol.h index 992239ec54d5..4b13e6a79a57 100644 --- a/axmol/axmol.h +++ b/axmol/axmol.h @@ -42,8 +42,8 @@ THE SOFTWARE. #include "axmol/base/Logging.h" #include "axmol/base/Data.h" #include "axmol/base/Director.h" -#include "axmol/base/IMEDelegate.h" -#include "axmol/base/IMEDispatcher.h" +#include "axmol/base/InputDelegate.h" +#include "axmol/base/InputDispatcher.h" #include "axmol/base/Map.h" #include "axmol/base/Profiling.h" #include "axmol/base/Properties.h" diff --git a/axmol/base/CMakeLists.txt b/axmol/base/CMakeLists.txt index 57598aad325f..88196ebb1121 100644 --- a/axmol/base/CMakeLists.txt +++ b/axmol/base/CMakeLists.txt @@ -65,7 +65,7 @@ set(_AX_BASE_HEADER base/Protocols.h base/TGAlib.h base/EventMouse.h - base/IMEDelegate.h + base/InputDelegate.h base/AutoreleasePool.h base/StencilStateManager.h base/EventListenerTouch.h @@ -74,7 +74,7 @@ set(_AX_BASE_HEADER base/EventListener.h base/Scheduler.h base/EventType.h - base/IMEDispatcher.h + base/InputDispatcher.h base/JsonWriter.h base/JobSystem.h ) @@ -105,7 +105,7 @@ set(_AX_BASE_SRC base/EventListenerTouch.cpp base/EventMouse.cpp base/EventTouch.cpp - base/IMEDispatcher.cpp + base/InputDispatcher.cpp base/Profiling.cpp base/Properties.cpp base/Object.cpp diff --git a/axmol/base/IMEDelegate.h b/axmol/base/InputDelegate.h similarity index 86% rename from axmol/base/IMEDelegate.h rename to axmol/base/InputDelegate.h index 32224cf40843..0c3b6dea7e3d 100644 --- a/axmol/base/IMEDelegate.h +++ b/axmol/base/InputDelegate.h @@ -54,16 +54,16 @@ typedef struct } IMEKeyboardNotificationInfo; /** - *@brief Input method editor delegate. + *@brief Input delegate. */ -class AX_DLL IMEDelegate +class AX_DLL InputDelegate { public: /** * Default constructor. * @lua NA */ - virtual ~IMEDelegate(); + virtual ~InputDelegate(); /** * Default destructor. @@ -77,25 +77,25 @@ class AX_DLL IMEDelegate */ virtual bool detachWithIME(); +protected: + friend class InputDispatcher; + /** * @brief IME hit-test. * @param location Touch point in axmol world coordinates. * @return true to keep the IME active; false otherwise. */ - virtual bool onHitTestWithIME(const Vec2& location) { return false; } - -protected: - friend class IMEDispatcher; + virtual bool hitTestWithIME(const Vec2& location) { return false; } /** @brief Decide if the delegate instance is ready to receive an IME message. - Called by IMEDispatcher. + Called by InputDispatcher. * @lua NA */ virtual bool canAttachWithIME() { return false; } /** - @brief When the delegate detaches from the IME, this method is called by IMEDispatcher. + @brief When the delegate detaches from the IME, this method is called by InputDispatcher. * @lua NA */ virtual void didAttachWithIME() {} @@ -107,37 +107,37 @@ class AX_DLL IMEDelegate virtual bool canDetachWithIME() { return false; } /** - @brief When the delegate detaches from the IME, this method is called by IMEDispatcher. + @brief When the delegate detaches from the IME, this method is called by InputDispatcher. * @lua NA */ virtual void didDetachWithIME() {} /** - @brief Called by IMEDispatcher when text input received from the IME. + @brief Called by InputDispatcher when text input received from the IME. * @lua NA */ virtual void insertText(std::string_view /*text*/) {} /** - @brief Called by IMEDispatcher when the preedit text is updated. + @brief Called by InputDispatcher when the preedit text is updated. * @lua NA */ virtual void updatePreeditText(std::string_view /*text*/, int /*caretPos*/) {} /** - @brief Called by IMEDispatcher after the user clicks the backward key. + @brief Called by InputDispatcher after the user clicks the backward key. * @lua NA */ virtual void deleteBackward(unsigned int numChars) {} /** - @brief Called by IMEDispatcher after the user press control key. + @brief Called by InputDispatcher after the user press control key. * @lua NA */ virtual void controlKey(EventKeyboard::KeyCode /*keyCode*/) {} /** - @brief Called by IMEDispatcher for text stored in delegate. + @brief Called by InputDispatcher for text stored in delegate. * @lua NA */ virtual std::string_view getContentText() const { return STD_STRING_EMPTY; } @@ -166,7 +166,7 @@ class AX_DLL IMEDelegate /** * @lua NA */ - IMEDelegate(); + InputDelegate(); }; } // namespace ax diff --git a/axmol/base/IMEDispatcher.cpp b/axmol/base/InputDispatcher.cpp similarity index 74% rename from axmol/base/IMEDispatcher.cpp rename to axmol/base/InputDispatcher.cpp index 89829f3842fd..188b46abdc77 100644 --- a/axmol/base/IMEDispatcher.cpp +++ b/axmol/base/InputDispatcher.cpp @@ -24,7 +24,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ -#include "axmol/base/IMEDispatcher.h" +#include "axmol/base/InputDispatcher.h" #include @@ -32,42 +32,42 @@ namespace ax { ////////////////////////////////////////////////////////////////////////// -// add/remove delegate in IMEDelegate Cons/Destructor +// add/remove delegate in InputDelegate Cons/Destructor ////////////////////////////////////////////////////////////////////////// -IMEDelegate::IMEDelegate() +InputDelegate::InputDelegate() { - IMEDispatcher::getInstance()->addDelegate(this); + InputDispatcher::getInstance()->addDelegate(this); } -IMEDelegate::~IMEDelegate() +InputDelegate::~InputDelegate() { - IMEDispatcher::getInstance()->removeDelegate(this); + InputDispatcher::getInstance()->removeDelegate(this); } -bool IMEDelegate::attachWithIME() +bool InputDelegate::attachWithIME() { - return IMEDispatcher::getInstance()->attachDelegateWithIME(this); + return InputDispatcher::getInstance()->attachDelegateWithIME(this); } -bool IMEDelegate::detachWithIME() +bool InputDelegate::detachWithIME() { - return IMEDispatcher::getInstance()->detachDelegateWithIME(this); + return InputDispatcher::getInstance()->detachDelegateWithIME(this); } ////////////////////////////////////////////////////////////////////////// -typedef std::list DelegateList; -typedef std::list::iterator DelegateIter; +typedef std::list DelegateList; +typedef std::list::iterator DelegateIter; ////////////////////////////////////////////////////////////////////////// // Delegate List manage class ////////////////////////////////////////////////////////////////////////// -class IMEDispatcher::Impl +class InputDispatcher::Impl { public: - DelegateIter findDelegate(IMEDelegate* delegate) + DelegateIter findDelegate(InputDelegate* delegate) { DelegateIter end = _delegateList.end(); for (DelegateIter iter = _delegateList.begin(); iter != end; ++iter) @@ -81,30 +81,37 @@ class IMEDispatcher::Impl } DelegateList _delegateList{}; - IMEDelegate* _delegateWithIme{nullptr}; + InputDelegate* _delegateWithIme{nullptr}; }; ////////////////////////////////////////////////////////////////////////// // Cons/Destructor ////////////////////////////////////////////////////////////////////////// -IMEDispatcher::IMEDispatcher() : _impl(new IMEDispatcher::Impl) {} +InputDispatcher::InputDispatcher() : _impl(new InputDispatcher::Impl) {} -IMEDispatcher::~IMEDispatcher() +InputDispatcher::~InputDispatcher() { AX_SAFE_DELETE(_impl); } -IMEDelegate* IMEDispatcher::getAttachedDelegate() const +bool InputDispatcher::hasAttachedDelegate() const { - return _impl ? _impl->_delegateWithIme : nullptr; + return _impl && _impl->_delegateWithIme != nullptr; +} + +bool InputDispatcher::dispatchHitTestWithIME(const Vec2& location) +{ + if (_impl && _impl->_delegateWithIme) + return _impl->_delegateWithIme->hitTestWithIME(location); + return false; } ////////////////////////////////////////////////////////////////////////// -// Add/Attach/Remove IMEDelegate +// Add/Attach/Remove InputDelegate ////////////////////////////////////////////////////////////////////////// -void IMEDispatcher::addDelegate(IMEDelegate* delegate) +void InputDispatcher::addDelegate(InputDelegate* delegate) { if (!delegate || !_impl) { @@ -118,7 +125,7 @@ void IMEDispatcher::addDelegate(IMEDelegate* delegate) _impl->_delegateList.push_front(delegate); } -bool IMEDispatcher::attachDelegateWithIME(IMEDelegate* delegate) +bool InputDispatcher::attachDelegateWithIME(InputDelegate* delegate) { bool ret = false; do @@ -141,7 +148,7 @@ bool IMEDispatcher::attachDelegateWithIME(IMEDelegate* delegate) AX_BREAK_IF(!_impl->_delegateWithIme->canDetachWithIME() || !delegate->canAttachWithIME()); // detach first - IMEDelegate* oldDelegate = _impl->_delegateWithIme; + InputDelegate* oldDelegate = _impl->_delegateWithIme; _impl->_delegateWithIme = 0; oldDelegate->didDetachWithIME(); @@ -162,7 +169,7 @@ bool IMEDispatcher::attachDelegateWithIME(IMEDelegate* delegate) return ret; } -bool IMEDispatcher::detachDelegateWithIME(IMEDelegate* delegate) +bool InputDispatcher::detachDelegateWithIME(InputDelegate* delegate) { bool ret = false; do @@ -181,7 +188,7 @@ bool IMEDispatcher::detachDelegateWithIME(IMEDelegate* delegate) return ret; } -void IMEDispatcher::removeDelegate(IMEDelegate* delegate) +void InputDispatcher::removeDelegate(InputDelegate* delegate) { do { @@ -201,9 +208,9 @@ void IMEDispatcher::removeDelegate(IMEDelegate* delegate) } while (0); } -void IMEDispatcher::dispatchUpdatePreedit(std::string_view preeditText, int caret) +void InputDispatcher::dispatchUpdatePreedit(std::string_view preeditText, int caret) { - if (_impl && _impl->_delegateWithIme && !preeditText.empty()) + if (_impl && _impl->_delegateWithIme) _impl->_delegateWithIme->updatePreeditText(preeditText, caret); } @@ -211,25 +218,25 @@ void IMEDispatcher::dispatchUpdatePreedit(std::string_view preeditText, int care // dispatch text message ////////////////////////////////////////////////////////////////////////// -void IMEDispatcher::dispatchInsertText(std::string_view text) +void InputDispatcher::dispatchInsertText(std::string_view text) { if (_impl && _impl->_delegateWithIme && !text.empty()) _impl->_delegateWithIme->insertText(text); } -void IMEDispatcher::dispatchDeleteBackward(unsigned int numChars) +void InputDispatcher::dispatchDeleteBackward(unsigned int numChars) { if (_impl && _impl->_delegateWithIme) _impl->_delegateWithIme->deleteBackward(numChars); } -void IMEDispatcher::dispatchControlKey(EventKeyboard::KeyCode keyCode) +void InputDispatcher::dispatchControlKey(EventKeyboard::KeyCode keyCode) { if (_impl && _impl->_delegateWithIme) _impl->_delegateWithIme->controlKey(keyCode); } -std::string_view IMEDispatcher::getContentText() +std::string_view InputDispatcher::getContentText() { if (_impl && _impl->_delegateWithIme) return _impl->_delegateWithIme->getContentText(); @@ -241,11 +248,11 @@ std::string_view IMEDispatcher::getContentText() // dispatch keyboard message ////////////////////////////////////////////////////////////////////////// -void IMEDispatcher::dispatchKeyboardWillShow(IMEKeyboardNotificationInfo& info) +void InputDispatcher::dispatchKeyboardWillShow(IMEKeyboardNotificationInfo& info) { if (_impl) { - IMEDelegate* delegate = nullptr; + InputDelegate* delegate = nullptr; DelegateIter last = _impl->_delegateList.end(); for (DelegateIter first = _impl->_delegateList.begin(); first != last; ++first) { @@ -258,11 +265,11 @@ void IMEDispatcher::dispatchKeyboardWillShow(IMEKeyboardNotificationInfo& info) } } -void IMEDispatcher::dispatchKeyboardDidShow(IMEKeyboardNotificationInfo& info) +void InputDispatcher::dispatchKeyboardDidShow(IMEKeyboardNotificationInfo& info) { if (_impl) { - IMEDelegate* delegate = nullptr; + InputDelegate* delegate = nullptr; DelegateIter last = _impl->_delegateList.end(); for (DelegateIter first = _impl->_delegateList.begin(); first != last; ++first) { @@ -275,11 +282,11 @@ void IMEDispatcher::dispatchKeyboardDidShow(IMEKeyboardNotificationInfo& info) } } -void IMEDispatcher::dispatchKeyboardWillHide(IMEKeyboardNotificationInfo& info) +void InputDispatcher::dispatchKeyboardWillHide(IMEKeyboardNotificationInfo& info) { if (_impl) { - IMEDelegate* delegate = nullptr; + InputDelegate* delegate = nullptr; DelegateIter last = _impl->_delegateList.end(); for (DelegateIter first = _impl->_delegateList.begin(); first != last; ++first) { @@ -292,11 +299,11 @@ void IMEDispatcher::dispatchKeyboardWillHide(IMEKeyboardNotificationInfo& info) } } -void IMEDispatcher::dispatchKeyboardDidHide(IMEKeyboardNotificationInfo& info) +void InputDispatcher::dispatchKeyboardDidHide(IMEKeyboardNotificationInfo& info) { if (_impl) { - IMEDelegate* delegate = nullptr; + InputDelegate* delegate = nullptr; DelegateIter last = _impl->_delegateList.end(); for (DelegateIter first = _impl->_delegateList.begin(); first != last; ++first) { @@ -317,9 +324,9 @@ void IMEDispatcher::dispatchKeyboardDidHide(IMEKeyboardNotificationInfo& info) // static member function ////////////////////////////////////////////////////////////////////////// -IMEDispatcher* IMEDispatcher::getInstance() +InputDispatcher* InputDispatcher::getInstance() { - static IMEDispatcher s_instance; + static InputDispatcher s_instance; return &s_instance; } diff --git a/axmol/base/IMEDispatcher.h b/axmol/base/InputDispatcher.h similarity index 71% rename from axmol/base/IMEDispatcher.h rename to axmol/base/InputDispatcher.h index 6ce81d2684fb..1d7848ddeff7 100644 --- a/axmol/base/IMEDispatcher.h +++ b/axmol/base/InputDispatcher.h @@ -26,7 +26,7 @@ THE SOFTWARE. #pragma once -#include "axmol/base/IMEDelegate.h" +#include "axmol/base/InputDelegate.h" /** * @addtogroup base @@ -38,22 +38,35 @@ namespace ax /** @brief Input Method Edit Message Dispatcher. */ -class AX_DLL IMEDispatcher +class AX_DLL InputDispatcher { public: /** * @lua NA */ - ~IMEDispatcher(); + ~InputDispatcher(); /** - * @brief Returns the shared IMEDispatcher object for the system. + * @brief Returns the shared InputDispatcher object for the system. * @lua NA */ - static IMEDispatcher* getInstance(); + static InputDispatcher* getInstance(); - IMEDelegate* getAttachedDelegate() const; + /** + * @brief Returns the delegate attached to the IME, or nullptr if no delegate is attached. + */ + bool hasAttachedDelegate() const; + + /** + * @brief Returns the delegate attached to the IME, or nullptr if no delegate is attached. + * @lua NA + */ + bool dispatchHitTestWithIME(const Vec2& location); + /* + * @brief Dispatches the update-preedit-text message from IME. + * @lua NA + */ void dispatchUpdatePreedit(std::string_view preeditText, int caret); /** @@ -75,7 +88,7 @@ class AX_DLL IMEDispatcher void dispatchControlKey(EventKeyboard::KeyCode keyCode); /** - * @brief Get the content text from IMEDelegate, retrieved previously from IME. + * @brief Get the content text from InputDelegate, retrieved previously from IME. * @lua NA */ std::string_view getContentText(); @@ -101,38 +114,38 @@ class AX_DLL IMEDispatcher void dispatchKeyboardDidHide(IMEKeyboardNotificationInfo& info); protected: - friend class IMEDelegate; + friend class InputDelegate; /** *@brief Add delegate to receive IME messages. - *@param delegate A instance implements IMEDelegate delegate. + *@param delegate A instance implements InputDelegate delegate. */ - void addDelegate(IMEDelegate* delegate); + void addDelegate(InputDelegate* delegate); /** *@brief Attach the Delegate to the IME. - *@param delegate A instance implements IMEDelegate delegate. + *@param delegate A instance implements InputDelegate delegate. *@return If the old delegate can detach from the IME, and the new delegate * can attach to the IME, return true, otherwise false. */ - bool attachDelegateWithIME(IMEDelegate* delegate); + bool attachDelegateWithIME(InputDelegate* delegate); /** * Detach the delegate to the IME - *@see `attachDelegateWithIME(IMEDelegate*)` - *@param delegate A instance implements IMEDelegate delegate. + *@see `attachDelegateWithIME(InputDelegate*)` + *@param delegate A instance implements InputDelegate delegate. *@return Whether the IME is detached or not. */ - bool detachDelegateWithIME(IMEDelegate* delegate); + bool detachDelegateWithIME(InputDelegate* delegate); /** *@brief Remove the delegate from the delegates which receive IME messages. - *@param delegate A instance implements the IMEDelegate delegate. + *@param delegate A instance implements the InputDelegate delegate. */ - void removeDelegate(IMEDelegate* delegate); + void removeDelegate(InputDelegate* delegate); private: - IMEDispatcher(); + InputDispatcher(); class Impl; Impl* _impl; diff --git a/axmol/platform/Device.h b/axmol/platform/Device.h index 381e757a5f86..0070264b6c8e 100644 --- a/axmol/platform/Device.h +++ b/axmol/platform/Device.h @@ -83,6 +83,25 @@ class AX_DLL Device static constexpr int MAX_REFRESH_RATE = 1000; static constexpr int DEFAULT_REFRESH_RATE = 60; + /** + * Gets the current device orientation. + * @return The current device orientation. + * @since axmol-3.0.0 + */ + static std::string getClipboardText(); + + /** + * Sets the clipboard text. + * @since axmol-3.0.0 + */ + static void setClipboardText(std::string_view text); + + /** + * Clears the clipboard content. + * @since axmol-3.0.0 + */ + static void clearClipboard(); + /** * Gets the DPI of device * @return The DPI of device. diff --git a/axmol/platform/android/Device-android.cpp b/axmol/platform/android/Device-android.cpp index 86ddfea058c5..28d976dbbe2e 100644 --- a/axmol/platform/android/Device-android.cpp +++ b/axmol/platform/android/Device-android.cpp @@ -38,6 +38,21 @@ static const char* deviceHelperClassName = "dev.axmol.lib.AxmolEngine"; namespace ax { +std::string Device::getClipboardText() +{ + return JniHelper::callStaticStringMethod(deviceHelperClassName, "getClipboardText"); +} + +void Device::setClipboardText(std::string_view text) +{ + JniHelper::callStaticVoidMethod(deviceHelperClassName, "setClipboardText", std::string{text}.c_str()); +} + +void Device::clearClipboard() +{ + JniHelper::callStaticVoidMethod(deviceHelperClassName, "clearClipboard"); +} + int Device::getDPI() { static int dpi = -1; diff --git a/axmol/platform/android/java/src/dev/axmol/lib/AxmolEngine.java b/axmol/platform/android/java/src/dev/axmol/lib/AxmolEngine.java index 9046971571a4..66c503e9a8ce 100644 --- a/axmol/platform/android/java/src/dev/axmol/lib/AxmolEngine.java +++ b/axmol/platform/android/java/src/dev/axmol/lib/AxmolEngine.java @@ -104,6 +104,7 @@ public class AxmolEngine { private static boolean sCompassEnabled; private static boolean sActivityVisible; private static String sPackageName; + private static Context sAppContext = null; private static AppCompatActivity sActivity = null; private static AxmolEngineListener sAxmolEngineListener; private static Set onActivityResultListeners = new LinkedHashSet(); @@ -141,6 +142,7 @@ public void run() { private static boolean sInitialized = false; public static void init(final AppCompatActivity activity) { + sAppContext = activity.getApplicationContext(); sActivity = activity; AxmolEngine.sAxmolEngineListener = (AxmolEngineListener)activity; @@ -218,7 +220,7 @@ public static AppCompatActivity getActivity() { return sActivity; } - public static Context getApplicationContext() { return sActivity != null ? sActivity.getApplicationContext() : null; } + public static Context getApplicationContext() { return sAppContext; } public static void addOnActivityResultListener(OnActivityResultListener listener) { onActivityResultListeners.add(listener); @@ -1006,6 +1008,28 @@ public void onAccuracyChanged(Sensor sensor, int accuracy) {} return result[0]; } + @SuppressWarnings("unused") + public static String getClipboardText() { + ClipboardManager clipboard = (ClipboardManager) sAppContext.getSystemService(Context.CLIPBOARD_SERVICE); + if (clipboard.hasPrimaryClip()) { + return clipboard.getPrimaryClip().getItemAt(0).getText().toString(); + } + return ""; + } + + @SuppressWarnings("unused") + public static void setClipboardText(String text) { + ClipboardManager clipboard = (ClipboardManager) sAppContext.getSystemService(Context.CLIPBOARD_SERVICE); + ClipData clip = ClipData.newPlainText("Axmol Clipboard", text); + clipboard.setPrimaryClip(clip); + } + + @SuppressWarnings("unused") + public static void clearClipboard() { + ClipboardManager clipboard = (ClipboardManager) sAppContext.getSystemService(Context.CLIPBOARD_SERVICE); + clipboard.setPrimaryClip(ClipData.newPlainText("Axmol Clipboard", "")); + } + // =========================================================== // Native methods for AxmolEngine // =========================================================== diff --git a/axmol/platform/android/jni/AxmolPlayerJni.cpp b/axmol/platform/android/jni/AxmolPlayerJni.cpp index 1c08cfa0b584..09b165b6621d 100644 --- a/axmol/platform/android/jni/AxmolPlayerJni.cpp +++ b/axmol/platform/android/jni/AxmolPlayerJni.cpp @@ -22,7 +22,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ -#include "axmol/base/IMEDispatcher.h" +#include "axmol/base/InputDispatcher.h" #include "axmol/base/Director.h" #include "axmol/base/Scheduler.h" #include "axmol/base/EventType.h" @@ -256,17 +256,17 @@ JNIEXPORT void JNICALL Java_dev_axmol_lib_AxmolPlayer_nativeOnResume(JNIEnv*, jc JNIEXPORT void JNICALL Java_dev_axmol_lib_AxmolPlayer_nativeInsertText(JNIEnv* env, jclass, jstring text) { std::string strValue = ax::text_utils::getStringUTFCharsJNI(env, text); - ax::IMEDispatcher::getInstance()->dispatchInsertText(strValue); + ax::InputDispatcher::getInstance()->dispatchInsertText(strValue); } JNIEXPORT void JNICALL Java_dev_axmol_lib_AxmolPlayer_nativeDeleteBackward(JNIEnv*, jclass, jint numChars) { - ax::IMEDispatcher::getInstance()->dispatchDeleteBackward(static_cast(numChars)); + ax::InputDispatcher::getInstance()->dispatchDeleteBackward(static_cast(numChars)); } JNIEXPORT jstring JNICALL Java_dev_axmol_lib_AxmolPlayer_nativeGetContentText(JNIEnv* env, jclass) { - auto pszText = ax::IMEDispatcher::getInstance()->getContentText(); + auto pszText = ax::InputDispatcher::getInstance()->getContentText(); return ax::text_utils::newStringUTFJNI(env, pszText); } } diff --git a/axmol/platform/desktop/Device-desktop.cpp b/axmol/platform/desktop/Device-desktop.cpp index dba4db300cf8..3115678fa5f3 100644 --- a/axmol/platform/desktop/Device-desktop.cpp +++ b/axmol/platform/desktop/Device-desktop.cpp @@ -27,6 +27,22 @@ THE SOFTWARE. namespace ax { + +std::string getClipboardText() +{ + return glfwGetClipboardString(nullptr); +} + +void Device::setClipboardText(std::string_view text) +{ + glfwSetClipboardString(nullptr, text.data()); +} + +void Device::clearClipboard() +{ + glfwSetClipboardString(nullptr, nullptr); +} + int Device::getDisplayRefreshRate() { // Retrieve the display refresh rate from GLFW. diff --git a/axmol/platform/desktop/RenderViewImpl.cpp b/axmol/platform/desktop/RenderViewImpl.cpp index 01c508c51d05..d98bbc21c615 100644 --- a/axmol/platform/desktop/RenderViewImpl.cpp +++ b/axmol/platform/desktop/RenderViewImpl.cpp @@ -39,7 +39,7 @@ The RenderViewImpl for win32,linux,macos,wasm #include "axmol/base/EventDispatcher.h" #include "axmol/base/EventKeyboard.h" #include "axmol/base/EventMouse.h" -#include "axmol/base/IMEDispatcher.h" +#include "axmol/base/InputDispatcher.h" #include "axmol/base/Utils.h" #include "axmol/base/text_utils.h" #include "axmol/scene/Camera.h" @@ -1427,7 +1427,7 @@ void RenderViewImpl::onGLFWKeyCallback(GLFWwindow* /*window*/, int key, int /*sc switch (g_keyCodeMap[key]) { case EventKeyboard::KeyCode::KEY_BACKSPACE: - IMEDispatcher::getInstance()->dispatchDeleteBackward(1); + InputDispatcher::getInstance()->dispatchDeleteBackward(1); break; case EventKeyboard::KeyCode::KEY_HOME: case EventKeyboard::KeyCode::KEY_KP_HOME: @@ -1437,11 +1437,11 @@ void RenderViewImpl::onGLFWKeyCallback(GLFWwindow* /*window*/, int key, int /*sc case EventKeyboard::KeyCode::KEY_LEFT_ARROW: case EventKeyboard::KeyCode::KEY_RIGHT_ARROW: case EventKeyboard::KeyCode::KEY_ESCAPE: - IMEDispatcher::getInstance()->dispatchControlKey(g_keyCodeMap[key]); + InputDispatcher::getInstance()->dispatchControlKey(g_keyCodeMap[key]); break; case EventKeyboard::KeyCode::KEY_ENTER: case EventKeyboard::KeyCode::KEY_KP_ENTER: - IMEDispatcher::getInstance()->dispatchInsertText("\n"sv); + InputDispatcher::getInstance()->dispatchInsertText("\n"sv); break; default: break; @@ -1484,7 +1484,7 @@ void RenderViewImpl::onGLFWCharCallback(GLFWwindow* /*window*/, unsigned int cha std::string utf8String; char32_t codepoint = static_cast(charCode); text_utils::UTF32ToUTF8(std::u32string_view{&codepoint, 1zu}, utf8String); - IMEDispatcher::getInstance()->dispatchInsertText(utf8String); + InputDispatcher::getInstance()->dispatchInsertText(utf8String); } } @@ -1505,7 +1505,7 @@ void RenderViewImpl::onGLFWPreeditCallback(GLFWwindow* window, utf8String); } - IMEDispatcher::getInstance()->dispatchUpdatePreedit(utf8String, caret); + InputDispatcher::getInstance()->dispatchUpdatePreedit(utf8String, caret); } void RenderViewImpl::onGLFWWindowPosCallback(GLFWwindow* /*window*/, int x, int y) diff --git a/axmol/platform/ios/Device-ios.mm b/axmol/platform/ios/Device-ios.mm index dee568b93be5..e86c351bd827 100644 --- a/axmol/platform/ios/Device-ios.mm +++ b/axmol/platform/ios/Device-ios.mm @@ -995,4 +995,23 @@ static bool _initWithString(std::string_view text, return resolvedOrientation; } +std::string Device::getClipboardText() +{ + NSString* text = [UIPasteboard generalPasteboard].string; + if (text) + return std::string([text UTF8String]); + else + return std::string(); +} + +void Device::setClipboardText(std::string_view text) +{ + [UIPasteboard generalPasteboard].string = [NSString stringWithUTF8String:text.data()]; +} + +void Device::clearClipboard() +{ + [UIPasteboard generalPasteboard].string = nil; +} + } // namespace ax diff --git a/axmol/platform/ios/InputView-ios.mm b/axmol/platform/ios/InputView-ios.mm index 705b21afab25..6f12cd988fa1 100644 --- a/axmol/platform/ios/InputView-ios.mm +++ b/axmol/platform/ios/InputView-ios.mm @@ -22,7 +22,7 @@ of this software and associated documentation files (the "Software"), to deal THE SOFTWARE. ****************************************************************************/ #import "axmol/platform/ios/InputView-ios.h" -#import "axmol/base/IMEDispatcher.h" +#import "axmol/base/InputDispatcher.h" #import "axmol/base/Director.h" @interface TextInputView () @@ -68,8 +68,8 @@ - (BOOL)canBecomeFirstResponder - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent*)event { - ax::IMEDelegate* attachedDelegate = ax::IMEDispatcher::getInstance()->getAttachedDelegate(); - if (attachedDelegate) + auto inputDisp = ax::InputDispatcher::getInstance(); + if (inputDisp->hasAttachedDelegate()) { ax::Vec2 pt{static_cast(point.x * [self contentScaleFactor]), static_cast(point.y * [self contentScaleFactor])}; @@ -81,7 +81,7 @@ - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent*)event // convert axmol screen to world coordinate pt = director->screenToWorld(pt); - bool keep = attachedDelegate->onHitTestWithIME(pt); + bool keep = inputDisp->dispatchHitTestWithIME(pt); if (keep) return NO; } @@ -121,7 +121,7 @@ - (void)deleteBackward [self.myMarkedText release]; self.myMarkedText = nil; } - ax::IMEDispatcher::getInstance()->dispatchDeleteBackward(1u); + ax::InputDispatcher::getInstance()->dispatchDeleteBackward(1u); } - (void)insertText:(nonnull NSString*)text @@ -132,7 +132,7 @@ - (void)insertText:(nonnull NSString*)text self.myMarkedText = nil; } const char* pszText = [text cStringUsingEncoding:NSUTF8StringEncoding]; - ax::IMEDispatcher::getInstance()->dispatchInsertText(std::string_view{pszText, strlen(pszText)}); + ax::InputDispatcher::getInstance()->dispatchInsertText(std::string_view{pszText, strlen(pszText)}); } - (NSWritingDirection)baseWritingDirectionForPosition:(nonnull UITextPosition*)position @@ -274,7 +274,7 @@ - (void)unmarkText return; } const char* pszText = [self.myMarkedText cStringUsingEncoding:NSUTF8StringEncoding]; - ax::IMEDispatcher::getInstance()->dispatchInsertText(std::string_view{pszText, strlen(pszText)}); + ax::InputDispatcher::getInstance()->dispatchInsertText(std::string_view{pszText, strlen(pszText)}); [self.myMarkedText release]; self.myMarkedText = nil; } diff --git a/axmol/platform/ios/RenderHostView-ios.mm b/axmol/platform/ios/RenderHostView-ios.mm index 390093dac5e1..8bc9221436eb 100644 --- a/axmol/platform/ios/RenderHostView-ios.mm +++ b/axmol/platform/ios/RenderHostView-ios.mm @@ -57,7 +57,7 @@ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE #import "axmol/base/Director.h" #import "axmol/base/Touch.h" -#import "axmol/base/IMEDispatcher.h" +#import "axmol/base/InputDispatcher.h" #import "axmol/platform/ios/InputView-ios.h" #if AX_ENABLE_MTL @@ -669,7 +669,7 @@ - (void)onUIKeyboardNotification:(NSNotification*)notif notiInfo.end = convertKeyboardRectToViewport(end, viewSize); notiInfo.duration = aniDuration; - ax::IMEDispatcher* dispatcher = ax::IMEDispatcher::getInstance(); + ax::InputDispatcher* dispatcher = ax::InputDispatcher::getInstance(); if (UIKeyboardWillShowNotification == type) { dispatcher->dispatchKeyboardWillShow(notiInfo); diff --git a/axmol/platform/winrt/InputEvent.cpp b/axmol/platform/winrt/InputEvent.cpp index 8e10e331988e..50ea19a3470f 100644 --- a/axmol/platform/winrt/InputEvent.cpp +++ b/axmol/platform/winrt/InputEvent.cpp @@ -31,7 +31,7 @@ THE SOFTWARE. #include "axmol/base/EventAcceleration.h" #include "axmol/base/Director.h" #include "axmol/base/EventDispatcher.h" -#include "axmol/base/IMEDispatcher.h" +#include "axmol/base/InputDispatcher.h" namespace ax { @@ -88,7 +88,7 @@ void KeyboardEvent::execute() case AxmolKeyEvent::Text: { std::string utf8String = PlatformStringToString(m_text); - IMEDispatcher::getInstance()->dispatchInsertText(utf8String); + InputDispatcher::getInstance()->dispatchInsertText(utf8String); break; } @@ -96,10 +96,10 @@ void KeyboardEvent::execute() switch (m_type) { case AxmolKeyEvent::Back: - IMEDispatcher::getInstance()->dispatchDeleteBackward(1); + InputDispatcher::getInstance()->dispatchDeleteBackward(1); break; case AxmolKeyEvent::Enter: - IMEDispatcher::getInstance()->dispatchInsertText("\n"sv); + InputDispatcher::getInstance()->dispatchInsertText("\n"sv); break; default: break; diff --git a/axmol/platform/winrt/Keyboard-winrt.cpp b/axmol/platform/winrt/Keyboard-winrt.cpp index 7902adfb2743..ebd8defd20df 100644 --- a/axmol/platform/winrt/Keyboard-winrt.cpp +++ b/axmol/platform/winrt/Keyboard-winrt.cpp @@ -30,7 +30,7 @@ THE SOFTWARE. #include "axmol/platform/winrt/Keyboard-winrt.h" #include "axmol/base/EventKeyboard.h" #include "axmol/platform/winrt/RenderViewImpl-winrt.h" -#include "axmol/base/IMEDispatcher.h" +#include "axmol/base/InputDispatcher.h" #include "axmol/base/Director.h" #include "axmol/base/EventDispatcher.h" @@ -287,7 +287,7 @@ void KeyBoardWinRT::OnWinRTKeyboardEvent(WinRTKeyboardEventType type, KeyEventAr dispatcher->dispatchEvent(&event); if (keyCode == EventKeyboard::KeyCode::KEY_ENTER) { - IMEDispatcher::getInstance()->dispatchInsertText("\n"sv); + InputDispatcher::getInstance()->dispatchInsertText("\n"sv); } if (isKeyDown && !event.isStopped()) @@ -295,7 +295,7 @@ void KeyBoardWinRT::OnWinRTKeyboardEvent(WinRTKeyboardEventType type, KeyEventAr switch (keyCode) { case EventKeyboard::KeyCode::KEY_BACKSPACE: - IMEDispatcher::getInstance()->dispatchDeleteBackward(1); + InputDispatcher::getInstance()->dispatchDeleteBackward(1); break; case EventKeyboard::KeyCode::KEY_HOME: case EventKeyboard::KeyCode::KEY_KP_HOME: @@ -305,7 +305,7 @@ void KeyBoardWinRT::OnWinRTKeyboardEvent(WinRTKeyboardEventType type, KeyEventAr case EventKeyboard::KeyCode::KEY_LEFT_ARROW: case EventKeyboard::KeyCode::KEY_RIGHT_ARROW: case EventKeyboard::KeyCode::KEY_ESCAPE: - IMEDispatcher::getInstance()->dispatchControlKey(keyCode); + InputDispatcher::getInstance()->dispatchControlKey(keyCode); break; default: break; diff --git a/axmol/platform/winrt/RenderViewImpl-winrt.cpp b/axmol/platform/winrt/RenderViewImpl-winrt.cpp index 674e256de45b..2bc8d4234860 100644 --- a/axmol/platform/winrt/RenderViewImpl-winrt.cpp +++ b/axmol/platform/winrt/RenderViewImpl-winrt.cpp @@ -29,7 +29,7 @@ THE SOFTWARE. #include "axmol/base/Macros.h" #include "axmol/base/Director.h" #include "axmol/base/Touch.h" -#include "axmol/base/IMEDispatcher.h" +#include "axmol/base/InputDispatcher.h" #include "axmol/base/EventListenerKeyboard.h" #include "axmol/platform/winrt/Application-winrt.h" #include "axmol/platform/winrt/WinRTUtils.h" diff --git a/axmol/ui/EditBox/EditBox.h b/axmol/ui/EditBox/EditBox.h index a3f6e39dbbb8..c0de1abdc484 100644 --- a/axmol/ui/EditBox/EditBox.h +++ b/axmol/ui/EditBox/EditBox.h @@ -27,7 +27,7 @@ #pragma once -#include "axmol/base/IMEDelegate.h" +#include "axmol/base/InputDelegate.h" #include "axmol/ui/GUIDefine.h" #include "axmol/ui/Widget.h" #include "axmol/ui/Scale9Sprite.h" @@ -100,7 +100,7 @@ class AX_GUI_DLL EditBoxDelegate * You can use this widget to gather small amounts of text from the user. * */ -class AX_GUI_DLL EditBox : public Widget, public IMEDelegate +class AX_GUI_DLL EditBox : public Widget, public InputDelegate { public: /** diff --git a/axmol/ui/InputField.cpp b/axmol/ui/InputField.cpp index 895c01f36281..27ae95196714 100644 --- a/axmol/ui/InputField.cpp +++ b/axmol/ui/InputField.cpp @@ -25,6 +25,7 @@ THE SOFTWARE. #include "axmol/ui/InputField.h" #include "axmol/base/Director.h" #include "axmol/base/text_utils.h" +#include "axmol/platform/Device.h" #include #include @@ -49,43 +50,8 @@ namespace ui namespace { -static std::string s_clipboardFallback; -static constexpr int INPUT_FIELD_RENDERER_Z = (-1); - -#if (AX_TARGET_PLATFORM == AX_PLATFORM_WIN32 || AX_TARGET_PLATFORM == AX_PLATFORM_MAC || \ - AX_TARGET_PLATFORM == AX_PLATFORM_LINUX) -static GLFWwindow* getClipboardWindow() -{ - auto renderView = dynamic_cast(Director::getInstance()->getRenderView()); - return renderView ? renderView->getWindow() : nullptr; -} -#endif - -static std::string readClipboardText() -{ -#if (AX_TARGET_PLATFORM == AX_PLATFORM_WIN32 || AX_TARGET_PLATFORM == AX_PLATFORM_MAC || \ - AX_TARGET_PLATFORM == AX_PLATFORM_LINUX) - if (auto window = getClipboardWindow()) - { - if (auto text = glfwGetClipboardString(window)) - return text; - } -#endif - - return s_clipboardFallback; -} - -static void writeClipboardText(std::string_view text) -{ - s_clipboardFallback = text; - -#if (AX_TARGET_PLATFORM == AX_PLATFORM_WIN32 || AX_TARGET_PLATFORM == AX_PLATFORM_MAC || \ - AX_TARGET_PLATFORM == AX_PLATFORM_LINUX) - if (auto window = getClipboardWindow()) - glfwSetClipboardString(window, s_clipboardFallback.c_str()); -#endif -} - +static constexpr int INPUT_FIELD_RENDERER_Z = (-1); +static constexpr std::string_view DEFAULT_PASSWORD_CHAR = "\xe2\x80\xa2"sv; static FontType labelTypeToFontType(Label::LabelType type) { switch (type) @@ -101,8 +67,6 @@ static FontType labelTypeToFontType(Label::LabelType type) } } -static constexpr std::string_view DEFAULT_PASSWORD_CHAR = "\xe2\x80\xa2"sv; - } // namespace ////////////////////////////////////////////////////////////////////////// @@ -127,6 +91,18 @@ InputField::~InputField() ////////////////////////////////////////////////////////////////////////// // static constructor ////////////////////////////////////////////////////////////////////////// + +InputField* InputField::create() +{ + InputField* ret = new InputField(); + if (ret && ret->initWithPlaceholder(""sv, "Arial"sv, 24, 2, Color32::BLACK)) + { + ret->autorelease(); + return ret; + } + AX_SAFE_DELETE(ret); + return nullptr; +} InputField* InputField::create(std::string_view placeholder, std::string_view fontName, float fontSize, @@ -134,7 +110,7 @@ InputField* InputField::create(std::string_view placeholder, const Color32& cursorColor) { InputField* ret = new InputField(); - if (ret && ret->initWithPlaceHolder(placeholder, fontName, fontSize, cursorWidth, cursorColor)) + if (ret && ret->initWithPlaceholder(placeholder, fontName, fontSize, cursorWidth, cursorColor)) { ret->autorelease(); return ret; @@ -163,7 +139,7 @@ Vec2 InputField::measureText(std::string_view text) const ////////////////////////////////////////////////////////////////////////// // initialize ////////////////////////////////////////////////////////////////////////// -bool InputField::initWithPlaceHolder(std::string_view placeholder, +bool InputField::initWithPlaceholder(std::string_view placeholder, std::string_view fontName, float fontSize, float cursorWidth, @@ -174,7 +150,7 @@ bool InputField::initWithPlaceHolder(std::string_view placeholder, _fontName = fontName; _fontSize = fontSize; - _placeHolder = placeholder; + _placeholder = placeholder; /// render label // Create render label according to font type: BMFont (.fnt), TTF file, or system font @@ -389,14 +365,14 @@ Label* InputField::getRenderLabel() } ////////////////////////////////////////////////////////////////////////// -// IMEDelegate +// InputDelegate ////////////////////////////////////////////////////////////////////////// bool InputField::attachWithIME() { if (_isAttachWithIME) return true; - bool ret = IMEDelegate::attachWithIME(); + bool ret = InputDelegate::attachWithIME(); if (ret) { // Initialize touch selection state @@ -420,7 +396,7 @@ bool InputField::attachWithIME() bool InputField::detachWithIME() { - bool ret = IMEDelegate::detachWithIME(); + bool ret = InputDelegate::detachWithIME(); if (ret) { _isAttachWithIME = false; @@ -439,7 +415,7 @@ bool InputField::detachWithIME() return ret; } -bool InputField::onHitTestWithIME(const Vec2& location) +bool InputField::hitTestWithIME(const Vec2& location) { auto camera = Camera::getDefaultCamera(); bool hitted = hitTest(location, camera, nullptr); @@ -455,7 +431,7 @@ void InputField::keyboardDidHide(IMEKeyboardNotificationInfo& /*info*/) { s_keyboardVisible = false; - bool ret = IMEDelegate::detachWithIME(); + bool ret = InputDelegate::detachWithIME(); if (ret) { _isAttachWithIME = false; @@ -788,7 +764,7 @@ void InputField::updatePresentation(uint32_t newCharCount, int oldInsertCharInde if (_inputText.empty()) { _renderLabel->setTextColor(_colorSpaceHolder); - _renderLabel->setString(_placeHolder); + _renderLabel->setString(_placeholder); } else { @@ -906,11 +882,11 @@ void InputField::setPasswordChar(std::string_view ch) // place holder text property void InputField::setPlaceholderText(std::string_view text) { - _placeHolder = text; + _placeholder = text; if (_inputText.empty()) { _renderLabel->setTextColor(_colorSpaceHolder); - _renderLabel->setString(_placeHolder); + _renderLabel->setString(_placeholder); } _layoutDirty = true; updateContentSize(); @@ -918,7 +894,7 @@ void InputField::setPlaceholderText(std::string_view text) std::string_view InputField::getPlaceholderText() const { - return _placeHolder; + return _placeholder; } // secureTextEntry @@ -1020,12 +996,12 @@ const Color& InputField::getSelectionColor() const std::string InputField::getClipboardText() { - return readClipboardText(); + return Device::getClipboardText(); } void InputField::setClipboardText(std::string_view text) { - writeClipboardText(text); + Device::setClipboardText(text); } void InputField::showCursor(void) diff --git a/axmol/ui/InputField.h b/axmol/ui/InputField.h index d98ce42603df..82bb807284f8 100644 --- a/axmol/ui/InputField.h +++ b/axmol/ui/InputField.h @@ -25,7 +25,7 @@ THE SOFTWARE. #pragma once #include "axmol/ui/Widget.h" -#include "axmol/base/IMEDelegate.h" +#include "axmol/base/InputDelegate.h" #include "axmol/2d/DrawNode.h" #include "axmol/2d/Label.h" #include "axmol/base/EventListenerKeyboard.h" @@ -47,7 +47,7 @@ namespace ui * This class is the base component for single-line input fields, and can be * extended or configured to support multiline input scenarios. */ -class AX_DLL InputField : public Widget, public IMEDelegate +class AX_DLL InputField : public Widget, public InputDelegate { public: /** @@ -64,6 +64,12 @@ class AX_DLL InputField : public Widget, public IMEDelegate */ virtual ~InputField(); + /** + * @brief Create a new InputField instance. + * @return A new InputField instance or nullptr on failure. + */ + static InputField* create(); + /** * @brief Create and initialize an InputField. * @param placeholder Placeholder text shown when the field is empty. @@ -83,7 +89,7 @@ class AX_DLL InputField : public Widget, public IMEDelegate * @brief Initialize the InputField with placeholder and font settings. * @return True if initialization succeeded. */ - bool initWithPlaceHolder(std::string_view placeholder, + bool initWithPlaceholder(std::string_view placeholder, std::string_view fontName, float fontSize, float cursorWidth = 2, @@ -433,7 +439,7 @@ class AX_DLL InputField : public Widget, public IMEDelegate bool canAttachWithIME() override; bool canDetachWithIME() override; - // IMEDelegate interface + // InputDelegate interface void insertText(std::string_view text) override; void deleteBackward(unsigned int numChars) override; @@ -451,7 +457,7 @@ class AX_DLL InputField : public Widget, public IMEDelegate */ bool detachWithIME() override; - bool onHitTestWithIME(const Vec2& location) override; + bool hitTestWithIME(const Vec2& location) override; void keyboardDidShow(IMEKeyboardNotificationInfo& /*info*/) override; void keyboardDidHide(IMEKeyboardNotificationInfo& /*info*/) override; @@ -561,7 +567,7 @@ class AX_DLL InputField : public Widget, public IMEDelegate Label* _renderLabel{nullptr}; std::string _inputText; - std::string _placeHolder; + std::string _placeholder; std::string _passwordChar; std::vector _charByteOffsets; // Maps UTF-8 character index to byte offset in _inputText diff --git a/extensions/ImGui/src/ImGui/backends/imgui_impl_axmol_sw.cpp b/extensions/ImGui/src/ImGui/backends/imgui_impl_axmol_sw.cpp index 935f5deedc35..ade648ebcf55 100644 --- a/extensions/ImGui/src/ImGui/backends/imgui_impl_axmol_sw.cpp +++ b/extensions/ImGui/src/ImGui/backends/imgui_impl_axmol_sw.cpp @@ -1,12 +1,11 @@ #include "imgui_impl_axmol_sw.h" #include "axmol/base/Director.h" #include "axmol/base/EventListenerTouch.h" -#include "axmol/base/IMEDelegate.h" #include "axmol/rhi/axmol-rhi.h" +#include "axmol/base/InputDelegate.h" +#include "axmol/base/EventDispatcher.h" #include #include -#include "axmol/base/IMEDelegate.h" -#include "axmol/base/EventDispatcher.h" using namespace ax; using namespace ax::rhi; @@ -22,7 +21,7 @@ using namespace ax::rhi; #endif // Text handling -class KeyboardInputDelegate : public IMEDelegate +class KeyboardInputDelegate : public InputDelegate { protected: bool canAttachWithIME() override { return true; } diff --git a/extensions/sceneio/CMakeLists.txt b/extensions/sceneio/CMakeLists.txt index 9a3d4b593599..b490d077b2f5 100644 --- a/extensions/sceneio/CMakeLists.txt +++ b/extensions/sceneio/CMakeLists.txt @@ -1,7 +1,6 @@ set(target_name sceneio) FILE(GLOB_RECURSE sceneio_SOURCES ./*.h;./*.cpp) -list(FILTER sceneio_SOURCES EXCLUDE REGEX "TextFieldReader/TextFieldReader\\.(h|cpp)$") add_library(${target_name} ${sceneio_SOURCES}) diff --git a/extensions/sceneio/src/sceneio/ActionTimeline/CSLoader.cpp b/extensions/sceneio/src/sceneio/ActionTimeline/CSLoader.cpp index e8c81b48041a..d8e15efd2e2c 100644 --- a/extensions/sceneio/src/sceneio/ActionTimeline/CSLoader.cpp +++ b/extensions/sceneio/src/sceneio/ActionTimeline/CSLoader.cpp @@ -59,6 +59,7 @@ #include "sceneio/WidgetReader/ImageViewReader/ImageViewReader.h" #include "sceneio/WidgetReader/TextBMFontReader/TextBMFontReader.h" #include "sceneio/WidgetReader/TextReader/TextReader.h" +#include "sceneio/WidgetReader/TextFieldReader/TextFieldReader.h" #include "sceneio/WidgetReader/TextAtlasReader/TextAtlasReader.h" #include "sceneio/WidgetReader/LoadingBarReader/LoadingBarReader.h" #include "sceneio/WidgetReader/SliderReader/SliderReader.h" @@ -121,6 +122,7 @@ static const char* ClassName_LabelBMFont = "LabelBMFont"; static const char* ClassName_TextBMFont = "TextBMFont"; static const char* ClassName_Text = "Text"; static const char* ClassName_LoadingBar = "LoadingBar"; +static const char* ClassName_TextField = "TextField"; static const char* ClassName_Slider = "Slider"; static const char* ClassName_Layout = "Layout"; static const char* ClassName_ScrollView = "ScrollView"; @@ -214,6 +216,7 @@ CSLoader::CSLoader() CREATE_CLASS_NODE_READER_INFO(ImageViewReader); CREATE_CLASS_NODE_READER_INFO(TextBMFontReader); CREATE_CLASS_NODE_READER_INFO(TextReader); + CREATE_CLASS_NODE_READER_INFO(TextFieldReader); CREATE_CLASS_NODE_READER_INFO(TextAtlasReader); CREATE_CLASS_NODE_READER_INFO(LoadingBarReader); CREATE_CLASS_NODE_READER_INFO(SliderReader); @@ -268,6 +271,7 @@ void CSLoader::init() _funcs.insert(Pair(ClassName_TextBMFont, std::bind(&CSLoader::loadWidget, this, _1))); _funcs.insert(Pair(ClassName_Text, std::bind(&CSLoader::loadWidget, this, _1))); _funcs.insert(Pair(ClassName_LoadingBar, std::bind(&CSLoader::loadWidget, this, _1))); + _funcs.insert(Pair(ClassName_TextField, std::bind(&CSLoader::loadWidget, this, _1))); _funcs.insert(Pair(ClassName_Slider, std::bind(&CSLoader::loadWidget, this, _1))); _funcs.insert(Pair(ClassName_Layout, std::bind(&CSLoader::loadWidget, this, _1))); _funcs.insert(Pair(ClassName_ScrollView, std::bind(&CSLoader::loadWidget, this, _1))); @@ -1273,9 +1277,9 @@ bool CSLoader::isWidget(std::string_view type) return (type == ClassName_Panel || type == ClassName_Button || type == ClassName_CheckBox || type == ClassName_ImageView || type == ClassName_TextAtlas || type == ClassName_LabelAtlas || type == ClassName_LabelBMFont || type == ClassName_TextBMFont || type == ClassName_Text || - type == ClassName_LoadingBar || type == ClassName_Slider || type == ClassName_Layout || - type == ClassName_ScrollView || type == ClassName_ListView || type == ClassName_PageView || - type == ClassName_Widget || type == ClassName_Label); + type == ClassName_LoadingBar || type == ClassName_TextField || type == ClassName_Slider || + type == ClassName_Layout || type == ClassName_ScrollView || type == ClassName_ListView || + type == ClassName_PageView || type == ClassName_Widget || type == ClassName_Label); } bool CSLoader::isCustomWidget(std::string_view type) @@ -1360,6 +1364,10 @@ std::string_view CSLoader::getWidgetReaderClassName(Widget* widget) { readerName = "SliderReader"; } + else if (dynamic_cast(widget)) + { + readerName = "TextFieldReader"; + } else if (dynamic_cast(widget)) { readerName = "ListViewReader"; diff --git a/extensions/sceneio/src/sceneio/FlatBuffersSerialize.cpp b/extensions/sceneio/src/sceneio/FlatBuffersSerialize.cpp index eef3a53d08a1..aff4df469518 100644 --- a/extensions/sceneio/src/sceneio/FlatBuffersSerialize.cpp +++ b/extensions/sceneio/src/sceneio/FlatBuffersSerialize.cpp @@ -50,6 +50,7 @@ #include "sceneio/WidgetReader/ImageViewReader/ImageViewReader.h" #include "sceneio/WidgetReader/TextBMFontReader/TextBMFontReader.h" #include "sceneio/WidgetReader/TextReader/TextReader.h" +#include "sceneio/WidgetReader/TextFieldReader/TextFieldReader.h" #include "sceneio/WidgetReader/TextAtlasReader/TextAtlasReader.h" #include "sceneio/WidgetReader/LoadingBarReader/LoadingBarReader.h" #include "sceneio/WidgetReader/SliderReader/SliderReader.h" @@ -99,6 +100,7 @@ FlatBuffersSerialize::FlatBuffersSerialize() : _isSimulator(false), _builder(nul CREATE_CLASS_NODE_READER_INFO(ImageViewReader); CREATE_CLASS_NODE_READER_INFO(TextBMFontReader); CREATE_CLASS_NODE_READER_INFO(TextReader); + CREATE_CLASS_NODE_READER_INFO(TextFieldReader); CREATE_CLASS_NODE_READER_INFO(TextAtlasReader); CREATE_CLASS_NODE_READER_INFO(LoadingBarReader); CREATE_CLASS_NODE_READER_INFO(SliderReader); @@ -512,6 +514,10 @@ std::string FlatBuffersSerialize::getWidgetReaderClassName(Widget* widget) { readerName = "SliderReader"; } + else if (dynamic_cast(widget)) + { + readerName = "TextFieldReader"; + } else if (dynamic_cast(widget)) { readerName = "ListViewReader"; diff --git a/extensions/sceneio/src/sceneio/WidgetReader/TextFieldReader/TextFieldExReader.cpp b/extensions/sceneio/src/sceneio/WidgetReader/TextFieldReader/TextFieldExReader.cpp index 87d3143a5777..4a520fad1a4f 100644 --- a/extensions/sceneio/src/sceneio/WidgetReader/TextFieldReader/TextFieldExReader.cpp +++ b/extensions/sceneio/src/sceneio/WidgetReader/TextFieldReader/TextFieldExReader.cpp @@ -91,7 +91,7 @@ Offset
TextFieldExReader::createOptionsWithFlatBuffers(pugi::xml_node obj int fontSize = 20; std::string text; bool isLocalized = false; - std::string placeHolder = "Text Field Extend"; + std::string placeHolder = "Input Field"; bool passwordEnabled = false; std::string passwordStyleText = "*"; bool maxLengthEnabled = false; @@ -344,11 +344,11 @@ void TextFieldExReader::setPropsWithFlatBuffers(ax::Node* node, const flatbuffer textField->setPasswordEnabled(passwordEnabled); - /*if (passwordEnabled) + if (passwordEnabled) { std::string passwordStyleText = options->passwordStyleText()->c_str(); - textField->setPasswordStyleText(passwordStyleText.c_str()); - }*/ + textField->setPasswordChar(passwordStyleText); + } textField->setString(text); textField->setTextColor(Color32FromFb(options->textColor())); @@ -370,10 +370,10 @@ void TextFieldExReader::setPropsWithFlatBuffers(ax::Node* node, const flatbuffer textField->setReadOnly(!options->editable()); // InputField will enable IME when user interacts with it - /*if (!textField->isIgnoreContentAdaptWithSize()) + if (!textField->isAutoSize()) { ((Label*)(textField->getRenderNode()))->setLineBreakWithoutSpace(true); - }*/ + } } Node* TextFieldExReader::createNodeWithFlatBuffers(const flatbuffers::Table* textFieldOptions) diff --git a/extensions/sceneio/src/sceneio/WidgetReader/TextFieldReader/TextFieldReader.cpp b/extensions/sceneio/src/sceneio/WidgetReader/TextFieldReader/TextFieldReader.cpp index b7082835d6a4..13b22304ac21 100644 --- a/extensions/sceneio/src/sceneio/WidgetReader/TextFieldReader/TextFieldReader.cpp +++ b/extensions/sceneio/src/sceneio/WidgetReader/TextFieldReader/TextFieldReader.cpp @@ -98,19 +98,19 @@ void TextFieldReader::setPropsFromBinary(ax::ui::Widget* widget, CocoLoader* coc } else if (key == P_FontSize) { - textField->setTextFontSize(valueToInt(value)); + textField->setFontSize(valueToInt(value)); } else if (key == P_FontName) { - textField->setTextFontName(value); + textField->setFontName(value); } else if (key == P_TouchSizeWidth) { - textField->setTouchSize(Size(valueToFloat(value), textField->getTouchSize().height)); + textField->setTouchAreaSize(Size(valueToFloat(value), textField->getTouchAreaSize().height)); } else if (key == P_TouchSizeHeight) { - textField->setTouchSize(Size(textField->getTouchSize().width, valueToFloat(value))); + textField->setTouchAreaSize(Size(textField->getTouchAreaSize().width, valueToFloat(value))); } else if (key == P_MaxLengthEnable) { @@ -126,7 +126,7 @@ void TextFieldReader::setPropsFromBinary(ax::ui::Widget* widget, CocoLoader* coc } else if (key == P_PasswordStyleText) { - // InputField doesn't support custom password style text + textField->setPasswordChar(value); } } // end of for loop this->endSetBasicProperties(widget); @@ -144,21 +144,21 @@ void TextFieldReader::setPropsFromJsonDictionary(Widget* widget, const rapidjson } textField->setString(DICTOOL->getStringValue_json(options, P_Text, "Text Tield")); - textField->setTextFontSize(DICTOOL->getIntValue_json(options, P_FontSize, 20)); + textField->setFontSize(DICTOOL->getIntValue_json(options, P_FontSize, 20)); std::string fontFilePath{GUIReader::getInstance()->getFilePath()}; auto fontName = DICTOOL->getStringValue_json(options, P_FontName, ""); fontFilePath.append(fontName); if (FileUtils::getInstance()->isFileExist(fontFilePath)) - textField->setTextFontName(fontFilePath); + textField->setFontName(fontFilePath); else - textField->setTextFontName(fontName); + textField->setFontName(fontName); bool tsw = DICTOOL->checkObjectExist_json(options, P_TouchSizeWidth); bool tsh = DICTOOL->checkObjectExist_json(options, P_TouchSizeHeight); if (tsw && tsh) { - textField->setTouchSize(Size(DICTOOL->getFloatValue_json(options, P_TouchSizeWidth), + textField->setTouchAreaSize(Size(DICTOOL->getFloatValue_json(options, P_TouchSizeWidth), DICTOOL->getFloatValue_json(options, P_TouchSizeHeight))); } @@ -177,10 +177,9 @@ void TextFieldReader::setPropsFromJsonDictionary(Widget* widget, const rapidjson } bool passwordEnable = DICTOOL->getBooleanValue_json(options, P_PasswordEnable); textField->setPasswordEnabled(passwordEnable); - // InputField doesn't support custom password style text if (passwordEnable) { - // setPasswordStyleText is not available in InputField + textField->setPasswordChar(DICTOOL->getStringValue_json(options, P_PasswordStyleText, "*")); } WidgetReader::setColorPropsFromJsonDictionary(widget, options); @@ -330,10 +329,10 @@ void TextFieldReader::setPropsWithFlatBuffers(ax::Node* node, const flatbuffers: } int fontSize = options->fontSize(); - textField->setTextFontSize(fontSize); + textField->setFontSize(fontSize); std::string fontName = options->fontName()->c_str(); - textField->setTextFontName(fontName); + textField->setFontName(fontName); bool maxLengthEnabled = options->maxLengthEnabled() != 0; // InputField doesn't have setMaxLengthEnabled, only setMaxLength @@ -344,10 +343,10 @@ void TextFieldReader::setPropsWithFlatBuffers(ax::Node* node, const flatbuffers: } bool passwordEnabled = options->passwordEnabled() != 0; textField->setPasswordEnabled(passwordEnabled); - // InputField doesn't support custom password style text if (passwordEnabled) { - // setPasswordStyleText is not available in InputField + std::string passwordStyleText = options->passwordStyleText()->c_str(); + textField->setPasswordChar(passwordStyleText); } bool fileExist = false; @@ -367,18 +366,17 @@ void TextFieldReader::setPropsWithFlatBuffers(ax::Node* node, const flatbuffers: } if (fileExist) { - textField->setTextFontName(path); + textField->setFontName(path); } } auto widgetReader = WidgetReader::getInstance(); widgetReader->setPropsWithFlatBuffers(node, (Table*)options->widgetOptions()); - textField->setUnifySizeEnabled(false); - textField->ignoreContentAdaptWithSize(false); + textField->setAutoSize(false); auto widgetOptions = options->widgetOptions(); - if (!textField->isIgnoreContentAdaptWithSize()) + if (!textField->isAutoSize()) { ((Label*)(textField->getRenderNode()))->setLineBreakWithoutSpace(true); Size contentSize(widgetOptions->size()->width(), widgetOptions->size()->height()); @@ -388,11 +386,11 @@ void TextFieldReader::setPropsWithFlatBuffers(ax::Node* node, const flatbuffers: Node* TextFieldReader::createNodeWithFlatBuffers(const flatbuffers::Table* textFieldOptions) { - TextField* textField = TextField::create(); + InputField* inputField = InputField::create(); - setPropsWithFlatBuffers(textField, (Table*)textFieldOptions); + setPropsWithFlatBuffers(inputField, (Table*)textFieldOptions); - return textField; + return inputField; } } // namespace ax::ext diff --git a/extensions/sceneio/src/sceneio/sceneio.cpp b/extensions/sceneio/src/sceneio/sceneio.cpp index c9c28a728387..cea643eee4e0 100644 --- a/extensions/sceneio/src/sceneio/sceneio.cpp +++ b/extensions/sceneio/src/sceneio/sceneio.cpp @@ -15,6 +15,7 @@ #include "sceneio/WidgetReader/ImageViewReader/ImageViewReader.h" #include "sceneio/WidgetReader/TextBMFontReader/TextBMFontReader.h" #include "sceneio/WidgetReader/TextReader/TextReader.h" +#include "sceneio/WidgetReader/TextFieldReader/TextFieldReader.h" #include "sceneio/WidgetReader/TextAtlasReader/TextAtlasReader.h" #include "sceneio/WidgetReader/LoadingBarReader/LoadingBarReader.h" #include "sceneio/WidgetReader/SliderReader/SliderReader.h" @@ -48,6 +49,7 @@ SCNIO_API void initializeSceneIO() factoryCreate->registerType(CREATE_CLASS_WIDGET_READER_INFO(TextAtlasReader)); factoryCreate->registerType(CREATE_CLASS_WIDGET_READER_INFO(TextReader)); factoryCreate->registerType(CREATE_CLASS_WIDGET_READER_INFO(TextBMFontReader)); + factoryCreate->registerType(CREATE_CLASS_WIDGET_READER_INFO(TextFieldReader)); factoryCreate->registerType(CREATE_CLASS_WIDGET_READER_INFO(LayoutReader)); factoryCreate->registerType(CREATE_CLASS_WIDGET_READER_INFO(PageViewReader)); factoryCreate->registerType(CREATE_CLASS_WIDGET_READER_INFO(ScrollViewReader)); @@ -70,6 +72,7 @@ SCNIO_API void cleanupSceneIO() factoryCreate->unregisterType(_AXSTR(TextAtlasReader)); factoryCreate->unregisterType(_AXSTR(TextReader)); factoryCreate->unregisterType(_AXSTR(TextBMFontReader)); + factoryCreate->unregisterType(_AXSTR(TextFieldReader)); factoryCreate->unregisterType(_AXSTR(LayoutReader)); factoryCreate->unregisterType(_AXSTR(PageViewReader)); factoryCreate->unregisterType(_AXSTR(ScrollViewReader)); @@ -89,6 +92,7 @@ SCNIO_API void cleanupSceneIO() ImageViewReader::destroyInstance(); TextBMFontReader::destroyInstance(); TextReader::destroyInstance(); + TextFieldReader::destroyInstance(); TextAtlasReader::destroyInstance(); LoadingBarReader::destroyInstance(); SliderReader::destroyInstance(); From 2effb51dde04e1335d75c113a2f38d6a5b5d6845 Mon Sep 17 00:00:00 2001 From: halx99 Date: Sat, 23 May 2026 15:36:24 +0800 Subject: [PATCH 47/52] Fixup --- axmol/platform/android/java/src/dev/axmol/lib/AxmolEngine.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/axmol/platform/android/java/src/dev/axmol/lib/AxmolEngine.java b/axmol/platform/android/java/src/dev/axmol/lib/AxmolEngine.java index 66c503e9a8ce..5a3389e2f2b8 100644 --- a/axmol/platform/android/java/src/dev/axmol/lib/AxmolEngine.java +++ b/axmol/platform/android/java/src/dev/axmol/lib/AxmolEngine.java @@ -27,6 +27,8 @@ of this software and associated documentation files (the "Software"), to deal package dev.axmol.lib; import android.annotation.SuppressLint; +import android.content.ClipData; +import android.content.ClipboardManager; import android.content.pm.ActivityInfo; import android.content.pm.PackageManager; import android.graphics.Rect; From eee77cfdab6492685dff74edd72f4915dafbf710 Mon Sep 17 00:00:00 2001 From: halx99 Date: Sat, 23 May 2026 15:37:19 +0800 Subject: [PATCH 48/52] Update luabindings --- .../lua-bindings/auto/axlua_base_auto.cpp | 107 ++++++++++++++++++ 1 file changed, 107 insertions(+) diff --git a/extensions/scripting/lua-bindings/auto/axlua_base_auto.cpp b/extensions/scripting/lua-bindings/auto/axlua_base_auto.cpp index 4786943a74ed..9dfd9b190def 100644 --- a/extensions/scripting/lua-bindings/auto/axlua_base_auto.cpp +++ b/extensions/scripting/lua-bindings/auto/axlua_base_auto.cpp @@ -104281,6 +104281,110 @@ int lua_register_ax_base_TextureCache(lua_State* tolua_S) return 1; } +int lua_ax_base_Device_getClipboardText(lua_State* tolua_S) +{ + int argc = 0; + bool ok = true; + +#if _AX_DEBUG >= 1 + tolua_Error tolua_err; +#endif + +#if _AX_DEBUG >= 1 + if (!tolua_isusertable(tolua_S,1,"ax.Device",0,&tolua_err)) goto tolua_lerror; +#endif + + argc = lua_gettop(tolua_S) - 1; + + if (argc == 0) + { + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_ax_base_Device_getClipboardText'", nullptr); + return 0; + } + auto&& ret = ax::Device::getClipboardText(); + lua_pushlstring(tolua_S,ret.c_str(),ret.length()); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d\n ", "ax.Device:getClipboardText",argc, 0); + return 0; +#if _AX_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_ax_base_Device_getClipboardText'.",&tolua_err); +#endif + return 0; +} +int lua_ax_base_Device_setClipboardText(lua_State* tolua_S) +{ + int argc = 0; + bool ok = true; + +#if _AX_DEBUG >= 1 + tolua_Error tolua_err; +#endif + +#if _AX_DEBUG >= 1 + if (!tolua_isusertable(tolua_S,1,"ax.Device",0,&tolua_err)) goto tolua_lerror; +#endif + + argc = lua_gettop(tolua_S) - 1; + + if (argc == 1) + { + std::string_view arg0; + ok &= luaval_to_std_string_view(tolua_S, 2,&arg0, "ax.Device:setClipboardText"); + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_ax_base_Device_setClipboardText'", nullptr); + return 0; + } + ax::Device::setClipboardText(arg0); + lua_settop(tolua_S, 1); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d\n ", "ax.Device:setClipboardText",argc, 1); + return 0; +#if _AX_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_ax_base_Device_setClipboardText'.",&tolua_err); +#endif + return 0; +} +int lua_ax_base_Device_clearClipboard(lua_State* tolua_S) +{ + int argc = 0; + bool ok = true; + +#if _AX_DEBUG >= 1 + tolua_Error tolua_err; +#endif + +#if _AX_DEBUG >= 1 + if (!tolua_isusertable(tolua_S,1,"ax.Device",0,&tolua_err)) goto tolua_lerror; +#endif + + argc = lua_gettop(tolua_S) - 1; + + if (argc == 0) + { + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_ax_base_Device_clearClipboard'", nullptr); + return 0; + } + ax::Device::clearClipboard(); + lua_settop(tolua_S, 1); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d\n ", "ax.Device:clearClipboard",argc, 0); + return 0; +#if _AX_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_ax_base_Device_clearClipboard'.",&tolua_err); +#endif + return 0; +} int lua_ax_base_Device_getDPI(lua_State* tolua_S) { int argc = 0; @@ -104955,6 +105059,9 @@ int lua_register_ax_base_Device(lua_State* tolua_S) tolua_cclass(tolua_S,"Device","ax.Device","",nullptr); tolua_beginmodule(tolua_S,"Device"); + tolua_function(tolua_S,"getClipboardText", lua_ax_base_Device_getClipboardText); + tolua_function(tolua_S,"setClipboardText", lua_ax_base_Device_setClipboardText); + tolua_function(tolua_S,"clearClipboard", lua_ax_base_Device_clearClipboard); tolua_function(tolua_S,"getDPI", lua_ax_base_Device_getDPI); tolua_function(tolua_S,"getPixelRatio", lua_ax_base_Device_getPixelRatio); tolua_function(tolua_S,"setAccelerometerEnabled", lua_ax_base_Device_setAccelerometerEnabled); From 505582fdf37ee7f40bac6d74b1718fc91e57d7ee Mon Sep 17 00:00:00 2001 From: axmol-bot <116471739+axmol-bot@users.noreply.github.com> Date: Sat, 23 May 2026 07:38:27 +0000 Subject: [PATCH 49/52] Committing clang-format changes --- axmol/base/InputDispatcher.cpp | 10 +++++----- .../WidgetReader/TextFieldReader/TextFieldReader.cpp | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/axmol/base/InputDispatcher.cpp b/axmol/base/InputDispatcher.cpp index 188b46abdc77..f28164d685ac 100644 --- a/axmol/base/InputDispatcher.cpp +++ b/axmol/base/InputDispatcher.cpp @@ -149,7 +149,7 @@ bool InputDispatcher::attachDelegateWithIME(InputDelegate* delegate) // detach first InputDelegate* oldDelegate = _impl->_delegateWithIme; - _impl->_delegateWithIme = 0; + _impl->_delegateWithIme = 0; oldDelegate->didDetachWithIME(); _impl->_delegateWithIme = *iter; @@ -253,7 +253,7 @@ void InputDispatcher::dispatchKeyboardWillShow(IMEKeyboardNotificationInfo& info if (_impl) { InputDelegate* delegate = nullptr; - DelegateIter last = _impl->_delegateList.end(); + DelegateIter last = _impl->_delegateList.end(); for (DelegateIter first = _impl->_delegateList.begin(); first != last; ++first) { delegate = *(first); @@ -270,7 +270,7 @@ void InputDispatcher::dispatchKeyboardDidShow(IMEKeyboardNotificationInfo& info) if (_impl) { InputDelegate* delegate = nullptr; - DelegateIter last = _impl->_delegateList.end(); + DelegateIter last = _impl->_delegateList.end(); for (DelegateIter first = _impl->_delegateList.begin(); first != last; ++first) { delegate = *(first); @@ -287,7 +287,7 @@ void InputDispatcher::dispatchKeyboardWillHide(IMEKeyboardNotificationInfo& info if (_impl) { InputDelegate* delegate = nullptr; - DelegateIter last = _impl->_delegateList.end(); + DelegateIter last = _impl->_delegateList.end(); for (DelegateIter first = _impl->_delegateList.begin(); first != last; ++first) { delegate = *(first); @@ -304,7 +304,7 @@ void InputDispatcher::dispatchKeyboardDidHide(IMEKeyboardNotificationInfo& info) if (_impl) { InputDelegate* delegate = nullptr; - DelegateIter last = _impl->_delegateList.end(); + DelegateIter last = _impl->_delegateList.end(); for (DelegateIter first = _impl->_delegateList.begin(); first != last; ++first) { delegate = *(first); diff --git a/extensions/sceneio/src/sceneio/WidgetReader/TextFieldReader/TextFieldReader.cpp b/extensions/sceneio/src/sceneio/WidgetReader/TextFieldReader/TextFieldReader.cpp index 13b22304ac21..017d2c84aef3 100644 --- a/extensions/sceneio/src/sceneio/WidgetReader/TextFieldReader/TextFieldReader.cpp +++ b/extensions/sceneio/src/sceneio/WidgetReader/TextFieldReader/TextFieldReader.cpp @@ -126,7 +126,7 @@ void TextFieldReader::setPropsFromBinary(ax::ui::Widget* widget, CocoLoader* coc } else if (key == P_PasswordStyleText) { - textField->setPasswordChar(value); + textField->setPasswordChar(value); } } // end of for loop this->endSetBasicProperties(widget); @@ -159,7 +159,7 @@ void TextFieldReader::setPropsFromJsonDictionary(Widget* widget, const rapidjson if (tsw && tsh) { textField->setTouchAreaSize(Size(DICTOOL->getFloatValue_json(options, P_TouchSizeWidth), - DICTOOL->getFloatValue_json(options, P_TouchSizeHeight))); + DICTOOL->getFloatValue_json(options, P_TouchSizeHeight))); } // float dw = DICTOOL->getFloatValue_json(options, "width"); From 461fa327b1a03476a6fb6346888ae8b1e441d794 Mon Sep 17 00:00:00 2001 From: halx99 Date: Sat, 23 May 2026 15:45:19 +0800 Subject: [PATCH 50/52] fixup --- axmol/platform/ios/Device-ios.mm | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/axmol/platform/ios/Device-ios.mm b/axmol/platform/ios/Device-ios.mm index e86c351bd827..3b82374459fc 100644 --- a/axmol/platform/ios/Device-ios.mm +++ b/axmol/platform/ios/Device-ios.mm @@ -1006,12 +1006,16 @@ static bool _initWithString(std::string_view text, void Device::setClipboardText(std::string_view text) { +#if TARGET_OS_IOS [UIPasteboard generalPasteboard].string = [NSString stringWithUTF8String:text.data()]; +#endif } void Device::clearClipboard() { +#if TARGET_OS_IOS [UIPasteboard generalPasteboard].string = nil; +#endif } } // namespace ax From 7e4d580136077846525eb88cdc7bacf094abd050 Mon Sep 17 00:00:00 2001 From: halx99 Date: Sat, 23 May 2026 16:36:22 +0800 Subject: [PATCH 51/52] fixup --- axmol/platform/desktop/Device-desktop.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/axmol/platform/desktop/Device-desktop.cpp b/axmol/platform/desktop/Device-desktop.cpp index 3115678fa5f3..f0f7dd463a8e 100644 --- a/axmol/platform/desktop/Device-desktop.cpp +++ b/axmol/platform/desktop/Device-desktop.cpp @@ -28,7 +28,7 @@ THE SOFTWARE. namespace ax { -std::string getClipboardText() +std::string Device::getClipboardText() { return glfwGetClipboardString(nullptr); } From ac07dc212c893411965a89a4fa9af365c3bac0b6 Mon Sep 17 00:00:00 2001 From: halx99 Date: Sat, 23 May 2026 17:09:45 +0800 Subject: [PATCH 52/52] Fixup --- axmol/platform/ios/Device-ios.mm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/axmol/platform/ios/Device-ios.mm b/axmol/platform/ios/Device-ios.mm index 3b82374459fc..2141e1c3a738 100644 --- a/axmol/platform/ios/Device-ios.mm +++ b/axmol/platform/ios/Device-ios.mm @@ -997,11 +997,12 @@ static bool _initWithString(std::string_view text, std::string Device::getClipboardText() { +#if TARGET_OS_IOS NSString* text = [UIPasteboard generalPasteboard].string; if (text) return std::string([text UTF8String]); - else - return std::string(); +#endif + return std::string{}; } void Device::setClipboardText(std::string_view text)