GUI text overlays other elements Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
marc873a
Posts: 37
Joined: 23 Jun 2020, 10:49

GUI text overlays other elements

Post by marc873a » 27 Jun 2022, 14:19

Hi.

I have a GUI window with multiple texts. The code is here:

Code: Select all

Gui, -DPIScale
Gui, Font, s22, Arial
Gui, Add, Text, x0 y10 w960 +Center, % var.1
Gui, Add, Text, x0 y10 w1920 +Center, % var.2
Gui, Add, Text, x960 y10 w960 +Center, % var.3
Gui, Submit
Gui, Show,  maximize
return
var.1, .2, and 3 are just lists of numbers from 1 to 60, with 20 numbers per column.

It produces this:
image.png
image.png (65.28 KiB) Viewed 863 times
Can I somehow stop the text from overlapping each other? The text needs to be evenly spaced like I tried to do.

Thx in advance and have a good day
Marcus :D

User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: GUI text overlays other elements

Post by mikeyww » 27 Jun 2022, 14:44

If you eliminate your absolute positioning, the GUI will auto-position the controls. If you want absolute positioning, then, well-- use different positions! :)

Code: Select all

var := ["1`n2`n3", "4`n5`n6", "7`n8`n9"]
Gui, -DPIScale
Gui, Font, s12, Arial
Gui, Add, Text,   , % var.1
Gui, Add, Text, ym, % var.2
Gui, Add, Text, ym, % var.3
Gui, Show, w250, Numbers
Return
This GUI uses a different x-value for each control, instead of having two controls with the same x-value.

marc873a
Posts: 37
Joined: 23 Jun 2020, 10:49

Re: GUI text overlays other elements

Post by marc873a » 27 Jun 2022, 15:10

I'm a little confused about this.
I want it to look like this:
image.png
image.png (96.31 KiB) Viewed 824 times
(Photoshop)
x, y, and a are just examples.

How should I do this?

Best Regards,
Marcus

User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: GUI text overlays other elements

Post by mikeyww » 27 Jun 2022, 15:18

If you are asking a question about how to work with your variables, then why not provide them (e.g., in text form, as you have it in your script)? Please provide the values of your variables below, so that a test can be done.

marc873a
Posts: 37
Joined: 23 Jun 2020, 10:49

Re: GUI text overlays other elements

Post by marc873a » 28 Jun 2022, 04:31

Okay here is there code for the entire script:

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

Numpad1::
file         = C:\Users\marc8\Downloads\AHK Scripts\Fullmovie\test.txt
wordsPerVar  = 20
var         := []
FileRead, text, %file%
While (text > "") {
 word := StrSplit(text, [" ", "`n"], "`r", rest := wordsPerVar + 1), str := ""
 Loop, %wordsPerVar%
  str .= word[A_Index] "`n"
 var.Push(Trim(str)), text := word[rest]
 ;MsgBox,, % "String #" var.Count(), % var[var.Count()]
}
;Msgbox % var.2
;return

;Numpad2::
Gui, -DPIScale
Gui, Font, s22, Arial

Gui, Add, Text, x0 y10 w960 +Center, % var.1

Gui, Add, Text, x0 y10 w1920 +Center, % var.2

Gui, Add, Text, x960 y10 w960 +Center, % var.3

Gui, Submit
Gui, Show,  maximize
return

+esc::reload
The first file I refer to is a txt file with numbers, I use for testing. I attached that too.
Hope it helps :)
Attachments
test.txt
(229 Bytes) Downloaded 18 times

User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: GUI text overlays other elements

Post by mikeyww » 28 Jun 2022, 05:12

Code: Select all

dir         := StrReplace(A_AppData, "AppData\Roaming", "Downloads")
file         = %dir%\AHK Scripts\Fullmovie\test.txt
wordsPerVar  = 20
var         := []
If !FileExist(file) {
 MsgBox, 48, Error, File not found. Aborting.`n`n%file%
 Return
} Else FileRead, text, %file%
Gui, -DPIScale
Gui, Font, s22, Arial
While (text > "") {
 pos  := InStr(text, "`n",,, wordsPerVar), pos := pos ? pos : StrLen(text)
 Gui, Add, Text, Center ym, % Trim(SubStr(text, 1, pos), " `t`r`n")
 text := SubStr(text, pos + 1)
}
Gui, Show, Maximize, Text
Return
image220628-1134-001.png
Output
image220628-1134-001.png (72.08 KiB) Viewed 590 times

marc873a
Posts: 37
Joined: 23 Jun 2020, 10:49

Re: GUI text overlays other elements

Post by marc873a » 28 Jun 2022, 14:57

Very nicely done.

How should I code it so it is aligned like this:
image.png
image.png (126.54 KiB) Viewed 586 times
Best regards,
Me

User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: GUI text overlays other elements

Post by mikeyww » 28 Jun 2022, 15:25

It seems like we are going in circles a bit. I provided the script. You provide the text. See how it works as is, since you are the only person who has your text file.

User avatar
flyingDman
Posts: 2791
Joined: 29 Sep 2013, 19:01

Re: GUI text overlays other elements  Topic is solved

Post by flyingDman » 28 Jun 2022, 16:08

I believe this is a fine-tuning nightmare as the placement in your gui is dependent on the font and the (variable) space each character takes in the gui. So, it's dependent on your resolution, your font type, your font size, your dpi scaling. You might get it working on your system, but someone else on theirs will see gobbledygook (that's a professional term! ;)) . I got a decent result using the script below, but only if all elements on one row are of the same size and a mono-spaced font.
You'll have a much better chance trying to format it this way using HTML.

Code: Select all

file := A_ScriptDir "\test0000.txt", z  := 3, cnt := 1, yy := 5
fileread, fl, % file
while % cnt
	fl := strreplace(strreplace(fl,"`r`n", " ",, z-1),"`r`n", "`n",cnt, 1)
gui, font, s13, consolas  ;Lucida Sans Typewriter
for x,y in strsplit(fl, "`n")
    {
    xx := 100 - strlen(Strsplit(y," ").1) * 4.8		; found the 4.8 conversion factor using trial and error... 
    gui, add, text, x%xx% y%yy%, % Strsplit(y," ").1
    xx := 200 - strlen(Strsplit(y," ").2) * 9.6
    gui, add, text, x+%xx% y%yy%, % Strsplit(y," ").2
    xx := 200 - strlen(Strsplit(y," ").3) * 9.6
    gui, add, text, x+%xx% y%yy%, % Strsplit(y," ").3
    yy += 20
    }
gui, show, w600
20220628_140015.jpg
20220628_140015.jpg (27.65 KiB) Viewed 565 times
test0000.txt
(436 Bytes) Downloaded 11 times
14.3 & 1.3.7

garry
Posts: 3740
Joined: 22 Dec 2013, 12:50

Re: GUI text overlays other elements

Post by garry » 28 Jun 2022, 16:26

first example from mikeyww / but not read a file

Code: Select all

;- GUI text overlays other elements   / mikeyww
;- https://www.autohotkey.com/boards/viewtopic.php?f=76&t=105840

var := ["XX`nXXXX`nXXXXXXX`nXXXX`nXX", "YYY`nYYYYY`nYYYYYYY`nYYYYY`nYYY", "aa`naaaa`naaaaaa`naaaa`naa"]
Gui, -DPIScale
Gui, Font, s16, Lucida Console
Gui, Add, Text, center         , % var.1
Gui, Add, Text, center x+120 ym, % var.2
Gui, Add, Text, center x+120 ym, % var.3
Gui, Show, , Numbers
Return
Guiclose:
Exitapp

User avatar
flyingDman
Posts: 2791
Joined: 29 Sep 2013, 19:01

Re: GUI text overlays other elements

Post by flyingDman » 28 Jun 2022, 16:32

Nice @garry . Much better than I thought possible!
14.3 & 1.3.7

User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: GUI text overlays other elements

Post by mikeyww » 28 Jun 2022, 16:36

Output from my script.

image220628-1737-001.png
Output
image220628-1737-001.png (93.29 KiB) Viewed 547 times

User avatar
flyingDman
Posts: 2791
Joined: 29 Sep 2013, 19:01

Re: GUI text overlays other elements

Post by flyingDman » 28 Jun 2022, 16:40

Nice!
14.3 & 1.3.7

Post Reply

Return to “Ask for Help (v1)”