mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 07:04:33 +00:00
01971f210e
# 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() }); }); }); } } ``` |
||
---|---|---|
.. | ||
bevy_a11y | ||
bevy_animation | ||
bevy_app | ||
bevy_asset | ||
bevy_audio | ||
bevy_color | ||
bevy_core | ||
bevy_core_pipeline | ||
bevy_derive | ||
bevy_dev_tools | ||
bevy_diagnostic | ||
bevy_dylib | ||
bevy_dynamic_plugin | ||
bevy_ecs | ||
bevy_encase_derive | ||
bevy_gilrs | ||
bevy_gizmos | ||
bevy_gltf | ||
bevy_hierarchy | ||
bevy_input | ||
bevy_internal | ||
bevy_log | ||
bevy_macro_utils | ||
bevy_math | ||
bevy_mikktspace | ||
bevy_pbr | ||
bevy_ptr | ||
bevy_reflect | ||
bevy_render | ||
bevy_scene | ||
bevy_sprite | ||
bevy_state | ||
bevy_tasks | ||
bevy_text | ||
bevy_time | ||
bevy_transform | ||
bevy_ui | ||
bevy_utils | ||
bevy_window | ||
bevy_winit |