Introduction
GridGUI is a library that allows placing Controls relative to eachother without being limited in the order that they are placed, as well as automatically resizing Controls.
How it works: By adding Controls to an instance of GridGUI they will be placed relative to each other so that no row/column will ever be in another although they can have zero area.
You will need: The main source file and the lib directory in the same directory, if you add it to your lib directory then you might want to change the name of the lib directory from this project.
After inclusion of GridGUI.ahk in a script a GridGUI can be made like this.
Code: Select all
myGui := new GridGUI("Title", Options := "resize")
Code: Select all
myGui.Show()
Code: Select all
myGui.Add(row := 1, column := 1, type := "Button", options := "", text := "A Button")
Expand
To make the grid cell auto-expand in both height and width, when additional space is available, add the following two arguments.
Code: Select all
myGui.Add(1, 1, "Button", , "A Button", exW := 1, exH := 1)
Fill
Alternatively, you make it fill out the cells that the control is defined in by using these two arguments. This can be useful when aligning Controls.
Code: Select all
myGui.Add(1, 1, "Button", , "A Longer Button")
myGui.Add(1, 2, "Button", , "A Button", , , fillW := 1, fillH := 0)
myGui.Add(1, 3, "Button", , "A Button", , , fillW := 1, fillH := 0)
Auto Resizing Controls
Combining the previous two options makes the Control automatically expand.
Code: Select all
myGui.Add(1, 1, "Button", , "A Button", exW := 1, exH := 1, fillW := 1, fillH := 1)
Spanning
When adding a Control it is posible to make it span multriple rows and or columns using a string on the format start-end
Code: Select all
#Include <GridGUI>
myGui := new GridGUI("Title", Options := "resize")
myGui.Add(1, 1, "Button", , "A Longer Button")
myGui.Add(1, 2, "Button", , "A Button", , , fillW := 1, fillH := 0)
myGui.Add(1, 3, "Button", , "A Button", , , fillW := 1, fillH := 0)
myGui.Add(2, "1-3", "Button", , "An Expanding Button", exW := 1, exH := 1, fillW := 1, fillH := 1)
myGui.Show()
Overlapping Controls
Controls can be put in the same cells. Take care the order that overlapping controls are put into the GridGUI is no longer arbitrary and can affect the resulting look, for instance, if the background image is added before the ActiveX Control in the Backgound Example the ActiveX Control will not be visible.
Code: Select all
myGui.Add("1-3", "1-3", "GroupBox", "w40 h40", "Title", , , 1, 1)
myGui.Add(2, 2, "Button", "w50 h50", "Button", 1, 1, 1, 1)
Justify
The position of a Control inside of a cell can be set to one of 9 positions by using the Justify parameter.
Code: Select all
myGui.Add(1, 1, "Button", {justify:"CN", text:"N", exW:1, exH:1})
myGui.Add(1, 1, "Button", {justify:"CNE", text:"NE", exW:1, exH:1})
myGui.Add(1, 1, "Button", {justify:"CE", text:"E", exW:1, exH:1})
myGui.Add(1, 1, "Button", {justify:"CSE", text:"SE", exW:1, exH:1})
myGui.Add(1, 1, "Button", {justify:"CS", text:"S", exW:1, exH:1})
myGui.Add(1, 1, "Button", {justify:"CSW", text:"SW", exW:1, exH:1})
myGui.Add(1, 1, "Button", {justify:"CW", text:"W", exW:1, exH:1})
myGui.Add(1, 1, "Button", {justify:"CNW", text:"NW", exW:1, exH:1})
myGui.Add(1, 1, "Button", {justify:"C", text:"C", exW:1, exH:1})
Debug
To help debug issues there is an option available when making a GridGUI instance that shows the dividing grid lines.
Code: Select all
myGui := new GridGUI("Title", Options := "resize", showGrid := true)
User Input
When adding a Control an instance of ControlClass is returned allowing access to vVars, hwnd and setting up gLabels.
Code: Select all
bt := myGui.Add(1, 1, "Button", , "A Button")
bt.callback := Func("ToolTip").Bind("You Pressed the Button")
ToolTip(text) {
ToolTip, % text
}
Docs: See https://capnodin.github.io/GridGUI/
Source: See https://github.com/CapnOdin/GridGUI
Examples: See https://github.com/CapnOdin/GridGUI/tree/master/Examples
Issues:
Doesn't support overlapping Controls that is only one Control can be at any given grid cell.- Due to me being dumb and not being able to calculate the positions and sizes correctly some of the computations happen after the GUI have been resized to correct mistakes, otherwise most computations are done when a Control is added.
Controls are sized wrong on systems with non-standard DPI.- Groupboxes can't currently be easily made to look good as the margin of the box relative to the content is not currently configurable, a workaround is to add an invisible control to each corner of the box.
MinSize of controls are currently not being handled correctly when the GUI has less width than the controls require.- The wrappers classes seem to be having some issues when using default arguments as an empty string is interpreted as non-default in some functions, if you find any such function please post a message so that I can fix it.
- Changes to the DPI after the GUI has been created will not be handled properly.
It is currently not possible to set a callback on TabControls as the callback is used to draw the selected tab.Overlapping controls prevent user input (Example Background.ahk)- And probably a lot of other issues.