forum.vdsworld.com Forum Index forum.vdsworld.com
Visit VDSWORLD.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


eSpace

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Visual DialogScript 6 Source Code
View previous topic :: View next topic  
Author Message
LiquidCode
Moderator Team


Joined: 05 Dec 2000
Posts: 1751
Location: Space and Time

PostPosted: Tue Dec 27, 2011 9:06 pm    Post subject: eSpace Reply with quote

This is command to evenly space controls on a dialog centered in width or height when resizing.

Give it a try and let me know if you find any errors.

Code:

#define command,espace

  DIALOG CREATE,eSpace demo,-1,0,578,393,RESIZABLE
REM *** Modified by Dialog Designer on 12/27/2011 - 14:48 ***
  DIALOG ADD,BUTTON,BUTTON1,73,97,64,24,BUTTON1
  DIALOG ADD,BUTTON,BUTTON2,72,172,64,24,BUTTON2
  DIALOG ADD,BUTTON,BUTTON3,70,253,64,24,BUTTON3
  DIALOG ADD,BUTTON,BUTTON4,71,349,64,24,BUTTON4
  DIALOG ADD,BUTTON,BUTTON5,76,18,64,24,BUTTON5
  DIALOG ADD,BUTTON,BUTTON6,117,27,64,24,BUTTON6
  DIALOG ADD,BUTTON,BUTTON7,167,26,64,24,BUTTON7
  DIALOG ADD,BUTTON,BUTTON10,199,26,64,24,BUTTON10
  DIALOG ADD,BUTTON,BUTTON11,124,107,,,BUTTON11
  DIALOG ADD,BUTTON,BUTTON12,129,194,,,BUTTON12
  DIALOG ADD,BUTTON,BUTTON13,134,288,,,BUTTON13
  DIALOG ADD,BUTTON,BUTTON14,132,396,,,BUTTON14
  DIALOG ADD,BUTTON,BUTTON15,173,108,,,BUTTON15
  DIALOG ADD,BUTTON,BUTTON16,180,201,,,BUTTON16
  DIALOG ADD,BUTTON,BUTTON17,187,303,,,BUTTON17
  DIALOG ADD,BUTTON,BUTTON18,187,406,,,BUTTON18
  DIALOG ADD,BUTTON,BUTTON19,238,242,,,BUTTON19
  DIALOG SHOW

  :evloop
  wait event
  %e = @event()
  if @equal(%e,close)
     stop
  elsif @equal(%e,Resize)
      #center buttons in height and left 23
      espace h,button5@fsep()button6@fsep()button7@fsep()button10,@dlgpos(,H),,,23
      #center buttons with a gap of 50 and top aligned with button5
      espace w,button1@fsep()button2@fsep()button3@fsep()Button4,@dlgpos(,W),50,c,@dlgpos(button5,T)
      #center buttons starting at the end of button6 aligned with top of button 6
      espace w,button11@fsep()button12@fsep()button13@fsep()Button14,@dlgpos(,W),,@sum(@dlgpos(button6,L),@dlgpos(button6,W)),@dlgpos(button6,T)
      #center buttons starting at beginning of button7 aligned with top of button 7
      espace w,button15@fsep()button16@fsep()button17@fsep()Button18,@dlgpos(,W),,@dlgpos(button7,L),@dlgpos(button7,T)
      #center button on dialog aligned with top of button 10
      espace w,button19,@dlgpos(,W),,,@dlgpos(button10,T)
  end
  goto evloop

 
:espace
#espace W/H,[Dialog elements],[Width or height to occupy],[Optional gap],[Optional Start position or C to center],[Optional top/left pos]
#W/H = Allows the spacing to be [W]idth (horizontal) or [H]eight (vertical) of dialog
#Dialog Elements = The names of the dialog elements to space IN ORDER of placement
#        seperated by the current field sep.
#Width or height to occupy = Usially the Width ot height of dialog
#Optional gap = Gap between controls. If not provided, then the gap is calculated
#Optional Start position or C to center = Start posigion of the first control, then others are based on that. If C is provided
#then controls are centered in the occupy space. You must provide a GAP if using C. Elements are already evenly spaced if no GAP is provided.
#Optional top/left pos = If using H, then this will be the LEFT pos of the elements. If not provided the LEFT pos stays the same.
#                  If using W, then this will be the TOP pos of the elements. If not provided the TOP pos stays the same.

#Errors
#        102 - Need to specify a gap if using C for start pos. Elements are already centered if no gap is provided
if @not(%1)
   error 2
end
if @not(%2)
   error 2
end
if @not(%3)
   error 2
end
if @equal(%5,C)
   if @not(%4)
      Error 102
   end
end
#Total width or height starting with start pos
if @equal(%5,C)
   %t = 0
else
   %t = %5
end
#Dialog elements
%a = %2
#Total number of elements
%e = 0
repeat
   %p = @pos(@fsep(),%a)
   if @greater(%p,0)
      %s = @substr(%a,1,@pred(%p))
      %a = @strdel(%a,1,%p)
      %t = @sum(%t,@dlgpos(%s,%1))
   else
      %s = %a
      %a =
      %t = @sum(%t,@dlgpos(%s,%1))
   end
   %e = @succ(%e)
until @not(%a)
#if @greater(%t,%3)
#   error 101
#end
%d = @diff(%3,%t)
if @not(%4)
   %g = @name(@fdiv(%d,%e))
else
   %g = %4
end
#Add the start pos + the gap / 2
#unless centered
if @equal(%5,C)
   #if centered, add the total width/height
   #and the total gap
   %x = @name(@fmul(%g,@pred(%e)))
   %x = @sum(%t,%x)
   #Get the diff between width/height to occupy
   %x = @diff(%3,%x)
   #divide by 2 to get start pos
   %t = @name(@fdiv(%x,2))
else
   %t = @sum(%5,@name(@fdiv(%g,2)))
end
#Dialog elements
%a = %2
repeat
   %p = @pos(@fsep(),%a)
   if @greater(%p,0)
      %s = @substr(%a,1,@pred(%p))
      %a = @strdel(%a,1,%p)
      if @equal(%1,W)
         dialog setpos,%s,%6,%t
      else
         dialog setpos,%s,%t,%6
      end
      #Get the start pos of the next element based
      #on the width/height and gap of current element
      %t = @sum(%t,@dlgpos(%s,%1))
      %t = @sum(%t,%g)
   else
      %s = %a
      %a =
      if @equal(%1,W)
         dialog setpos,%s,%6,%t
      else
         dialog setpos,%s,%t,%6
      end
      #Get the start pos of the next element based
      #on the width/height and gap of current element
      %t = @sum(%t,@dlgpos(%s,%1))
      %t = @sum(%t,%g)
   end
   %e = @succ(%e)
until @not(%a)
exit


_________________
Chris
Http://theblindhouse.com
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Visual DialogScript 6 Source Code All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Twitter@vdsworld       RSS

Powered by phpBB © 2001, 2005 phpBB Group