#bevy_ui align text within parent gui node

1 messages · Page 1 of 1 (latest)

full igloo
#

I'm trying to align text within a parent GUI node. The pink is the child node, taking up 100% of the space of the parent node, but the text of this node remains left justified no matter what I do, regardless of the size of the node in which it exists. Changing the Text::alignment field only shifts the kerning a bit, but doesn't seem to actually move the text anywhere within the node

#

So the hierarchy is
Parent node (covered in the screenshot) -> Child node (Pink, contains the TextBundle components)

#

According to flexbox.help

{
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    justify-content: center;
    align-items: stretch;
    align-content: stretch;
}``` should do it, but instead it does nothing
#

Ah! I had to set the parent's style to column too

storm folio
#

yes it's a bit confusing but the text alignment field doesn't affect the position of the text only its internal alignment

full igloo
#

Then I actually don't understand what the text alignment field even does

#

I guess that doesn't matter though

storm folio
#

if you have a text with multiple lines

#

then left aligned text will be lined up against the left edge, and right aligned text will lined up against the right edge

full igloo
#

Okay but then why can't I align a child node within a parent?

storm folio
#

within its ui node, but the node containing the text doesn't move

full igloo
#

It can take up all the space inside the parent but it seemingly can't be aligned within that space

storm folio
#

usually you just need to just need to set either align_items or justify_content depending on the flex direction

full igloo
#

Look! It works now!

storm folio
#

if you add a background_color to the text node entity it often makes it clearer whats happening

full igloo
#

Hmm I wonder if I could shrink the parent to fit its contents

#

That's what the pink was

#

I could take up all the parent's space, but I couldn't actually move the alignment within that space, other than vertically

#

Hmm it seems like I can't actually both make the column grow in width to fit the contents AND make it align to the right side of the screen

#

Maybe with another parent node on top of that in ColumnReverse

storm folio
#

that should work

#

there are still bugs in 0.10 with text nodes, often wrapping them in other nodes can help

full igloo
#

Hm now the text node disappeared

#

Weird