uf_display_in_center() to group buttons in the middle

Share this topic:



Link to this posting

Postby Ursego » 30 Jan 2014, 09:18

Please read the description in the header comment:

Code: Select all
/**********************************************************************************************************************
Acc:   public
-----------------------------------------------------------------------------------------------------------------------
Dscr:   Places passed controls (like buttons) in the center of their parent window HORIZONTALLY.
      This function is useful when different sets of buttons are displayed under different conditions
      and the buttons should be placed in the middle to look nice (no matter how many buttons they are).
      For example (there are 4 buttons in the window - cb_ok, cb_yes, cb_no, cb_cancel):
      
      CommandButton   lcb_buttons[]
      
      if <some condition> then
         lcb_buttons[] = {cb_yes, cb_no, cb_cancel}
      esle
         lcb_buttons[] = {cb_ok, cb_cancel}
      end if
      gnvuo_util.uf_display_in_center(lcb_buttons[])
      
      The function also makes the displayed controls visible, so all the controls can be invisible by default.
-----------------------------------------------------------------------------------------------------------------------
Arg:   ado_controls[] (array of DragObject)
**********************************************************************************************************************/
int      li_count // quantity of controlls to center
int      i
int      li_frag_len // "fragment" is the distance between the beginning of the 1st control and the end of the last one
int      li_X
window   lw_parent

constant int SPACE = 15 // between controls

li_count = UpperBound(ado_controls[])
if li_count = 0 then return

// Calculate fragment's length:
for i = 1 to li_count
   li_frag_len += ado_controls[i].Width + SPACE
next
li_frag_len -= SPACE

// Calculate X coordinate (on the window) of 1st control:
lw_parent = ado_controls[1].GetParent()
li_X = (lw_parent.Width - li_frag_len) / 2

// Place all controls:
for i = 1 to li_count
   ado_controls[i].Visible = true
   ado_controls[i].X = li_X
   li_X += ado_controls[i].Width + SPACE // "move" X to right, i.e. calc it for next control
next

return
User avatar
Ursego
Site Admin
 
Posts: 112
Joined: 19 Feb 2013, 20:33

Return to Tips and Tricks

Who is online

Users browsing this forum: No registered users and 1 guest


uf_display_in_center() to group buttons in the middle

Share this topic:


If you think that this site is not too bad, please LIKE it in Facebook. Thanks!





cron
free counters

eXTReMe Tracker