Skip to content

Positioning or Transforming Text within a Node doesn't work #676

@chrisburnor

Description

@chrisburnor

This may be as much an issue of documentation as of code, but I'm trying to center a single character within a square node with the following code:

commands
        .spawn(
            NodeComponents {
                style: Style {
                    size: Size::new(Val::Px(64.0), Val::Px(64.0)),
                    border: Rect::all(Val::Px(2.0)),
                    position_type: PositionType::Absolute,
                    position: Rect {
                        left: Val::Px(64.0),
                        right: Val::Px(64.0),
                        top: Val::Px(64.0),
                        bottom: Val::Px(64.0),
                    },

                    // I expect one of these to center the text in the node
                    align_content: AlignContent::Center,
                    align_items: AlignItems::Center,
                    align_self: AlignSelf::Center,

                    ..Default::default()
                },
                material: materials.add(Color::rgb(0.4, 0.4, 0.4).into()),
                ..Default::default()
            }
        )
        .with_children(|parent| {
            parent
                .spawn(TextComponents {
                    text: Text {
                        value: "0".to_string(),
                        font: font_handle,
                        style: TextStyle {
                            font_size: 64.0,
                            color: Color::WHITE,
                        }
                    },
                    
                    // I would expect this to horizontally stretch the text within the node
                    transform: Transform::from_non_uniform_scale(Vec3::new(2.0, 1.0, 1.0)),
                    ..Default::default()
                });
        })
    ;

However, what I get is just this:
Screen Shot 2020-10-13 at 10 34 57 AM

The stretch transform seems to do nothing and neither do any of the align attributes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-UIGraphical user interfaces, styles, layouts, and widgetsC-BugAn unexpected or incorrect behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions