Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Control Anchoring v4 for resizing windows


  • Please log in to reply
78 replies to this topic
polyethene
  • Members
  • 5519 posts
  • Last active: May 17 2015 06:39 AM
  • Joined: 26 Oct 2012

I don't get this thing with the factors e.g. x0.5. What's it good for?

Click to open the second window in the example script on the front page.

Then I'd like to ask if it would be possible to get a commented version of your new script (just like toralf but for the new version ;))?

I never comment my scripts, I find it confusing lol. Chris taught me the importance of commenting and I tried to make it a habit, but I guess I'm too lazy sometimes. I'll post a commented version soon.

Do I have to change s.th here or could I just paste your new version over the old one?

Version 1.x, 2.x nor 3.x are not compatible with each other. For v3 you'll have to make calls like this instead (you won't need to get control positions!):
Anchor("EdtComment", "wh")
Anchor("GrpMenuBorder", "w")
Anchor("ChkSig", "y")
Anchor("DDLSig", "y")
Anchor("BtnEditSig", "y")
Anchor("BtnDelSig", "y")
Anchor("BtnSend", "xy", true)
Anchor("BtnPreview", "xy", true)
Anchor("BtnReset", "xy", true)
Anchor("BtnPinned", "x")
If you have many more controls and speed is not an issue you can use a fancy parser:
a = EdtComment: wh, GrpMenuBorder: w, ChkSig: y, DDLSig: y, BtnEditSig: y
	, BtnDelSig: y, BtnSend: xy draw, BtnPreview: xy draw, BtnReset: xy draw
	, BtnPinned: x

Loop, Parse, a, `,, %A_Space%
{
	StringSplit, a, A_LoopField, :
	a3 := InStr(a2, "draw")
	Anchor(a1, a3 ? SubStr(a2, 1, a3 - 1) : a2, !!a3)
}

autohotkey.com/net Site Manager

 

Contact me by email (polyethene at autohotkey.net) or message tidbit


AGU
  • Guests
  • Last active:
  • Joined: --
hmm, Ok I checked the example but I don't get it.

Could you maybe describe this factors feature in some words? What would e.g. x0.5 do? Sorry if this a dumb question but I'm having a dumb moment. ;)
_______________________
Cheers
AGU

AGU
  • Guests
  • Last active:
  • Joined: --
Hi Titan,

still waiting for the commented version ;) :mrgreen:

My ambition is always to only use code which I fully understand. That's why I started studying your new code (v3) line by line. I even managed to understand this first regex (puh, that was a tough job :)). But now I'm stuck and would be happy about a commented version.

If it's not asked too much, I would be happy about some words about the basic mechanism behind the script. How are these positions calculated with the help of A_GuiWidth and A_GuiHeight. You don't have to, if you think this is too much. :) Sooner or later I will get it by studying the script but any help would be cool.
______________________
Cheers
AGU

polyethene
  • Members
  • 5519 posts
  • Last active: May 17 2015 06:39 AM
  • Joined: 26 Oct 2012
Oh sorry about that, I started and left it half way to work on a javascript for this forum. I'll try have it ready by around this time tomorrow, thanks.

autohotkey.com/net Site Manager

 

Contact me by email (polyethene at autohotkey.net) or message tidbit


polyethene
  • Members
  • 5519 posts
  • Last active: May 17 2015 06:39 AM
  • Joined: 26 Oct 2012
Phew, done: https://ahknet.autoh... ... .1-RFC.ahk

autohotkey.com/net Site Manager

 

Contact me by email (polyethene at autohotkey.net) or message tidbit


skwire
  • Moderators
  • 279 posts
  • Last active: Aug 12 2014 05:16 PM
  • Joined: 18 Jan 2006
Titan, this may be a bug in the Anchor script. Example code:

Gui, +Resize
Gui, Margin, 10, 10
Gui, Add, ListView, xm ym+20  w200 h100 Grid vlv_One, One|Two|Three
Gui, Add, ListView, xm ym+140 w200 h200 Grid vlv_Two , Four|Five|Six
Gui, Add, StatusBar
Gui, Show, Autosize Center
Return
; ------------------------------------------------------------------------

GuiEscape:
GuiClose:
ExitApp

; ------------------------------------------------------------------------

GuiSize:
{
    ; This works perfectly...
    
    Anchor( "lv_One", "w h0.2", 1 )
    Anchor( "lv_Two", "y0.2 w", 1 )
    
    ; ...but, I want the bottom listview to resize vertically as well so I
    ; add the 'h'.  
    
    ; Anchor( "lv_Two", "y0.2 w h", 1 )
    
    ; However, when I add the 'h', the bottom listview disappears (or is
    ; somewhere off the main form).
    
    ; Furthermore, if you take out the 'y' param, it does what it should
    ; (except, of course, that the bottom listview doesn't move up/down now).
    
    ; Anchor( "lv_Two", "w h", 1 )
}
Return

; ------------------------------------------------------------------------

Anchor( ctrl, a, draw = false ) { ; v3.4.1 - Titan
	static d
	GuiControlGet, p, Pos, %ctrl%
	If !A_Gui or ErrorLevel
		Return
	s = `n%A_Gui%:%ctrl%=
	c = x.w.y.h./.7.%A_GuiWidth%.%A_GuiHeight%
	StringSplit, c, c, .
	Loop, 4
		b%A_Index% += !RegExMatch(a, c%A_Index% . "(?P<" . A_Index . ">[\d.]+)", b)
	If !InStr(d, s)
		d := d . s . px - c7 * b1 . c5 . pw - c7 * b2
			. c5 . py - c8 * b3 . c5 . ph - c8 * b4 . c5
	Loop, 4
		If InStr(a, c%A_Index%) {
			i = %A_Index%
			c6 += i > 2
			RegExMatch(d, s . "(?:(-?[\d.]+)/){" . i . "}", p)
			m := m . c%i% . p1 + c%c6% * b%i%
		}
	If draw
		t = Draw
	GuiControl, Move%t%, %ctrl%, %m%
}

