Refactor legacy text input stack to ui::InputField and unify font handling APIs#3173
Refactor legacy text input stack to ui::InputField and unify font handling APIs#3173halx99 wants to merge 88 commits into
Conversation
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 211c215351
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
/clang-format |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d2aff1905b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex Again, provide merge title and change detail list about this PR via https://patch-diff.githubusercontent.com/raw/axmolengine/axmol/pull/3173.diff |
|
/clang-format |
|
@codex review |
|
@gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors the UI and text input systems, replacing legacy TextField components with a new InputField widget and introducing a cross-platform clipboard API. It also updates the layout system by replacing ignoreContentAdaptWithSize with setAutoSize and renames various UI headers for consistency. Feedback highlights critical logic inversions in the setAutoSize implementation for several widgets (Button, ImageView, Slider, and LoadingBar) when Scale9 is enabled, which hinders manual sizing. Further improvements are suggested for Android clipboard robustness, touch position tracking in InputField, and optimizing the O(N^2) performance of the text layout measurement logic.
|
Hello halx99, thank you for reaching out. Regarding your question about the Key improvements include:
If you are looking to migrate from |
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
|
@gemini review |
There was a problem hiding this comment.
Code Review
This pull request performs a major refactoring of the UI and input systems, replacing the deprecated TextFieldTTF and TextFieldEx widgets with a new InputField component that supports multiline text, cursors, and selections. The refactor includes a widespread renaming of UI classes and core methods (e.g., setAutoSize, getRenderNode) to improve API consistency, renames the IME system to a more general Input system, and introduces a cross-platform clipboard API. Review feedback identifies a high-severity risk of null pointer exceptions in the Android clipboard implementation and suggests adopting safer string access patterns in the InputField logic.
|
/clang-format |
|
/clang-format |
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request overhauls the text input and UI widget systems by introducing a modern InputField component to replace the deprecated TextFieldTTF and TextFieldEx. The new InputField supports multiline text, cursor control, selection, and native clipboard integration. Additionally, the Widget base class and its derivatives have been refactored to use a standardized setAutoSize and initRenderNode API, and the IME system has been renamed to InputDelegate. Reviewer feedback highlights significant efficiency and correctness concerns regarding character-by-character text measurement and the lack of word-level wrapping in multiline mode. Other actionable suggestions include syncing measurement labels with rendering effects, adjusting long-press trigger timing on mobile platforms, and correcting a typo in Label.cpp.
| { | ||
| size_t nextByteOffset = _charByteOffsets[currentCharIdx + 1]; | ||
| std::string_view charView(_inputText.data() + charByteOffset, nextByteOffset - charByteOffset); | ||
| charWidth = measureText(charView).width; |
There was a problem hiding this comment.
Measuring text character-by-character in a loop is extremely inefficient (O(N) heavy label updates) and typographically incorrect. It ignores kerning and ligatures, which will result in inaccurate cursor positioning for many fonts and languages. A better approach would be to measure the entire string and extract glyph positions from the FontAtlas or use Label's internal layout data if it can be exposed.
|
|
||
| void Label::setFontInfo(std::string_view fontName, float fontSize) | ||
| { | ||
| auto prevLableType = _currentLabelType; |
| // Lazy initialize instance-specific measure label | ||
| if (!_measureLabel) | ||
| { | ||
| _measureLabel = Label::create(""sv, _fontName, _fontSize); |
There was a problem hiding this comment.
The _measureLabel is initialized with the font name and size, but it is never updated if the _renderLabel is subsequently modified with effects like outline or shadow. This will cause character width measurements to be incorrect, leading to cursor misalignment. Consider implementing a mechanism to sync the measure label's configuration with the render label.
| } | ||
|
|
||
| // If the Label exposes internal padding or baseline offsets, apply them here. | ||
| // Example (pseudo): textBottomYInLabel += _renderLabel->getInternalPaddingBottom(); |
| Vec2 localPoint = this->convertToNodeSpace(worldPoint); | ||
| moveCursorTo(localPoint, _selectionTouchMoved); | ||
|
|
||
| if (_continuousTouchPending && _continuousTouchElapsedTime >= _continuousTouchDelayTime) |
There was a problem hiding this comment.
| if (_multilineEnabled && currentCharIdx > currentLine.startCharIndex) | ||
| { | ||
| // If adding this character exceeds available width, commit current line before tracking it | ||
| if (currentLine.charXOffsets.back() + charWidth > availableWidth) |
There was a problem hiding this comment.
Describe your changes
TextFieldTTFusage/removal and shift text input flows towardui::InputField/IME-based behavior.Label::create(text, fontName, fontSize)API with automatic font-type detection (BMFont/TTF/system font).Label::setFontInfo(fontName, fontSize)to centralize runtime font switching.Labelinternals by removing cached_lengthOfStringstate and deriving count from UTF-32 text (getCharCount()), reducing stale-length risks.getLineCount(),getCharCount()) while keeping backward-compatible deprecated wrappers.#pragma once, include path corrections, minor code hygiene).Issue ticket number and link
Checklist before requesting a review
For each PR
Add Copyright if it missed:
-
"Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md)."I have performed a self-review of my code.
Optional:
For core/new feature PR
Axmol 3.x ------------------------------------------------------------
For each 3.x PR