How to wrap multiple text controls?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
m3user
Posts: 235
Joined: 17 Jan 2014, 18:11

How to wrap multiple text controls?

Post by m3user » 21 Aug 2023, 09:09

Hi, I need to show multiple text controls in a gui, one after another, shown as a single text flow, wrapped according to the available width.

Please see the script below. I tried +wrap option and setting the control widths but couldn't make it work.
How would it be possible to wrap the text to a window size? Thanks.

Code: Select all

text:="This is a text example."
gui, font, s10
gui, add, text, cRed, Title text
gui, add, text, x+10 cBlue, %text%
gui, add, text, x+10, %text%
gui, show, w300 h200, MyGui
RussF
Posts: 1311
Joined: 05 Aug 2021, 06:36

Re: How to wrap multiple text controls?

Post by RussF » 21 Aug 2023, 09:33

You can wrap a single text field by using +Wrap and setting the height of the control as such:

Code: Select all

#Requires AutoHotkey v1.1.33+

gui, font, s10
gui, add, text, cRed w150 h100 +wrap, Now is the time for all good programmers to come to the aid of their computer.
gui, show, w300 h200, MyGui
I don't know of any way to do the same with multiple controls and I don't know how you would get different text colors within one control (unless you just did that for illustrative purposes).

Russ
m3user
Posts: 235
Joined: 17 Jan 2014, 18:11

Re: How to wrap multiple text controls?

Post by m3user » 21 Aug 2023, 10:43

Yes thanks, I'm aware about height and width of the control.

My question is if it possible to wrap the text in situation where text does not start at the very left side of the control...
Any other ideas?
Rohwedder
Posts: 7774
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: How to wrap multiple text controls?

Post by Rohwedder » 21 Aug 2023, 11:29

Hallo,
use https://github.com/AHK-just-me/Class_RichEdit
With that you can get different text colors within one control.
RussF
Posts: 1311
Joined: 05 Aug 2021, 06:36

Re: How to wrap multiple text controls?

Post by RussF » 21 Aug 2023, 11:30

I'm not sure I understand your question. In order for the text NOT to start at the left of the control, you would preface it with spaces as in:

Code: Select all

#Requires AutoHotkey v1.1.33+

gui, font, s10
gui, add, text, cRed w150 h100 +wrap, % "          Now is the time for all good programmers to come to the aid of their computer."
gui, show, w300 h200, MyGui

It still works.

Russ
m3user
Posts: 235
Joined: 17 Jan 2014, 18:11

Re: How to wrap multiple text controls?

Post by m3user » 21 Aug 2023, 12:00

Thanks both. Another example to illustrate it better. There are multiple controls added to complete the sentence with missing data. The text length could vary.
Would it be possible to wrap the sentence to gui width?

Code: Select all

gui, font, s10
gui, add, text, , Hi
gui, add, edit, x+5 vName, 
gui, add, text, x+5, % ", you can contact me on "
gui, add, DropDownList, x+5 vAddress, a@yahoo.com|a@gmail.com
gui, add, text, x+5, Thanks.
gui, show, w450 h200, MyGui
RussF
Posts: 1311
Joined: 05 Aug 2021, 06:36

Re: How to wrap multiple text controls?

Post by RussF » 21 Aug 2023, 12:23

Something like this?

Code: Select all

#Requires AutoHotkey v1.1.33+

greeting := "Hi"
body := ", you can contact me on "
closing := "Thanks."
fulltext := ""

gui, font, s10
gui, add, text, , % greeting
gui, add, edit, x+5 vName, 
gui, add, text, x+5, % body
gui, add, DropDownList, x+5 vAddress, a@yahoo.com|a@gmail.com
gui, add, text, x+5, % closing

gui, add, button, xm, Ok
gui, add, text,, Result:
gui, add, edit, x+5 +wrap vfulltext w200 h100, % fulltext
gui, show, w600 h200, MyGui
Return

GuiClose:
    ExitApp

ButtonOk:
    gui, submit, nohide
    fulltext := greeting . " " . Name . body . " " . Address . ". " . closing
    guicontrol,, fulltext, % fulltext
return
Russ
m3user
Posts: 235
Joined: 17 Jan 2014, 18:11

Re: How to wrap multiple text controls?

Post by m3user » 21 Aug 2023, 13:32

Thanks for your help! Very much appreciated. However I was hoping to wrap the original text between controls..
RussF
Posts: 1311
Joined: 05 Aug 2021, 06:36

Re: How to wrap multiple text controls?

Post by RussF » 21 Aug 2023, 14:19

Well, then, I'm not sure I can help. You seem to be trying to get three different types of controls to resize themselves based on the content and then to rearrange themselves within the gui. I suppose it could possibly be done, but I don't think I would want to try to come up with the complex code to accomplish it.

If you're just trying to get all your controls to fit within a specific gui width, why are you putting them all on the same line? Why not just intentionally stack them vertically instead of horizontally?

Russ
Rohwedder
Posts: 7774
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: How to wrap multiple text controls?

Post by Rohwedder » 22 Aug 2023, 02:07

As the gui is created, you can measure the size and position of each control and act accordingly:

Code: Select all

gui, -DPIScale +HwndGui
gui, font, s10
gui, add, text, , Hi
gui, add, edit, x+5 vName, 
gui, add, text, x+5, % ", you can contact me on "
gui, add, DropDownList, x+5 vAddress, a@yahoo.com|a@gmail.com
DetectHiddenWindows, On
ControlGetPos, X,, Width,, ComboBox1, ahk_id %Gui% ;measure X and Width of DropDownList
GuiWidth := X + Width -3
;positions the left edge of the gui on the left edge of the DropDownList
gui, add, text, x+5, Thanks. ;this control to the right of the DropDownList will not be visible!
gui, show, w%GuiWidth% h200, MyGui
DetectHiddenWindows, Off
To wrap a control you would have to split it, i.e. create two conrols i.e. "control parts" .
However, the problem will be that these "control parts" will act independently.
Post Reply

Return to “Ask for Help (v1)”