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

Sliced scaling does not play well with Anchor #12680

Closed
Cyborus04 opened this issue Mar 24, 2024 · 2 comments · Fixed by #12769
Closed

Sliced scaling does not play well with Anchor #12680

Cyborus04 opened this issue Mar 24, 2024 · 2 comments · Fixed by #12769
Labels
A-UI Graphical user interfaces, styles, layouts, and widgets C-Bug An unexpected or incorrect behavior

Comments

@Cyborus04
Copy link

Bevy version

v0.13.1

What you did

I was upgrading my RPG textboxes to use the new 9-slicing feature, but creating a sliced sprite with an anchor not set to Anchor::Center does not work right.

What went wrong

Creating the textbox background with Anchor::Center works fine, and looks like this:

image

Created with this code:

let sprite_child = commands
    .spawn(SpriteBundle {
        sprite: Sprite {
            custom_size: Some(vec2(296.5, 83.5)),
            ..default()
        },
        transform: Transform {
            translation: Vec3::new(0.0, -77.75, 4.9),
            rotation: Quat::IDENTITY,
            scale: Vec3::splat(1.0),
        },
        texture: asset_server.load("textbox.png"),
        ..default()
    })
    .insert(ImageScaleMode::Sliced(TextureSlicer {
        border: BorderRect::square(13.0),
        max_corner_scale: 1.0,
        ..default()
    }))
    .id();

Creating the textbox background with Anchor::TopLeft (with position adjusted correspondingly) does not work fine, and looks like this:

image

Created with this code:

let sprite_child = commands
    .spawn(SpriteBundle {
        sprite: Sprite {
            anchor: Anchor::TopLeft,
            custom_size: Some(vec2(296.5, 83.5)),
            ..default()
        },
        transform: Transform {
            translation: Vec3::new(-148.25, -36.0, 4.9),
            rotation: Quat::IDENTITY,
            scale: Vec3::splat(1.0),
        },
        texture: asset_server.load("textbox.png"),
        ..default()
    })
    .insert(ImageScaleMode::Sliced(TextureSlicer {
        border: BorderRect::square(13.0),
        max_corner_scale: 1.0,
        ..default()
    }))
    .id();

Additional information

My guess is that the anchor is being taken into consideration when scaling the center of the sliced texture, but not for the other parts.

@Cyborus04 Cyborus04 added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Mar 24, 2024
@Cyborus04
Copy link
Author

I'll try to get a small reproduction made tomorrow, but right now it is 1:51 AM and I need to sleep...

@james7132 james7132 added A-UI Graphical user interfaces, styles, layouts, and widgets and removed S-Needs-Triage This issue needs to be labelled labels Mar 24, 2024
@james7132
Copy link
Member

Looks like the same cause as #12408.

github-merge-queue bot pushed a commit that referenced this issue Apr 16, 2024
…2769)

# Objective

Fixes #12408 .
Fixes #12680.

## Solution

- Recaclulated anchor from dimensions of sprite to dimension of each
part of it (each part contains its own anchor)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-UI Graphical user interfaces, styles, layouts, and widgets C-Bug An unexpected or incorrect behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants