AutoHotkey Community

It is currently May 27th, 2012, 8:37 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 172 posts ]  Go to page 1, 2, 3, 4, 5 ... 12  Next
Author Message
PostPosted: July 7th, 2005, 2:39 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
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 polyethene on September 29th, 2009, 3:13 pm, edited 17 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 21st, 2005, 11:04 pm 
Offline

Joined: September 2nd, 2004, 1:08 am
Posts: 124
Location: Sunnyvale
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! :D

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... :roll:

_________________
I am he of whom he speaks!


Last edited by Atomhrt on October 22nd, 2005, 3:41 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 21st, 2005, 11:54 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
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 :wink:. Glad you liked it anyway.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 22nd, 2005, 1:31 am 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
Great script. It should probably be one of the things put in the forthcoming library of standard include files.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 16th, 2006, 12:32 am 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
I updated the function again. This time it's even easier to use.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 22nd, 2006, 10:20 am 
Offline

Joined: August 15th, 2005, 7:15 am
Posts: 107
Location: North Carolina
Thank You, Titan.

Bob

_________________
When it comes to Binary, there are 10 types of people. Those who get it and those who don't. :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 22nd, 2006, 12:53 pm 
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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 22nd, 2006, 8:05 pm 
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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 22nd, 2006, 8:31 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
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).

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 23rd, 2006, 9:10 am 
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.

Image

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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 23rd, 2006, 10:55 am 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
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.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 12th, 2006, 9:11 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
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.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 12th, 2006, 9:38 pm 
Offline

Joined: March 28th, 2004, 3:53 pm
Posts: 1870
Titan,
I got late in testing out this nice function... its very well-made and works great.. thanks for posting!

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 12th, 2006, 10:54 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
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 :roll:

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 13th, 2006, 2:29 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
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.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 172 posts ]  Go to page 1, 2, 3, 4, 5 ... 12  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: AndyJenk, Aravind, hyper_, xXDarknessXx and 11 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group