GridGUI v1.1.11 - Simplify Control Placement and Resizing

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
Capn Odin
Posts: 1352
Joined: 23 Feb 2016, 19:45
Location: Denmark
Contact:

Re: GridGUI v1.1.10 - Simplify Control Placement and Resizing

Post by Capn Odin » 11 Oct 2021, 11:17

ozzii wrote:
11 Oct 2021, 04:56
The example with the tooltip works. Thank you for the help and the explanation.

Sorry to ask the question again (because I didn't see an answer from you message from the 9th), but did you see my question about testing the 'id/name' of the button instead of his vVal :oops: :oops: :oops: :oops:

About my issue:
I have this

Code: Select all

args := {exW: 1, exH: 1, fillW: true, fillH: false}
myGui := new GridGUI("CTM", "resize")
myGui.GuiClose := GridGUI.ExitApp
myGui.Color("4389A5")
myGui.Font("bold s13")
myGui.Add("1-2", 1, "Text", "cWhite", "● Relance CTM ●", , , , , "C")
myGui.Font("normal s11")

bt1 := myGui.Add(1, 2, "Button", , "bt1 -> Y", args)
bt1.callback := Func("bt1")
bt1_sans := myGui.Add(2, 2, "Button", , "bt1 -> N", args)
bt1_sans.callback := Func("bt1_sans")
bt2 := myGui.Add(1, 3, "Button", , "bt2", args)
bt2.callback := Func("bt2")
bt3 := myGui.Add(2, 3, "Button", , "bt3", args)
bt3.callback := Func("bt3")
bt4 := myGui.Add(1, 4, "Button", , "bt4 -> Y", args)
bt4.callback := Func("bt4")
bt4_sans := myGui.Add(2, 4, "Button", , "bt4 -> N", args)
bt4_sans.callback := Func("bt4_sans")
Demat := myGui.Add("1-2", 5, "Button", , "Démat factures", args)
Demat.callback := Func("Demat")
Fichier := myGui.Add(1, 6, "Button", , "Fichiers 1C/1V...", args)
Fichier.callback := Func("Fichier")
HR := myGui.Add(2, 6, "Button", , "Demandes DSN/HR", args)
HR.callback := Func("HR")

myGui.Add("1-2", 11, "Text", "cWhite", "", , , , , "C")
btq := myGui.Add("1-2", 12, "Button", "Default", "Quitter", args)
btq.callback := Func("Sortie")

global SERVEUR, FOLDER, VARIABLE, DTE

myGui.AutoSize()
myGui.MinSize()
myGui.Show()
Return
The win is cropped on the right
Image
But when I change Demandes DSN/HR with Demandes DSN it's OK.
Am I doing something wrong ?
No, you are not doing anything wrong. I can see from this that I have some work to do but for now you can workaround the issue like this.

Code: Select all

#Include %A_ScriptDir%\..\GridGUI.ahk

args := {exW: 1, exH: 1, fillW: true, fillH: false}
myGui := new GridGUI("CTM", "resize")
myGui.GuiClose := GridGUI.ExitApp
myGui.Color("4389A5")
myGui.Font("bold s13")
			   myGui.Add("1-2", 1, "Text", "cWhite", "● Relance CTM ●", , , , , "C")
myGui.Font("normal s11")

bt1			:= myGui.Add(1,		2, "Button", , "bt1 -> Y", args)
bt1_sans	:= myGui.Add(2,		2, "Button", , "bt1 -> N", args)
bt2			:= myGui.Add(1,		3, "Button", , "bt2", args)
bt3			:= myGui.Add(2,		3, "Button", , "bt3", args)
bt4			:= myGui.Add(1,		4, "Button", , "bt4 -> Y", args)
bt4_sans	:= myGui.Add(2,		4, "Button", , "bt4 -> N", args)
Demat		:= myGui.Add("1-2",	5, "Button", , "Démat factures", args)
Fichier		:= myGui.Add(1,		6, "Button", , "Fichiers 1C/1V...", args)
HR			:= myGui.Add(2,		6, "Button", , "Demandes DSN/HR", args)

			   myGui.Add("1-2", 11, "Text", "cWhite", "", , , , , "C")
btq			:= myGui.Add("1-2", 12, "Button", "Default", "Quitter", args)

myGui.AutoSize()
;MsgBox, % myGui.pos.ToStr() "`n`nW: " GridGUI.Util.Sum(myGui.grid.widths) "`nH: " GridGUI.Util.Sum(myGui.grid.heights)
myGui.pos.w := GridGUI.Util.Sum(myGui.grid.widths)
myGui.pos.h := GridGUI.Util.Sum(myGui.grid.heights)
myGui.MinSize()
myGui.Show("w" myGui.pos.w " h" myGui.pos.h)
Return
In regards to testing the 'id/name' of the controls in the callbacks, I am not sure what you are asking about, could you make an example script in normal ahk that is without my lib that does what you want, so that I can get a better understanding of the issue?

Edit: I forgot to explain how the workaround worked. It first draws the GUI using myGui.AutoSize() it then takes the combined width and height of the cells and put them in myGui.pos before applying myGui.MinSize() so that all the cells are fully visible. and then finally it calls myGui.Show("w" myGui.pos.w " h" myGui.pos.h) with the width and height that was put in myGui.pos.
Please excuse my spelling I am dyslexic.

ozzii
Posts: 481
Joined: 30 Oct 2013, 06:04

Re: GridGUI v1.1.10 - Simplify Control Placement and Resizing

Post by ozzii » 12 Oct 2021, 06:07

For example :
I have

Code: Select all

bt1 := myGui.Add(1, 2, "Button", , "bt1 -> Y", args)
bt1.callback := Func("bt1").Bind(bt1)
And I use a switch command.
But instead of doing

Code: Select all

switch bt1.vVar {
case "bt1 -> Y":
msgbox
return
}
Something like

Code: Select all

switch bt1.vName {
case "bt1":
msgbox
return
}
Here, the vName is the bt1 of bt1 := myGui.Add(1, 2, "Button", , "bt1 -> Y", args)
So it's easier to test "bt1" than "bt1 -> Y".
And If I change the text of the button I don't need to change the switch case.
I hope that this is clearer :oops:

Thank you for the GUI patch :clap:

User avatar
Capn Odin
Posts: 1352
Joined: 23 Feb 2016, 19:45
Location: Denmark
Contact:

Re: GridGUI v1.1.10 - Simplify Control Placement and Resizing

Post by Capn Odin » 12 Oct 2021, 10:02

ozzii wrote:
12 Oct 2021, 06:07
For example :
I have

Code: Select all

bt1 := myGui.Add(1, 2, "Button", , "bt1 -> Y", args)
bt1.callback := Func("bt1").Bind(bt1)
And I use a switch command.
But instead of doing

Code: Select all

switch bt1.vVar {
case "bt1 -> Y":
msgbox
return
}
Something like

Code: Select all

switch bt1.vName {
case "bt1":
msgbox
return
}
Here, the vName is the bt1 of bt1 := myGui.Add(1, 2, "Button", , "bt1 -> Y", args)
So it's easier to test "bt1" than "bt1 -> Y".
And If I change the text of the button I don't need to change the switch case.
I hope that this is clearer :oops:

Thank you for the GUI patch :clap:
Yeah, it is clear to me now. I don't think that there is a way for me to retrieve the variable name but I can think of two ways to do what you are after. The first way is to bind another parameter that is used in the switch statement. The second way is to use the hwnd of the controls in the function by including them in the scope using Global statement. Personally, I prefer the first option but here are examples of them both.
First Option:

Code: Select all

#Include <GridGUI>

args := {exW: 1, exH: 1, fillW: true, fillH: false}
myGui := new GridGUI("CTM", "resize")
myGui.GuiClose := GridGUI.ExitApp
myGui.Color("4389A5")
myGui.Font("bold s13")
			   myGui.Add("1-2", 1, "Text", "cWhite", "● Relance CTM ●", , , , , "C")
myGui.Font("normal s11")

bt1			:= myGui.Add(1,		2, "Button", , "bt1 -> Y", args)
bt1_sans	:= myGui.Add(2,		2, "Button", , "bt1 -> N", args)
bt2			:= myGui.Add(1,		3, "Button", , "bt2", args)
bt3			:= myGui.Add(2,		3, "Button", , "bt3", args)
bt4			:= myGui.Add(1,		4, "Button", , "bt4 -> Y", args)
bt4_sans	:= myGui.Add(2,		4, "Button", , "bt4 -> N", args)
Demat		:= myGui.Add("1-2",	5, "Button", , "Démat factures", args)
Fichier		:= myGui.Add(1,		6, "Button", , "Fichiers 1C/1V...", args)
HR			:= myGui.Add(2,		6, "Button", , "Demandes DSN/HR", args)

			   myGui.Add("1-2", 11, "Text", "cWhite", "", , , , , "C")
btq			:= myGui.Add("1-2", 12, "Button", "Default", "Quitter", args)

bt1.callback		:= Func("Fun").Bind("bt1",		bt1)
bt1_sans.callback	:= Func("Fun").Bind("bt1_sans",	bt1_sans)
bt2.callback		:= Func("Fun").Bind("bt2",		bt2)
bt3.callback		:= Func("Fun").Bind("bt3",		bt3)
bt4.callback		:= Func("Fun").Bind("bt4",		bt4)
bt4_sans.callback	:= Func("Fun").Bind("bt4_sans",	bt4_sans)
Demat.callback		:= Func("Fun").Bind("Demat",	Demat)
Fichier.callback	:= Func("Fun").Bind("Fichier",	Fichier)
HR.callback			:= Func("Fun").Bind("HR",		HR)
btq.callback		:= Func("Fun").Bind("btq",		btq)

myGui.AutoSize()
;MsgBox, % myGui.pos.ToStr() "`n`nW: " GridGUI.Util.Sum(myGui.grid.widths) "`nH: " GridGUI.Util.Sum(myGui.grid.heights)
myGui.pos.w := GridGUI.Util.Sum(myGui.grid.widths)
myGui.pos.h := GridGUI.Util.Sum(myGui.grid.heights)
myGui.MinSize()
myGui.Show("w" myGui.pos.w " h" myGui.pos.h)
Return

Fun(name, ctrl) {
	switch name {
		case "bt1":
			MsgBox, % "You pressed bt1"
		case "bt1_sans":
			MsgBox, % "You pressed bt1_sans"
		case "bt2":
			MsgBox, % "You pressed bt2"
		case "bt3":
			MsgBox, % "You pressed bt3"
		case "bt4":
			MsgBox, % "You pressed bt4"
		case "bt4_sans":
			MsgBox, % "You pressed bt4_sans"
		case "Demat":
			MsgBox, % "You pressed Demat"
		case "Fichier":
			MsgBox, % "You pressed Fichier"
		case "HR":
			MsgBox, % "You pressed HR"
		case "btq":
			MsgBox, % "You pressed btq"
	}
}
Second Option:

Code: Select all

#Include <GridGUI>

args := {exW: 1, exH: 1, fillW: true, fillH: false}
myGui := new GridGUI("CTM", "resize")
myGui.GuiClose := GridGUI.ExitApp
myGui.Color("4389A5")
myGui.Font("bold s13")
			   myGui.Add("1-2", 1, "Text", "cWhite", "● Relance CTM ●", , , , , "C")
myGui.Font("normal s11")

bt1			:= myGui.Add(1,		2, "Button", , "bt1 -> Y", args)
bt1_sans	:= myGui.Add(2,		2, "Button", , "bt1 -> N", args)
bt2			:= myGui.Add(1,		3, "Button", , "bt2", args)
bt3			:= myGui.Add(2,		3, "Button", , "bt3", args)
bt4			:= myGui.Add(1,		4, "Button", , "bt4 -> Y", args)
bt4_sans	:= myGui.Add(2,		4, "Button", , "bt4 -> N", args)
Demat		:= myGui.Add("1-2",	5, "Button", , "Démat factures", args)
Fichier		:= myGui.Add(1,		6, "Button", , "Fichiers 1C/1V...", args)
HR			:= myGui.Add(2,		6, "Button", , "Demandes DSN/HR", args)

			   myGui.Add("1-2", 11, "Text", "cWhite", "", , , , , "C")
btq			:= myGui.Add("1-2", 12, "Button", "Default", "Quitter", args)

bt1.callback		:= Func("Fun").Bind(bt1)
bt1_sans.callback	:= Func("Fun").Bind(bt1_sans)
bt2.callback		:= Func("Fun").Bind(bt2)
bt3.callback		:= Func("Fun").Bind(bt3)
bt4.callback		:= Func("Fun").Bind(bt4)
bt4_sans.callback	:= Func("Fun").Bind(bt4_sans)
Demat.callback		:= Func("Fun").Bind(Demat)
Fichier.callback	:= Func("Fun").Bind(Fichier)
HR.callback			:= Func("Fun").Bind(HR)
btq.callback		:= Func("Fun").Bind(btq)

myGui.AutoSize()
;MsgBox, % myGui.pos.ToStr() "`n`nW: " GridGUI.Util.Sum(myGui.grid.widths) "`nH: " GridGUI.Util.Sum(myGui.grid.heights)
myGui.pos.w := GridGUI.Util.Sum(myGui.grid.widths)
myGui.pos.h := GridGUI.Util.Sum(myGui.grid.heights)
myGui.MinSize()
myGui.Show("w" myGui.pos.w " h" myGui.pos.h)
Return

Fun(ctrl) {
	Global bt1, bt1_sans, bt2, bt3, bt4, bt4_sans, Demat, Fichier, HR, btq
	switch ctrl.hwnd {
		case bt1.hwnd:
			MsgBox, % "You pressed bt1"
		case bt1_sans.hwnd:
			MsgBox, % "You pressed bt1_sans"
		case bt2.hwnd:
			MsgBox, % "You pressed bt2"
		case bt3.hwnd:
			MsgBox, % "You pressed bt3"
		case bt4.hwnd:
			MsgBox, % "You pressed bt4"
		case bt4_sans.hwnd:
			MsgBox, % "You pressed bt4_sans"
		case Demat.hwnd:
			MsgBox, % "You pressed Demat"
		case Fichier.hwnd:
			MsgBox, % "You pressed Fichier"
		case HR.hwnd:
			MsgBox, % "You pressed HR"
		case btq.hwnd:
			MsgBox, % "You pressed btq"
	}
}
Please excuse my spelling I am dyslexic.

ozzii
Posts: 481
Joined: 30 Oct 2013, 06:04

Re: GridGUI v1.1.10 - Simplify Control Placement and Resizing

Post by ozzii » 13 Oct 2021, 09:17

Thank you again @Capn Odin for the detailed explanation
I will use the first option (it's somehow prettier ;) ).

User avatar
Capn Odin
Posts: 1352
Joined: 23 Feb 2016, 19:45
Location: Denmark
Contact:

Re: GridGUI v1.1.11 - Simplify Control Placement and Resizing

Post by Capn Odin » 06 Nov 2021, 12:13

Quick update on the state of the docs and the newest release.

I updated the way that the class reference is styled to hopefully make it easier to read, any feedback on the current format of the class reference is greatly appreciated.

I recently released version 1.1.11 which added a gdi control and support for setting aspect ratios for cells, but I had forgotten to include one of the changes in the main class interface so I have made a quick extra update to make sure to get the newest commit if you want to try it out.

Edit: the documentation for the control classes is still not completely finished.
Please excuse my spelling I am dyslexic.

ozzii
Posts: 481
Joined: 30 Oct 2013, 06:04

Re: GridGUI v1.1.11 - Simplify Control Placement and Resizing

Post by ozzii » 21 Mar 2023, 02:34

Sorry for diging the post ;)
How can I do to make my Edit box (ed) focused after the show of the gui?
I have this (just an extract of the code)

Code: Select all

myGui.Font("normal s11 cBlack")
ed := myGui.Add(1, 4, "Edit", , , 1, , 1)
btv := myGui.Add(1, 5, "Button", "Default", "Convert", args)
btv.callback := Func("Result").Bind(ed, RG1)
myGui.AutoSize()
myGui.MinSize()
myGui.Show()
Return

Post Reply

Return to “Scripts and Functions (v1)”