Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
d761ad8
input-field-step1
halx99 May 16, 2026
d075958
up
halx99 May 16, 2026
4eb10db
up
halx99 May 17, 2026
720d064
up
halx99 May 17, 2026
cf21e33
up
halx99 May 17, 2026
82b15b8
up
halx99 May 18, 2026
bde0823
fix cursor postion when horiz alignemt not left
halx99 May 18, 2026
a16d94d
up
halx99 May 18, 2026
f60fbe7
Clenaup code
halx99 May 18, 2026
a39b238
up
halx99 May 18, 2026
431911e
up
halx99 May 18, 2026
638bf82
up
halx99 May 19, 2026
8f85460
up
halx99 May 19, 2026
211c215
up
halx99 May 19, 2026
486ec1e
up
halx99 May 19, 2026
42c0610
luabindings
halx99 May 20, 2026
3d383c0
Fix luabindings
halx99 May 20, 2026
1368c5a
Improve API style
halx99 May 20, 2026
bb6dff5
up
halx99 May 20, 2026
d2aff19
Committing clang-format changes
axmol-bot May 20, 2026
d95931b
fix reviews
halx99 May 20, 2026
06e07b8
fix reviews
halx99 May 20, 2026
5675846
Refactor file name
halx99 May 20, 2026
0222c41
up
halx99 May 20, 2026
3f61b22
Fixup
halx99 May 20, 2026
d68dc48
Committing clang-format changes
axmol-bot May 20, 2026
77d9e35
up
halx99 May 20, 2026
4ce4d08
up
halx99 May 21, 2026
b1cdf42
multiline support inprogress
halx99 May 21, 2026
f90264f
Fix multiline cursor positioning
halx99 May 21, 2026
36a0478
Fixup
halx99 May 21, 2026
4690564
Improve
halx99 May 21, 2026
aa51937
Improve code style
halx99 May 21, 2026
b68940b
Add ime preedit callback
halx99 May 22, 2026
72c4952
update luabindings
halx99 May 22, 2026
65f5dfb
up
halx99 May 22, 2026
991b4e3
Improve
halx99 May 22, 2026
7a1c290
up
halx99 May 22, 2026
6ad1afb
Committing clang-format changes
axmol-bot May 22, 2026
0f47d67
Fix reviews
halx99 May 22, 2026
ca81b1b
Improve ios IME delegate
halx99 May 22, 2026
0a2ce4a
Committing clang-format changes
axmol-bot May 22, 2026
f219568
Fix reviews
halx99 May 22, 2026
a950fb8
Improve performance
halx99 May 22, 2026
00d565b
Fix reviews
halx99 May 22, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions axmol/2d/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
87 changes: 67 additions & 20 deletions axmol/2d/Label.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -227,11 +228,31 @@ std::array<CustomCommand*, 3> 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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -569,7 +615,6 @@ void Label::reset()
_currLabelEffect = LabelEffect::NORMAL;
_contentDirty = false;
_numberOfLines = 0;
_lengthOfString = 0;
_utf32Text.clear();
_utf8Text.clear();

Expand Down Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1102,7 +1151,6 @@ void Label::alignText()

bool Label::tryTextPlacement(float fontSize)
{
_lengthOfString = 0;
_textDesiredHeight = 0.f;
_linesWidth.clear();

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -2424,25 +2472,24 @@ void Label::computeStringNumLines()
_numberOfLines = quantityOfLines;
}

int Label::getStringNumLines()
int Label::getLineCount() const
{
if (_contentDirty)
{
updateContent();
const_cast<Label*>(this)->updateContent();
}

if (_currentLabelType == LabelType::STRING_TEXTURE)
{
computeStringNumLines();
const_cast<Label*>(this)->computeStringNumLines();
}

return _numberOfLines;
}

int Label::getStringLength()
int Label::getCharCount() const
{
_lengthOfString = static_cast<int>(_utf32Text.length());
return _lengthOfString;
return static_cast<int>(_utf32Text.length());
}

// RGBA protocol
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down
62 changes: 58 additions & 4 deletions axmol/2d/Label.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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`
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
Loading
Loading