Skip to content

[IDEA] TextToy improvements #391

@Xname7

Description

@Xname7

Goal Description

I finally tried to use TextToys for something more than displaying a simple label and I hit a wall.
At the moment TextToys (through the use of TMP tags) allow us to align text in 5 ways.. but that's not enough for a sane developer. I'm talking about missing Vertical Alignment options (Top, Bottom) and also Overflow Modes (Truncate).

Notes

Of course with the addition of VerticalAlignment syncvar, there would also be a need for HorizontalAlignment syncvar. This is because of RectTransform pivots that would need to be set depending on Vertical and Horizontal alignments combo. Without correct pivots the text instead of rotating in place will look like it's "orbiting"

But the more efficient option would be to have one syncvar that controls all alignment options using TMPro.TextAlignmentOptions enum and on client just set TMP_Text.alignment and handle mentioned pivots.

Method for calculating pivots could look like this: (as TextAlignmentOptions is a bitmask)

Vector2 GetPivotFromAlignment(TextAlignmentOptions alignment)
{
    int h = (int)alignment & 0x00FF;
    int v = (int)alignment & 0xFF00;

    float x = h switch
    {
        1 => 0f,     // Left
        2 => 0.5f,   // Center
        4 => 1f,     // Right
        _ => 0.5f    // Justified/Flush fallback
    };

    float y = v switch
    {
        0x0100 => 1f,     // Top
        0x0200 => 0.5f,   // Middle
        0x0400 => 0f,     // Bottom
        0x0800 => 0.5f,   // Baseline
        0x1000 => 0.5f,   // Midline
        0x2000 => 0.5f,   // Capline
        _ => 0.5f
    };

    return new Vector2(x, y);
}

Tbh I don't really care that much about correct pivots nor OverflowMode, I only need VerticalAlignment options and that's all.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ideaThis is an idea to doimportedImported to internal git

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions