Skip to content

fix: prevent text loss in UITextEllipsisOverflow#36

Open
kangsangyeon wants to merge 1 commit intoHaruma-K:masterfrom
kangsangyeon:fix/text-elipsis-text-loss
Open

fix: prevent text loss in UITextEllipsisOverflow#36
kangsangyeon wants to merge 1 commit intoHaruma-K:masterfrom
kangsangyeon:fix/text-elipsis-text-loss

Conversation

@kangsangyeon
Copy link

Dear Maintainer,

I am submitting this PR to address a bug where the UITextEllipsisOverflow component permanently clears the text when it is initialized within dynamic layout systems (such as GridLayoutGroup).

Summary of Changes

Unity_gSdidbN1AP

Before Fix: There was an issue where labels were cleared if the number of buttons added to a ButtonCollection was 2 or fewer.

Unity_c8JgK6BwdC

After Fix: Labels are preserved and displayed correctly regardless of the button count.

How to Reproduce

In DefaultCellDemoDebugPage.cs, simply change line 210 from for (var i = 0; i < 9; i++) to for (var i = 0; i < 2; i++).

The Problem

The issue stems from a timing conflict between text assignment and layout initialization:

  1. Assignment: New text is assigned to the component (e.g., during a cell's Setup).
  2. Premature Truncation: The component immediately runs its Apply() logic using the initial dimensions of the RectTransform.
  3. Data Loss: If these initial dimensions have not yet been properly calculated by the layout engine, the component determines that there is insufficient space and begins removing characters from the text one by one from the end, eventually removing them all.
  4. Layout Initialization: When the layout is subsequently initialized and the dimensions are updated, the original text is already lost, leaving the UI element empty.

The Solution

I have updated the component to decouple the Original Text (Source of Truth) from the Display Output:

  • The component now preserves the original string whenever a new value is assigned.
  • It always uses this preserved original text as the starting point for truncation.
  • This allows the component to correctly re-calculate the ellipsis during OnRectTransformDimensionsChange once the layout initialization is complete.

This change ensures that text remains visible and correctly truncated regardless of whether the ellipsis logic triggers before or after the layout engine provides the final dimensions.

@kangsangyeon
Copy link
Author

kangsangyeon commented Feb 25, 2026

Additionally, this PR can resolve existing issues that have been posted. #30
Please review it. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant