Automatic sizing of GUI width

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
JoeWinograd
Posts: 2200
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Automatic sizing of GUI width

23 May 2020, 14:10

Hi Folks,

AHK's GUI does a good job of knowing the height of the GUI, so that a Gui,Show command without specifying the Height (H) option displays nicely. However, the same is sometimes not true for the width of the GUI because of the Title. The GUI width, without specifying the Width (W) option, is auto-sized based on the controls that it contains, but if the Title, along with the other elements in the Title bar (Minimize, Maximize/Restore, Close buttons), is longer than the longest control, the Title will be cut off. Example code and result:

Code: Select all

Gui,Add,Text,,What to process:
Gui,Add,Radio,Checked,Root folder only
Gui,Add,Radio,,Recurse subfolders
Gui,Add,Radio,,Individual files
Gui,Add,Button,Default,&OK
Gui,Add,Button,x+10,&Cancel
Gui,Show,,Select folder or files
Return
GuiClose:
GuiEscape:
ButtonOK:
ButtonCancel:
ExitApp
gui auto-width cuts off title.png
gui auto-width cuts off title.png (5.08 KiB) Viewed 2376 times

Other than specifying the Width (W) option in Gui,Show, is there any way to make the auto-sizing take into account the Title bar width (something similar to the AutoHdr option in LV_ModifyCol)? Or is this a Wish List item?

Thanks much, Joe
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Automatic sizing of GUI width

23 May 2020, 15:36

I've played with your settings and it was interesting to see how the GUI is built. If using "w0" you'll see its start position. Controls are fixed to the left side of the frame, so does the icon at the title bar. Once the width gets increased the text occurs between the icon and the window title bar controls to its right. It could be interesting to do the math for a font's characters (fixed monospaced) width to get the correct size to display the full title.
Anyone willing to deal with this (or something similar)?

https://css-tricks.com/books/fundamental-css-tactics/scale-typography-screen-size/
https://websemantics.uk/articles/responsive-fonts/
https://www.translatorscafe.com/unit-converter/EN/typography/

:)

Code: Select all

Gui,Add,Text,,What to process:
Gui,Add,Radio,Checked,Root folder only
Gui,Add,Radio,,Recurse subfolders
Gui,Add,Radio,,Individual files
Gui,Add,Button,Default,&OK
Gui,Add,Button,x+10,&Cancel
Loop 270 {
	Gui,Show,% "w" A_Index, Select folder or files
	Sleep 20
	}
Return

GuiClose:
GuiEscape:
ButtonOK:
ButtonCancel:
ExitApp
User avatar
JoeWinograd
Posts: 2200
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: Automatic sizing of GUI width

23 May 2020, 16:15

Hi BoBo,
BoBo wrote:interesting to see how the GUI is built
Indeed! Very cool loop to build the GUI!
BoBo wrote:Without any w-param it seems to spread to the width of the widest control.
Yes, that's documented:
If there is no previous size, the window will be auto-sized according to the size and positions of the controls it contains.
BoBo wrote:Could be interesting to do the math for a font's characters (fixed) width to get the correct size to display the full title.
Good idea! Wish List item? Regards, Joe
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Automatic sizing of GUI width

24 May 2020, 02:19

Wish list? I guess for the reason that a title won't change that often during runtime this option wouldn't get that high priority?!
But some genius math geeks could have a look at the formulas I've linked above to create a UDF that provides it as a feature, right?

Here's a noobish attempt to get an idea about that whole stuff ...

Code: Select all

#NoEnv
#SingleInstance, Force

title :=["one"
		,"one two"
		,"one two three"
		,"one two three four"
		,"one two three four five"
		,"one two three four five six"
		,"one two three four five six seven"]
fSize := 8

Random, item, 1, 7										
title := title[item]										; selecting one of multiple title options of different length at startup

Gui, Add, Text,,											; dummy line
Loop % wCal(title,fSize) + 156 {							; 156px ~ icon+window controls
	Gui,Show,% "w" A_Index " h 0",% title					; create title bar
	}
Return

GuiClose:
GuiEscape:
ToolTip
ExitApp

wCal(title,fSize) {											; use title/font size
	t := StrSplit(title,A_Space)							; get number of space characters
	Loop, Parse, title										; get number of characters
		width := (fSize/1.3*A_Index) + fSize*1.3-t.Length()	; doing some "math" (far from being exact, just t&e) 
	ToolTip % Round(width)									; peep show
	Return width
	}
...(btw, it seems that the gap between the title and the window controls to its right is slightly increasing with the number of words used in the title) :shh:
User avatar
JoeWinograd
Posts: 2200
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: Automatic sizing of GUI width

24 May 2020, 15:19

Hi BoBo,
BoBo wrote:this option wouldn't get that high priority?!
Probably true. Definitely a nice-to-have, not a need-to-have.
BoBo wrote:But some genius math geeks could have a look at the formulas I've linked above to create a UDF that provides it as a feature, right?
Yep!
BoBo wrote:Here's a noobish attempt to get an idea about that whole stuff
Nice! I think your "noobish attempt" is very good. Not sure what a "genius math geek" would do to improve it. :)
seems that the gap between the title and the window controls to its right is slightly increasing with the number of words used in the title
Fascinating!

Thanks for your comments...good stuff! Regards, Joe
btonasse
Posts: 2
Joined: 25 Nov 2019, 10:33

Re: Automatic sizing of GUI width

16 Oct 2020, 06:37

Has anybody ever come up with a solution to this? I really like to leave my GUIs at autosize, but once you start using dynamic titles it becomes useless. :(

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: filipemb, Ineedhelplz and 317 guests