Jump to content

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

Positioning of Controls: a cheat sheet


  • Please log in to reply
3 replies to this topic
PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005
I often forget what are the differences between xm, xp and xs...
So I wrote a "cheat sheet", ie. a small script implementing (almost) all variants of these parameters.
I hope you will find it useful to get around...
#SingleInstance Force
#NoEnv

Gui Add, Button, gX-Y x50 w200 Center, &1   x y (base)
Gui Add, Button, gXP-YP x50 w200 Center, &2   xp yp (top-left)
Gui Add, Button, gXM-YM x50 w200 Center, &3   xm ym (margin)
Gui Add, Button, gXS-YS x50 w200 Center, &4   xs ys (section)

Gui Show, w300, Control Position Reference
Return


X-Y:

Gui 2:Add, Button, g2X, Default first control placement
Gui 2:Add, Button, g2X, Default next placement

Gui 2:Add, Text, x50 y150 Center, 0:   (Absolute: x50 y150)`nMoves relative to`nbottom or right`nof previously`nadded control

Gui 2:Add, Button, g2X y+150, 1: v`ny+150
Gui 2:Add, Button, g2X x+150, 2: >`nx+150
Gui 2:Add, Button, g2X y+-150, 3: ^`ny+-150
Gui 2:Add, Button, g2X x+-150, 4: <`nx+-150

Gui 2:Add, Button, g2X x100 y100, 5: Absolute: x100 y100
Gui 2:Add, Button, g2X x100, 6: Absolute: x100 (no y)`nBeneath all previously added controls
Gui 2:Add, Button, g2X y100, 7: Absolute: y100 (no x)`nRight of all previously added controls

Gui 2:Show, w500 h500, Default and base positions
Return


XP-YP:

Gui 2:Add, Text, x150 y50 Center, 0:   (Absolute: x150 y50)`nMoves relative to`ntop-left corner`nof previously`nadded control

Gui 2:Add, Button, g2X xp+200, 1: >`nxp+200
Gui 2:Add, Button, g2X yp+150, 2: v`nyp+150
Gui 2:Add, Button, g2X xp-250, 3: <`nxp-250
Gui 2:Add, Button, g2X yp-100, 4: ^`nyp-100

Gui 2:Show, w500 h500, Top-left based positions
Return


XM-YM:

Gui 2:Add, Text, x50 y50 Center, 0:   (Absolute: x50 y50)`nMargin relative moves

Gui 2:Add, Button, g2X xm, 1: xm`nleft margin,`nbelow all previous controls`n(new row)
Gui 2:Add, Button, g2X ym, 2: ym`ntop margin,`non right of all previous controls`n(new column)
Gui 2:Add, Button, g2X xm+50, 3: xm+50`nleft margin + offset,`nbelow all previous controls
Gui 2:Add, Button, g2X ym+50, 4: ym+50`ntop margin + offset,`non right of all previous controls
Gui 2:Add, Button, g2X xm ym, 5: xm ym
Gui 2:Add, Button, g2X xm+50 ym+20, 6: xm+50 ym+20

Gui 2:Show, w500 h500, Margin based positions
Return


XS-YS:

n = 0
Gui 2:Add, Text, x20 y20 Center Section, %n%:   (Absolute:`nx20 y20, Section)`nSection relative moves
n++
Gui 2:Add, Button, g2X, %n%: Default`nsecond`ncontrol`nplacement
n++
Gui 2:Add, Button, g2X, %n%: Default`nnext`nplacement
n++

