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/Label.cpp b/axmol/2d/Label.cpp index 4ed93429c17a..ff4d26f45b91 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); @@ -569,7 +615,6 @@ void Label::reset() _currLabelEffect = LabelEffect::NORMAL; _contentDirty = false; _numberOfLines = 0; - _lengthOfString = 0; _utf32Text.clear(); _utf8Text.clear(); @@ -907,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); } } } @@ -1006,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); @@ -1102,7 +1151,6 @@ void Label::alignText() bool Label::tryTextPlacement(float fontSize) { - _lengthOfString = 0; _textDesiredHeight = 0.f; _linesWidth.clear(); @@ -1212,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) @@ -2066,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; } @@ -2297,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) @@ -2424,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 @@ -2901,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; @@ -3119,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 94f8484eb6c9..70d5271f2a9b 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` @@ -376,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. @@ -835,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/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/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/axmol.h b/axmol/axmol.h index d7e04c434a8f..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" @@ -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/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 75% rename from axmol/base/IMEDelegate.h rename to axmol/base/InputDelegate.h index 011e023a8966..0c3b6dea7e3d 100644 --- a/axmol/base/IMEDelegate.h +++ b/axmol/base/InputDelegate.h @@ -27,6 +27,7 @@ THE SOFTWARE. #pragma once #include +#include #include "axmol/math/Math.h" #include "axmol/base/EventKeyboard.h" @@ -53,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,17 +78,24 @@ class AX_DLL IMEDelegate virtual bool detachWithIME(); protected: - friend class IMEDispatcher; + 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 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() {} @@ -99,34 +107,40 @@ 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 InputDispatcher when the preedit text is updated. * @lua NA */ - virtual void insertText(const char* /*text*/, size_t /*len*/) {} + 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(size_t numChars) {} + 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() { return STD_STRING_EMPTY; } + virtual std::string_view getContentText() const { return STD_STRING_EMPTY; } ////////////////////////////////////////////////////////////////////////// // keyboard show/hide notification @@ -152,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 69% rename from axmol/base/IMEDispatcher.cpp rename to axmol/base/InputDispatcher.cpp index 7c24cac92c7a..f28164d685ac 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::sharedDispatcher()->addDelegate(this); + InputDispatcher::getInstance()->addDelegate(this); } -IMEDelegate::~IMEDelegate() +InputDelegate::~InputDelegate() { - IMEDispatcher::sharedDispatcher()->removeDelegate(this); + InputDispatcher::getInstance()->removeDelegate(this); } -bool IMEDelegate::attachWithIME() +bool InputDelegate::attachWithIME() { - return IMEDispatcher::sharedDispatcher()->attachDelegateWithIME(this); + return InputDispatcher::getInstance()->attachDelegateWithIME(this); } -bool IMEDelegate::detachWithIME() +bool InputDelegate::detachWithIME() { - return IMEDispatcher::sharedDispatcher()->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,25 +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); } +bool InputDispatcher::hasAttachedDelegate() const +{ + 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) { @@ -113,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 @@ -136,8 +148,8 @@ bool IMEDispatcher::attachDelegateWithIME(IMEDelegate* delegate) AX_BREAK_IF(!_impl->_delegateWithIme->canDetachWithIME() || !delegate->canAttachWithIME()); // detach first - IMEDelegate* oldDelegate = _impl->_delegateWithIme; - _impl->_delegateWithIme = 0; + InputDelegate* oldDelegate = _impl->_delegateWithIme; + _impl->_delegateWithIme = 0; oldDelegate->didDetachWithIME(); _impl->_delegateWithIme = *iter; @@ -157,7 +169,7 @@ bool IMEDispatcher::attachDelegateWithIME(IMEDelegate* delegate) return ret; } -bool IMEDispatcher::detachDelegateWithIME(IMEDelegate* delegate) +bool InputDispatcher::detachDelegateWithIME(InputDelegate* delegate) { bool ret = false; do @@ -176,7 +188,7 @@ bool IMEDispatcher::detachDelegateWithIME(IMEDelegate* delegate) return ret; } -void IMEDispatcher::removeDelegate(IMEDelegate* delegate) +void InputDispatcher::removeDelegate(InputDelegate* delegate) { do { @@ -196,55 +208,39 @@ void IMEDispatcher::removeDelegate(IMEDelegate* delegate) } while (0); } +void InputDispatcher::dispatchUpdatePreedit(std::string_view preeditText, int caret) +{ + if (_impl && _impl->_delegateWithIme) + _impl->_delegateWithIme->updatePreeditText(preeditText, caret); +} + ////////////////////////////////////////////////////////////////////////// // dispatch text message ////////////////////////////////////////////////////////////////////////// -void IMEDispatcher::dispatchInsertText(const char* text, size_t len) +void InputDispatcher::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(int numChars) +void InputDispatcher::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) +void InputDispatcher::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() +std::string_view InputDispatcher::getContentText() { if (_impl && _impl->_delegateWithIme) - { return _impl->_delegateWithIme->getContentText(); - } + return STD_STRING_EMPTY; } @@ -252,12 +248,12 @@ std::string_view IMEDispatcher::getContentText() // dispatch keyboard message ////////////////////////////////////////////////////////////////////////// -void IMEDispatcher::dispatchKeyboardWillShow(IMEKeyboardNotificationInfo& info) +void InputDispatcher::dispatchKeyboardWillShow(IMEKeyboardNotificationInfo& info) { if (_impl) { - IMEDelegate* delegate = nullptr; - DelegateIter last = _impl->_delegateList.end(); + InputDelegate* delegate = nullptr; + DelegateIter last = _impl->_delegateList.end(); for (DelegateIter first = _impl->_delegateList.begin(); first != last; ++first) { delegate = *(first); @@ -269,12 +265,12 @@ void IMEDispatcher::dispatchKeyboardWillShow(IMEKeyboardNotificationInfo& info) } } -void IMEDispatcher::dispatchKeyboardDidShow(IMEKeyboardNotificationInfo& info) +void InputDispatcher::dispatchKeyboardDidShow(IMEKeyboardNotificationInfo& info) { if (_impl) { - IMEDelegate* delegate = nullptr; - DelegateIter last = _impl->_delegateList.end(); + InputDelegate* delegate = nullptr; + DelegateIter last = _impl->_delegateList.end(); for (DelegateIter first = _impl->_delegateList.begin(); first != last; ++first) { delegate = *(first); @@ -286,12 +282,12 @@ void IMEDispatcher::dispatchKeyboardDidShow(IMEKeyboardNotificationInfo& info) } } -void IMEDispatcher::dispatchKeyboardWillHide(IMEKeyboardNotificationInfo& info) +void InputDispatcher::dispatchKeyboardWillHide(IMEKeyboardNotificationInfo& info) { if (_impl) { - IMEDelegate* delegate = nullptr; - DelegateIter last = _impl->_delegateList.end(); + InputDelegate* delegate = nullptr; + DelegateIter last = _impl->_delegateList.end(); for (DelegateIter first = _impl->_delegateList.begin(); first != last; ++first) { delegate = *(first); @@ -303,12 +299,12 @@ void IMEDispatcher::dispatchKeyboardWillHide(IMEKeyboardNotificationInfo& info) } } -void IMEDispatcher::dispatchKeyboardDidHide(IMEKeyboardNotificationInfo& info) +void InputDispatcher::dispatchKeyboardDidHide(IMEKeyboardNotificationInfo& info) { if (_impl) { - IMEDelegate* delegate = nullptr; - DelegateIter last = _impl->_delegateList.end(); + InputDelegate* delegate = nullptr; + DelegateIter last = _impl->_delegateList.end(); for (DelegateIter first = _impl->_delegateList.begin(); first != last; ++first) { delegate = *(first); @@ -328,9 +324,9 @@ void IMEDispatcher::dispatchKeyboardDidHide(IMEKeyboardNotificationInfo& info) // static member function ////////////////////////////////////////////////////////////////////////// -IMEDispatcher* IMEDispatcher::sharedDispatcher() +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 67% rename from axmol/base/IMEDispatcher.h rename to axmol/base/InputDispatcher.h index 71bb82ce9304..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,31 +38,48 @@ 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* sharedDispatcher(); + static InputDispatcher* getInstance(); + + /** + * @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); /** * @brief Dispatches the input text from IME. * @lua NA */ - void dispatchInsertText(const char* text, size_t len); + void dispatchInsertText(std::string_view text); /** * @brief Dispatches the delete-backward operation. * @lua NA */ - void dispatchDeleteBackward(int numChars); + void dispatchDeleteBackward(unsigned int numChars); /** * @brief Dispatches the press control key operation. @@ -71,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(); @@ -97,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/base/text_utils.cpp b/axmol/base/text_utils.cpp index 3624796a22dc..b49848157536 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,36 @@ size_t countUTF8Chars(std::string_view utf8) return count; } +UTF8CountResult countUTF8WithLimit(std::string_view strUTF8, size_t charLimit) +{ + UTF8CountResult result{}; + + 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 + result.success = false; + break; + } + 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/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/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/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..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; @@ -104,6 +106,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 +144,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 +222,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 +1010,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 e65c5cde1116..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::sharedDispatcher()->dispatchInsertText(strValue.c_str(), strValue.size()); + ax::InputDispatcher::getInstance()->dispatchInsertText(strValue); } JNIEXPORT void JNICALL Java_dev_axmol_lib_AxmolPlayer_nativeDeleteBackward(JNIEnv*, jclass, jint numChars) { - ax::IMEDispatcher::sharedDispatcher()->dispatchDeleteBackward(numChars); + ax::InputDispatcher::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::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..25a13402dcd6 100644 --- a/axmol/platform/desktop/Device-desktop.cpp +++ b/axmol/platform/desktop/Device-desktop.cpp @@ -27,6 +27,24 @@ THE SOFTWARE. namespace ax { + +#ifndef _WIN32 +std::string Device::getClipboardText() +{ + return glfwGetClipboardString(nullptr); +} + +void Device::setClipboardText(std::string_view text) +{ + glfwSetClipboardString(nullptr, text.data()); +} + +void Device::clearClipboard() +{ + glfwSetClipboardString(nullptr, nullptr); +} +#endif + 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 40b0f4446811..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" @@ -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; }; @@ -720,6 +735,8 @@ bool RenderViewImpl::initWithRect(std::string_view viewName, }); } // clang-format on +#else + glfwSetPreeditCallback(_mainWindow, GLFWEventHandler::onGLFWPreeditCallback); #endif glfwSetScrollCallback(_mainWindow, GLFWEventHandler::onGLFWMouseScrollCallback); @@ -1410,7 +1427,7 @@ void RenderViewImpl::onGLFWKeyCallback(GLFWwindow* /*window*/, int key, int /*sc switch (g_keyCodeMap[key]) { case EventKeyboard::KeyCode::KEY_BACKSPACE: - IMEDispatcher::sharedDispatcher()->dispatchDeleteBackward(1); + InputDispatcher::getInstance()->dispatchDeleteBackward(1); break; case EventKeyboard::KeyCode::KEY_HOME: case EventKeyboard::KeyCode::KEY_KP_HOME: @@ -1420,7 +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::sharedDispatcher()->dispatchControlKey(g_keyCodeMap[key]); + InputDispatcher::getInstance()->dispatchControlKey(g_keyCodeMap[key]); + break; + case EventKeyboard::KeyCode::KEY_ENTER: + case EventKeyboard::KeyCode::KEY_KP_ENTER: + InputDispatcher::getInstance()->dispatchInsertText("\n"sv); break; default: break; @@ -1430,27 +1451,63 @@ 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(), utf8String.size()); + std::string utf8String; + char32_t codepoint = static_cast(charCode); + text_utils::UTF32ToUTF8(std::u32string_view{&codepoint, 1zu}, utf8String); + InputDispatcher::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) +{ + std::string utf8String; + + if (preedit_count > 0) + { + text_utils::UTF32ToUTF8( + std::u32string_view{std::bit_cast(preedit_string), static_cast(preedit_count)}, + utf8String); + } + + InputDispatcher::getInstance()->dispatchUpdatePreedit(utf8String, caret); +} + void RenderViewImpl::onGLFWWindowPosCallback(GLFWwindow* /*window*/, int x, int y) { auto director = Director::getInstance(); 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/Device-ios.mm b/axmol/platform/ios/Device-ios.mm index dee568b93be5..2141e1c3a738 100644 --- a/axmol/platform/ios/Device-ios.mm +++ b/axmol/platform/ios/Device-ios.mm @@ -995,4 +995,28 @@ static bool _initWithString(std::string_view text, return resolvedOrientation; } +std::string Device::getClipboardText() +{ +#if TARGET_OS_IOS + NSString* text = [UIPasteboard generalPasteboard].string; + if (text) + return std::string([text UTF8String]); +#endif + return std::string{}; +} + +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 diff --git a/axmol/platform/ios/InputView-ios.mm b/axmol/platform/ios/InputView-ios.mm index 3ffd437b7988..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 () @@ -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,28 @@ - (BOOL)canBecomeFirstResponder return YES; } +- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent*)event +{ + auto inputDisp = ax::InputDispatcher::getInstance(); + if (inputDisp->hasAttachedDelegate()) + { + 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 = inputDisp->dispatchHitTestWithIME(pt); + if (keep) + return NO; + } + return YES; +} + - (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event { [self resignFirstResponder]; @@ -98,7 +121,7 @@ - (void)deleteBackward [self.myMarkedText release]; self.myMarkedText = nil; } - ax::IMEDispatcher::sharedDispatcher()->dispatchDeleteBackward(1); + ax::InputDispatcher::getInstance()->dispatchDeleteBackward(1u); } - (void)insertText:(nonnull NSString*)text @@ -109,7 +132,7 @@ - (void)insertText:(nonnull NSString*)text self.myMarkedText = nil; } const char* pszText = [text cStringUsingEncoding:NSUTF8StringEncoding]; - ax::IMEDispatcher::sharedDispatcher()->dispatchInsertText(pszText, strlen(pszText)); + ax::InputDispatcher::getInstance()->dispatchInsertText(std::string_view{pszText, strlen(pszText)}); } - (NSWritingDirection)baseWritingDirectionForPosition:(nonnull UITextPosition*)position @@ -251,7 +274,7 @@ - (void)unmarkText return; } const char* pszText = [self.myMarkedText cStringUsingEncoding:NSUTF8StringEncoding]; - ax::IMEDispatcher::sharedDispatcher()->dispatchInsertText(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 0cad17857d0a..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::sharedDispatcher(); + ax::InputDispatcher* dispatcher = ax::InputDispatcher::getInstance(); if (UIKeyboardWillShowNotification == type) { dispatcher->dispatchKeyboardWillShow(notiInfo); diff --git a/axmol/platform/win32/Device-win32.cpp b/axmol/platform/win32/Device-win32.cpp index 0b7c06cb6801..5cc6373eac77 100644 --- a/axmol/platform/win32/Device-win32.cpp +++ b/axmol/platform/win32/Device-win32.cpp @@ -31,6 +31,82 @@ THE SOFTWARE. namespace ax { + +std::string Device::getClipboardText() +{ + std::string result; + if (!OpenClipboard(nullptr)) + return result; + + HANDLE hData = GetClipboardData(CF_UNICODETEXT); + if (hData) + { + LPCWSTR pwsz = static_cast(GlobalLock(hData)); + if (pwsz) + { + result = ntcvt::from_chars(pwsz, CP_UTF8); + GlobalUnlock(hData); + } + } + + CloseClipboard(); + return result; +} + +void Device::setClipboardText(std::string_view text) +{ + // Convert to wide (UTF-16) + std::wstring w = ntcvt::from_chars(text, CP_UTF8); + + if (!OpenClipboard(nullptr)) + return; + + // Empty clipboard first + if (!EmptyClipboard()) + { + CloseClipboard(); + return; + } + + // Allocate global memory for the wide string including null terminator + size_t bytes = (w.size() + 1) * sizeof(wchar_t); + HGLOBAL hGlob = GlobalAlloc(GMEM_MOVEABLE, bytes); + if (!hGlob) + { + CloseClipboard(); + return; + } + + void* pGlob = GlobalLock(hGlob); + if (!pGlob) + { + GlobalFree(hGlob); + CloseClipboard(); + return; + } + + memcpy(pGlob, w.c_str(), bytes); + GlobalUnlock(hGlob); + + // Set clipboard data as CF_UNICODETEXT + if (SetClipboardData(CF_UNICODETEXT, hGlob) == nullptr) + { + GlobalFree(hGlob); + } + + CloseClipboard(); + // Do not free hGlob after SetClipboardData succeeds; system owns it. +} + +void Device::clearClipboard() +{ + if (!OpenClipboard(nullptr)) + return; + + EmptyClipboard(); + CloseClipboard(); +} + int Device::getDPI() { static int dpi = -1; diff --git a/axmol/platform/winrt/Device-winrt.cpp b/axmol/platform/winrt/Device-winrt.cpp index 23198cb74aa9..bcf26480666e 100644 --- a/axmol/platform/winrt/Device-winrt.cpp +++ b/axmol/platform/winrt/Device-winrt.cpp @@ -33,6 +33,7 @@ THE SOFTWARE. # include # include # include +# include # include "ntcvt/ntcvt.hpp" # include "axmol/platform/StdC.h" # include "axmol/platform/Device.h" @@ -40,11 +41,16 @@ THE SOFTWARE. # include "axmol/platform/winrt/WinRTUtils.h" # include "axmol/platform/winrt/RenderViewImpl-winrt.h" # include +# include +# include using namespace winrt; using namespace Windows::Graphics::Display; using namespace Windows::Devices::Sensors; using namespace Windows::Foundation; +using namespace Windows::UI::Core; +using namespace Windows::ApplicationModel::Core; +using namespace Windows::ApplicationModel::DataTransfer; # if (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP) using namespace Windows::Phone::Devices::Notification; @@ -53,6 +59,49 @@ using namespace Windows::Phone::Devices::Notification; namespace ax { +std::string Device::getClipboardText() +{ + try + { + DataPackageView view = Clipboard::GetContent(); + if (!view) + return std::string{}; + hstring hs = view.GetTextAsync().get(); + return ntcvt::from_chars(std::wstring_view{hs.c_str(), hs.size()}, CP_UTF8); + } + catch (hresult_error const&) + { + return std::string{}; + } +} + +void Device::setClipboardText(std::string_view text) +{ + DataPackage dp; + dp.RequestedOperation(DataPackageOperation::Copy); + dp.SetText(winrt::to_hstring(text)); + + auto dispatcher = CoreApplication::MainView().CoreWindow().Dispatcher(); + dispatcher.RunAsync(CoreDispatcherPriority::Normal, [dp]() mutable { + try + { + Clipboard::SetContent(dp); + } + catch (hresult_error const& e) + {} + }); +} + +void Device::clearClipboard() +{ + try + { + Clipboard::Clear(); + } + catch (hresult_error const&) + {} +} + int Device::getDPI() { return static_cast(ax::RenderViewImpl::sharedRenderView()->GetDPI()); diff --git a/axmol/platform/winrt/InputEvent.cpp b/axmol/platform/winrt/InputEvent.cpp index ea9dd1496b42..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,21 +88,18 @@ void KeyboardEvent::execute() case AxmolKeyEvent::Text: { std::string utf8String = PlatformStringToString(m_text); - IMEDispatcher::sharedDispatcher()->dispatchInsertText(utf8String.c_str(), utf8String.size()); + InputDispatcher::getInstance()->dispatchInsertText(utf8String); break; } default: switch (m_type) { - case AxmolKeyEvent::Escape: - // Director::getInstance()()->getKeypadDispatcher()->dispatchKeypadMSG(kTypeBackClicked); - break; case AxmolKeyEvent::Back: - IMEDispatcher::sharedDispatcher()->dispatchDeleteBackward(1); + InputDispatcher::getInstance()->dispatchDeleteBackward(1); break; case AxmolKeyEvent::Enter: - IMEDispatcher::sharedDispatcher()->dispatchInsertText("\n", 1); + 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 f40ce549a23c..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::sharedDispatcher()->dispatchInsertText("\n", 1); + 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::sharedDispatcher()->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::sharedDispatcher()->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/UIAbstractCheckButton.cpp b/axmol/ui/AbstractCheckButton.cpp similarity index 97% rename from axmol/ui/UIAbstractCheckButton.cpp rename to axmol/ui/AbstractCheckButton.cpp index f0b84d36cdc8..a6fe190747cb 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" @@ -107,7 +107,7 @@ bool AbstractCheckButton::init() return false; } -void AbstractCheckButton::initRenderer() +void AbstractCheckButton::initRenderNode() { _backGroundBoxRenderer = Sprite::create(); _backGroundSelectedBoxRenderer = Sprite::create(); @@ -161,7 +161,7 @@ void AbstractCheckButton::setupBackgroundTexture() this->updateChildrenDisplayedRGBA(); - updateContentSizeWithTextureSize(_backGroundBoxRenderer->getContentSize()); + updateContentSize(); _backGroundBoxRendererAdaptDirty = true; } @@ -405,7 +405,7 @@ void AbstractCheckButton::onSizeChanged() _frontCrossDisabledRendererAdaptDirty = true; } -void AbstractCheckButton::adaptRenderers() +void AbstractCheckButton::updateLayout() { if (_backGroundBoxRendererAdaptDirty) { @@ -434,19 +434,19 @@ void AbstractCheckButton::adaptRenderers() } } -Vec2 AbstractCheckButton::getVirtualRendererSize() const +Vec2 AbstractCheckButton::resolvePreferredSize(const Vec2& /*sizeHint*/) const { return _backGroundBoxRenderer->getContentSize(); } -Node* AbstractCheckButton::getVirtualRenderer() +Node* AbstractCheckButton::getRenderNode() { return _backGroundBoxRenderer; } void AbstractCheckButton::backGroundTextureScaleChangedWithSize() { - if (_ignoreSize) + if (_autoSize) { _backGroundBoxRenderer->setScale(1.0f); _backgroundTextureScaleX = _backgroundTextureScaleY = 1.0f; @@ -472,7 +472,7 @@ void AbstractCheckButton::backGroundTextureScaleChangedWithSize() void AbstractCheckButton::backGroundSelectedTextureScaleChangedWithSize() { - if (_ignoreSize) + if (_autoSize) { _backGroundSelectedBoxRenderer->setScale(1.0f); } @@ -494,7 +494,7 @@ void AbstractCheckButton::backGroundSelectedTextureScaleChangedWithSize() void AbstractCheckButton::frontCrossTextureScaleChangedWithSize() { - if (_ignoreSize) + if (_autoSize) { _frontCrossRenderer->setScale(1.0f); } @@ -516,7 +516,7 @@ void AbstractCheckButton::frontCrossTextureScaleChangedWithSize() void AbstractCheckButton::backGroundDisabledTextureScaleChangedWithSize() { - if (_ignoreSize) + if (_autoSize) { _backGroundBoxDisabledRenderer->setScale(1.0f); } @@ -538,7 +538,7 @@ void AbstractCheckButton::backGroundDisabledTextureScaleChangedWithSize() void AbstractCheckButton::frontCrossDisabledTextureScaleChangedWithSize() { - if (_ignoreSize) + if (_autoSize) { _frontCrossDisabledRenderer->setScale(1.0f); } diff --git a/axmol/ui/UIAbstractCheckButton.h b/axmol/ui/AbstractCheckButton.h similarity index 97% rename from axmol/ui/UIAbstractCheckButton.h rename to axmol/ui/AbstractCheckButton.h index 0ad318290b70..105758fda4c0 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" /** @@ -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 resolvePreferredSize(const Vec2& sizeHint) 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) @@ -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/Button.cpp similarity index 85% rename from axmol/ui/UIButton.cpp rename to axmol/ui/Button.cpp index 7a433e2cbe0f..7337e9f7b824 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 @@ -53,7 +53,7 @@ Button::Button() , _buttonDisabledRenderer(nullptr) , _titleRenderer(nullptr) , _zoomScale(0.1f) - , _prevIgnoreSize(true) + , _prevAutoSize(true) , _scale9Enabled(false) , _pressedActionEnabled(false) , _capInsetsNormal(Rect::ZERO) @@ -133,7 +133,7 @@ bool Button::init() return false; } -void Button::initRenderer() +void Button::initRenderNode() { _buttonNormalRenderer = Scale9Sprite::create(); _buttonClickedRenderer = Scale9Sprite::create(); @@ -213,13 +213,55 @@ void Button::setScale9Enabled(bool able) if (_scale9Enabled) { - bool ignoreBefore = _ignoreSize; - ignoreContentAdaptWithSize(false); - _prevIgnoreSize = ignoreBefore; + 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. + + // Original: + // bool autoSizeBefore = _autoSize; // true if adapting + // setAutoSize(false); // Switch to fixed size + // _prevAutoSize = autoSizeBefore; + + // If autoSizeBefore was true (adapting), _prevAutoSize becomes false. + // If autoSizeBefore was false (fixed), _prevAutoSize becomes true. + + setAutoSize(false); + _prevAutoSize = autoSizeBefore; } else { - ignoreContentAdaptWithSize(_prevIgnoreSize); + // When disabling scale9, restore previous autoSize state. + // _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 _prevAutoSize is true, then !true = false? No. + + // Let's stick to the behavior: + // Old: _prevAutoSize stored the value passed to ignoreContentAdaptWithSize. + // ignoreContentAdaptWithSize(true) -> Adapt to content. + // New: setAutoSize(true) -> Adapt to content. + // So _prevAutoSize actually corresponds directly to autoSize now? + + // 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: + // _prevAutoSize = autoSize; + + // If we use the reference implementation for setAutoSize: + // It sets _prevAutoSize = autoSize. + + // So in setScale9Enabled: + // else { setAutoSize(_prevAutoSize); } + // If _prevAutoSize = autoSize, then _prevAutoSize = autoSize. + // So it restores the autoSize value. This is correct. + + setAutoSize(_prevAutoSize); } setCapInsetsNormalRenderer(_capInsetsNormal); @@ -239,18 +281,38 @@ bool Button::isScale9Enabled() const return _scale9Enabled; } -void Button::ignoreContentAdaptWithSize(bool ignore) +void Button::setAutoSize(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::setAutoSize(autoSize); + _prevAutoSize = autoSize; // Store the value 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::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: + 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 (!_autoSize && _customSize.equals(Vec2::ZERO)) { _customSize = _buttonNormalRenderer->getContentSize(); } @@ -302,17 +364,8 @@ void Button::setupNormalTexture(bool textureLoaded) this->updateChildrenDisplayedRGBA(); - if (_unifySize) - { - if (!_scale9Enabled) - { - updateContentSizeWithTextureSize(this->getNormalSize()); - } - } - else - { - updateContentSizeWithTextureSize(_normalTextureSize); - } + updateContentSize(); + _normalTextureLoaded = textureLoaded; _normalTextureAdaptDirty = true; } @@ -491,7 +544,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 +645,7 @@ void Button::updateTitleLocation() void Button::updateContentSize() { - if (_unifySize) + if (!_autoSize) { if (_scale9Enabled) { @@ -607,9 +660,9 @@ void Button::updateContentSize() return; } - if (_ignoreSize) + if (_autoSize) { - this->setContentSize(getVirtualRendererSize()); + this->setContentSize(resolvePreferredSize(_customSize)); } } @@ -625,7 +678,7 @@ void Button::onSizeChanged() _disabledTextureAdaptDirty = true; } -void Button::adaptRenderers() +void Button::updateLayout() { if (_normalTextureAdaptDirty) { @@ -646,9 +699,9 @@ void Button::adaptRenderers() } } -Vec2 Button::getVirtualRendererSize() const +Vec2 Button::resolvePreferredSize(const Vec2& /*sizeHint*/) const { - if (_unifySize) + if (!_autoSize) { return this->getNormalSize(); } @@ -664,7 +717,7 @@ Vec2 Button::getVirtualRendererSize() const return _normalTextureSize; } -Node* Button::getVirtualRenderer() +Node* Button::getRenderNode() { if (_bright) { @@ -686,21 +739,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); } @@ -880,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/Button.h similarity index 97% rename from axmol/ui/UIButton.h rename to axmol/ui/Button.h index b1be7b33662f..2ed926faaf9b 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" /** @@ -190,9 +190,9 @@ class AX_GUI_DLL Button : public Widget void setPressedActionEnabled(bool enabled); // override methods - void ignoreContentAdaptWithSize(bool ignore) override; - Vec2 getVirtualRendererSize() const override; - Node* getVirtualRenderer() override; + void setAutoSize(bool autoSize) override; + Vec2 resolvePreferredSize(const Vec2& /*sizeHint*/) const override; + Node* getRenderNode() override; std::string getDescription() const override; /** @@ -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,9 +339,9 @@ class AX_GUI_DLL Button : public Widget void pressedTextureScaleChangedWithSize(); void disabledTextureScaleChangedWithSize(); - void adaptRenderers() override; + void updateLayout() override; virtual void updateTitleLocation(); - void updateContentSize(); + void updateContentSize() override; virtual void createTitleRenderer(); bool createTitleRendererIfNull(); @@ -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/CMakeLists.txt b/axmol/ui/CMakeLists.txt index 869b1fafefc6..fd5f3614833c 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/EditBox/EditBoxImpl-winrt.h ) set(_AX_UI_SPECIFIC_SRC - ui/UIEditBox/UIEditBoxImpl-winrt.cpp + ui/EditBox/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/TextView.h + ui/EditBox/iOS/TextField.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.mm + ui/EditBox/iOS/TextView.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/TextView.h + ui/EditBox/iOS/TextField.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.mm + ui/EditBox/iOS/TextView.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/EditBox/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,69 +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/UITextField.h - ui/UITextFieldEx.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/UITextField.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 + 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 98% rename from axmol/ui/UIEditBox/UIEditBox.cpp rename to axmol/ui/EditBox/EditBox.cpp index 807125338d04..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 { @@ -171,7 +171,7 @@ bool EditBox::initWithSizeAndTexture(const Vec2& size, return false; } -void EditBox::initRenderer() +void EditBox::initRenderNode() { _normalRenderer = Scale9Sprite::create(); _pressedRenderer = Scale9Sprite::create(); @@ -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 (!_autoSize && _customSize.equals(Vec2::ZERO)) { _customSize = _normalRenderer->getContentSize(); } @@ -720,7 +720,7 @@ void EditBox::onSizeChanged() _disabledTextureAdaptDirty = true; } -void EditBox::adaptRenderers() +void EditBox::updateLayout() { if (_normalTextureAdaptDirty) { @@ -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/UIEditBox/UIEditBox.h b/axmol/ui/EditBox/EditBox.h similarity index 98% rename from axmol/ui/UIEditBox/UIEditBox.h rename to axmol/ui/EditBox/EditBox.h index 617a6aedd290..c0de1abdc484 100644 --- a/axmol/ui/UIEditBox/UIEditBox.h +++ b/axmol/ui/EditBox/EditBox.h @@ -27,10 +27,10 @@ #pragma once -#include "axmol/base/IMEDelegate.h" +#include "axmol/base/InputDelegate.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 { @@ -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: /** @@ -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/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 98% rename from axmol/ui/UIEditBox/UIEditBoxImpl-winrt.cpp rename to axmol/ui/EditBox/EditBoxImpl-winrt.cpp index 26796a116175..ed63935d14d1 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" @@ -468,8 +468,8 @@ void UIEditBoxImplWinrt::setNativeFont(std::string_view fontName, int fontSize) auto font = ax::FontFreeType::create(fontName, fontSize, ax::GlyphCollection::DYNAMIC, ""sv); if (font != nullptr) { - std::string fontName = fmt::format("ms-appx:///Content/{}#{}", fontName, font->getFontFamily()); - _system_control->setFontFamily(PlatformStringFromString(fontName)); + std::string family = fmt::format("ms-appx:///Content/{}#{}", fontName, font->getFontFamily()); + _system_control->setFontFamily(PlatformStringFromString(family)); } } 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 91% rename from axmol/ui/UIEditBox/Mac/UIEditBoxMac.h rename to axmol/ui/EditBox/Mac/EditBoxMac.h index 391f2649bf08..070b481ebae3 100644 --- a/axmol/ui/UIEditBox/Mac/UIEditBoxMac.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/ @@ -27,8 +28,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 @@ -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/UIEditBox/Mac/UIEditBoxMac.mm b/axmol/ui/EditBox/Mac/EditBoxMac.mm similarity index 93% rename from axmol/ui/UIEditBox/Mac/UIEditBoxMac.mm rename to axmol/ui/EditBox/Mac/EditBoxMac.mm index 8b8d3e8491c9..e7f70c70deb6 100644 --- a/axmol/ui/UIEditBox/Mac/UIEditBoxMac.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/ @@ -24,11 +25,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) @@ -56,32 +57,32 @@ - (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; - _textInput = textInput; + NSView* oldInput = _textInput; + _textInput = textInput; if (_textInput != nil) { [_textInput retain]; // retain new input view diff --git a/axmol/ui/UIEditBox/Mac/UIMultilineTextField.h b/axmol/ui/EditBox/Mac/MultilineTextField.h similarity index 88% rename from axmol/ui/UIEditBox/Mac/UIMultilineTextField.h rename to axmol/ui/EditBox/Mac/MultilineTextField.h index 02ae18afe325..1e81856bf699 100644 --- a/axmol/ui/UIEditBox/Mac/UIMultilineTextField.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/ @@ -26,9 +27,9 @@ #pragma once #import -#include "axmol/ui/UIEditBox/Mac/UITextInput.h" +#include "axmol/ui/EditBox/Mac/TextInput.h" -@interface CCUIMultilineTextField : NSTextView { +@interface AxmolMultilineTextField : NSTextView { NSString* _placeHolder; } diff --git a/axmol/ui/UIEditBox/Mac/UIMultilineTextField.m b/axmol/ui/EditBox/Mac/MultilineTextField.m similarity index 91% rename from axmol/ui/UIEditBox/Mac/UIMultilineTextField.m rename to axmol/ui/EditBox/Mac/MultilineTextField.m index 035a85ccbb8f..f326abcc9987 100644 --- a/axmol/ui/UIEditBox/Mac/UIMultilineTextField.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/ @@ -23,13 +24,13 @@ 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() +@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/UIEditBox/Mac/UIPasswordTextField.h b/axmol/ui/EditBox/Mac/PasswordTextField.h similarity index 88% rename from axmol/ui/UIEditBox/Mac/UIPasswordTextField.h rename to axmol/ui/EditBox/Mac/PasswordTextField.h index c24aa53c3257..1acc5c730098 100644 --- a/axmol/ui/UIEditBox/Mac/UIPasswordTextField.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/ @@ -26,9 +27,9 @@ #pragma once #import -#include "axmol/ui/UIEditBox/Mac/UITextInput.h" +#include "axmol/ui/EditBox/Mac/TextInput.h" -@interface CCUIPasswordTextField : NSSecureTextField { +@interface AxmolPasswordTextField : NSSecureTextField { } @end diff --git a/axmol/ui/UIEditBox/Mac/UIPasswordTextField.m b/axmol/ui/EditBox/Mac/PasswordTextField.m similarity index 93% rename from axmol/ui/UIEditBox/Mac/UIPasswordTextField.m rename to axmol/ui/EditBox/Mac/PasswordTextField.m index c7887a8de0f3..01bcc648e037 100644 --- a/axmol/ui/UIEditBox/Mac/UIPasswordTextField.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/ @@ -23,8 +24,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 { @@ -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/UIEditBox/Mac/UISingleLineTextField.h b/axmol/ui/EditBox/Mac/SingleLineTextField.h similarity index 88% rename from axmol/ui/UIEditBox/Mac/UISingleLineTextField.h rename to axmol/ui/EditBox/Mac/SingleLineTextField.h index e1602fc27c83..e618b62ef9c7 100644 --- a/axmol/ui/UIEditBox/Mac/UISingleLineTextField.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/ @@ -26,9 +27,9 @@ #pragma once #import -#include "axmol/ui/UIEditBox/Mac/UITextInput.h" +#include "axmol/ui/EditBox/Mac/TextInput.h" -@interface CCUISingleLineTextField : NSTextField { +@interface AxmolSingleLineTextField : NSTextField { } @end diff --git a/axmol/ui/UIEditBox/Mac/UISingleLineTextField.m b/axmol/ui/EditBox/Mac/SingleLineTextField.m similarity index 94% rename from axmol/ui/UIEditBox/Mac/UISingleLineTextField.m rename to axmol/ui/EditBox/Mac/SingleLineTextField.m index abacfc1e3f7d..b1eae3d30de4 100644 --- a/axmol/ui/UIEditBox/Mac/UISingleLineTextField.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/ @@ -23,8 +24,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 { @@ -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/UIEditBox/Mac/UITextFieldFormatter.h b/axmol/ui/EditBox/Mac/TextFieldFormatter.h similarity index 92% rename from axmol/ui/UIEditBox/Mac/UITextFieldFormatter.h rename to axmol/ui/EditBox/Mac/TextFieldFormatter.h index c120bd9ef97e..b9bccec7f65d 100644 --- a/axmol/ui/UIEditBox/Mac/UITextFieldFormatter.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/UIEditBox/Mac/UITextFieldFormatter.m b/axmol/ui/EditBox/Mac/TextFieldFormatter.m similarity index 92% rename from axmol/ui/UIEditBox/Mac/UITextFieldFormatter.m rename to axmol/ui/EditBox/Mac/TextFieldFormatter.m index 350273544e36..5fff03d44090 100644 --- a/axmol/ui/UIEditBox/Mac/UITextFieldFormatter.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/ @@ -23,9 +24,9 @@ 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 +@implementation AxmolTextFieldFormatter { } diff --git a/axmol/ui/UIEditBox/Mac/UITextInput.h b/axmol/ui/EditBox/Mac/TextInput.h similarity index 95% rename from axmol/ui/UIEditBox/Mac/UITextInput.h rename to axmol/ui/EditBox/Mac/TextInput.h index a5c1ae4190c8..0c2fa21cb844 100644 --- a/axmol/ui/UIEditBox/Mac/UITextInput.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/UIEditBox/iOS/UIEditBoxIOS.h b/axmol/ui/EditBox/iOS/EditBoxIOS.h similarity index 92% rename from axmol/ui/UIEditBox/iOS/UIEditBoxIOS.h rename to axmol/ui/EditBox/iOS/EditBoxIOS.h index 2160c139b008..994be0c4a644 100644 --- a/axmol/ui/UIEditBox/iOS/UIEditBoxIOS.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/ @@ -28,12 +29,12 @@ #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 -@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/UIEditBox/iOS/UIEditBoxIOS.mm b/axmol/ui/EditBox/iOS/EditBoxIOS.mm similarity index 95% rename from axmol/ui/UIEditBox/iOS/UIEditBoxIOS.mm rename to axmol/ui/EditBox/iOS/EditBoxIOS.mm index 49a9ccd5f66b..b34836989719 100644 --- a/axmol/ui/UIEditBox/iOS/UIEditBoxIOS.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/ @@ -26,9 +27,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" @@ -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,9 +110,9 @@ - (void)setTextInput:(UIView*)textInput - (void)createSingleLineTextField { - CCUISingleLineTextField* textField = [[[CCUISingleLineTextField alloc] initWithFrame:self.frameRect] autorelease]; - textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; - textField.borderStyle = UITextBorderStyleNone; + AxmolSingleLineTextField* textField = [[[AxmolSingleLineTextField alloc] initWithFrame:self.frameRect] autorelease]; + textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; + textField.borderStyle = UITextBorderStyleNone; [textField addTarget:self action:@selector(textChanged:) forControlEvents:UIControlEventEditingChanged]; @@ -123,8 +121,8 @@ - (void)createSingleLineTextField - (void)createMultiLineTextField { - CCUIMultilineTextField* textView = [[[CCUIMultilineTextField alloc] initWithFrame:self.frameRect] autorelease]; - self.textInput = textView; + AxmolMultilineTextField* textView = [[[AxmolMultilineTextField alloc] initWithFrame:self.frameRect] autorelease]; + self.textInput = textView; } #pragma mark - Public methods diff --git a/axmol/ui/UIEditBox/iOS/UIMultilineTextField.h b/axmol/ui/EditBox/iOS/MultilineTextField.h similarity index 87% rename from axmol/ui/UIEditBox/iOS/UIMultilineTextField.h rename to axmol/ui/EditBox/iOS/MultilineTextField.h index 4bf84115b17e..7683c7c613ad 100644 --- a/axmol/ui/UIEditBox/iOS/UIMultilineTextField.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/UIEditBox/iOS/UITextView+UITextInput.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/UIEditBox/iOS/UIMultilineTextField.mm b/axmol/ui/EditBox/iOS/MultilineTextField.mm similarity index 96% rename from axmol/ui/UIEditBox/iOS/UIMultilineTextField.mm rename to axmol/ui/EditBox/iOS/MultilineTextField.mm index 79f1a82f0df9..6eeb9fd977e8 100644 --- a/axmol/ui/UIEditBox/iOS/UIMultilineTextField.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/ @@ -25,7 +26,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" @@ -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/UIEditBox/iOS/UISingleLineTextField.h b/axmol/ui/EditBox/iOS/SingleLineTextField.h similarity index 87% rename from axmol/ui/UIEditBox/iOS/UISingleLineTextField.h rename to axmol/ui/EditBox/iOS/SingleLineTextField.h index ef5443f1249c..346d0c4dc4a8 100644 --- a/axmol/ui/UIEditBox/iOS/UISingleLineTextField.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/UIEditBox/iOS/UITextField+UITextInput.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/UIEditBox/iOS/UISingleLineTextField.mm b/axmol/ui/EditBox/iOS/SingleLineTextField.mm similarity index 92% rename from axmol/ui/UIEditBox/iOS/UISingleLineTextField.mm rename to axmol/ui/EditBox/iOS/SingleLineTextField.mm index 04f79d1888b9..a78cb57eaad8 100644 --- a/axmol/ui/UIEditBox/iOS/UISingleLineTextField.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/ @@ -25,8 +26,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" @@ -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/TextField.h b/axmol/ui/EditBox/iOS/TextField.h new file mode 100644 index 000000000000..ad11e5f9cb57 --- /dev/null +++ b/axmol/ui/EditBox/iOS/TextField.h @@ -0,0 +1,32 @@ +/**************************************************************************** + 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/ + + 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 + +#import +#import "axmol/ui/EditBox/iOS/TextInput.h" + +@interface UITextField (AxmolTextInput) +@end diff --git a/axmol/ui/UIEditBox/iOS/UITextField+UITextInput.mm b/axmol/ui/EditBox/iOS/TextField.mm similarity index 95% rename from axmol/ui/UIEditBox/iOS/UITextField+UITextInput.mm rename to axmol/ui/EditBox/iOS/TextField.mm index 17a69a37b4ef..029eda8a1874 100644 --- a/axmol/ui/UIEditBox/iOS/UITextField+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/UIEditBox/iOS/UITextField+UITextInput.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/UIEditBox/iOS/UITextInput.h b/axmol/ui/EditBox/iOS/TextInput.h similarity index 95% rename from axmol/ui/UIEditBox/iOS/UITextInput.h rename to axmol/ui/EditBox/iOS/TextInput.h index 255d6d1f64a0..78d098deeb37 100644 --- a/axmol/ui/UIEditBox/iOS/UITextInput.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/TextView.h b/axmol/ui/EditBox/iOS/TextView.h new file mode 100644 index 000000000000..c8010f3f1dd6 --- /dev/null +++ b/axmol/ui/EditBox/iOS/TextView.h @@ -0,0 +1,31 @@ +/**************************************************************************** + Copyright (c) 2015 Mazyad Alabduljaleel + 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. + ****************************************************************************/ +#pragma once + +#import +#import "axmol/ui/EditBox/iOS/TextInput.h" + +@interface UITextView (AxmolTextInput) +@end diff --git a/axmol/ui/UIEditBox/iOS/UITextView+UITextInput.mm b/axmol/ui/EditBox/iOS/TextView.mm similarity index 96% rename from axmol/ui/UIEditBox/iOS/UITextView+UITextInput.mm rename to axmol/ui/EditBox/iOS/TextView.mm index 3bae4adf1d64..a83e2c5fed80 100644 --- a/axmol/ui/UIEditBox/iOS/UITextView+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/UIEditBox/iOS/UITextView+UITextInput.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/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 87% rename from axmol/ui/UIImageView.cpp rename to axmol/ui/ImageView.cpp index c501161a6009..b18105a22ed6 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 @@ -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) @@ -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); @@ -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 (!_autoSize && _customSize.equals(Vec2::ZERO)) { _customSize = _imageRenderer->getContentSize(); } @@ -154,7 +154,7 @@ void ImageView::setupTexture() this->updateChildrenDisplayedRGBA(); - updateContentSizeWithTextureSize(_imageTextureSize); + updateContentSize(); _imageRendererAdaptDirty = true; } @@ -197,13 +197,13 @@ void ImageView::setScale9Enabled(bool able) if (_scale9Enabled) { - bool ignoreBefore = _ignoreSize; - ignoreContentAdaptWithSize(false); - _prevIgnoreSize = ignoreBefore; + bool autoSizeBefore = _autoSize; + setAutoSize(false); + _prevAutoSize = autoSizeBefore; } else { - ignoreContentAdaptWithSize(_prevIgnoreSize); + setAutoSize(_prevAutoSize); } 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); @@ -244,7 +235,7 @@ void ImageView::onSizeChanged() _imageRendererAdaptDirty = true; } -void ImageView::adaptRenderers() +void ImageView::updateLayout() { if (_imageRendererAdaptDirty) { @@ -253,19 +244,19 @@ void ImageView::adaptRenderers() } } -Vec2 ImageView::getVirtualRendererSize() const +Vec2 ImageView::resolvePreferredSize(const Vec2& /*sizeHint*/) const { return _imageTextureSize; } -Node* ImageView::getVirtualRenderer() +Node* ImageView::getRenderNode() { return _imageRenderer; } void ImageView::imageTextureScaleChangedWithSize() { - _imageRenderer->setPreferredSize(_contentSize); + _imageRenderer->setContentSize(_contentSize); _imageRenderer->setPosition(_contentSize.width / 2.0f, _contentSize.height / 2.0f); } @@ -285,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) @@ -314,6 +305,17 @@ const BlendFunc& ImageView::getBlendFunc() const return _imageRenderer->getBlendFunc(); } +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::setAutoSize(autoSize); + _prevAutoSize = autoSize; // Store the current value for backward compatibility + } +} + } // namespace ui } // namespace ax diff --git a/axmol/ui/UIImageView.h b/axmol/ui/ImageView.h similarity index 94% rename from axmol/ui/UIImageView.h rename to axmol/ui/ImageView.h index 208f1decec3d..1ea29b236d7b 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" /** @@ -136,10 +136,10 @@ class AX_GUI_DLL ImageView : public Widget, public ax::BlendProtocol const BlendFunc& getBlendFunc() const override; // override methods. - void ignoreContentAdaptWithSize(bool ignore) override; + void setAutoSize(bool autoSize) override; std::string getDescription() const override; - Vec2 getVirtualRendererSize() const override; - Node* getVirtualRenderer() override; + Vec2 resolvePreferredSize(const Vec2& /*sizeHint*/) const override; + Node* getRenderNode() override; ResourceData getRenderFile(); @@ -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(); @@ -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/InputField.cpp b/axmol/ui/InputField.cpp new file mode 100644 index 000000000000..613f78b9b499 --- /dev/null +++ b/axmol/ui/InputField.cpp @@ -0,0 +1,1683 @@ +/**************************************************************************** +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/InputField.h" +#include "axmol/base/Director.h" +#include "axmol/base/text_utils.h" +#include "axmol/platform/Device.h" + +#include +#include +#include + +namespace ax +{ + +#if defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP +# define axbeep(t) MessageBeep(t) +#else +# define axbeep(t) +#endif + +namespace ui +{ + +namespace +{ +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) + { + 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; + } +} + +} // namespace + +////////////////////////////////////////////////////////////////////////// +// constructor and destructor +////////////////////////////////////////////////////////////////////////// +bool InputField::s_keyboardVisible = false; + +InputField::InputField() +{ + _passwordChar = DEFAULT_PASSWORD_CHAR; +} + +InputField::~InputField() +{ + if (_kbdListener != nullptr) + _eventDispatcher->removeEventListener(_kbdListener); + + // Release instance-specific measure label + AX_SAFE_RELEASE_NULL(_measureLabel); +} + +////////////////////////////////////////////////////////////////////////// +// 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, + float cursorWidth, + const Color32& cursorColor) +{ + InputField* ret = new InputField(); + if (ret && ret->initWithPlaceholder(placeholder, fontName, fontSize, cursorWidth, cursorColor)) + { + ret->autorelease(); + return ret; + } + AX_SAFE_DELETE(ret); + return nullptr; +} + +////////////////////////////////////////////////////////////////////////// +// text measurement +////////////////////////////////////////////////////////////////////////// +Vec2 InputField::measureText(std::string_view text) const +{ + // Lazy initialize instance-specific measure label + if (!_measureLabel) + { + _measureLabel = Label::create(""sv, _fontName, _fontSize); + _measureLabel->retain(); // Manual reference counting + } + + // Measure text (font is already synced in setFontName/setFontSize) + _measureLabel->setString(text); + return _measureLabel->getContentSize(); +} + +////////////////////////////////////////////////////////////////////////// +// initialize +////////////////////////////////////////////////////////////////////////// +bool InputField::initWithPlaceholder(std::string_view placeholder, + std::string_view fontName, + float fontSize, + float cursorWidth, + const Color32& cursorColor) +{ + + ui::Widget::init(); + + _fontName = fontName; + _fontSize = fontSize; + _placeholder = placeholder; + + /// render label + // 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); + this->addProtectedChild(_renderLabel, INPUT_FIELD_RENDERER_Z); + + /// selection layer + _selectionLayer = DrawNode::create(); + this->addProtectedChild(_selectionLayer); + + /// 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; +} + +void InputField::onEnter() +{ + Widget::onEnter(); + + setTouchEnabled(true); + + // Enable keyboard listener for cursor control and shortcuts + if (!_kbdListener) + { + _kbdListener = EventListenerKeyboard::create(); + AX_SAFE_RETAIN(_kbdListener); + _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 (isCursorVisible()) + { + 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; +#if AX_TARGET_PLATFORM != AX_PLATFORM_WINRT // Windows UWP TextBox will dispatchInsertText event with clipboard text, + // so no need to handle paste action in keyboard event. + case EventKeyboard::KeyCode::KEY_V: + case EventKeyboard::KeyCode::KEY_CAPITAL_V: + this->pasteFromClipboard(); + return; +#endif + 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; + case EventKeyboard::KeyCode::KEY_UP_ARROW: + this->moveCursorVertically(-1); + break; + case EventKeyboard::KeyCode::KEY_DOWN_ARROW: + this->moveCursorVertically(1); + 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() +{ + detachWithIME(); + + if (_kbdListener) + { + _eventDispatcher->removeEventListener(_kbdListener); + AX_SAFE_RELEASE_NULL(_kbdListener); + } + setTouchEnabled(false); + Widget::onExit(); +} + +std::string_view InputField::getFontName() const +{ + return _fontName; +} + +void InputField::setFontName(std::string_view fontName) +{ + _renderLabel->setFontInfo(fontName, _fontSize); + + _fontName = fontName; + _fontType = labelTypeToFontType(_renderLabel->getLabelType()); + + // Sync measure label font + if (_measureLabel) + _measureLabel->setFontInfo(fontName, _fontSize); + + _passwordCharWidth = measureText(_passwordChar).width; + _lineHeight = measureText("M"sv).height; + _cursor->setContentSize(Vec2{_cursor->getContentSize().width, _lineHeight}); + _layoutDirty = true; +} + +void InputField::setFontSize(float size) +{ + 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 if (_fontType == FontType::TTF) + { + TTFConfig config = _renderLabel->getTTFConfig(); + config.fontSize = size; + _renderLabel->setTTFConfig(config); + } + + _fontSize = size; + + // Sync measure label to the same font type and configuration as the render label. + if (_measureLabel) + { + if (_fontType == FontType::SYSTEM) + _measureLabel->setSystemFontSize(_fontSize); + else if (_fontType == FontType::TTF) + _measureLabel->setTTFConfig(_renderLabel->getTTFConfig()); + } + + _passwordCharWidth = measureText(_passwordChar).width; + _lineHeight = measureText("M"sv).height; + _layoutDirty = true; +} + +float InputField::getFontSize() const +{ + return _fontSize; +} + +Label* InputField::getRenderLabel() +{ + return _renderLabel; +} + +////////////////////////////////////////////////////////////////////////// +// InputDelegate +////////////////////////////////////////////////////////////////////////// + +bool InputField::attachWithIME() +{ + if (_isAttachWithIME) + return true; + bool ret = InputDelegate::attachWithIME(); + if (ret) + { + // Initialize touch selection state + _selectingByTouch = false; + _selectionTouchMoved = false; + + // Open keyboard + RenderView* renderView = _director->getRenderView(); + if (renderView) + renderView->setIMEKeyboardState(true); + + // updateCursorPosition(); + showCursor(); + dispatchEvent(EventType::ATTACH_WITH_IME); + _isAttachWithIME = true; + + _layoutDirty = true; + } + return ret; +} + +bool InputField::detachWithIME() +{ + bool ret = InputDelegate::detachWithIME(); + if (ret) + { + _isAttachWithIME = false; + + // Hide cursor immediately + hideCursor(); + + // Close keyboard + RenderView* renderView = _director->getRenderView(); + if (renderView) + renderView->setIMEKeyboardState(false); + + // Dispatch event before removing listeners + dispatchEvent(EventType::DETACH_WITH_IME); + } + return ret; +} + +bool InputField::hitTestWithIME(const Vec2& location) +{ + auto camera = Camera::getDefaultCamera(); + bool hitted = hitTest(location, camera, nullptr); + return hitted; +} + +void InputField::keyboardDidShow(IMEKeyboardNotificationInfo& /*info*/) +{ + s_keyboardVisible = true; +} + +void InputField::keyboardDidHide(IMEKeyboardNotificationInfo& /*info*/) +{ + s_keyboardVisible = false; + + bool ret = InputDelegate::detachWithIME(); + if (ret) + { + _isAttachWithIME = false; + + // Hide cursor immediately + hideCursor(); + } +} + +void InputField::addEventListener(const InputFieldCallback& callback) +{ + _eventCallback = callback; +} + +void InputField::dispatchEvent(EventType eventType) +{ + if (_eventCallback) + { + _eventCallback(this, eventType); + } +} + +bool InputField::isCursorVisible() const +{ + return _cursor && _cursor->isVisible(); +} + +bool InputField::canAttachWithIME() +{ + return true; +} + +bool InputField::canDetachWithIME() +{ + return true; +} + +void InputField::setCharLimit(uint32_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_view textView(_inputText); + setString(textView.substr(0, byteOffset)); + // Ensure cursor is not past the new limit + setCursorPosition(static_cast(_charLimit), false); + } +} + +void InputField::insertText(std::string_view text) +{ + if (_readOnly || !this->_enabled) + return; + + if (hasSelection()) + deleteSelection(false); + + // In multiline mode we allow newline characters; otherwise they signify commit and we strip them. + if (!_multilineEnabled) + { + auto pos = text.find_first_of("\r\n"); + if (pos != std::string::npos) + text = text.substr(0, pos); // text.erase(pos); + if (text.empty()) + return; + } + + size_t numOfChars; + + // Character limit + if (_charLimit > 0) + { + int remaining = static_cast(_charLimit - _charCount); + if (remaining <= 0) + { + axbeep(0); + return; + } + // Truncate insertStr to not exceed limit + auto result = text_utils::countUTF8WithLimit(text, remaining); + if (!result) + { + axbeep(0); + return; + } + text = text.substr(0, result.byteCount); + numOfChars = result.charCount; + } + else + { + numOfChars = text_utils::countUTF8Chars(text); + } + + if (text.empty()) + return; + + 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()); + + // 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); +} + +void InputField::deleteBackward(unsigned int numChars) +{ + if (hasSelection()) + { + deleteSelection(true); + return; + } + + if (_readOnly || !this->_enabled || 0 == _charCount) + { + axbeep(0); + return; + } + + int len = static_cast(_inputText.length()); + if (0 == len || _cursorByteIndex == 0) + { + axbeep(0); + return; + } + + auto deleteChars = (std::min)(static_cast(numChars), _cursorCharIndex); + auto startCharIndex = _cursorCharIndex - deleteChars; + auto startByteIndex = getByteOffset(startCharIndex); + auto totalDeleteLen = _cursorByteIndex - startByteIndex; + + _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) + { + _inputText.clear(); + updatePresentation(0, 0, false); + + dispatchEvent(EventType::DELETE_BACKWARD); + return; + } + + // Performance optimization: Erase characters in-place to avoid copying the whole string + _inputText.erase(startByteIndex, totalDeleteLen); + + // 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); +} + +void InputField::handleDeleteKeyEvent() +{ + if (hasSelection()) + { + deleteSelection(true); + return; + } + + if (_readOnly || !this->_enabled || 0 == _charCount) + { + axbeep(0); + return; + } + + int len = static_cast(_inputText.length()); + if (0 == len || _cursorCharIndex == static_cast(_charCount)) + { + axbeep(0); + return; + } + + auto nextByteIndex = getByteOffset(_cursorCharIndex + 1); + auto deleteLen = nextByteIndex - _cursorByteIndex; + + _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) + { + _inputText.clear(); + updatePresentation(0, 0, false); + + dispatchEvent(EventType::DELETE_BACKWARD); + return; + } + + // 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); + + // Maintain the cursor position at the current index + setCursorPosition(_cursorCharIndex, false); + + dispatchEvent(EventType::DELETE_BACKWARD); +} + +std::string_view InputField::getContentText() const +{ + return _inputText; +} + +void InputField::setTextColor(const Color32& color) +{ + _colorText = color; + if (!_inputText.empty()) + _renderLabel->setTextColor(_colorText); +} + +const Color32& InputField::getTextColor(void) const +{ + return _colorText; +} + +void InputField::setCursorColor(const Color32& color) +{ + _cursor->setColor(color); +} + +const Color32& InputField::getCursorColor(void) const +{ + return _cursor->getColor(); +} + +const Color32& InputField::getPlaceholderColor() const +{ + return _colorSpaceHolder; +} + +void InputField::setPlaceholderColor(const Color32& color) +{ + _colorSpaceHolder = color; + if (_inputText.empty()) + _renderLabel->setTextColor(color); +} + +////////////////////////////////////////////////////////////////////////// +// properties +////////////////////////////////////////////////////////////////////////// + +void InputField::setMultilineEnabled(bool enabled) +{ + if (_multilineEnabled != enabled) + { + _multilineEnabled = enabled; + _layoutDirty = true; + } +} + +Node* InputField::getRenderNode() +{ + return _renderLabel; +} + +Vec2 InputField::resolvePreferredSize(const Vec2& /*sizeHint*/) const +{ + return _renderLabel->getContentSize(); +} + +// input text property +void InputField::setString(std::string_view text) +{ + auto oldInsertCharIndex = static_cast(_cursorCharIndex); + bool bInsertAtEnd = (oldInsertCharIndex == static_cast(_charCount)); + _inputText = text; + auto newCharCount = text_utils::countUTF8Chars(_inputText); + + 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()) + { + if (_passwordEnabled) + { + 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); + --length; + } + } + } + + // Toggle between the text and the placeholder + if (_inputText.empty()) + { + _renderLabel->setTextColor(_colorSpaceHolder); + _renderLabel->setString(_placeholder); + } + else + { + _renderLabel->setTextColor(_colorText); + _renderLabel->setString(*displayText); + } + + // Direct assignment avoids recalculating the whole string length + _charCount = static_cast(newCharCount); + + // Update content size to match the rendered text + updateContentSize(); + + if (bInsertAtEnd) + { + setCursorPosition(_charCount, false); + } + else + { + setCursorPosition((std::min)(oldInsertCharIndex, static_cast(_charCount)), hasSelection()); + } + + _selectionStart = (std::min)(_selectionStart, static_cast(_charCount)); + _selectionEnd = (std::min)(_selectionEnd, static_cast(_charCount)); + + _charByteOffsetDirty = true; + _layoutDirty = true; +} + +void InputField::updateContentSize() +{ + Widget::updateContentSize(); + + if (_autoSize && _multilineEnabled) + { + float height = _lineMetrics.size() * _lineHeight; + _contentSize.height = height; + } + if (_autoSize) + { + _layoutDirty = true; + } +} + +void InputField::onSizeChanged() +{ + Widget::onSizeChanged(); + _layoutDirty = true; +} + +void InputField::updateLayout() +{ + if (_charByteOffsetDirty) + { + _charByteOffsetDirty = false; + rebuildCharByteOffsets(); + } + + if (_layoutDirty) + { + _layoutDirty = false; + + 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(); + } +} + +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; +} + +void InputField::setPasswordChar(std::string_view ch) +{ + if (ch != _passwordChar) + { + _passwordChar = !ch.empty() ? ch : DEFAULT_PASSWORD_CHAR; + _passwordCharWidth = measureText(_passwordChar).width; + if (_passwordEnabled) + setString(getString()); + } +} + +// place holder text property +void InputField::setPlaceholderText(std::string_view text) +{ + _placeholder = text; + if (_inputText.empty()) + { + _renderLabel->setTextColor(_colorSpaceHolder); + _renderLabel->setString(_placeholder); + } + _layoutDirty = true; + updateContentSize(); +} + +std::string_view InputField::getPlaceholderText() const +{ + return _placeholder; +} + +// secureTextEntry +void InputField::setPasswordEnabled(bool value) +{ + if (_passwordEnabled != value) + { + _passwordEnabled = value; + this->setString(this->getString()); + } +} + +bool InputField::isPasswordEnabled() const +{ + return _passwordEnabled; +} + +void InputField::setEnabled(bool bEnabled) +{ + if (_enabled != bEnabled) + { + _enabled = bEnabled; + if (!bEnabled) + this->detachWithIME(); + } +} + +bool InputField::hasSelection() const +{ + return _selectionStart != _selectionEnd; +} + +void InputField::selectAll() +{ + setSelection(0, _charCount); + _selectionAnchor = 0; + setCursorPosition(_charCount, true); +} + +void InputField::clearSelection() +{ + _selectionStart = _selectionEnd = _cursorCharIndex; + _selectionAnchor = _cursorCharIndex; + updateSelectionLayer(); +} + +std::string InputField::getSelectedText() const +{ + if (!hasSelection()) + return {}; + + auto startByte = getByteOffset(_selectionStart); + auto endByte = getByteOffset(_selectionEnd); + + return _inputText.substr(startByte, endByte - startByte); +} + +bool InputField::copySelectionToClipboard() const +{ + auto selectedText = getSelectedText(); + if (selectedText.empty() || _passwordEnabled) + return false; + + setClipboardText(selectedText); + return true; +} + +bool InputField::cutSelectionToClipboard() +{ + if (_readOnly || !this->_enabled || !copySelectionToClipboard()) + return false; + + return deleteSelection(true); +} + +bool InputField::pasteFromClipboard() +{ + if (_readOnly || !this->_enabled) + return false; + + auto text = getClipboardText(); + if (text.empty()) + return false; + + insertText(text); + return true; +} + +void InputField::setSelectionColor(const Color& color) +{ + _selectionColor = color; + updateSelectionLayer(); +} + +const Color& InputField::getSelectionColor() const +{ + return _selectionColor; +} + +std::string InputField::getClipboardText() +{ + return Device::getClipboardText(); +} + +void InputField::setClipboardText(std::string_view text) +{ + Device::setClipboardText(text); +} + +void InputField::showCursor(void) +{ + if (_cursor) + { + _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 blinkSequence = Sequence::create(fadeOut, fadeIn, nullptr); + _cursor->runAction(RepeatForever::create(blinkSequence)); + } +} + +void InputField::hideCursor(void) +{ + if (_cursor) + { + _cursor->stopAllActions(); + _cursor->setOpacity(255); // Reset to full opacity + _cursor->setVisible(false); + } +} + +void InputField::updateCursorPosition(void) +{ + 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) +{ + moveCursor(direction, false); +} + +void InputField::moveCursor(int direction, bool keepSelection) +{ + auto cursorIndex = static_cast(_cursorCharIndex) + direction; + cursorIndex = std::clamp(cursorIndex, 0, static_cast(_charCount)); + setCursorPosition(cursorIndex, keepSelection); +} + +void InputField::moveCursorTo(const Vec2& point) +{ + moveCursorTo(point, false); +} + +void InputField::moveCursorTo(const Vec2& point, bool keepSelection) +{ + setCursorPosition(cursorIndexFromPosition(point), keepSelection); +} + +void InputField::setCursorPosition(int cursorIndex, bool keepSelection) +{ + cursorIndex = (std::min)(cursorIndex, static_cast(_charCount)); + + if (keepSelection) + { + setSelection(_selectionAnchor, cursorIndex); + } + else + { + _selectionAnchor = cursorIndex; + _selectionStart = cursorIndex; + _selectionEnd = cursorIndex; + } + + _cursorCharIndex = cursorIndex; + _cursorByteIndex = getByteOffset(cursorIndex); + + auto cursorPosition = cursorPositionFromIndex(cursorIndex); + if (_cursor) + _cursor->setPosition(cursorPosition); + + if (!keepSelection) + _preferredCursorX = cursorPosition.x; // remember horizontal position for vertical movement + + updateSelectionLayer(); +} + +int InputField::getByteOffset(int cursorIndex) const +{ + if (_charByteOffsetDirty) + const_cast(this)->rebuildCharByteOffsets(); + + if (cursorIndex >= _charCount) + return _inputText.length(); + + return _charByteOffsets[cursorIndex]; +} + +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)); + _selectionEnd = (std::min)(end, static_cast(_charCount)); + if (_selectionStart > _selectionEnd) + std::swap(_selectionStart, _selectionEnd); + updateSelectionLayer(); +} + +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; + + 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; + + // 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 + invertedLineIdx * _lineHeight; + float selY2 = selY1 + _lineHeight; + + _selectionLayer->drawSolidRect(Vec2(selX1, selY1), Vec2(selX2, selY2), _selectionColor); + } +} + +bool InputField::deleteSelection(bool notify) +{ + if (_readOnly || !this->_enabled || !hasSelection()) + return false; + + auto startByte = getByteOffset(_selectionStart); + auto endByte = getByteOffset(_selectionEnd); + auto newCursor = _selectionStart; + + // 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) + dispatchEvent(EventType::DELETE_BACKWARD); + + return true; +} + +////////////////////////////////////////////////////////////////////////// +// Touch Area and Hit Test +////////////////////////////////////////////////////////////////////////// +void InputField::setTouchAreaSize(const Vec2& size) +{ + _touchAreaSize = size; +} + +Vec2 InputField::getTouchAreaSize() const +{ + return _touchAreaSize; +} + +void InputField::setTouchAreaEnabled(bool enable) +{ + _useTouchArea = enable; +} + +bool InputField::hitTest(const Vec2& pt, const Camera* camera, Vec3* /*p*/) const +{ + if (!_useTouchArea) + { + return Widget::hitTest(pt, camera, nullptr); + } + + auto size = getContentSize(); + auto anch = getAnchorPoint(); + 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); +} + +////////////////////////////////////////////////////////////////////////// +// Text Alignment +////////////////////////////////////////////////////////////////////////// +void InputField::setTextHorizontalAlignment(TextHAlignment alignment) +{ + if (_textHAlignment != alignment) + { + _textHAlignment = alignment; + if (_renderLabel) + { + _renderLabel->setHorizontalAlignment(alignment); + _layoutDirty = true; + } + } +} + +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; +} + +////////////////////////////////////////////////////////////////////////// +// Touch Event Handlers (Override Widget's methods) +////////////////////////////////////////////////////////////////////////// + +bool InputField::onTouchBegan(Touch* touch, Event* event) +{ + auto hitted = Widget::onTouchBegan(touch, event); + if (!hitted) + { + detachWithIME(); + return false; + } + if (_readOnly || !_enabled) + return false; + + bool focus = isCursorVisible(); + if (focus && _continuousTouchCallback) + { + _continuousTouchPending = true; + _continuousTouchElapsedTime = 0.0f; + _continuousTouchWorldPoint = touch->getLocation(); + } + + _selectingByTouch = focus; + _selectionTouchMoved = false; + _selectionAnchor = _cursorCharIndex; + + if (focus) + { + Vec2 inputFieldPoint = this->convertToNodeSpace(touch->getLocation()); + _selectionAnchor = cursorIndexFromPosition(inputFieldPoint); + } + + return true; +} + +void InputField::onTouchMoved(Touch* touch, Event* event) +{ + Widget::onTouchMoved(touch, event); + if (!_selectingByTouch || _readOnly || !_enabled) + return; + + Vec2 inputFieldPoint = this->convertToNodeSpace(touch->getLocation()); + setCursorPosition(cursorIndexFromPosition(inputFieldPoint), true); + _selectionTouchMoved = hasSelection(); +} + +void InputField::onTouchEnded(Touch* touch, Event* event) +{ + _continuousTouchPending = false; + Widget::onTouchEnded(touch, event); + + bool focus = _hitted && !_readOnly && _enabled; + if (focus) + { + if (!s_keyboardVisible || !isCursorVisible()) + attachWithIME(); + + Vec2 localPoint = this->convertToNodeSpace(touch->getLocation()); + moveCursorTo(localPoint, _selectionTouchMoved); + } + else + { + detachWithIME(); + } + + _selectingByTouch = false; +} + +void InputField::onTouchCancelled(Touch* touch, Event* event) +{ + // Cancel continuous touch pending state + _continuousTouchPending = false; + + // Call parent class + Widget::onTouchCancelled(touch, event); + + _selectingByTouch = false; +} + +Vec2 InputField::cursorPositionFromIndex(int cursorIndex) const +{ + cursorIndex = std::min(cursorIndex, static_cast(_charCount)); + if (_lineMetrics.empty()) + return Vec2::ZERO; + + // 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; + + 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; + + 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; + + float finalX = lineStartX + x; + + // Use the label text bottom Y as the vertical base + 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); +} + +int InputField::cursorIndexFromPosition(const Vec2& position) const +{ + if (_inputText.empty() || _lineMetrics.empty()) + return 0; + + float yOffset = getRenderLabelTextBottomY(); + + // 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]; + + // 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; + + float relX = position.x - lineStartX; + + // 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 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()); // 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 left = offsets[idx - 1]; + float right = offsets[idx]; + float mid = (left + right) * 0.5f; + + // 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::rebuildLineMetrics() +{ + _lineMetrics.clear(); + if (_inputText.empty()) + { + // 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 + + const int totalChars = static_cast(_charByteOffsets.size() - 1); + int currentCharIdx = 0; + int lineStartCharIdx = 0; + + // Helper to calculate character offsets and record the current line's metrics + auto recordLineMetrics = [&](int lineEndCharIdx) { + LineMetrics line; + line.startCharIndex = lineStartCharIdx; + line.endCharIndex = lineEndCharIdx; + + const int charsInLine = lineEndCharIdx - lineStartCharIdx; + line.charXOffsets.resize(charsInLine + 1); + line.charXOffsets[0] = 0.0f; + + float accumulatedXOffset = 0.0f; + + for (int i = 0; i < charsInLine; ++i) + { + const int absoluteCharIdx = lineStartCharIdx + i; + + // 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; + + accumulatedXOffset += charWidth; + line.charXOffsets[i + 1] = accumulatedXOffset; + } + line.lineWidth = accumulatedXOffset; + _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) + { + size_t charByteOffset = _charByteOffsets[currentCharIdx]; + + // Check if the character is a line-feed (single byte 0x0A) + if (_inputText[charByteOffset] == '\n') + { + recordLineMetrics(currentCharIdx); + lineStartCharIdx = currentCharIdx + 1; // Skip '\n' + currentCharIdx = lineStartCharIdx; + continue; + } + } + + // Measure cumulative width from lineStartCharIdx to currentCharIdx + 1 + const int nextCharIdx = currentCharIdx + 1; + size_t nextCharByteOffset = _charByteOffsets[nextCharIdx]; + size_t lineStartByteOffset = _charByteOffsets[lineStartCharIdx]; + + // Extract the line prefix view cleanly using O(1) lookups + std::string_view linePrefixView(_inputText.data() + lineStartByteOffset, + nextCharByteOffset - lineStartByteOffset); + + float linePrefixWidth = (_passwordEnabled) ? _passwordCharWidth * (nextCharIdx - lineStartCharIdx) + : measureText(linePrefixView).width; + + if (linePrefixWidth > availableWidth && currentCharIdx > lineStartCharIdx) + { + // Text exceeds available width, record the line up to currentCharIdx before wrapping + recordLineMetrics(currentCharIdx); + lineStartCharIdx = currentCharIdx; + // 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() +{ + _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()) + return; + + // Determine current line index + 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); + 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 + +} // namespace ax diff --git a/axmol/ui/InputField.h b/axmol/ui/InputField.h new file mode 100644 index 000000000000..82bb807284f8 --- /dev/null +++ b/axmol/ui/InputField.h @@ -0,0 +1,621 @@ +/**************************************************************************** +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/Widget.h" +#include "axmol/base/InputDelegate.h" +#include "axmol/2d/DrawNode.h" +#include "axmol/2d/Label.h" +#include "axmol/base/EventListenerKeyboard.h" +#include + +namespace ax +{ + +namespace ui +{ + +/** + * @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 InputDelegate +{ +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(); + + /** + * @brief Destroy the InputField instance. + */ + 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. + * @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; + + /** + * @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; + + FontType getFontType() const { return _fontType; } + + /** + * @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); + } + + /** + * @brief Set the single visible mask character used when password mode is enabled. + * @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; } + + /** + * @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; + + /** + * @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 setReadOnly(bool bReadOnly) { _readOnly = bReadOnly; } + + /** + * @brief Query whether the field is read-only. + */ + bool isReadOnly(void) const { return _readOnly; } + + /** + * @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; + + /** + * @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(uint32_t limit); + + /** + * @brief Get the configured character limit. + * @return The maximum number of characters allowed (0 means unlimited). + */ + 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. + */ + Node* getRenderNode() override; + + /** + * @brief Get preferred size based on rendered text. + * @return Preferred size. + */ + Vec2 resolvePreferredSize(const Vec2& /*sizeHint*/) const override; + + /** + * @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); + +protected: + void updatePresentation(uint32_t newCharCount, int oldInsertCharIndex, bool bInsertAtEnd); + + ////////////////////////////////////////////////////////////////////////// + + void onEnter() override; + void onExit() override; + + bool canAttachWithIME() override; + bool canDetachWithIME() override; + + // InputDelegate interface + void insertText(std::string_view text) override; + void deleteBackward(unsigned int numChars) override; + + std::string_view getContentText() const override; + + void handleDeleteKeyEvent(); + + /** + @brief Open keyboard and receive input text. + */ + bool attachWithIME() override; + + /** + @brief End text input and close keyboard. + */ + bool detachWithIME() override; + + bool hitTestWithIME(const Vec2& location) override; + void keyboardDidShow(IMEKeyboardNotificationInfo& /*info*/) override; + void keyboardDidHide(IMEKeyboardNotificationInfo& /*info*/) override; + + void updateContentSize(void) override; + + void showCursor(void); + void hideCursor(void); + void updateCursorPosition(void); + + void moveCursor(int direction); + void moveCursor(int direction, 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 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 + */ + Vec2 cursorPositionFromIndex(int cursorIndex) const; + + /** + * @brief Find the cursor index at a given coordinate. + * @param x X coordinate in local node space + * @return UTF-8 character index (inverse of cursorPositionFromIndex) + */ + int cursorIndexFromPosition(const Vec2& position) const; + + int getByteOffset(int cursorIndex) const; + + float getRenderLabelTextBottomY() const; + + void setSelection(int start, int end); + 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); + + bool isCursorVisible() const; + + void updateLayout() override; + void onSizeChanged() override; + void update(float dt) 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; + + /** + * @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 rebuildLineMetrics(); + void rebuildCharByteOffsets(); + + // 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 + }; + + 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}; + + bool _readOnly{false}; + bool _layoutDirty{true}; + bool _charByteOffsetDirty{true}; + bool _passwordEnabled{false}; + bool _cursorVisible{false}; + bool _selectingByTouch{false}; + bool _selectionTouchMoved{false}; + bool _ctrlKeyPressed{false}; + bool _shiftKeyPressed{false}; + 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}; + float _continuousTouchDelayTime{0.6f}; + Vec2 _continuousTouchWorldPoint{Vec2::ZERO}; + + Label* _renderLabel{nullptr}; + + std::string _inputText; + std::string _placeholder; + std::string _passwordChar; + std::vector _charByteOffsets; // Maps UTF-8 character index to byte offset in _inputText + + Color32 _colorSpaceHolder{Color32::GRAY}; + Color32 _colorText{Color32::WHITE}; + + Sprite* _cursor{nullptr}; + + DrawNode* _selectionLayer{nullptr}; + Color _selectionColor{0.26f, 0.52f, 1.0f, 0.35f}; + + FontType _fontType{FontType::SYSTEM}; + + uint32_t _charLimit{0}; + uint32_t _charCount{0}; + + 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) + + 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{TextHAlignment::LEFT}; + TextVAlignment _textVAlignment{TextVAlignment::TOP}; + + std::function _continuousTouchCallback; + + /// Event callback + InputFieldCallback _eventCallback{nullptr}; + + // Instance-specific measure label (lazy initialized, no sharing overhead) + mutable Label* _measureLabel{nullptr}; + + static bool s_keyboardVisible; +}; + +// end of input group +/// @} + +}; // namespace ui + +} // namespace ax diff --git a/axmol/ui/UILayout.cpp b/axmol/ui/Layout.cpp similarity index 98% rename from axmol/ui/UILayout.cpp rename to axmol/ui/Layout.cpp index 386d945d3e2a..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" @@ -135,7 +135,7 @@ bool Layout::init() { if (Widget::init()) { - ignoreContentAdaptWithSize(false); + setAutoSize(false); setContentSize(Vec2::ZERO); setAnchorPoint(Vec2::ZERO); onPassFocusToChild = AX_CALLBACK_2(Layout::findNearestChildWidgetIndex, this); @@ -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) @@ -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/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 90% rename from axmol/ui/UILoadingBar.cpp rename to axmol/ui/LoadingBar.cpp index e01450dff39e..3cfc02dd637e 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 @@ -53,7 +53,7 @@ LoadingBar::LoadingBar() , _barRendererTextureSize(Vec2::ZERO) , _originalRect(Rect::ZERO) , _scale9Enabled(false) - , _prevIgnoreSize(true) + , _prevAutoSize(true) , _capInsets(Rect::ZERO) , _barRendererAdaptDirty(true) , _textureFile("") @@ -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); @@ -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 (!_autoSize && _customSize.equals(Vec2::ZERO)) { _customSize = _barRenderer->getContentSize(); } @@ -183,7 +183,7 @@ void LoadingBar::setupTexture() barRendererScaleChangedWithSize(); - updateContentSizeWithTextureSize(_barRendererTextureSize); + updateContentSize(); this->updateProgressBar(); @@ -220,13 +220,13 @@ void LoadingBar::setScale9Enabled(bool enabled) if (_scale9Enabled) { - bool ignoreBefore = _ignoreSize; - ignoreContentAdaptWithSize(false); - _prevIgnoreSize = ignoreBefore; + bool autoSizeBefore = _autoSize; + setAutoSize(false); + _prevAutoSize = autoSizeBefore; } else { - ignoreContentAdaptWithSize(_prevIgnoreSize); + setAutoSize(_prevAutoSize); } setCapInsets(_capInsets); @@ -308,7 +308,7 @@ void LoadingBar::onSizeChanged() _barRendererAdaptDirty = true; } -void LoadingBar::adaptRenderers() +void LoadingBar::updateLayout() { if (_barRendererAdaptDirty) { @@ -317,34 +317,36 @@ void LoadingBar::adaptRenderers() } } -void LoadingBar::ignoreContentAdaptWithSize(bool ignore) +void LoadingBar::setAutoSize(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::setAutoSize(autoSize); + _prevAutoSize = autoSize; // Store the current value for backward compatibility } } -Vec2 LoadingBar::getVirtualRendererSize() const +Vec2 LoadingBar::resolvePreferredSize(const Vec2& /*sizeHint*/) const { return _barRendererTextureSize; } -Node* LoadingBar::getVirtualRenderer() +Node* LoadingBar::getRenderNode() { return _barRenderer; } void LoadingBar::barRendererScaleChangedWithSize() { - if (_unifySize) + if (!_autoSize) { //_barRenderer->setPreferredSize(_contentSize); _totalLength = _contentSize.width; this->setPercent(_percent); } - else if (_ignoreSize) + else if (_autoSize) { if (!_scale9Enabled) { @@ -391,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 @@ -409,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/LoadingBar.h similarity index 95% rename from axmol/ui/UILoadingBar.h rename to axmol/ui/LoadingBar.h index cfb427bb10fb..968afbd0dd50 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 @@ -164,15 +164,15 @@ class AX_GUI_DLL LoadingBar : public Widget const Rect& getCapInsets() const; // override methods. - void ignoreContentAdaptWithSize(bool ignore) override; - Vec2 getVirtualRendererSize() const override; - Node* getVirtualRenderer() override; + void setAutoSize(bool autoSize) override; + Vec2 resolvePreferredSize(const Vec2& /*sizeHint*/) const override; + Node* getRenderNode() override; std::string getDescription() const override; 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; @@ -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/UIMediaPlayer.cpp b/axmol/ui/MediaPlayer.cpp similarity index 98% rename from axmol/ui/UIMediaPlayer.cpp rename to axmol/ui/MediaPlayer.cpp index aae5eefa9309..6482ca6ef9fe 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" //----------------------------------------------------------------------------------------------------------- @@ -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 (!_ignoreSize && _customSize.equals(Vec2::ZERO)) + if (!_autoSize && _customSize.equals(Vec2::ZERO)) { _customSize = _overlay->getContentSize(); } this->updateChildrenDisplayedRGBA(); - if (_unifySize) - { - if (!_scale9Enabled) - { - updateContentSizeWithTextureSize(spriteSize); - } - } - else - { - updateContentSizeWithTextureSize(spriteSize); - } + updateContentSize(); } return true; @@ -610,14 +598,14 @@ void MediaPlayerControl::onSizeChanged() } } -Vec2 MediaPlayerControl::getVirtualRendererSize() const +Vec2 MediaPlayerControl::resolvePreferredSize(const Vec2& /*sizeHint*/) const { - if (_unifySize) + if (!_autoSize) { return this->getNormalSize(); } - if (nullptr != _overlay) + if (_overlay) { Vec2 overlaySize = _overlay->getContentSize(); if (!_normalTextureLoaded) @@ -645,7 +633,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); @@ -711,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 @@ -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,17 @@ void MediaPlayer::setContentSize(const Size& contentSize) } } +Vec2 MediaPlayer::resolvePreferredSize(const Vec2& sizeHint) const +{ + auto pvd = reinterpret_cast(_videoContext); + if (!pvd) + return sizeHint; + auto videoSize = pvd->_vrender->getContentSize(); + if (videoSize.equals(Vec2::ZERO)) + return sizeHint; + return videoSize; +} + MediaPlayer::MediaState MediaPlayer::getState() const { if (_videoURL.empty()) diff --git a/axmol/ui/UIMediaPlayer.h b/axmol/ui/MediaPlayer.h similarity index 97% rename from axmol/ui/UIMediaPlayer.h rename to axmol/ui/MediaPlayer.h index 8955b1993a58..6a81d4bad36c 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 @@ -87,7 +87,7 @@ class MediaPlayerControl : public ax::ui::Button virtual bool init(SpriteFrame* frame); void onSizeChanged() override; - Vec2 getVirtualRendererSize() const override; + Vec2 resolvePreferredSize(const Vec2& /*sizeHint*/) const override; Vec2 getNormalSize() const override; void onPressStateChangedToNormal() override; @@ -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; @@ -382,7 +382,8 @@ class AX_GUI_DLL MediaPlayer : public ax::ui::Widget */ MediaState getState() const; - Node* getVirtualRenderer() override; + Node* getRenderNode() override; + Vec2 resolvePreferredSize(const Vec2& /*sizeHint*/) const override; void setMediaController(MediaController* controller); MediaController* getMediaController() const { return _mediaController; } 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 7e6a817bf026..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" @@ -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) { @@ -1757,7 +1757,7 @@ void RichText::formatText(bool force) this->removeAllProtectedChildren(); _elementRenders.clear(); _lineHeights.clear(); - if (_ignoreSize) + 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 (_ignoreSize) + 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 (_ignoreSize) - { - Vec2 s = getVirtualRendererSize(); - this->setContentSize(s); - } - else - { - this->setContentSize(_customSize); - } - updateContentSizeWithTextureSize(_contentSize); + updateContentSize(); } namespace @@ -2465,7 +2456,7 @@ float RichText::stripTrailingWhitespace(const Vector& row) return 0.0f; } -void RichText::adaptRenderers() +void RichText::updateLayout() { this->formatText(); } @@ -2484,12 +2475,12 @@ void RichText::setVerticalSpace(float space) _defaults[KEY_VERTICAL_SPACE] = space; } -void RichText::ignoreContentAdaptWithSize(bool ignore) +void RichText::setAutoSize(bool autoSize) { - if (_ignoreSize != ignore) + if (_autoSize != autoSize) { _formatTextDirty = true; - Widget::ignoreContentAdaptWithSize(ignore); + Widget::setAutoSize(autoSize); } } 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 45e061ae48ce..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" @@ -503,7 +503,7 @@ class AX_GUI_DLL RichText : public Widget void formatText(bool force = false); // override functions. - void ignoreContentAdaptWithSize(bool ignore) 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 */ @@ -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/UIScale9Sprite.cpp b/axmol/ui/Scale9Sprite.cpp similarity index 98% rename from axmol/ui/UIScale9Sprite.cpp rename to axmol/ui/Scale9Sprite.cpp index ef30ead52bf2..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" @@ -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/Scale9Sprite.h similarity index 98% rename from axmol/ui/UIScale9Sprite.h rename to axmol/ui/Scale9Sprite.h index 0e21cf8449c8..5aeb7c7f5a1e 100644 --- a/axmol/ui/UIScale9Sprite.h +++ b/axmol/ui/Scale9Sprite.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/UIScrollView.cpp b/axmol/ui/ScrollView.cpp similarity index 99% rename from axmol/ui/UIScrollView.cpp rename to axmol/ui/ScrollView.cpp index dba3090d2ff2..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 @@ -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/ScrollView.h similarity index 99% rename from axmol/ui/UIScrollView.h rename to axmol/ui/ScrollView.h index 7f87f6c6afa8..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 @@ -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/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 93% rename from axmol/ui/UISlider.cpp rename to axmol/ui/Slider.cpp index 566c6f8c632d..262e6fc6c138 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" @@ -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) @@ -128,7 +128,7 @@ bool Slider::init() return false; } -void Slider::initRenderer() +void Slider::initRenderNode() { _barRenderer = Scale9Sprite::create(); _progressBarRenderer = Scale9Sprite::create(); @@ -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 (!_autoSize && _customSize.equals(Vec2::ZERO)) { _customSize = _barRenderer->getContentSize(); } @@ -193,12 +193,14 @@ void Slider::loadBarTexture(SpriteFrame* spriteframe) void Slider::setupBarTexture() { - this->updateChildrenDisplayedRGBA(); + _barRendererAdaptDirty = true; _progressBarRendererDirty = true; - updateContentSizeWithTextureSize(_barRenderer->getContentSize()); - _barTextureSize = _barRenderer->getContentSize(); - _originalBarRect = _barRenderer->getTextureRect(); + _barTextureSize = _barRenderer->getContentSize(); + _originalBarRect = _barRenderer->getTextureRect(); + + updateChildrenDisplayedRGBA(); + updateContentSize(); } void Slider::loadProgressBarTexture(std::string_view fileName, TextureResType texType) @@ -254,13 +256,13 @@ void Slider::setScale9Enabled(bool able) if (_scale9Enabled) { - bool ignoreBefore = _ignoreSize; - ignoreContentAdaptWithSize(false); - _prevIgnoreSize = ignoreBefore; + bool autoSizeBefore = _autoSize; + setAutoSize(false); + _prevAutoSize = autoSizeBefore; } else { - ignoreContentAdaptWithSize(_prevIgnoreSize); + setAutoSize(_prevAutoSize); } setCapInsetsBarRenderer(_capInsetsBarRenderer); setCapInsetProgressBarRenderer(_capInsetsProgressBarRenderer); @@ -273,12 +275,14 @@ bool Slider::isScale9Enabled() const return _scale9Enabled; } -void Slider::ignoreContentAdaptWithSize(bool ignore) +void Slider::setAutoSize(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::setAutoSize(autoSize); + _prevAutoSize = autoSize; // Store the current value for backward compatibility } } @@ -478,7 +482,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 { @@ -568,7 +572,7 @@ void Slider::onSizeChanged() _progressBarRendererDirty = true; } -void Slider::adaptRenderers() +void Slider::updateLayout() { if (_barRendererAdaptDirty) { @@ -582,24 +586,24 @@ void Slider::adaptRenderers() } } -Vec2 Slider::getVirtualRendererSize() const +Vec2 Slider::resolvePreferredSize(const Vec2& /*sizeHint*/) const { return _barRenderer->getContentSize(); } -Node* Slider::getVirtualRenderer() +Node* Slider::getRenderNode() { return _barRenderer; } void Slider::barRendererScaleChangedWithSize() { - if (_unifySize) + if (!_autoSize) { _barLength = _contentSize.width; - _barRenderer->setPreferredSize(_contentSize); + _barRenderer->setContentSize(_contentSize); } - else if (_ignoreSize) + else if (!_autoSize) // Previously isIgnoreContentAdaptWithSize() { _barRenderer->setScale(1.0f); @@ -610,7 +614,7 @@ void Slider::barRendererScaleChangedWithSize() _barLength = _contentSize.width; if (_scale9Enabled) { - _barRenderer->setPreferredSize(_contentSize); + _barRenderer->setContentSize(_contentSize); _barRenderer->setScale(1.0f); } else @@ -635,11 +639,11 @@ void Slider::barRendererScaleChangedWithSize() void Slider::progressBarRendererScaleChangedWithSize() { - if (_unifySize) + if (!_autoSize) { - _progressBarRenderer->setPreferredSize(_contentSize); + _progressBarRenderer->setContentSize(_contentSize); } - else if (_ignoreSize) + else if (!_autoSize) // Previously isIgnoreContentAdaptWithSize() { if (!_scale9Enabled) { @@ -654,7 +658,7 @@ void Slider::progressBarRendererScaleChangedWithSize() { if (_scale9Enabled) { - _progressBarRenderer->setPreferredSize(_contentSize); + _progressBarRenderer->setContentSize(_contentSize); _progressBarRenderer->setScale(1.0); } else @@ -745,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/Slider.h similarity index 95% rename from axmol/ui/UISlider.h rename to axmol/ui/Slider.h index dde7431a5a25..b3698ed00a4a 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 @@ -240,14 +240,14 @@ 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 "resolvePreferredSize" method of widget. + Vec2 resolvePreferredSize(const Vec2& /*sizeHint*/) const override; - // override "getVirtualRenderer" method of widget. - Node* getVirtualRenderer() override; + // override "getRenderNode" method of widget. + Node* getRenderNode() override; - // override "ignoreContentAdaptWithSize" method of widget. - void ignoreContentAdaptWithSize(bool ignore) 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; @@ -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; @@ -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/axmol/ui/UITabControl.cpp b/axmol/ui/TabControl.cpp similarity index 98% rename from axmol/ui/UITabControl.cpp rename to axmol/ui/TabControl.cpp index 7db8438a91b4..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 { @@ -98,9 +98,9 @@ void TabControl::initAfterInsert(int index) headerCell->setContentSize(Vec2(_headerWidth, _headerHeight)); headerCell->setAnchorPoint(getHeaderAnchorWithDock()); - if (headerCell->isIgnoreContentAdaptWithSize() == _ignoreHeaderTextureSize) + if (headerCell->_autoSize == !_ignoreHeaderTextureSize) { - headerCell->ignoreContentAdaptWithSize(!_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->ignoreContentAdaptWithSize(!ignore); + item->header->setAutoSize(ignore); if (ignore) item->header->setContentSize(Vec2(_headerWidth, _headerHeight)); item->header->backGroundDisabledTextureScaleChangedWithSize(); @@ -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/TabControl.h similarity index 98% rename from axmol/ui/UITabControl.h rename to axmol/ui/TabControl.h index 810f3c6404cc..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 @@ -159,7 +159,7 @@ class AX_GUI_DLL TabHeader : public AbstractCheckButton TabHeader(); ~TabHeader(); - void initRenderer() override; + void initRenderNode() override; void onSizeChanged() override; void updateContentSize(); @@ -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/UIText.cpp b/axmol/ui/Text.cpp similarity index 93% rename from axmol/ui/UIText.cpp rename to axmol/ui/Text.cpp index fb352a30fbf6..e45207f78a41 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" @@ -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); @@ -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 (!_ignoreSize) + if (!_autoSize) { _customSize = size; } - updateContentSizeWithTextureSize(_labelRenderer->getContentSize()); + updateContentSize(); _labelRendererAdaptDirty = true; } @@ -269,7 +269,7 @@ void Text::onSizeChanged() _labelRendererAdaptDirty = true; } -void Text::adaptRenderers() +void Text::updateLayout() { if (_labelRendererAdaptDirty) { @@ -278,7 +278,7 @@ void Text::adaptRenderers() } } -Vec2 Text::getVirtualRendererSize() const +Vec2 Text::resolvePreferredSize(const Vec2& /*sizeHint*/) const { return _labelRenderer->getContentSize(); } @@ -286,7 +286,7 @@ Vec2 Text::getVirtualRendererSize() const Vec2 Text::getAutoRenderSize() { Vec2 virtualSize = _labelRenderer->getContentSize(); - if (!_ignoreSize) + 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 (_ignoreSize) + 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/Text.h similarity index 96% rename from axmol/ui/UIText.h rename to axmol/ui/Text.h index a8d034a96a67..0661240796c9 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" @@ -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 "resolvePreferredSize" method of widget. + Vec2 resolvePreferredSize(const Vec2& /*sizeHint*/) 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. * @@ -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/TextAtlas.cpp similarity index 94% rename from axmol/ui/UITextAtlas.cpp rename to axmol/ui/TextAtlas.cpp index 54a1890c7630..42e81e9ebdb9 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 @@ -61,7 +61,7 @@ TextAtlas* TextAtlas::create() return nullptr; } -void TextAtlas::initRenderer() +void TextAtlas::initRenderNode() { _labelAtlasRenderer = Label::create(); _labelAtlasRenderer->setAnchorPoint(Point::ANCHOR_MIDDLE); @@ -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); } @@ -134,7 +134,7 @@ void TextAtlas::onSizeChanged() _labelAtlasRendererAdaptDirty = true; } -void TextAtlas::adaptRenderers() +void TextAtlas::updateLayout() { if (_labelAtlasRendererAdaptDirty) { @@ -143,19 +143,19 @@ void TextAtlas::adaptRenderers() } } -Vec2 TextAtlas::getVirtualRendererSize() const +Vec2 TextAtlas::resolvePreferredSize(const Vec2& /*sizeHint*/) const { return _labelAtlasRenderer->getContentSize(); } -Node* TextAtlas::getVirtualRenderer() +Node* TextAtlas::getRenderNode() { return _labelAtlasRenderer; } void TextAtlas::labelAtlasScaleChangedWithSize() { - if (_ignoreSize) + if (_autoSize) { _labelAtlasRenderer->setScale(1.0f); } diff --git a/axmol/ui/UITextAtlas.h b/axmol/ui/TextAtlas.h similarity index 93% rename from axmol/ui/UITextAtlas.h rename to axmol/ui/TextAtlas.h index 09daed6270a6..edae80b224d7 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 @@ -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 "resolvePreferredSize" method of widget. + Vec2 resolvePreferredSize(const Vec2& /*sizeHint*/) const override; - // override "getVirtualRenderer" method of widget. - Node* getVirtualRenderer() override; + // override "getRenderNode" method of widget. + Node* getRenderNode() override; /** * Returns the "class name" of widget. @@ -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/TextBMFont.cpp similarity index 92% rename from axmol/ui/UITextBMFont.cpp rename to axmol/ui/TextBMFont.cpp index e14b7e80e12f..8c420f8d29a7 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 @@ -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); @@ -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; } @@ -116,7 +116,7 @@ void TextBMFont::onSizeChanged() _labelBMFontRendererAdaptDirty = true; } -void TextBMFont::adaptRenderers() +void TextBMFont::updateLayout() { if (_labelBMFontRendererAdaptDirty) { @@ -125,19 +125,19 @@ void TextBMFont::adaptRenderers() } } -Vec2 TextBMFont::getVirtualRendererSize() const +Vec2 TextBMFont::resolvePreferredSize(const Vec2& /*sizeHint*/) const { return _labelBMFontRenderer->getContentSize(); } -Node* TextBMFont::getVirtualRenderer() +Node* TextBMFont::getRenderNode() { return _labelBMFontRenderer; } void TextBMFont::labelBMFontScaleChangedWithSize() { - if (_ignoreSize) + if (_autoSize) { _labelBMFontRenderer->setScale(1.0f); } @@ -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/TextBMFont.h similarity index 93% rename from axmol/ui/UITextBMFont.h rename to axmol/ui/TextBMFont.h index aa607cd76210..5a708b930e0b 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" /** @@ -88,8 +88,8 @@ class AX_GUI_DLL TextBMFont : public Widget */ ssize_t getStringLength() const; - Vec2 getVirtualRendererSize() const override; - Node* getVirtualRenderer() override; + Vec2 resolvePreferredSize(const Vec2& /*sizeHint*/) const override; + Node* getRenderNode() override; /** * Returns the "class name" of widget. */ @@ -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/UIEditBox/iOS/UITextField+UITextInput.h b/axmol/ui/UIEditBox/iOS/UITextField+UITextInput.h deleted file mode 100644 index 4d7afd4ad85f..000000000000 --- a/axmol/ui/UIEditBox/iOS/UITextField+UITextInput.h +++ /dev/null @@ -1,36 +0,0 @@ -/**************************************************************************** - Copyright (c) 2015 Mazyad Alabduljaleel - 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. - ****************************************************************************/ -#pragma once - -#import -#import "axmol/ui/UIEditBox/iOS/UITextInput.h" - -@interface UITextField (AXUITextInput) -@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/UIEditBox/iOS/UITextView+UITextInput.h b/axmol/ui/UIEditBox/iOS/UITextView+UITextInput.h deleted file mode 100644 index 69c761cb8fde..000000000000 --- a/axmol/ui/UIEditBox/iOS/UITextView+UITextInput.h +++ /dev/null @@ -1,36 +0,0 @@ -/**************************************************************************** - Copyright (c) 2015 Mazyad Alabduljaleel - 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. - ****************************************************************************/ -#pragma once - -#import -#import "axmol/ui/UIEditBox/iOS/UITextInput.h" - -@interface UITextView (AXUITextInput) -@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/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/UITextFieldEx.cpp b/axmol/ui/UITextFieldEx.cpp deleted file mode 100644 index 8901666731ab..000000000000 --- a/axmol/ui/UITextFieldEx.cpp +++ /dev/null @@ -1,1036 +0,0 @@ -/**************************************************************************** -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/UITextFieldEx.h" -#include "axmol/base/Director.h" - -namespace ax -{ - -#if defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP -# define axbeep(t) MessageBeep(t) -#else -# define axbeep(t) -#endif - -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 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 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) -{ - 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] = engine_inj_c4b2dw(fillColor); // 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 -{ - -/// calculate the UTF-8 string's char count. -static int _truncateUTF8String(const char* text, int limit, int& nb) -{ - int n = 0; - char ch = 0; - nb = 0; - while ((ch = *text) != 0x0) - { - AX_BREAK_IF(!ch || n > limit); - - if (0x80 != (0xC0 & ch)) - { - ++n; - } - ++nb; - ++text; - } - return n; -} - -static void internalSetLableFont(Label* l, 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; -} - -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() - : _editable(true) - , _renderLabel(nullptr) - , _charCount(0) - , _inputText("") - , _placeHolder("") - , _colorText(Color32::WHITE) - , _colorSpaceHolder(Color32::GRAY) - , _secureTextEntry(false) - , _cursor(nullptr) - , _touchListener(nullptr) - , _kbdListener(nullptr) - , onTextModify(nullptr) - , onOpenIME(nullptr) - , onCloseIME(nullptr) - , _charLimit(std::numeric_limits::max()) - , _systemFontUsed(false) - , _fontSize(24) - , _insertPosUtf8(0) - , _insertPos(0) - , _cursorPos(0) - , _touchCursorControlEnabled(true) - , _cursorVisible(false) - , _continuousTouchDelayTimerID(nullptr) - , _continuousTouchDelayTime(0.6) -{} - -TextFieldEx::~TextFieldEx() -{ - if (_kbdListener != nullptr) - _eventDispatcher->removeEventListener(_kbdListener); - if (_touchListener != nullptr) - _eventDispatcher->removeEventListener(_touchListener); -} - -////////////////////////////////////////////////////////////////////////// -// static constructor -////////////////////////////////////////////////////////////////////////// -TextFieldEx* TextFieldEx::create(std::string_view placeholder, - std::string_view fontName, - float fontSize, - float cursorWidth, - const Color32& cursorColor) -{ - TextFieldEx* ret = new TextFieldEx(); - if (ret && ret->initWithPlaceHolder("", fontName, fontSize, cursorWidth, cursorColor)) - { - ret->autorelease(); - if (placeholder.size() > 0) - { - ret->setPlaceholderText(placeholder); - } - return ret; - } - AX_SAFE_DELETE(ret); - return nullptr; -} - -////////////////////////////////////////////////////////////////////////// -// initialize -////////////////////////////////////////////////////////////////////////// -bool TextFieldEx::initWithPlaceHolder(std::string_view placeholder, - std::string_view fontName, - float fontSize, - float cursorWidth, - const Color32& cursorColor) -{ - _placeHolder = placeholder; - - _renderLabel = - _createLabel(placeholder, fontName, fontSize, Vec2::ZERO, TextHAlignment::CENTER, TextVAlignment::CENTER); - _renderLabel->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT); - this->addChild(_renderLabel); - - _director->getScheduler()->runOnAxmolThread( - [this] { _renderLabel->setPosition(Point(0, this->getContentSize().height / 2)); }); - - __initCursor(fontSize, cursorWidth, cursorColor); - - _fontName = fontName; - _fontSize = fontSize; - _systemFontUsed = !FileUtils::getInstance()->isFileExist(fontName); - - return true; -} - -std::string_view TextFieldEx::getTextFontName() const -{ - return _fontName; -} - -void TextFieldEx::setTextFontName(std::string_view fontName) -{ - if (FileUtils::getInstance()->isFileExist(fontName)) - { - TTFConfig config = _renderLabel->getTTFConfig(); - config.fontFilePath = fontName; - config.fontSize = _fontSize; - _renderLabel->setTTFConfig(config); - _systemFontUsed = false; - _fontType = 1; - } - else - { - _renderLabel->setSystemFontName(fontName); - if (!_systemFontUsed) - { - _renderLabel->requestSystemFontRefresh(); - } - _renderLabel->setSystemFontSize(_fontSize); - _systemFontUsed = true; - _fontType = 0; - } - _fontName = fontName; - - using namespace std::string_view_literals; - _asteriskWidth = internalCalcStringWidth("*"sv, _fontName, _fontSize); -} - -void TextFieldEx::setTextFontSize(float size) -{ - if (_systemFontUsed) - { - _renderLabel->setSystemFontSize(size); - } - else - { - TTFConfig config = _renderLabel->getTTFConfig(); - config.fontSize = size; - _renderLabel->setTTFConfig(config); - } - - _fontSize = size; - - using namespace std::string_view_literals; - _asteriskWidth = internalCalcStringWidth("*"sv, _fontName, _fontSize); -} - -float TextFieldEx::getTextFontSize() const -{ - return _fontSize; -} - -void TextFieldEx::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); }); - } - } - return true; - }; - _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); - } - } - else - { - closeIME(); - } - }; - - _eventDispatcher->addEventListenerWithSceneGraphPriority(_touchListener, this); - - /// enable use keyboard <- -> to move cursor. - _kbdListener = EventListenerKeyboard::create(); - _kbdListener->onKeyPressed = [this](EventKeyboard::KeyCode code, Event*) { - if (_cursorVisible) - { - switch (code) - { - case EventKeyboard::KeyCode::KEY_LEFT_ARROW: - this->__moveCursor(-1); - break; - case EventKeyboard::KeyCode::KEY_RIGHT_ARROW: - this->__moveCursor(1); - break; - case EventKeyboard::KeyCode::KEY_DELETE: - case EventKeyboard::KeyCode::KEY_KP_DELETE: - this->handleDeleteKeyEvent(); - break; - default:; - } - } - }; - - _eventDispatcher->addEventListenerWithSceneGraphPriority(_kbdListener, this); -} - -void TextFieldEx::disableIME(void) -{ - _eventDispatcher->removeEventListener(_kbdListener); - _eventDispatcher->removeEventListener(_touchListener); - - _kbdListener = nullptr; - _touchListener = nullptr; - closeIME(); -} - -Label* TextFieldEx::getRenderLabel() -{ - return _renderLabel; -} - -////////////////////////////////////////////////////////////////////////// -// IMEDelegate -////////////////////////////////////////////////////////////////////////// - -bool TextFieldEx::attachWithIME() -{ - bool ret = IMEDelegate::attachWithIME(); - if (ret) - { - // open keyboard - RenderView* renderView = _director->getRenderView(); - if (renderView) - renderView->setIMEKeyboardState(true); - } - return ret; -} - -bool TextFieldEx::detachWithIME() -{ - bool ret = IMEDelegate::detachWithIME(); - if (ret) - { - // close keyboard - RenderView* renderView = _director->getRenderView(); - if (renderView) - renderView->setIMEKeyboardState(false); - } - return ret; -} - -void TextFieldEx::keyboardDidShow(IMEKeyboardNotificationInfo& /*info*/) -{ - s_keyboardVisible = true; -} - -void TextFieldEx::keyboardDidHide(IMEKeyboardNotificationInfo& /*info*/) -{ - s_keyboardVisible = false; -} - -void TextFieldEx::openIME(void) -{ - AXLOGD("TextFieldEx:: openIME"); - this->attachWithIME(); - __updateCursorPosition(); - __showCursor(); - - if (this->onOpenIME) - this->onOpenIME(); -} - -void TextFieldEx::closeIME(void) -{ - AXLOGD("TextFieldEx:: closeIME"); - __hideCursor(); - this->detachWithIME(); - - if (this->onCloseIME) - this->onCloseIME(); -} - -bool TextFieldEx::canAttachWithIME() -{ - return true; //(_delegate) ? (! _delegate->onTextFieldAttachWithIME(this)) : true; -} - -bool TextFieldEx::canDetachWithIME() -{ - return true; //(_delegate) ? (! _delegate->onTextFieldDetachWithIME(this)) : true; -} - -void TextFieldEx::insertText(const char* text, size_t len) -{ - if (!_editable || !this->_enabled) - { - return; - } - - if (_charLimit > 0 && _charCount >= _charLimit) - { // regard zero as unlimited - axbeep(0); - return; - } - - int nb; - auto n = _truncateUTF8String(text, static_cast(_charLimit - _charCount), nb); - - std::string insert(text, nb); - - // insert \n means input end - auto pos = insert.find('\n'); - if (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; - // } - - _charCount += n; // _calcCharCount(insert.c_str()); - std::string sText(_inputText); - sText.insert(_insertPos, insert); // original is: sText.append(insert); - - // bool needUpdatePos - this->setString(sText); - while (n-- > 0) - __moveCursor(1); - - // this->contentDirty = true; - // __updateCursorPosition(); - - if (this->onTextModify) - this->onTextModify(); - } - - if (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 - this->closeIME(); -} - -void TextFieldEx::deleteBackward(size_t numChars) -{ - if (!_editable || !this->_enabled || 0 == _charCount) - { - axbeep(0); - return; - } - - size_t len = _inputText.length(); - if (0 == len || _insertPos == 0) - { - axbeep(0); - // there is no string - // __updateCursorPosition(); - 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; - } - - // 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) - { - __moveCursor(-1); - - _inputText.clear(); - _charCount = 0; - _renderLabel->setTextColor(_colorSpaceHolder); - _renderLabel->setString(_placeHolder); - - // __updateCursorPosition(); - - // this->contentDirty = true; - - if (this->onTextModify) - this->onTextModify(); - return; - } - - // set new input text - std::string text = _inputText; // (inputText.c_str(), len - deleteLen); - text.erase(_insertPos - totalDeleteLen, totalDeleteLen); - - __moveCursor(-1); - - this->setString(text); - - //__updateCursorPosition(); - // __moveCursor(-1); - - if (this->onTextModify) - this->onTextModify(); -} - -void TextFieldEx::handleDeleteKeyEvent() -{ - if (!_editable || !this->_enabled || 0 == _charCount) - { - axbeep(0); - return; - } - - size_t len = _inputText.length(); - if (0 == len || _insertPosUtf8 == _charCount) - { - axbeep(0); - // there is no string - // __updateCursorPosition(); - 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; - } - - // 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) - { - _inputText.clear(); - _charCount = 0; - _renderLabel->setTextColor(_colorSpaceHolder); - _renderLabel->setString(_placeHolder); - - __updateCursorPosition(); - - // this->contentDirty = true; - - if (this->onTextModify) - this->onTextModify(); - return; - } - - // set new input text - std::string text = _inputText; // (inputText.c_str(), len - deleteLen); - text.erase(_insertPos, deleteLen); - - // __moveCursor(-1); - - this->setString(text); - - if (this->onTextModify) - this->onTextModify(); -} - -std::string_view TextFieldEx::getContentText() -{ - return _inputText; -} - -void TextFieldEx::setTextColor(const Color32& color) -{ - _colorText = color; - if (!_inputText.empty()) - _renderLabel->setTextColor(_colorText); -} - -const Color32& TextFieldEx::getTextColor(void) const -{ - return _colorText; -} - -void TextFieldEx::setCursorColor(const Color32& color) -{ - _cursor->setColor(color); -} - -const Color32& TextFieldEx::getCursorColor(void) const -{ - return _cursor->getColor(); -} - -const Color32& TextFieldEx::getPlaceholderColor() const -{ - return _colorSpaceHolder; -} - -void TextFieldEx::setPlaceholderColor(const Color32& color) -{ - _colorSpaceHolder = color; - if (_inputText.empty()) - _renderLabel->setTextColor(color); -} - -////////////////////////////////////////////////////////////////////////// -// properties -////////////////////////////////////////////////////////////////////////// - -// input text property -void TextFieldEx::setString(std::string_view text) -{ - static char bulletString[] = {(char)0xe2, (char)0x80, (char)0xa2, (char)0x00}; - - _inputText = text; - - std::string secureText; - - std::string* displayText = &_inputText; - - if (!_inputText.empty()) - { - if (_secureTextEntry) - { - size_t length = _inputText.length(); - displayText = &secureText; - - while (length > 0) - { - displayText->append(bulletString); - --length; - } - } - } - - // if there is no input text, display placeholder instead - if (_inputText.empty()) - { - _renderLabel->setTextColor(_colorSpaceHolder); - _renderLabel->setString(_placeHolder); - } - else - { - _renderLabel->setTextColor(_colorText); - _renderLabel->setString(*displayText); - } - - bool bInsertAtEnd = (_insertPosUtf8 == _charCount); - - _charCount = text_utils::countUTF8Chars(_inputText); - - if (bInsertAtEnd) - { - _insertPosUtf8 = static_cast(_charCount); - _insertPos = static_cast(_inputText.length()); - _cursorPos = static_cast(displayText->length()); - } -} - -void TextFieldEx::updateContentSize(void) -{ - this->setContentSize(_renderLabel->getContentSize()); -} - -std::string_view TextFieldEx::getString() const -{ - return _inputText; -} - -// place holder text property -void TextFieldEx::setPlaceholderText(std::string_view text) -{ - _placeHolder = text; - if (_inputText.empty()) - { - _renderLabel->setTextColor(_colorSpaceHolder); - _renderLabel->setString(_placeHolder); - } -} - -std::string_view TextFieldEx::getPlaceholderText() const -{ - return _placeHolder; -} - -// secureTextEntry -void TextFieldEx::setPasswordEnabled(bool value) -{ - if (_secureTextEntry != value) - { - _secureTextEntry = value; - this->setString(this->getString()); - __updateCursorPosition(); - } -} - -bool TextFieldEx::isPasswordEnabled() const -{ - return _secureTextEntry; -} - -void TextFieldEx::setEnabled(bool bEnabled) -{ - if (this->_enabled != bEnabled) - { - if (!bEnabled) - { - this->closeIME(); - } - this->_enabled = bEnabled; - } -} - -int TextFieldEx::getFontType() const -{ - return _fontType; -} - -void TextFieldEx::__initCursor(int height, int width, const Color32& color) -{ - _cursor = engine_inj_create_lump(Color32(color), height, width); - - this->addChild(_cursor); - - _cursor->setPosition(Point(0, this->getContentSize().height / 2)); - // nodes_layout::setNodeLB(_cursor, ax::Point::ZERO); - - __hideCursor(); - - __updateCursorPosition(); -} - -void TextFieldEx::__showCursor(void) -{ - if (_cursor) - { - _cursorVisible = true; - _cursor->setVisible(true); - _cursor->runAction(RepeatForever::create(Blink::create(1, 1))); - } -} - -void TextFieldEx::__hideCursor(void) -{ - if (_cursor) - { - _cursor->setVisible(false); - _cursorVisible = false; - _cursor->stopAllActions(); - } -} - -void TextFieldEx::__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)); - } - } -} - -void TextFieldEx::__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(); - - if (direction < 0) - { - _insertPos = static_cast(internalUTF8MoveLeft(_inputText, _insertPos).size()); - - auto s = internalUTF8MoveLeft(displayText, _cursorPos); - - 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()); - - auto s = internalUTF8MoveRight(displayText, _cursorPos); - auto width = internalCalcStringWidth(s, _fontName, _fontSize); - _cursor->setPosition(Point(width, this->getContentSize().height / 2)); - _cursorPos = static_cast(s.length()); - } - - _insertPosUtf8 = newOffset; - } - else if (newOffset == 0) - { - _cursor->setPosition(Point(0, this->getContentSize().height / 2)); - _insertPosUtf8 = newOffset; - _insertPos = 0; - _cursorPos = 0; - } - else - { - // MessageBeep(0); - } -} - -void TextFieldEx::__moveCursorTo(float x) -{ // test - // normalized x - float normalizedX = 0; - - std::string_view displayText; - if (!_secureTextEntry) - { - displayText = _inputText; - } - else - { - if (!_inputText.empty()) - { - displayText = _renderLabel->getString(); - } - } - - int length = static_cast(displayText.length()); - int n = static_cast(_charCount); // UTF8 char counter - - 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; - } - - // clamp backward - size_t backwardLen = 1; // default, erase 1 byte - while (0x80 == (0xC0 & displayText.at(displayText.length() - backwardLen))) - { - ++backwardLen; - } - - --n; - displayText.remove_suffix(backwardLen); - - length -= backwardLen; - } - - _insertPos = !_secureTextEntry ? insertWhere : insertWhereUtf8; - _cursorPos = insertWhere; - _insertPosUtf8 = insertWhereUtf8; - _cursor->setPosition(Point(normalizedX, this->getContentSize().height / 2)); -} -}; // namespace ui - -} // namespace ax diff --git a/axmol/ui/UITextFieldEx.h b/axmol/ui/UITextFieldEx.h deleted file mode 100644 index 05ef2eba3b2d..000000000000 --- a/axmol/ui/UITextFieldEx.h +++ /dev/null @@ -1,214 +0,0 @@ -/**************************************************************************** -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/base/IMEDelegate.h" -#include "axmol/base/SimpleTimer.h" -#include "axmol/2d/Label.h" -#include "axmol/base/EventListenerKeyboard.h" - -namespace ax -{ - -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 -*/ -class AX_DLL TextFieldEx : public Widget, public IMEDelegate -{ -public: - /** - */ - TextFieldEx(); - /** - * @lua NA - */ - virtual ~TextFieldEx(); - - static TextFieldEx* create(std::string_view placeholder, - std::string_view fontName, - float fontSize, - float cursorWidth = 2, - const Color32& color = Color32::WHITE); - - bool initWithPlaceHolder(std::string_view placeholder, - std::string_view fontName, - float fontSize, - 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); }; - - virtual void setPlaceholderColor(const Color32& color); - virtual const Color32& getPlaceholderColor() const; - - virtual void setTextColor(const Color32& textColor); - virtual const Color32& getTextColor(void) const; - - void setCursorColor(const Color32& color); - const Color32& getCursorColor(void) const; - - // input text property - virtual void setString(std::string_view text); - virtual std::string_view getString() const; - - // Continuous touch event trigger support. - void setContinuousTouchDelayTime(float delay) { _continuousTouchDelayTime = delay; } - float getContinuousTouchDelayTime() const { return _continuousTouchDelayTime; } - void setContinuousTouchCallback(std::function callback) - { - _continuousTouchCallback = std::move(callback); - } - - // place holder text property - // place holder text displayed when there is no text in the text field. - virtual void setPlaceholderText(std::string_view text); - virtual std::string_view getPlaceholderText(void) const; - - virtual void setPasswordEnabled(bool value); - virtual bool isPasswordEnabled() const; - - bool empty(void) const { return _charCount == 0 || _inputText.empty(); } - - void setEnabled(bool bEnabled) override; - - void setEditable(bool bEditable) { _editable = bEditable; } - bool isEditable(void) const { return _editable; } - - void setMaxLength(int maxLength) { setCharLimit(maxLength); } - - int getFontType() const; - - /// fonts - void setTextFontSize(float size); - float getTextFontSize() const; - void setTextFontName(std::string_view fontName); - std::string_view getTextFontName() const; - - AX_SYNTHESIZE(size_t, _charLimit, CharLimit); - - bool isSystemFont(void) const { return _systemFontUsed; } - -public: - std::function onTextModify; - std::function onOpenIME; - std::function onCloseIME; - // IMEDelegate interface - ////////////////////////////////////////////////////////////////////////// - void openIME(void); - void closeIME(void); - - void insertText(const char* text, size_t len) override; - -protected: - ////////////////////////////////////////////////////////////////////////// - - bool canAttachWithIME() override; - bool canDetachWithIME() override; - - void deleteBackward(size_t numChars) override; - std::string_view getContentText() override; - - void handleDeleteKeyEvent(); - - /** - @brief Open keyboard and receive input text. - */ - bool attachWithIME() override; - - /** - @brief End text input and close keyboard. - */ - bool detachWithIME() override; - - void keyboardDidShow(IMEKeyboardNotificationInfo& /*info*/) override; - void keyboardDidHide(IMEKeyboardNotificationInfo& /*info*/) override; - - void updateContentSize(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 __moveCursorTo(float x); - -protected: - bool _systemFontUsed; - std::string _fontName; - float _fontSize; - - bool _editable; - - Label* _renderLabel; - - size_t _charCount; - std::string _inputText; - - std::string _placeHolder; - Color32 _colorSpaceHolder; - Color32 _colorText; - - bool _secureTextEntry; - - Sprite* _cursor; - bool _cursorVisible; - - int _insertPosUtf8; - int _insertPos; // The actual input content insertPos, step: bytes - int _cursorPos; // The cursor normalzed pos, - - EventListenerTouchOneByOne* _touchListener; - EventListenerKeyboard* _kbdListener; - - bool _touchCursorControlEnabled; - float _asteriskWidth; - - int _fontType; - - ax::stimer::TIMER_ID _continuousTouchDelayTimerID; - float _continuousTouchDelayTime; - std::function _continuousTouchCallback; - - static bool s_keyboardVisible; -}; - -// end of input group -/// @} - -}; // namespace ui - -} // namespace ax 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 14706336541b..4f10413157c6 100644 --- a/axmol/ui/UIWebView/UIWebViewImpl-win32.cpp +++ b/axmol/ui/WebView/WebViewImpl-win32.cpp @@ -27,16 +27,18 @@ #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" -# define WIN32_LEAN_AND_MEAN +# ifndef WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +# endif # include # include # include 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 95% rename from axmol/ui/UIWidget.cpp rename to axmol/ui/Widget.cpp index 1af6d391787d..f0a2431b49ba 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 { @@ -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) @@ -217,13 +216,13 @@ bool Widget::init() { if (ProtectedNode::init()) { - initRenderer(); + initRenderNode(); setBright(true); onFocusChanged = AX_CALLBACK_2(Widget::onFocusChange, this); onNextFocusedWidget = nullptr; this->setAnchorPoint(Vec2(0.5f, 0.5f)); - ignoreContentAdaptWithSize(true); + setAutoSize(true); return true; } @@ -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() { @@ -285,17 +284,11 @@ void Widget::setContentSize(const Vec2& contentSize) { return; } - ProtectedNode::setContentSize(contentSize); _customSize = contentSize; - if (_unifySize) - { - // unify size logic - } - else if (_ignoreSize) - { - ProtectedNode::setContentSize(getVirtualRendererSize()); - } + + ProtectedNode::setContentSize(_autoSize ? resolvePreferredSize(_customSize) : _customSize); + if (!_usingLayoutComponent && _running) { Widget* widgetParent = getWidgetParent(); @@ -349,14 +342,11 @@ void Widget::setSizePercent(const Vec2& percent) cSize = Vec2(_parent->getContentSize().width * percent.x, _parent->getContentSize().height * percent.y); } } - if (_ignoreSize) - { - this->setContentSize(getVirtualRendererSize()); - } + if (_autoSize) + setContentSize(resolvePreferredSize(cSize)); else - { - this->setContentSize(cSize); - } + setContentSize(cSize); + _customSize = cSize; } } @@ -374,9 +364,9 @@ void Widget::updateSizeAndPosition(const Vec2& parentSize) { case SizeType::ABSOLUTE: { - if (_ignoreSize) + if (_autoSize) { - this->setContentSize(getVirtualRendererSize()); + this->setContentSize(resolvePreferredSize(_customSize)); } else { @@ -398,9 +388,9 @@ void Widget::updateSizeAndPosition(const Vec2& parentSize) case SizeType::PERCENT: { Vec2 cSize = Vec2(parentSize.width * _sizePercent.x, parentSize.height * _sizePercent.y); - if (_ignoreSize) + if (_autoSize) { - this->setContentSize(getVirtualRendererSize()); + this->setContentSize(resolvePreferredSize(cSize)); } else { @@ -493,34 +483,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; @@ -537,7 +499,7 @@ const Vec2& Widget::getSizePercent() return _sizePercent; } -Node* Widget::getVirtualRenderer() +Node* Widget::getRenderNode() { return this; } @@ -557,25 +519,24 @@ void Widget::onSizeChanged() } } -Vec2 Widget::getVirtualRendererSize() const +Vec2 Widget::resolvePreferredSize(const Vec2& sizeHint) const { - return _contentSize; + return sizeHint; } -void Widget::updateContentSizeWithTextureSize(const Vec2& size) +void Widget::updateContentSize() { - if (_unifySize) - { - this->setContentSize(size); - return; - } - if (_ignoreSize) + auto preferredSize = resolvePreferredSize(_customSize); + + if (_autoSize) { - this->setContentSize(size); + // Auto size mode: update to the preferred size based on content + ProtectedNode::setContentSize(preferredSize); } else { - this->setContentSize(_customSize); + // Fixed size mode: keep custom size unchanged + ProtectedNode::setContentSize(_customSize); } } @@ -1303,7 +1264,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 +1534,25 @@ void Widget::enableDpadNavigation(bool enable) } } -bool Widget::isUnifySizeEnabled() const +void Widget::setAutoSize(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 + ProtectedNode::setContentSize(this->resolvePreferredSize(_customSize)); + + onSizeChanged(); + } } void Widget::setLayoutComponentEnabled(bool enable) diff --git a/axmol/ui/UIWidget.h b/axmol/ui/Widget.h similarity index 93% rename from axmol/ui/UIWidget.h rename to axmol/ui/Widget.h index 8347ed5fc7c4..506e629fbf2c 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" @@ -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`. @@ -538,35 +545,20 @@ 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. + * 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; + Vec2 getPreferredSize() const { return resolvePreferredSize(_contentSize); } /** * Returns the string representation of widget class name @@ -717,16 +709,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 setAutoSize(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 isAutoSize() const { return _autoSize; } /** * Set callback name. @@ -798,11 +791,21 @@ 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(); // initializes renderer of widget. - virtual void initRenderer(); + virtual void initRenderNode(); // call back function called widget's state changed to normal. virtual void onPressStateChangedToNormal(); @@ -819,7 +822,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); @@ -828,7 +831,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); @@ -839,15 +842,20 @@ 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; + bool _hitted; + bool _flippedX; + bool _flippedY; + bool _focused; + bool _focusEnabled; + bool _mouseHitted; BrightStyle _brightStyle; SizeType _sizeType; @@ -861,32 +869,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; @@ -895,6 +886,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/axmol/ui/axmol-ui.h b/axmol/ui/axmol-ui.h index 037731188547..fb7989b8fcd0 100644 --- a/axmol/ui/axmol-ui.h +++ b/axmol/ui/axmol-ui.h @@ -26,38 +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/UITextField.h" -#include "axmol/ui/UITextFieldEx.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.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/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..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; } @@ -34,12 +33,12 @@ class KeyboardInputDelegate : public IMEDelegate // Not handled at the moment } - void insertText(const char* text, size_t len) override + void insertText(std::string_view text) override { ImGuiIO& io = ImGui::GetIO(); - for (int i = 0; i < len && text[i] != 0; ++i) + for (auto ch : text) { - io.AddInputCharacter(text[i]); + io.AddInputCharacter(ch); } } }; 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.cpp b/extensions/sceneext/src/sceneext/SGUIReader.cpp index 9242c660d69c..e741b3ee39a4 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(); @@ -607,7 +597,7 @@ void WidgetPropertiesReader0250::setPropsForWidgetFromJsonDictionary(Widget* wid bool ignoreSizeExsit = DICTOOL->checkObjectExist_json(options, "ignoreSize"); if (ignoreSizeExsit) { - widget->ignoreContentAdaptWithSize(DICTOOL->getBooleanValue_json(options, "ignoreSize")); + widget->setAutoSize(DICTOOL->getBooleanValue_json(options, "ignoreSize")); } float w = DICTOOL->getFloatValue_json(options, "width"); @@ -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..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" @@ -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/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/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/src/sceneio/ActionTimeline/CSLoader.cpp b/extensions/sceneio/src/sceneio/ActionTimeline/CSLoader.cpp index f33693e1d5a0..d8e15efd2e2c 100644 --- a/extensions/sceneio/src/sceneio/ActionTimeline/CSLoader.cpp +++ b/extensions/sceneio/src/sceneio/ActionTimeline/CSLoader.cpp @@ -1364,7 +1364,7 @@ std::string_view CSLoader::getWidgetReaderClassName(Widget* widget) { readerName = "SliderReader"; } - else if (dynamic_cast(widget)) + else if (dynamic_cast(widget)) { readerName = "TextFieldReader"; } 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.cpp b/extensions/sceneio/src/sceneio/FlatBuffersSerialize.cpp index a474a62ec035..aff4df469518 100644 --- a/extensions/sceneio/src/sceneio/FlatBuffersSerialize.cpp +++ b/extensions/sceneio/src/sceneio/FlatBuffersSerialize.cpp @@ -514,7 +514,7 @@ std::string FlatBuffersSerialize::getWidgetReaderClassName(Widget* widget) { readerName = "SliderReader"; } - else if (dynamic_cast(widget)) + else if (dynamic_cast(widget)) { readerName = "TextFieldReader"; } 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 1277fa2adf4d..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" @@ -985,8 +985,7 @@ void ButtonReader::setPropsWithFlatBuffers(ax::Node* node, const flatbuffers::Ta if (scale9Enabled) { - button->setUnifySizeEnabled(false); - button->ignoreContentAdaptWithSize(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/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 16697cd8e523..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" @@ -378,8 +378,7 @@ void ImageViewReader::setPropsWithFlatBuffers(ax::Node* node, const flatbuffers: if (scale9Enabled) { - imageView->setUnifySizeEnabled(false); - imageView->ignoreContentAdaptWithSize(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 12210ff2a79a..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" @@ -729,7 +729,7 @@ void LayoutReader::setPropsWithFlatBuffers(ax::Node* node, const flatbuffers::Ta } else { - if (!panel->isIgnoreContentAdaptWithSize()) + 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 70f55b472250..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" @@ -562,7 +562,7 @@ void ListViewReader::setPropsWithFlatBuffers(ax::Node* node, const flatbuffers:: } else { - if (!listView->isIgnoreContentAdaptWithSize()) + if (!listView->isAutoSize()) { Size contentSize(widgetOptions->size()->width(), widgetOptions->size()->height()); listView->setContentSize(contentSize); 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 dec247c11675..11465213488e 100644 --- a/extensions/sceneio/src/sceneio/WidgetReader/PageViewReader/PageViewReader.cpp +++ b/extensions/sceneio/src/sceneio/WidgetReader/PageViewReader/PageViewReader.cpp @@ -1,9 +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" @@ -403,7 +401,7 @@ void PageViewReader::setPropsWithFlatBuffers(ax::Node* node, const flatbuffers:: } else { - if (!pageView->isIgnoreContentAdaptWithSize()) + if (!pageView->isAutoSize()) { Size contentSize(widgetOptions->size()->width(), widgetOptions->size()->height()); pageView->setContentSize(contentSize); 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 85414168ee6c..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" @@ -542,7 +542,7 @@ void ScrollViewReader::setPropsWithFlatBuffers(ax::Node* node, const flatbuffers } else { - if (!scrollView->isIgnoreContentAdaptWithSize()) + if (!scrollView->isAutoSize()) { Size contentSize(widgetOptions->size()->width(), widgetOptions->size()->height()); scrollView->setContentSize(contentSize); 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 c07da905f736..454391df47ce 100644 --- a/extensions/sceneio/src/sceneio/WidgetReader/TextAtlasReader/TextAtlasReader.cpp +++ b/extensions/sceneio/src/sceneio/WidgetReader/TextAtlasReader/TextAtlasReader.cpp @@ -1,8 +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" @@ -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->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 7f276734d264..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" @@ -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->setAutoSize(false); } Node* TextBMFontReader::createNodeWithFlatBuffers(const flatbuffers::Table* textBMFontOptions) diff --git a/extensions/sceneio/src/sceneio/WidgetReader/TextFieldReader/TextFieldExReader.cpp b/extensions/sceneio/src/sceneio/WidgetReader/TextFieldReader/TextFieldExReader.cpp index f9413c79ca87..4a520fad1a4f 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/InputField.h" #include "axmol/platform/FileUtils.h" #include "sceneext/CocoLoader.h" #include "sceneio/CSParseBinary_generated.h" @@ -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; @@ -290,8 +290,8 @@ Offset
TextFieldExReader::createOptionsWithFlatBuffers(pugi::xml_node obj void TextFieldExReader::setPropsWithFlatBuffers(ax::Node* node, const flatbuffers::Table* textFieldOptions) { - TextFieldEx** pTextField = (TextFieldEx**)(node); - auto options = (TextFieldExOptions*)textFieldOptions; + 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; @@ -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())); @@ -367,18 +367,18 @@ void TextFieldExReader::setPropsWithFlatBuffers(ax::Node* node, const flatbuffer textField->setContentSize(contentSize); textField->setEnabled(options->enabled()); - textField->setEditable(options->editable()); + textField->setReadOnly(!options->editable()); - textField->enableIME(nullptr); - /*if (!textField->isIgnoreContentAdaptWithSize()) + // InputField will enable IME when user interacts with it + if (!textField->isAutoSize()) { - ((Label*)(textField->getVirtualRenderer()))->setLineBreakWithoutSpace(true); - }*/ + ((Label*)(textField->getRenderNode()))->setLineBreakWithoutSpace(true); + } } 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/WidgetReader/TextFieldReader/TextFieldReader.cpp b/extensions/sceneio/src/sceneio/WidgetReader/TextFieldReader/TextFieldReader.cpp index 089c189e784d..017d2c84aef3 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/InputField.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) { @@ -106,15 +106,15 @@ void TextFieldReader::setPropsFromBinary(ax::ui::Widget* widget, CocoLoader* coc } 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) { - 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); + textField->setPasswordChar(value); } } // end of for loop this->endSetBasicProperties(widget); @@ -136,11 +136,11 @@ void TextFieldReader::setPropsFromJsonDictionary(Widget* widget, const rapidjson { WidgetReader::setPropsFromJsonDictionary(widget, options); - TextField* textField = static_cast(widget); - bool ph = DICTOOL->checkObjectExist_json(options, P_PlaceHolder); + 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")); @@ -158,8 +158,8 @@ void TextFieldReader::setPropsFromJsonDictionary(Widget* widget, const rapidjson bool tsh = DICTOOL->checkObjectExist_json(options, P_TouchSizeHeight); if (tsw && tsh) { - textField->setTouchSize(Size(DICTOOL->getFloatValue_json(options, P_TouchSizeWidth), - DICTOOL->getFloatValue_json(options, P_TouchSizeHeight))); + textField->setTouchAreaSize(Size(DICTOOL->getFloatValue_json(options, P_TouchSizeWidth), + DICTOOL->getFloatValue_json(options, P_TouchSizeHeight))); } // float dw = DICTOOL->getFloatValue_json(options, "width"); @@ -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); @@ -180,7 +179,7 @@ void TextFieldReader::setPropsFromJsonDictionary(Widget* widget, const rapidjson textField->setPasswordEnabled(passwordEnable); if (passwordEnable) { - textField->setPasswordStyleText(DICTOOL->getStringValue_json(options, P_PasswordStyleText, "*")); + textField->setPasswordChar(DICTOOL->getStringValue_json(options, P_PasswordStyleText, "*")); } WidgetReader::setColorPropsFromJsonDictionary(widget, options); @@ -307,11 +306,11 @@ Offset
TextFieldReader::createOptionsWithFlatBuffers(pugi::xml_node objec void TextFieldReader::setPropsWithFlatBuffers(ax::Node* node, const flatbuffers::Table* textFieldOptions) { - TextField* textField = static_cast(node); - auto options = (TextFieldOptions*)textFieldOptions; + 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; @@ -336,8 +335,7 @@ void TextFieldReader::setPropsWithFlatBuffers(ax::Node* node, const flatbuffers: textField->setFontName(fontName); bool maxLengthEnabled = options->maxLengthEnabled() != 0; - textField->setMaxLengthEnabled(maxLengthEnabled); - + // InputField doesn't have setMaxLengthEnabled, only setMaxLength if (maxLengthEnabled) { int maxLength = options->maxLength(); @@ -348,7 +346,7 @@ void TextFieldReader::setPropsWithFlatBuffers(ax::Node* node, const flatbuffers: if (passwordEnabled) { std::string passwordStyleText = options->passwordStyleText()->c_str(); - textField->setPasswordStyleText(passwordStyleText.c_str()); + textField->setPasswordChar(passwordStyleText); } bool fileExist = false; @@ -375,13 +373,12 @@ void TextFieldReader::setPropsWithFlatBuffers(ax::Node* node, const flatbuffers: 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->getVirtualRenderer()))->setLineBreakWithoutSpace(true); + ((Label*)(textField->getRenderNode()))->setLineBreakWithoutSpace(true); Size contentSize(widgetOptions->size()->width(), widgetOptions->size()->height()); textField->setContentSize(contentSize); } @@ -389,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/WidgetReader/TextReader/TextReader.cpp b/extensions/sceneio/src/sceneio/WidgetReader/TextReader/TextReader.cpp index 5a00728ae5bd..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" @@ -557,19 +557,16 @@ 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->setAutoSize(!options->isCustomSize()); auto widgetOptions = options->widgetOptions(); - if (!label->isIgnoreContentAdaptWithSize()) + if (!label->isAutoSize()) { Size contentSize(widgetOptions->size()->width(), widgetOptions->size()->height()); 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/sceneio/src/sceneio/WidgetReader/WidgetReader.cpp b/extensions/sceneio/src/sceneio/WidgetReader/WidgetReader.cpp index c0ea57596462..8b3b5dc34812 100644 --- a/extensions/sceneio/src/sceneio/WidgetReader/WidgetReader.cpp +++ b/extensions/sceneio/src/sceneio/WidgetReader/WidgetReader.cpp @@ -1,15 +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" @@ -136,7 +134,7 @@ 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)); + widget->setAutoSize(DICTOOL->getBooleanValue_json(options, P_IgnoreSize)); } widget->setSizeType((Widget::SizeType)DICTOOL->getIntValue_json(options, P_SizeType)); @@ -283,7 +281,7 @@ void WidgetReader::endSetBasicProperties(Widget* widget) } widget->setColor(_color); // the setSize method will be conflict with scale9Width & scale9Height - if (!widget->isIgnoreContentAdaptWithSize()) + if (!widget->isAutoSize()) { widget->setContentSize(Size(_width, _height)); } @@ -772,13 +770,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->setAutoSize(!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..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->ignoreContentAdaptWithSize(valueToBool(value)); \ + widget->setAutoSize(!valueToBool(value)); \ } \ else if (key == P_SizeType) \ { \ diff --git a/extensions/scripting/lua-bindings/auto/axlua_base_auto.cpp b/extensions/scripting/lua-bindings/auto/axlua_base_auto.cpp index 1a46fe0d8064..9dfd9b190def 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; @@ -55414,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; @@ -55434,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 @@ -55444,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; @@ -55481,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 @@ -55491,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_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_getStringLength'.",&tolua_err); + tolua_error(tolua_S,"#ferror in function 'lua_ax_base_Label_isEmpty'.",&tolua_err); #endif return 0; @@ -58553,7 +58653,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 +58661,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 +59016,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); @@ -58913,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); @@ -104164,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; @@ -104838,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); diff --git a/extensions/scripting/lua-bindings/auto/axlua_ui_auto.cpp b/extensions/scripting/lua-bindings/auto/axlua_ui_auto.cpp index 380cd6c0c268..12494758d1cd 100644 --- a/extensions/scripting/lua-bindings/auto/axlua_ui_auto.cpp +++ b/extensions/scripting/lua-bindings/auto/axlua_ui_auto.cpp @@ -2813,7 +2813,7 @@ int lua_ax_ui_Widget_getLayoutParameter(lua_State* tolua_S) return 0; } -int lua_ax_ui_Widget_ignoreContentAdaptWithSize(lua_State* tolua_S) +int lua_ax_ui_Widget_getRenderNode(lua_State* tolua_S) { int argc = 0; ax::ui::Widget* obj = nullptr; @@ -2833,57 +2833,7 @@ int lua_ax_ui_Widget_ignoreContentAdaptWithSize(lua_State* tolua_S) #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); + tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_Widget_getRenderNode'", nullptr); return 0; } #endif @@ -2893,71 +2843,24 @@ int lua_ax_ui_Widget_isIgnoreContentAdaptWithSize(lua_State* tolua_S) { if(!ok) { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_Widget_isIgnoreContentAdaptWithSize'", nullptr); + tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_Widget_getRenderNode'", 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_getVirtualRenderer(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_getVirtualRenderer'", 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_getVirtualRenderer'", 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 +2880,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 +2890,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; @@ -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_setAutoSize(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_setAutoSize'", 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:setAutoSize"); 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_setAutoSize'", nullptr); return 0; } - obj->setUnifySizeEnabled(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:setUnifySizeEnabled",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_setUnifySizeEnabled'.",&tolua_err); + tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_Widget_setAutoSize'.",&tolua_err); #endif return 0; } -int lua_ax_ui_Widget_isUnifySizeEnabled(lua_State* tolua_S) +int lua_ax_ui_Widget_isAutoSize(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_isAutoSize'", 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_isAutoSize'", nullptr); return 0; } - auto&& ret = obj->isUnifySizeEnabled(); + 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:isUnifySizeEnabled",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_isUnifySizeEnabled'.",&tolua_err); + tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_Widget_isAutoSize'.",&tolua_err); #endif return 0; @@ -4584,10 +4487,8 @@ 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,"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); @@ -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,"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); @@ -7238,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; @@ -8701,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); @@ -9258,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; @@ -9936,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); @@ -11545,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; @@ -11809,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); @@ -12302,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; @@ -13678,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); @@ -13917,7 +14022,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_resolvePreferredSize(lua_State* tolua_S) { int argc = 0; ax::ui::TextAtlas* obj = nullptr; @@ -13937,7 +14042,57 @@ 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_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; + 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_updateLayout'", nullptr); return 0; } #endif @@ -13947,19 +14102,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 +14309,8 @@ 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,"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); tolua_function(tolua_S,"create", lua_ax_ui_TextAtlas_create); @@ -14620,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; @@ -14851,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); @@ -21513,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; @@ -22200,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); @@ -22220,10 +22478,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 +22490,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 +22506,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 +22540,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 +22590,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 +22637,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_resolvePreferredSize(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,45 +22684,48 @@ 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_resolvePreferredSize'", nullptr); return 0; } #endif argc = lua_gettop(tolua_S)-1; - if (argc == 0) + 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_TextField_getPlaceHolder'", nullptr); + tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextBMFont_resolvePreferredSize'", nullptr); return 0; } - auto&& ret = obj->getPlaceHolder(); - lua_pushlstring(tolua_S,ret.data(),ret.length()); + 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.TextField:getPlaceHolder",argc, 0); + 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_TextField_getPlaceHolder'.",&tolua_err); + tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextBMFont_resolvePreferredSize'.",&tolua_err); #endif return 0; } -int lua_ax_ui_TextField_getPlaceHolderColor(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 @@ -22476,15 +22734,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_getRenderFile'", nullptr); return 0; } #endif @@ -22494,27 +22752,27 @@ 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_getRenderFile'", nullptr); return 0; } - auto&& ret = obj->getPlaceHolderColor(); - color32_to_luaval(tolua_S, ret); + 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:getPlaceHolderColor",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_getPlaceHolderColor'.",&tolua_err); + tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextBMFont_getRenderFile'.",&tolua_err); #endif return 0; } -int lua_ax_ui_TextField_setPlaceHolderColor(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 @@ -22523,145 +22781,191 @@ int lua_ax_ui_TextField_setPlaceHolderColor(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_setPlaceHolderColor'", nullptr); + 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 == 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_resetRender'", nullptr); return 0; } - obj->setPlaceHolderColor(arg0); + 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:setPlaceHolderColor",argc, 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_TextField_setPlaceHolderColor'.",&tolua_err); + tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextBMFont_resetRender'.",&tolua_err); #endif return 0; } -int lua_ax_ui_TextField_getTextColor(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_getTextColor'", nullptr); - return 0; - } -#endif + argc = lua_gettop(tolua_S) - 1; - 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_createInstance'", nullptr); return 0; } - auto&& ret = obj->getTextColor(); - color32_to_luaval(tolua_S, ret); + 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:getTextColor",argc, 0); + 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_getTextColor'.",&tolua_err); + tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextBMFont_createInstance'.",&tolua_err); #endif - return 0; } -int lua_ax_ui_TextField_setTextColor(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 + 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 - if (!obj) - { - tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_TextField_setTextColor'", nullptr); - return 0; - } + tolua_Error tolua_err; #endif + + 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:setTextColor"); 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_TextBMFont_constructor'", nullptr); return 0; } - obj->setTextColor(arg0); - lua_settop(tolua_S, 1); + 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:setTextColor",argc, 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_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_TextBMFont_constructor'.",&tolua_err); #endif return 0; } -int lua_ax_ui_TextField_setFontSize(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,"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); + 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 @@ -22670,15 +22974,15 @@ 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_addPage'", nullptr); return 0; } #endif @@ -22686,32 +22990,32 @@ int lua_ax_ui_TextField_setFontSize(lua_State* tolua_S) argc = lua_gettop(tolua_S)-1; if (argc == 1) { - int arg0; + ax::ui::Widget* arg0; - ok &= luaval_to_int(tolua_S, 2, &arg0, "axui.TextField:setFontSize"); + 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_setFontSize'", nullptr); + tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_PageView_addPage'", nullptr); return 0; } - obj->setFontSize(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:setFontSize",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_setFontSize'.",&tolua_err); + tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_PageView_addPage'.",&tolua_err); #endif return 0; } -int lua_ax_ui_TextField_getFontSize(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 @@ -22720,45 +23024,51 @@ 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_insertPage'", nullptr); return 0; } #endif argc = lua_gettop(tolua_S)-1; - if (argc == 0) + 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_TextField_getFontSize'", nullptr); + tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_PageView_insertPage'", nullptr); return 0; } - auto&& ret = obj->getFontSize(); - tolua_pushnumber(tolua_S,(lua_Number)ret); + 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:getFontSize",argc, 0); + 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_getFontSize'.",&tolua_err); + tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_PageView_insertPage'.",&tolua_err); #endif return 0; } -int lua_ax_ui_TextField_setFontName(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 @@ -22767,15 +23077,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_removePage'", nullptr); return 0; } #endif @@ -22783,32 +23093,32 @@ int lua_ax_ui_TextField_setFontName(lua_State* tolua_S) argc = lua_gettop(tolua_S)-1; if (argc == 1) { - std::string_view arg0; + ax::ui::Widget* arg0; - ok &= luaval_to_std_string_view(tolua_S, 2,&arg0, "axui.TextField:setFontName"); + 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_setFontName'", nullptr); + tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_PageView_removePage'", nullptr); return 0; } - obj->setFontName(arg0); + 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:setFontName",argc, 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_TextField_setFontName'.",&tolua_err); + tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_PageView_removePage'.",&tolua_err); #endif return 0; } -int lua_ax_ui_TextField_getFontName(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 @@ -22817,45 +23127,48 @@ 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_removePageAtIndex'", nullptr); return 0; } #endif argc = lua_gettop(tolua_S)-1; - if (argc == 0) + 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_TextField_getFontName'", nullptr); + tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_PageView_removePageAtIndex'", nullptr); return 0; } - auto&& ret = obj->getFontName(); - lua_pushlstring(tolua_S,ret.data(),ret.length()); + 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:getFontName",argc, 0); + 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_getFontName'.",&tolua_err); + tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_PageView_removePageAtIndex'.",&tolua_err); #endif return 0; } -int lua_ax_ui_TextField_didNotSelectSelf(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 @@ -22864,15 +23177,15 @@ int lua_ax_ui_TextField_didNotSelectSelf(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_didNotSelectSelf'", nullptr); + tolua_error(tolua_S,"invalid 'obj' in function 'lua_ax_ui_PageView_removeAllPages'", nullptr); return 0; } #endif @@ -22882,124 +23195,145 @@ int lua_ax_ui_TextField_didNotSelectSelf(lua_State* tolua_S) { if(!ok) { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextField_didNotSelectSelf'", nullptr); + tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_PageView_removeAllPages'", nullptr); return 0; } - obj->didNotSelectSelf(); + 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:didNotSelectSelf",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_didNotSelectSelf'.",&tolua_err); + tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_PageView_removeAllPages'.",&tolua_err); #endif return 0; } -int lua_ax_ui_TextField_setString(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_setString'", 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 == 1) - { - std::string_view arg0; + do { + if (argc == 2) { + ssize_t arg0; + ok &= luaval_to_ssize_t(tolua_S, 2, &arg0, "axui.PageView:scrollToPage"); - 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:scrollToPage"); + + if (!ok) { break; } + obj->scrollToPage(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: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_setString'.",&tolua_err); + tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_PageView_scrollToPage'.",&tolua_err); #endif return 0; } -int lua_ax_ui_TextField_getString(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_getString'", 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 == 0) - { - if(!ok) - { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextField_getString'", nullptr); - return 0; + 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; } - 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:getString",argc, 0); + }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_getString'.",&tolua_err); + tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_PageView_scrollToItem'.",&tolua_err); #endif return 0; } -int lua_ax_ui_TextField_setMaxLengthEnabled(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 @@ -23008,2424 +23342,21 @@ 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_getCurrentPageIndex'", 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:setMaxLengthEnabled"); - if(!ok) - { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextField_setMaxLengthEnabled'", nullptr); - return 0; - } - obj->setMaxLengthEnabled(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); - return 0; - -#if _AX_DEBUG >= 1 - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextField_setMaxLengthEnabled'.",&tolua_err); -#endif - - return 0; -} -int lua_ax_ui_TextField_isMaxLengthEnabled(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_isMaxLengthEnabled'", 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_isMaxLengthEnabled'", nullptr); - return 0; - } - auto&& ret = obj->isMaxLengthEnabled(); - 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:isMaxLengthEnabled",argc, 0); - return 0; - -#if _AX_DEBUG >= 1 - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextField_isMaxLengthEnabled'.",&tolua_err); -#endif - - return 0; -} -int lua_ax_ui_TextField_setMaxLength(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_setMaxLength'", nullptr); - return 0; - } -#endif - - argc = lua_gettop(tolua_S)-1; - if (argc == 1) - { - int arg0; - - ok &= luaval_to_int(tolua_S, 2, &arg0, "axui.TextField:setMaxLength"); - if(!ok) - { - tolua_error(tolua_S,"invalid arguments in function 'lua_ax_ui_TextField_setMaxLength'", nullptr); - return 0; - } - obj->setMaxLength(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); - return 0; - -#if _AX_DEBUG >= 1 - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_ax_ui_TextField_setMaxLength'.",&tolua_err); -#endif - - return 0; -} -int lua_ax_ui_TextField_getMaxLength(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_getMaxLength'", 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_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 (argc == 0) { if(!ok) { @@ -32629,103 +30560,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; @@ -33798,8 +31632,6 @@ 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,"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); @@ -41018,7 +38850,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/extensions/scripting/lua-bindings/auto/axlua_video_auto.cpp b/extensions/scripting/lua-bindings/auto/axlua_video_auto.cpp index a07232d6730e..077a5d533d5a 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" @@ -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); 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_ui_manual.cpp b/extensions/scripting/lua-bindings/manual/ui/axlua_ui_manual.cpp index d9cccd295820..e42f878212c8 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; + int argc = 0; + 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); 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/CMakeLists.txt b/tests/cpp-tests/CMakeLists.txt index a67026f1d323..6eb03f34d981 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 @@ -209,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/UIInputFieldTest/UIInputFieldTest.h Source/BillBoardTest/BillBoardTest.h Source/SpriteFrameCacheTest/SpriteFrameCacheTest.h Source/EffectsAdvancedTest/EffectsAdvancedTest.h @@ -312,7 +311,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,10 +339,10 @@ 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 + Source/UITest/CocoStudioGUITest/UIInputFieldTest/UIInputFieldTest.cpp Source/UITest/UITest.cpp Source/UserDefaultTest/UserDefaultTest.cpp Source/VisibleRect.cpp 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/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..a1d63f9fa2b3 100644 --- a/tests/cpp-tests/Source/BugsTest/Bug-14327.h +++ b/tests/cpp-tests/Source/BugsTest/Bug-14327.h @@ -22,14 +22,13 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef __cocos2d_tests__Bug_14327__ -#define __cocos2d_tests__Bug_14327__ +#pragma once #include "BugsTest.h" #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 { @@ -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.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; 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/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/LabelTest/LabelTest.cpp b/tests/cpp-tests/Source/LabelTest/LabelTest.cpp index 2d67705a0d04..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->ignoreContentAdaptWithSize(false); + richText2->setAutoSize(true); richText2->setContentSize(Size(400.0f, 400.0f)); richText2->setPosition(center); 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 7545bf96e8b1..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" @@ -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->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/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/SpritePolygonTest/SpritePolygonTest.h b/tests/cpp-tests/Source/SpritePolygonTest/SpritePolygonTest.h index ceba0b155776..7da9ae7dfd5b 100644 --- a/tests/cpp-tests/Source/SpritePolygonTest/SpritePolygonTest.h +++ b/tests/cpp-tests/Source/SpritePolygonTest/SpritePolygonTest.h @@ -22,10 +22,10 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef __cocos2d_tests__SpritePolygonTest__ +#pragma once -# include "../BaseTest.h" -# include "axmol/ui/CocosGUI.h" +#include "../BaseTest.h" +#include "axmol/ui/CocosGUI.h" DEFINE_TEST_SUITE(SpritePolygonTest); @@ -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 bc02ba34e255..813a4568d569 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" @@ -43,6 +42,7 @@ #include "UIRichTextTest/UIRichTextTest.h" #include "UIFocusTest/UIFocusTest.h" #include "UITabControlTest/UITabControlTest.h" +#include "UIInputFieldTest/UIInputFieldTest.h" #if defined(AX_ENABLE_MEDIA) # include "UIVideoPlayerTest/UIVideoPlayerTest.h" @@ -91,7 +91,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; }); @@ -102,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..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->ignoreContentAdaptWithSize(false); + 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->ignoreContentAdaptWithSize(false); + 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->ignoreContentAdaptWithSize(false); + 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->ignoreContentAdaptWithSize(false); + 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->ignoreContentAdaptWithSize(false); + 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 365361025fd3..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->ignoreContentAdaptWithSize(false); + 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/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/UIImageViewTest/UIImageViewTest.cpp b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.cpp index 43bd3ddd181a..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->ignoreContentAdaptWithSize(false); + 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->ignoreContentAdaptWithSize(false); + 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/UIInputFieldTest/UIInputFieldTest.cpp b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIInputFieldTest/UIInputFieldTest.cpp new file mode 100644 index 000000000000..179056b4d2d9 --- /dev/null +++ b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIInputFieldTest/UIInputFieldTest.cpp @@ -0,0 +1,443 @@ +/**************************************************************************** + 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->setAutoSize(false); + inputField->setContentSize(Vec2(480, 100)); + 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->setAutoSize(false); + inputField->setMultilineEnabled(true); + inputField->setContentSize(Vec2(240.0f, 170.0f)); + inputField->setString("input words here"); + 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 + 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/UIInputFieldTest/UIInputFieldTest.h similarity index 52% rename from tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.h rename to tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIInputFieldTest/UIInputFieldTest.h index fa21f661015d..41cc6b59fe61 100644 --- a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.h +++ b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIInputFieldTest/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/UILayoutTest/UILayoutTest.cpp b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest.cpp index c78dd9bf1606..bd29762fe563 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(); @@ -968,7 +968,7 @@ bool UILayoutComponent_Berth_Stretch_Test::init() if (UILayoutComponentTest::init()) { ImageView* leftTopSprite = ImageView::create("cocosui/CloseSelected.png"); - leftTopSprite->ignoreContentAdaptWithSize(false); + 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->ignoreContentAdaptWithSize(false); + 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->ignoreContentAdaptWithSize(false); + 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->ignoreContentAdaptWithSize(false); + 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/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/UILoadingBarTest/UILoadingBarTest.cpp b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.cpp index 79bf13bf31fd..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->ignoreContentAdaptWithSize(false); + 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->ignoreContentAdaptWithSize(false); + 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 cc9c00713b58..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->isIgnoreContentAdaptWithSize()) + if (_richText->isAutoSize()) { - _richText->ignoreContentAdaptWithSize(false); + _richText->setAutoSize(true); _richText->setContentSize(_defaultContentSize); } else { - _richText->ignoreContentAdaptWithSize(true); + _richText->setAutoSize(false); } } break; @@ -201,7 +201,7 @@ bool UIRichTextTest::init() // RichText _richText = RichText::create(); - _richText->ignoreContentAdaptWithSize(false); + _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->ignoreContentAdaptWithSize(false); + _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->ignoreContentAdaptWithSize(false); + _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->ignoreContentAdaptWithSize(false); + _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->ignoreContentAdaptWithSize(false); + _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->ignoreContentAdaptWithSize(false); + _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->ignoreContentAdaptWithSize(false); + _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->ignoreContentAdaptWithSize(false); + _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->ignoreContentAdaptWithSize(false); + _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->ignoreContentAdaptWithSize(false); + _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->ignoreContentAdaptWithSize(false); + _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->ignoreContentAdaptWithSize(false); + _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->ignoreContentAdaptWithSize(false); + _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->ignoreContentAdaptWithSize(false); + _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->ignoreContentAdaptWithSize(false); + _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->ignoreContentAdaptWithSize(false); + _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->ignoreContentAdaptWithSize(false); + _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->ignoreContentAdaptWithSize(false); + _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->ignoreContentAdaptWithSize(false); + _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->ignoreContentAdaptWithSize(false); + _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->ignoreContentAdaptWithSize(false); + _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->ignoreContentAdaptWithSize(false); + _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->ignoreContentAdaptWithSize(false); + _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/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/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/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/UISliderTest/UISliderTest.cpp b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UISliderTest/UISliderTest.cpp index 7a3322a7fc39..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->ignoreContentAdaptWithSize(false); + 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/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/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; 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..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->ignoreContentAdaptWithSize(false); + 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->ignoreContentAdaptWithSize(false); + 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->ignoreContentAdaptWithSize(false); + rightText->setAutoSize(true); _uiLayer->addChild(rightText); auto halighButton = Button::create(); diff --git a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIWebViewTest/UIWebViewTest.cpp b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIWebViewTest/UIWebViewTest.cpp index 069c69be589d..72012c1e78e1 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); + // 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/UITest/CocoStudioGUITest/UIWebViewTest/UIWebViewTest.h b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIWebViewTest/UIWebViewTest.h index 75f3ef03b18a..4c9844290fcb 100644 --- a/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIWebViewTest/UIWebViewTest.h +++ b/tests/cpp-tests/Source/UITest/CocoStudioGUITest/UIWebViewTest/UIWebViewTest.h @@ -23,11 +23,10 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef __cocos2d_tests__UIWebViewTest__ -#define __cocos2d_tests__UIWebViewTest__ +#pragma once #include "../UIScene.h" -#include "axmol/ui/UIWebView/UIWebView.h" +#include "axmol/ui/WebView/WebView.h" DEFINE_TEST_SUITE(WebViewTests); @@ -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__) */ 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 { 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" 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 98% rename from tests/unit-tests/Source/axmol/ui/UIHelperTests.cpp rename to tests/unit-tests/Source/axmol/ui/HelperTests.cpp index 2929efd10bbb..1358e76f7a99 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; 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*$".