bevy/crates
robtfm ccfae7ebe7
fix non-exact text h-alignment (#13846)
# Objective

when a parent container is auto-sized, text alignments `Center` and
`Right` don't align to the center and right properly. fix it

## Solution

ab_glyph positions return +/- values from an anchor point. we currently
transform them to positive values from the min-x of the glyphs, and then
offset from the left of the bounds. instead, we can keep the negative
values as ab_glyph intended and offset from the left/middle/right of the
bounds as appropriate.

## Testing

texts with align left, center, right, all contained in the purple boxes:
before (0.14.0-rc.2):
![Screenshot 2024-06-14
165456](https://github.com/bevyengine/bevy/assets/50659922/90fb73b0-d8bd-4ae8-abf3-7106eafc93ba)

after:

![Screenshot 2024-06-14
164449](https://github.com/bevyengine/bevy/assets/50659922/0a75ff09-b51d-4fbe-a491-b655a145c08b)

code:
```rs
use bevy::prelude::*;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_systems(Startup, setup)
        .run();
}

fn setup(mut commands: Commands) {
    commands.spawn(Camera2dBundle::default());

    for (left, justify) in [
        (100.0, JustifyText::Left),
        (500.0, JustifyText::Center),
        (900.0, JustifyText::Right),
    ] {
        commands
        // container
        .spawn(NodeBundle {
            style: Style {
                flex_direction: FlexDirection::Column,
                position_type: PositionType::Absolute,
                left: Val::Px(left),
                top: Val::Px(100.0),
                width: Val::Px(300.0),
                ..Default::default()
            },
            ..Default::default()
        })
        .with_children(|commands| {
            commands.spawn(NodeBundle{
                style: Style {
                    flex_direction: FlexDirection::Row,
                    height: Val::Px(75.0),
                    ..Default::default()
                },
                background_color: Color::srgb(1.0, 0.0, 1.0).into(),
                ..Default::default()
            }).with_children(|commands| {
                // a div that reduces the available size
                commands.spawn(NodeBundle {
                    style: Style {
                        width: Val::Px(75.0),
                        ..Default::default()
                    },
                    background_color: Color::srgb(0.0, 1.0, 0.0).into(),
                    ..Default::default()
                });

                // text with width=auto, but actual size will not be what it expcets due to the sibling div above
                commands.spawn(TextBundle {
                    text: Text::from_section("Some text that wraps onto a second line", Default::default()).with_justify(justify),
                    style: Style {
                        align_self: AlignSelf::Center,
                        ..Default::default()
                    },
                    ..Default::default()
                });
            });
        });
    }
}
```
2024-06-14 21:47:43 +02:00
..
bevy_a11y Release Candidate 0.14.0-rc.2 2024-06-06 23:56:56 +02:00
bevy_animation Make the component types of the new animation players clonable. (#13736) 2024-06-09 01:18:07 +02:00
bevy_app Ensure that events are updated even when using a bare-bones Bevy App (#13808) (#13842) 2024-06-14 20:53:37 +02:00
bevy_asset Improve error handling for AssetServer::add_async (#13745) 2024-06-10 19:31:41 +02:00
bevy_audio Release Candidate 0.14.0-rc.2 2024-06-06 23:56:56 +02:00
bevy_color Wgpu 0.20 (#13186) 2024-06-14 20:55:42 +02:00
bevy_core Release Candidate 0.14.0-rc.2 2024-06-06 23:56:56 +02:00
bevy_core_pipeline Release Candidate 0.14.0-rc.2 2024-06-06 23:56:56 +02:00
bevy_derive Release Candidate 0.14.0-rc.2 2024-06-06 23:56:56 +02:00
bevy_dev_tools Release Candidate 0.14.0-rc.2 2024-06-06 23:56:56 +02:00
bevy_diagnostic Poll system information in separate tasks (#13693) 2024-06-10 22:30:56 +02:00
bevy_dylib Release Candidate 0.14.0-rc.2 2024-06-06 23:56:56 +02:00
bevy_dynamic_plugin Release Candidate 0.14.0-rc.2 2024-06-06 23:56:56 +02:00
bevy_ecs Ensure that events are updated even when using a bare-bones Bevy App (#13808) (#13842) 2024-06-14 20:53:37 +02:00
bevy_encase_derive Release Candidate 0.14.0-rc.2 2024-06-06 23:56:56 +02:00
bevy_gilrs Release Candidate 0.14.0-rc.2 2024-06-06 23:56:56 +02:00
bevy_gizmos view.inverse_clip_from_world should be world_from_clip (#13756) 2024-06-09 16:55:22 +02:00
bevy_gltf Release Candidate 0.14.0-rc.2 2024-06-06 23:56:56 +02:00
bevy_hierarchy Fix EntityCommands::despawn docs (#13774) 2024-06-09 20:52:52 +02:00
bevy_input Release Candidate 0.14.0-rc.2 2024-06-06 23:56:56 +02:00
bevy_internal Add missing plugins to doc of DefaultPlugins (#13833) 2024-06-14 20:55:41 +02:00
bevy_log Release Candidate 0.14.0-rc.2 2024-06-06 23:56:56 +02:00
bevy_macro_utils Release Candidate 0.14.0-rc.2 2024-06-06 23:56:56 +02:00
bevy_math Release Candidate 0.14.0-rc.2 2024-06-06 23:56:56 +02:00
bevy_mikktspace Release Candidate 0.14.0-rc.2 2024-06-06 23:56:56 +02:00
bevy_pbr Revert "Make FOG_ENABLED a shader_def instead of material flag (#13783)" (#13803) 2024-06-11 02:01:14 +02:00
bevy_ptr Release Candidate 0.14.0-rc.2 2024-06-06 23:56:56 +02:00
bevy_reflect Release Candidate 0.14.0-rc.2 2024-06-06 23:56:56 +02:00
bevy_render Wgpu 0.20 (#13186) 2024-06-14 20:55:42 +02:00
bevy_scene Update serialize flag for bevy_ecs (#13740) 2024-06-10 19:31:41 +02:00
bevy_sprite Add from_color to StandardMaterial and ColorMaterial (#13791) 2024-06-11 02:01:14 +02:00
bevy_state fix docs around StateTransition and remove references to `apply_sta… (#13772) 2024-06-10 19:31:41 +02:00
bevy_tasks Release Candidate 0.14.0-rc.2 2024-06-06 23:56:56 +02:00
bevy_text fix non-exact text h-alignment (#13846) 2024-06-14 21:47:43 +02:00
bevy_time Ensure that events are updated even when using a bare-bones Bevy App (#13808) (#13842) 2024-06-14 20:53:37 +02:00
bevy_transform Release Candidate 0.14.0-rc.2 2024-06-06 23:56:56 +02:00
bevy_ui reduce the antialias strength (#13814) 2024-06-14 20:55:41 +02:00
bevy_utils Release Candidate 0.14.0-rc.2 2024-06-06 23:56:56 +02:00
bevy_window Release Candidate 0.14.0-rc.2 2024-06-06 23:56:56 +02:00
bevy_winit 13743 app exit hang (#13744) 2024-06-09 01:18:07 +02:00