Gui 2:Add, Button, g2X ys, %n%: ys`nStart a new column`n(relative to previous`nSection declaration)
n++
Gui 2:Add, Button, g2X, %n%: Default
n++
Gui 2:Add, Button, g2X, %n%: Default _______
n++

Gui 2:Add, Button, g2X ys x+50, %n%: ys x+50`nNew column`nand move a bit on the right`n(relative to 5)
n++
Gui 2:Add, Button, g2X, %n%: Default
n++
Gui 2:Add, Button, g2X, %n%: Default
n++

Gui 2:Add, Button, g2X xs, %n%: xs`nNew row`nrelative to previous Section declaration
n++
Gui 2:Add, Button, g2X xs+100 Section, %n%: xs+100 Section`nNew row`ndeclare new Section
n++
Gui 2:Add, Button, g2X ys, %n%: ys
n++
Gui 2:Add, Button, g2X, %n%: Default
n++
Gui 2:Add, Button, g2X ys, %n%: ys
n++
Gui 2:Add, Button, g2X, %n%: Default
n++
Gui 2:Add, Button, g2X xs Section, %n%: xs Section`nNew row`nrelative to previous Section declaration,`ndeclare new Section
n++
Gui 2:Add, Button, g2X ys+20, %n%: ys+20
n++
Gui 2:Add, Button, g2X, %n%: Default
n++
Gui 2:Add, Button, g2X ys+30, %n%: ys+30
n++
Gui 2:Add, Button, g2X, %n%: Default
n++
Gui 2:Add, Button, g2X xs+100 ys+100, %n%: xs+100 ys+100
n++
Gui 2:Add, Button, g2X, %n%: Default
n++

Gui 2:Show, w500 h500, Section based positions
Return

2X:
2GuiClose:
2GuiEscape:
Gui 2:Destroy
Return

GuiClose:
GuiEscape:
ExitApp

Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")

robiandi
  • Guests
  • Last active:
  • Joined: --
@PhiLho: Thank you for the script. With the same intention I had written for myself such a script (very modest in comparison with your script).
gui add, button,                 , 1.

gui add, button,                 , 2.

gui add, button, x+200           , 3. x+200

gui add, button, x+-150 y+10     , 4. x+-150 y+10

gui add, button, yp+30           , 5. yp+30

gui add, button, y+20            , 6. y+20

gui add, button,                 , 7.

gui add, button, x+10            , 8. x+10

gui add, button, section         , 9. section

gui add, button, ys              , 10. ys

gui add, button,                 , 11.

gui add, button, xm section      , 12. xm section

gui add, button, ym              , 13. ym

gui add, button, ym              , 14. ym

gui add, button,                 , 15.

gui add, button, xm+10           , 16. xm+10

gui add, button, x60 section     , 17. x60 section

gui add, button,                 , 18.

gui add, button, x+5             , 19. x+5

gui add, button,                 , 20.

gui add, button, xs              , 21. xs

gui add, button, x+100 ys section, 22. x+100 ys section

gui add, button,                 , 23.

gui add, button, x+5             , 24. x+5

gui add, button,                 , 25.

gui add, button, xs              , 26. xs

gui, show, x20 y20, xm xs xp ...



PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005
Actually, the first version of the script was even more cryptic than your...
No explaination, relying on reading the script and its comments to find how stuff work.
The code above was made hoping to be more self explaining.
Old code:
size = w20 h20

;-- Defaults
; Default first control placement: top-left corner
Gui Add, Button, %size%, A
; Default next placement: just below the previous one
Gui Add, Button, %size%, B

;-- Moves relative to bottom or right of previously added control
; Offset toward bottom
Gui Add, Button, %size% y+50, C
; Offset toward right
Gui Add, Button, %size% x+50, D
; Offset toward top
Gui Add, Button, %size% y+-50, E
; Offset toward left
Gui Add, Button, %size% x+-50, F
;-- Absolute
Gui Add, Button, %size% x150 y150, G

;-- Moves relative to top-left corner of previously added control
; Offset toward left
Gui Add, Button, %size% xp-40, H
; Offset toward right
Gui Add, Button, %size% xp+80, I
; Offset toward top
Gui Add, Button, %size% yp-40, J
; Offset toward bottom
Gui Add, Button, %size% yp+80, K

;-- Margin relative moves
; Left margin, below all previous controls
Gui Add, Button, %size% xm, L
; Top margin, on right of all previous controls
Gui Add, Button, %size% ym, M
; Reset to top-left corner (moved to avoid overlaying 'A' button)
Gui Add, Button, %size% xm+20 ym+20, N
; Left margin + move, below all previous controls
Gui Add, Button, %size% xm+30, O
; Top margin + move, on right of all previous controls
Gui Add, Button, %size% ym+30, P

;-- Another absolute position, starting a section
Gui Add, Button, %size% x240 y240 Section, Q
; Default position
Gui Add, Button, %size%, a
Gui Add, Button, %size%, b

;-- Section relative moves
; Start a new column (relative to previous Section declaration)
Gui Add, Button, %size% ys, T
; Default
Gui Add, Button, %size%, c
Gui Add, Button, %size%, d
; New column
Gui Add, Button, %size% ys Section, U
; New column (horizontal placement)
Gui Add, Button, %size% ys, e
; New column; and move a bit on the right
Gui Add, Button, %size% ys x+20, f
; New row (relative to previous Section declaration)
Gui Add, Button, %size% xs Section, V
; New column (horizontal placement)
Gui Add, Button, %size% ys, g
; New column; and move a bit on the right
Gui Add, Button, %size% ys x+20, h
; New row (relative to previous Section declaration), move to bottom
Gui Add, Button, %size% xs y+20 Section, W
; New column (horizontal placement)
Gui Add, Button, %size% ys, i
; New column; and move a bit on the right
Gui Add, Button, %size% ys x+20, j

Gui Show
Return

GuiClose:
GuiEscape:
ExitApp

Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")

Terrapin
  • Members
  • 107 posts
  • Last active: Feb 06 2007 03:38 PM
  • Joined: 15 Aug 2005
I saw this, or something like it, in I believe the help forum, a while back. Probably it was from you, PhilLo? I modified it so that the buttons were larger and had explanations on them, but never posted it. I'm glad I didn't! I noticed that a couple of my explanations were incorrect.

I think it is a great idea, and just the coding of it myself helped me learn and retain a lot of the positioning commands, but I still use the 'cheat sheet'. :)

Bob