Is there any equivalent of the Spacer() element from SwiftUI? #19
-
Hello, Is there anything similar to the Spacer() control from SwiftUI in Adwaita-swift? In SwiftUI I would write something like this:
The first text would be pushed to the left and the second to the right. What is the Adwaita equivalent, or is there an alternative to this? Here is an example of what I'm trying to do:
The first text should be aligned to the left and the second to the right, both on the same line. But they're both aligned to the left: If I remove the HStack, the alignment works, but each text will be displayed on a separate line. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
In the end, after taking a look at the upstream documentation for Adwaita, I improvised something using the xalign and frame methods:
|
Beta Was this translation helpful? Give feedback.
-
Have you tried: HStack {
Text("Left Text")
.hexpand()
.halign(.start)
Text("Right Text")
}
You have to set Because the width of Exactly the same result could be accomplished by expanding the right text: HStack {
Text("Left Text")
Text("Right Text")
.hexpand()
.halign(.end)
} |
Beta Was this translation helpful? Give feedback.
Have you tried:
halign
makes the widget align inside the widget's frame (the one ofText
itself, not ofHStack
). Therefore, you need to make the widget's frame expand viahexpand
. The frame of the parent (HStack
) will automatically expand as well.You have to set
halign
tostart
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), settinghalign(.end)
is not necessary.Exactly the same result could be accomplished by expanding the right text: