 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Titan
Joined: 11 Aug 2004 Posts: 4975 Location: /b/
|
Posted: Thu Jul 07, 2005 1:39 pm Post subject: Control Anchoring v4 for resizing windows |
|
|
This function defines how controls should be automatically positioned relatively to the new dimensions of a GUI when resized (see example).
Download
Last edited by Titan on Tue Sep 29, 2009 2:13 pm; edited 17 times in total |
|
| Back to top |
|
 |
Atomhrt
Joined: 02 Sep 2004 Posts: 124 Location: Sunnyvale
|
Posted: Fri Oct 21, 2005 10:04 pm Post subject: |
|
|
| Titan wrote: | * Just updated, it works much better now  |
I use it and another function almost just like it to resize one of my GUI's. It has 29 controls (that are run through the functions) including one listview and four tabs. Works great!
One thing that I did because I'm so lazy, is changed the order of the params to the function...
From:
Anchor(Control, Anchors="", x=0, y=0, w=0, h=0)
To:
Anchor(x=0, y=0, w=0, h=0, Control, Anchors="")
This made it a bit easier to create the call for most of the controls since it somewhat follows the format of most of my GUI, Add statements. That is, the x-y-h-w coords first usually followed by a variable name. Using a few find and replace statements with my editor could then do most of the work. Hope that makes sense...  _________________ I am he of whom he speaks!
Last edited by Atomhrt on Sat Oct 22, 2005 2:41 pm; edited 1 time in total |
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 4975 Location: /b/
|
Posted: Fri Oct 21, 2005 10:54 pm Post subject: |
|
|
| Atomhrt wrote: | | One thing that I did because I'm so lazy, is changed the order or params to the function... |
The open source is there so you can customize it to your needs . Glad you liked it anyway. |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10667
|
Posted: Sat Oct 22, 2005 12:31 am Post subject: |
|
|
| Great script. It should probably be one of the things put in the forthcoming library of standard include files. |
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 4975 Location: /b/
|
Posted: Sat Apr 15, 2006 11:32 pm Post subject: |
|
|
I updated the function again. This time it's even easier to use. _________________
 |
|
| Back to top |
|
 |
Terrapin
Joined: 15 Aug 2005 Posts: 107 Location: North Carolina
|
Posted: Sat Apr 22, 2006 9:20 am Post subject: |
|
|
Thank You, Titan.
Bob _________________ When it comes to Binary, there are 10 types of people. Those who get it and those who don't.  |
|
| Back to top |
|
 |
AGU Guest
|
Posted: Sat Apr 22, 2006 11:53 am Post subject: |
|
|
| Quote: | | It should probably be one of the things put in the forthcoming library of standard include files. | Does this library already exist?
___________________
Cheers
AGU |
|
| Back to top |
|
 |
AGU Guest
|
Posted: Sat Apr 22, 2006 7:05 pm Post subject: |
|
|
It's me again. As I'm using an older version of this function in BBCodeWriter I thought about updating to your new one. But I don't get the point of how to use it. Could you give me a short example?
I meanwhile took your old function and replaced GuiControl, Move with GuiControl, MoveDraw to workaround a displaying error when resizing the GUI in x-direction.
This is your older one:
| Code: | Anchor(Control, Anchors="", x=0, y=0, w=0, h=0)
{
; Thanks to Titan for this function
; Details under http://www.autohotkey.com/forum/viewtopic.php?p=26778
; Control : Variable assigned to the control (e.g. "MyEdit")
; Anchors : How control to be moved (e.g. "xy" for position or "wh" for size)
; x, y, w, h : respective values of control
; (note you can omit values that aren't needed by the Anchors by putting any value)
global GuiW, GuiH
If (not Anchors)
Anchors = xy
If Anchors contains x
GuiControl, MoveDraw, % Control, % "x" x+(A_GuiWidth-GuiW)
If Anchors contains y
GuiControl, MoveDraw, % Control, % "y" y+(A_GuiHeight-GuiH)
If Anchors contains w
GuiControl, MoveDraw, % Control, % "w" w+(A_GuiWidth-GuiW)
If Anchors contains h
GuiControl, MoveDraw, % Control, % "h" h+(A_GuiHeight-GuiH)
} |
I call it this way:
| Code: | ...
Anchor("EdtComment", "wh", 0, 0, EdtW, EdtH)
Anchor("GrpMenuBorder", "w", 0, 0, GrpW, 0)
Anchor("ChkSig", "y", 0, ChkY, 0, 0)
Anchor("DDLSig", "y", 0, DDLY, 0, 0)
Anchor("BtnEditSig", "y", 0, BSgY, 0, 0)
Anchor("BtnDelSig", "y", 0, BSgY, 0, 0)
Anchor("BtnSend", "xy", BG1X, BG3Y, 0, 0)
Anchor("BtnPreview", "xy", BG2X, BG3Y, 0, 0)
Anchor("BtnReset", "xy", BG3X, BG3Y, 0, 0)
Anchor("BtnPinned", "x", BG4X, 0, 0, 0)
... |
How would I have to call your updated function? I tried to remove all anchors to make the syntax compatible to your new function but it didn't work.
| Code: | | Anchor("EdtComment", 0, 0, EdtW, EdtH) |
_______________
Cheers
AGU |
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 4975 Location: /b/
|
Posted: Sat Apr 22, 2006 7:31 pm Post subject: |
|
|
Replace the 0's with a blank value (i.e. ""). If you want to force a MoveDraw, specify an extra parameter of 1. Using your code the correct version would be: Anchor("EdtComment", "", "", EdtW, EdtH, 1). _________________
 |
|
| Back to top |
|
 |
AGU Guest
|
Posted: Sun Apr 23, 2006 8:10 am Post subject: |
|
|
Thx Titan. I made the changes and it works great.
btw. wouldn't it be better to set Draw to 1? Because I spotted this displaying error when resizing a GUI in x-direction when using a normal move instead of a MoveDraw.
Therefore I predefined Draw to 1:
| Code: | Anchor(Control, x=0, y=0, w=0, h=0, Draw=1)
{
; Thanks to Titan for this function
; Details under http://www.autohotkey.com/forum/viewtopic.php?p=26778
; Control : Variable assigned to the control (e.g. "MyEdit")
; x, y, w, h : the anchor positions/dimensions
; Draw : false/0 to use Move otherwise leave blank for a MoveDraw
global GuiW, GuiH
IfEqual, GuiW
{
SetEnv, GuiW, %A_GuiWidth%
}
IfEqual, GuiH
{
SetEnv, GuiH, %A_GuiHeight%
}
pos = xywh
Loop, Parse, pos
{
If (%A_LoopField% != "")
{
If A_LoopField in x,w
{
v := %A_LoopField% + (A_GuiWidth - GuiW)
}
Else
{
v := %A_LoopField% + (A_GuiHeight - GuiH)
}
move := move . A_LoopField . v
}
IfNotEqual, Draw, 0
{
SetEnv, MDraw, Draw
}
}
GuiControl, Move%MDraw%, %Control%, %move%
Return, ErrorLevel
} |
__________________
Cheers
AGU |
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 4975 Location: /b/
|
Posted: Sun Apr 23, 2006 9:55 am Post subject: |
|
|
Setting Draw to 1 means a MoveDraw will be used instead. MoveDraw causes flickering with other controls like Edit so the standard Draw is better. If you have more buttons in your GUI then you can set Draw to 1 in the first line of the function without having to change anything else. _________________
 |
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 4975 Location: /b/
|
Posted: Sat Aug 12, 2006 8:11 pm Post subject: |
|
|
In version 2 you don't need to define GuiW or GuiH for multiple GUI's. I've also combined the x/y/w/h params so it's similar to GuiControl - see the example.
Older versions are still available for download. _________________
 |
|
| Back to top |
|
 |
Rajat
Joined: 28 Mar 2004 Posts: 1687
|
Posted: Sat Aug 12, 2006 8:38 pm Post subject: |
|
|
Titan,
I got late in testing out this nice function... its very well-made and works great.. thanks for posting! _________________
 |
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 4975 Location: /b/
|
Posted: Sat Aug 12, 2006 9:54 pm Post subject: |
|
|
Thanks. I have a bad habbit of not commenting my scripts and using short/cryptic variable names so I have to apologize if parts were hard to understand. Atleast this means they're smaller in size thus include-friendly  _________________
 |
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 4975 Location: /b/
|
Posted: Sun Aug 13, 2006 1:29 pm Post subject: |
|
|
Version 3 is much easier to use. The function does all the calculations itself so resizing with multiple windows and relatively positioned controls are not a problem at all. For example you can call Anchor("MyEdit", "wh") without having to specify the width, height or window number. _________________
 |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|