Jump to content


Photo

Control Anchoring v4 for resizing windows


  • Please log in to reply
76 replies to this topic

#1 polyethene

polyethene

    Administrator

  • Administrators
  • 5474 posts

Posted 07 July 2005 - 01:39 PM

This function defines how controls should be automatically positioned relatively to the new dimensions of a GUI when resized (see example).

Download

#2 Atomhrt

Atomhrt
  • Members
  • 124 posts

Posted 21 October 2005 - 10:04 PM

* 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:

#3 polyethene

polyethene

    Administrator

  • Administrators
  • 5474 posts

Posted 21 October 2005 - 10:54 PM

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.

#4 Chris

Chris
  • Administrators
  • 10727 posts

Posted 22 October 2005 - 12:31 AM

Great script. It should probably be one of the things put in the forthcoming library of standard include files.

#5 polyethene

polyethene

    Administrator

  • Administrators
  • 5474 posts

Posted 15 April 2006 - 11:32 PM

I updated the function again. This time it's even easier to use.

#6 Terrapin

Terrapin
  • Members
  • 107 posts

Posted 22 April 2006 - 09:20 AM

Thank You, Titan.

Bob

#7 AGU

AGU
  • Guests

Posted 22 April 2006 - 11:53 AM

It should probably be one of the things put in the forthcoming library of standard include files.

Does this library already exist?
___________________
Cheers
AGU

#8 AGU

AGU
  • Guests

Posted 22 April 2006 - 07: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:
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:
...
      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.
Anchor("EdtComment", 0, 0, EdtW, EdtH)
_______________
Cheers
AGU

#9 polyethene

polyethene

    Administrator

  • Administrators
  • 5474 posts

Posted 22 April 2006 - 07:31 PM

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).

#10 AGU

AGU
  • Guests

Posted 23 April 2006 - 08: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.

Posted Image

Therefore I predefined Draw to 1:
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

#11 polyethene

polyethene

    Administrator

  • Administrators
  • 5474 posts

Posted 23 April 2006 - 09:55 AM

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.

#12 polyethene

polyethene

    Administrator

  • Administrators
  • 5474 posts

Posted 12 August 2006 - 08:11 PM

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.

#13 Rajat

Rajat
  • Members
  • 1886 posts

Posted 12 August 2006 - 08:38 PM

Titan,
I got late in testing out this nice function... its very well-made and works great.. thanks for posting!

#14 polyethene

polyethene

    Administrator

  • Administrators
  • 5474 posts

Posted 12 August 2006 - 09:54 PM

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:

#15 polyethene

polyethene

    Administrator

  • Administrators
  • 5474 posts

Posted 13 August 2006 - 01:29 PM

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.