-
Notifications
You must be signed in to change notification settings - Fork 72
/
Get_TextCtrlSize.ahk
44 lines (38 loc) · 1.39 KB
/
Get_TextCtrlSize.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
Get_TextCtrlSize(txt, fontName, fontSize, maxWidth="", params="") {
/* Create a control with the specified text to retrieve
* the space (width/height) it would normally take
*/
Gui, GetTextSize:Destroy
Gui, GetTextSize:Font, S%fontSize%,% fontName
if (maxWidth)
Gui, GetTextSize:Add, Text,x0 y0 +Wrap w%maxWidth% hwndTxtHandler,% txt
else
Gui, GetTextSize:Add, Text,x0 y0 %params% hwndTxtHandler,% txt
coords := Get_ControlCoords("GetTextSize", TxtHandler)
Gui, GetTextSize:Destroy
return coords
/* Alternative version, with auto sizing
Gui, GetTextSize:Font, S%fontSize%,% fontName
Gui, GetTextsize:Add, Text,x0 y0 hwndTxtHandlerAutoSize,% txt
coordsAuto := Get_ControlCoords("GetTextSize", TxtHandlerAutoSize)
if (maxWidth) {
Gui, GetTextSize:Add, Text,x0 y0 +Wrap w%maxWidth% hwndTxtHandlerFixedSize,% txt
coordsFixed := Get_ControlCoords("GetTextSize", TxtHandlerFixedSize)
}
Gui, GetTextSize:Destroy
if (maxWidth > coords.Auto)
coords := coordsAuto
else
coords := coordsFixed
return coords
*/
}
Get_ControlCoords(guiName, ctrlHandler) {
/* Retrieve a control's position and return them in an array.
The reason of this function is because the variable content would be blank
unless its sub-variables (coordsX, coordsY, ...) were set to global.
(Weird AHK bug)
*/
GuiControlGet, coords, %guiName%:Pos,% ctrlHandler
return {X:coordsX,Y:coordsY,W:coordsW,H:coordsH}
}