Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Text Overflow Bug #12085

Open
franklinblanco opened this issue Feb 24, 2024 · 3 comments
Open

Text Overflow Bug #12085

franklinblanco opened this issue Feb 24, 2024 · 3 comments
Labels
A-Text Rendering and layout for characters A-UI Graphical user interfaces, styles, layouts, and widgets C-Bug An unexpected or incorrect behavior

Comments

@franklinblanco
Copy link
Contributor

franklinblanco commented Feb 24, 2024

Bevy version

0.13

Relevant system information

cargo 1.77.0-nightly (1ae631085 2024-01-17)

AdapterInfo { name: "Apple M1 Pro", vendor: 0, device: 0, device_type: IntegratedGpu, driver: "", driver_info: "", backend: Metal }

What you did

Added a TextBundle with a max_width of 80% of the parent, Overflow::Clip on both axis.

Item holder (Parent) (Corresponds to any slot that's blue in the screenshot)

    let item_holder = commands.spawn(NodeBundle {
        style: Style {
            position_type: PositionType::Absolute,
            grid_column,
            grid_row,
            margin: UiRect::all(Val::Auto),
            width: Val::Percent(100.0),
            height: Val::Percent(100.0),
            border: GRID_INNER_OCCUPIED_BORDER,
            display: Display::Flex,
            justify_content: JustifyContent::Center,
            align_items: AlignItems::Center,
            ..Default::default()
        },
        border_color: GRID_INNER_OCCUPIED_BORDER_COLOR,
        background_color: item.item.item.get_inventory_background_color(),
        z_index: ZIndex::Global(1),
        focus_policy: FocusPolicy::Block,
        ..Default::default()
    }).id();

Text inside parent (This is where the problem is)

commands.spawn(TextBundle {
        text: Text::from_section(item.item.item.get_item_properties().name, TextStyle {
            font_size: 13.0,
            color: Color::WHITE,
            ..Default::default()
        }).with_justify(JustifyText::Right),
        style: Style {
            position_type: PositionType::Absolute,
            right: Val::Px(1.0),
            top: Val::Px(1.0),
            overflow: Overflow { x: OverflowAxis::Clip, y: OverflowAxis::Clip },
            max_width: Val::Percent(80.0),
            max_height: Val::Px(13.0),
            ..Default::default()
        },
        z_index: ZIndex::Local(2),
        ..Default::default()
    })
    .set_parent(item_holder);

What went wrong

As this Screenshot shows, almost all the items have names that would take up more than the allowed width. But weirdly enough, the ones that have the first word take up the max_width or more, overflow. The ones that would take up >= max_width but with separate words in between them don't overflow. They clip, as expected.
inventory_bug_screenshot_text-overflow_on_word

Just so you have an Idea of how long the names are, here it is without a max_height property:

Screenshot 2024-02-24 at 12 17 20 PM

Additional information

Just wanted to know if this is considered a bug, (I'm pretty sure it is). Or if it's expected behaviour.
This isn't really the worst bug, I could just limit the characters and remove any length of characters past some formula calculating available width.

Thanks to the bevy devs for your work!

@franklinblanco franklinblanco added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Feb 24, 2024
@rparrett
Copy link
Contributor

I wonder if this is related to #6879.

You might need to wrap the text in a separate nodebundle to do the clipping.

@porkbrain
Copy link
Contributor

porkbrain commented Feb 24, 2024

Reporting a similar problem, wrapping in a child node bundle did not help. This is my setup:
no_clip

The red area is a child node bundle with just the text. The parent is the white bubble you see. Both the bubble and the text node have a width and height set (hence the red highlight.) Both have clipping in both axes set.

no_clip_when_partly_outside

When I made the height smaller, it kept showing the text until a threshold, then it finally clipped it.

finally_clips

@rparrett
Copy link
Contributor

It seems like there's something very interesting happening with PositionType::Absolute and clipping.

@TrialDragon TrialDragon added A-UI Graphical user interfaces, styles, layouts, and widgets and removed S-Needs-Triage This issue needs to be labelled labels Feb 28, 2024
@viridia viridia added the A-Text Rendering and layout for characters label Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Text Rendering and layout for characters A-UI Graphical user interfaces, styles, layouts, and widgets C-Bug An unexpected or incorrect behavior
Projects
None yet
Development

No branches or pull requests

5 participants