Skip to content

Is there any equivalent of the Spacer() element from SwiftUI? #19

Closed Answered by david-swift
alexmocanu asked this question in Q&A
Discussion options

You must be logged in to vote

Have you tried:

HStack {
    Text("Left Text")
        .hexpand()
        .halign(.start)
    Text("Right Text")
}

halign makes the widget align inside the widget's frame (the one of Text itself, not of HStack). Therefore, you need to make the widget's frame expand via hexpand. The frame of the parent (HStack) will automatically expand as well.

You have to set halign to start to make sure the widget aligns correctly inside the expanded frame.

Because the width of Text("Right Text) is the width of the text itself (no expanding), setting halign(.end) is not necessary.

Exactly the same result could be accomplished by expanding the right text:

HStack {
    Text("Left Text")
    Text("Right Text"

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@alexmocanu
Comment options

Answer selected by alexmocanu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants