Allow Spacer() to shrink to maintain text position - swift

I have a view laid out like this:
Text
Spacer
Rectangle
Spacer
I'm trying to make the position of the Rectangle remain constant unless the Text is close enough to push it down. But currently, if the text grows a line taller, the rectangle moves down.
VStack {
Text("Hello")
Spacer()
Rectangle()
.frame(width: 50, height: 50)
Spacer()
}
I tried making the Spacer layoutPriority lower than the Text and Rectangle to no avail.

I'm not sure if I understand the question clearly, but it looks like what you need.
VStack {
Text(
"Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World "
)
.frame(minHeight: 0, maxHeight: .infinity)
Rectangle()
.frame(width: 50, height: 50)
.padding(.vertical, 100)
}

If your view can have a fixed height, you could set a max height for the lower Spacer() and set higher LayoutPriority() for the Text and Rectangle.
Here is an example:
VStack {
Text("Make this text longer and longer")
.layoutPriority(1)
Spacer()
Rectangle()
.frame(width: 50, height: 50)
.layoutPriority(1)
Spacer()
.frame(maxHeight: 120)
}
.frame(width: 100, height: 300)
Now, if you make the text longer it will grow in height and push the rectangle down as soon as the text touches it. I hope it helps.

Related

How to randomize x y movements at Logitech G Hub

I'm a beginner and I'm trying to make a macro in Logitech GHub.
I managed to program everything, but I randomly movements .
Is it possible to add random moves to this macro?
I searched in many places and didn't find anything similar to my question.
I want them to move randomly and not the same as in the script.
Thank you!
function OnEvent(event, arg)
if event == "MOUSE_BUTTON_PRESSED" and arg == 3 then
PressKey("lshift")
MoveMouseTo(34650, 26299)
PressAndReleaseMouseButton(3)
Sleep(math.random(13, 30))
MoveMouseTo(34650,30854)
PressAndReleaseMouseButton(3)
Sleep(math.random(13, 30))
MoveMouseTo(32755,30854)
PressAndReleaseMouseButton(3)
Sleep(math.random(13, 30))
MoveMouseTo(30860,30794)
PressAndReleaseMouseButton(3)
Sleep(math.random(13, 30))
MoveMouseTo(30911,26360)
PressAndReleaseMouseButton(3)
Sleep(math.random(13, 30))
MoveMouseTo(30911,21865)
PressAndReleaseMouseButton(3)
Sleep(math.random(13, 30))
MoveMouseTo(32780,21805)
PressAndReleaseMouseButton(3)
Sleep(math.random(13, 30))
MoveMouseTo(34650,21926)
PressAndReleaseMouseButton(3)
ReleaseKey("lshift")
end
end

How to make text properly aligned with padding in SwiftUI?

So I have these two texts that I'm trying to align at the same pixel basically, but it seems that one is more offset than the other. Like so, the one on the bottom seems to be further left than the other.
Here is the code:
VStack(alignment: .leading) {
Text("Enter your phone number")
.padding(15)
.frame(alignment: .leading)
.foregroundColor(Color.white)
.font(Font.custom("URWDIN-Thin", size: 30))
//Subtitle
Text("You will be sent a code for verification")
.padding(15)
.frame(alignment: .leading)
.foregroundColor(Color.white)
.font(Font.custom("URWDIN-Thin", size: 16))
Any idea as to why this may be?
You have chosen a font in which capital ‘E’ has a noticeable left side bearing. Left side bearing is the distance from the “pen position” to the left edge of the tight bounding box of the glyph.
That's why your lines of text look misaligned. Here's my test:
PlaygroundPage.current.setLiveView(
VStack(alignment: .leading) {
Text("Enter your phone number")
.border(Color.red, width: 1)
.font(Font.custom("URWDIN-Thin", size: 30))
Text("You will be sent a code for verification")
.border(Color.red, width: 1)
.font(Font.custom("URWDIN-Thin", size: 16))
Text("Enter your phone number")
.border(Color.red, width: 1)
.font(Font.system(size: 30))
Text("You will be sent a code for verification")
.border(Color.red, width: 1)
.font(Font.system(size: 16))
}
)
Output:
Notice how, in both URW DIN Thin and in the system font (SF Pro), the capital ‘Y’ has a left side bearing of essentially zero: both glyphs touch the left edge of the frame.
The left side bearing of SF Pro's capital ‘E’ is not zero but it's small: a fraction of the vertical stroke width.
But the left side bearing of the capital ‘E’ in DRW UDM Thin is significant. It's about twice the vertical stroke width. That makes it quite noticeable compared to the zero bearing of the capital ‘Y’.

How can I use strokeBorder for trimed Shapes in SwiftUI?

I have difficulty to use strokeBorder after trim in SwiftUI, how can do this?
Circle()
.trim(from: 0, to: 0.5)
.strokeBorder(Color.red, style: StrokeStyle(lineWidth: 50.0, lineCap: .round, lineJoin: .round))
Error:
Value of type 'some Shape' has no member 'strokeBorder'
There is at least 2 ways to get the result like strokeBorder gives. But they are not using strokeBorder, I want solve the issue while using strokeBorder.

Finding a pixel and tracking its color change

There is a script that for some reason does not work.
I explain the situation: There is a mini game in which there are green rings and they change their position (not random) every time the white ring stops using the space bar on them.
I wrote a little script to find the green color, but for some reason it does not work.
F5::
loop {
PixelGetColor, color1, 957, 672, RGB
PixelGetColor, color2, 957, 672, RGB
if(color1 != 0x10A04B){
Sleep, 80
} else {
Soundbeep
Sleep, 80
}
if(color2 != 0xFDFFFE){
Sleep, 80
} else {
Send, {space}
}
}
return
To help you fully understand the mini game, I'm sending you a link to the video: https://youtu.be/b4y1aiQNea4
Please help me understand the implementation. Thank you!
Use a timer instead of the loop
Try using Alt or Slow mode
For finding the green ring coordinates try using PixelSearch, then you will be able to specify variation of the color (it's necessary due to it being partially transparent)
colorchange(x,y){
PixelGetColor,color,x,y
if (color=0xffffffffff){
Return 1}Else{
Return 0}
}
if colorchange(X,Y){
Send,{Space}
}

Resize Picture and Keep Aspect Ratio in Autohotkey GUI

Is it possible to have an image be 100% of the window width and keep it's aspect ratio while resizing an AutoHotKey GUI?
I have a simple GUI as follows:
Gui +Resize
Gui, Add, Picture, w440 h-1 vProductImage, default.png
Gui, Show, , MyApp
The closest thing I have been able to come to is Anchor.ahk http://www.autohotkey.com/board/topic/4105-control-anchoring-v4-for-resizing-windows/
Using it, I can have the image resized when the window is resized but it doesn't keep it's aspect ratio and gets deformed
Does anyone know how I can do this?
Closest thing I could come up with:
Assuming the picture is 440x350, is 85 pixels from the top of the app window (left:0)
GuiSize:
if(A_GuiWidth < A_GuiHeight)
{
GuiControl, MoveDraw, ProductImage, % "w" . (A_GuiWidth - 20) . " h" . (350/440) * (A_GuiWidth - 20)
}
else
{
GuiControl, MoveDraw, ProductImage, % "w" . (440/350) * (A_GuiHeight - 85) . " h" . (A_GuiHeight - 85)
}
return
(the 20 is for window padding)