; ------------------------------------------------------------------------

If my examples weren't clear enough, please let me know. As always, thanks for the Anchor script. =]

polyethene
  • Members
  • 5519 posts
  • Last active: May 17 2015 06:39 AM
  • Joined: 26 Oct 2012
Thanks for the example, I fixed this bug in version 3.4.2 with c6 += !t and (t := i > 2) to prevent repetitive increments so height values are calculated properly.

autohotkey.com/net Site Manager

 

Contact me by email (polyethene at autohotkey.net) or message tidbit


skwire
  • Moderators
  • 279 posts
  • Last active: Aug 12 2014 05:16 PM
  • Joined: 18 Jan 2006
Thank you very much. If anybody is interested, the final Anchor calls to do what I want look like this (using my example code above):

Anchor( "lv_One", "w h0.2", 1 )
Anchor( "lv_Two", "y0.2 w h0.8", 1 )


skwire
  • Moderators
  • 279 posts
  • Last active: Aug 12 2014 05:16 PM
  • Joined: 18 Jan 2006
Upon further testing of apps I've written that use the Anchor function, it seems that this latest version has broken controls when using Move mode. If you set those controls to MoveDraw mode, they work as before.

polyethene
  • Members
  • 5519 posts
  • Last active: May 17 2015 06:39 AM
  • Joined: 26 Oct 2012
My mistake sorry, the variable 't' is used for the Move/Draw part. I left the version number the same so just download it again.

autohotkey.com/net Site Manager

 

Contact me by email (polyethene at autohotkey.net) or message tidbit


skwire
  • Moderators
  • 279 posts
  • Last active: Aug 12 2014 05:16 PM
  • Joined: 18 Jan 2006
Beautiful. Thanks again.

AGU
  • Guests
  • Last active:
  • Joined: --
Hi Titan,

I have "AGUnized" your Anchor function. :lol:

Anchor(In_CtrlVar, In_Anchor, Draw = false) 
  { 
    ; Thanks to Titan for this function (v3.4.2)
    ; Details under http://www.autohotkey.com/forum/topic4348.html
    
    ; In_CtrlVar  : Controls associated variable (e.g. "MyEdit")
    ; In_Anchor   : Anchors (x, y, w, h)
    ; Draw        : true/1 to use MoveDraw otherwise leave blank for a normal Move  
  
    ; store control positions and sizes in an internally parsable table-like format
    static DataTbl
  	
    ; Retrieve control's size and position
    GuiControlGet, CtrlPS, Pos, %In_CtrlVar%
    ; If control doesn't exist or this thread isn't called by a GUI event... 
    If !A_Gui or ErrorLevel
      Return
  	
    ; Create identifier for the control in the current window
    Signtre = `n%A_Gui%:%In_CtrlVar%=
    ; Period-delimited variable for parsing support
    PrsHlp = x.w.y.h./.7.%A_GuiWidth%.%A_GuiHeight%
    StringSplit, PrsHlp, PrsHlp, .
  	
    ; Retrieve relative factors by RegEx and store them into "RelFact" array
    Loop, 4
      RelFact%A_Index% += !RegExMatch(In_Anchor, PrsHlp%A_Index% . "(?P<" . A_Index . ">[\d.]+)", RelFact)

    ; If current signature is not found in the data table, concatenate each value 
    ; subtracted by the gui width for x/w or height for y/h and multiplied by it's factor.
    If !InStr(DataTbl, Signtre)
      DataTbl := DataTbl . Signtre . CtrlPSX - PrsHlp7 * RelFact1 . PrsHlp5 . CtrlPSW - PrsHlp7 * RelFact2
              .  PrsHlp5 . CtrlPSY - PrsHlp8 * RelFact3 . PrsHlp5 . CtrlPSH - PrsHlp8 * RelFact4 . PrsHlp5
  	
    ; For each of the four possible anchors (again):
    Loop, 4
      If InStr(In_Anchor, PrsHlp%A_Index%) 
        {
          ; Alias for the Loop index
          LoopIdx = %A_Index%
          ; For x/w, PrsHlp6 equals to the GUI width, otherwise height 
        	PrsHlp6 += !cx AND (cx := LoopIdx > 2)
          ; This regular expression assigns the variable CtrlPS1 to the absolute dimension
          ; stored in the data table:
        	RegExMatch(DataTbl, Signtre . "(?:(-?[\d.]+)/){" . LoopIdx . "}", CtrlPS)
          ; Concatenate the new value and it's anchor to the variable 'NewVal':
        	NewVal := NewVal . PrsHlp%LoopIdx% . CtrlPS1 + PrsHlp%PrsHlp6% * RelFact%LoopIdx%
        }
    ; If Draw is true use GuiControl, MoveDraw instead of normal GuiControl, Move 
    If Draw
      GCtrlMv = Draw
    ; Update the positions of the control
    GuiControl, Move%GCtrlMv%, %In_CtrlVar%, %NewVal%
  }

The only thing I don't get at the moment is this 'cx' variable in
c6 += !cx and (cx := i > 2)
Is it a completely new variable or is it somehow connected to your period-delimited parse string?
__________________________
Cheers AGU

polyethene
  • Members
  • 5519 posts
  • Last active: May 17 2015 06:39 AM
  • Joined: 26 Oct 2012
It's a complicated way of saying If (i = 3) c6++ or c6 += i = 3. I can't remember why I used that, it will be changed in the next version.

autohotkey.com/net Site Manager

 

Contact me by email (polyethene at autohotkey.net) or message tidbit


polyethene
  • Members
  • 5519 posts
  • Last active: May 17 2015 06:39 AM
  • Joined: 26 Oct 2012
In update version 3.5 I simplified loops and expressions so it should hopefully work faster.

autohotkey.com/net Site Manager

 

Contact me by email (polyethene at autohotkey.net) or message tidbit


AGU
  • Guests
  • Last active:
  • Joined: --
Commented version? ;)
______________________
Cheers AGU