back to gui 

wxSizer

generated from ../src/mod_gui/misc/sizer.cpp

wxSizer is the prototype for all sizer objects : wxBoxSizer, wxFlexGridSizer, wxGridSizer and wxStaticBoxSizer. See also following wxWindow properties: sizer, and autoLayout.

The example will show a dialog box that asks the user to enter a name and a password. The labels, text controls and buttons are placed dynamically on the dialog using sizers.


    // The wxSizer example
    wxTheApp.onInit = init;
   
    function init()
    {
      //Create a dialog box

      var dlg = new wxDialog(null, -1, "wxSizer Example",
                             wxDefaultPosition, new wxSize(200, 150));
      // Create a wxBoxSizer for the dialog. 
      // The main direction of this sizer is vertical. 
      // This means that when an item is added to this sizer, it will be added below the previous item.

      dlg.sizer = new wxBoxSizer(wxOrientation.VERTICAL);
  
      // Use a wxFlexGridSizer to layout the labels with their corresponding text controls.
      // The sizer is created with 2 rows and 2 columns. The first column is used for the label, 
      // while the second column is used for the text controls. The space between the rows and 
      // columns is set to 10.

      var sizer1 = new wxFlexGridSizer(2, 2, 10, 10);

      // Add the labels and text controls to sizer1. A label is centered vertically. 
      // A grid sizer is filled from left to right, top to bottom.

      sizer1.add(new wxStaticText(dlg, -1, "Username"), 0, wxAlignment.CENTER_VERTICAL);
      sizer1.add(new wxTextCtrl(dlg, -1, "<user>"));
      sizer1.add(new wxStaticText(dlg, -1, "Password"), 0, wxAlignment.CENTER_VERTICAL);
      sizer1.add(new wxTextCtrl(dlg, -1, "<pwd>"));

      // Add this sizer to the sizer of the dialog. The flag argument is 0 which means 
      // that this item is not allowed to grow in the main direction (which is vertically).
      // The item is centered. Above (wxDirection.TOP) and below (wxDirection.BOTTOM) the item, 
      // a border is created with a size of 10.

      dlg.sizer.add(sizer1, 0, wxAlignment.CENTER | wxDirection.TOP | wxDirection.BOTTOM, 10);

      // Create a new wxBoxSizer and assign it to sizer1. The main direction of this sizer 
      // is horizontally. This means that when an item is added it will be shown on the same row.

      sizer1 = new wxBoxSizer(wxOrientation.HORIZONTAL);

      // Add the Ok button to the sizer and make sure that it has a right border of size 10. 
      // This way there's a space between the ok button and the cancel button.

      sizer1.add(new wxButton(dlg, wxId.OK, "Ok"), 0, wxDirection.RIGHT, 10);

      // Add the Cancel button to the sizer.

      sizer1.add(new wxButton(dlg, wxId.CANCEL, "Cancel"));

      // Add the sizer to the sizer of the dialog. The item is centered.

      dlg.sizer.add(sizer1, 0, wxAlignment.CENTER);

      // Before showing the dialog, set the autoLayout property to true and call 
      // layout to layout the controls. When the dialog is resized, the controls
      // will be automaticcally resized.

      dlg.autoLayout = true;
      dlg.layout();
      dlg.showModal();
      return false;
    }
  

Constants

Properties

Name Type Description
children read only Array Returns the list of the items in this sizer. See wxSizerItem.
containingWindow read only wxWindow Returns the window this sizer is used in or null if none
minSize wxSize Get/Set the minimal size of the sizer. See setMinSize
position read only wxPoint Gets the position of the sizer.
size read only wxSize Gets the current size of the sizer.

Methods

add

add(Window, 
    Flags) : wxSizerItem
 
Name Type Default Description
Window wxWindow An object with a wxWindow as its prototype.
Flags wxSizerFlags
add(Window, 
    Option = 0, 
    Flag = 0, 
    Border = 0) : wxSizerItem
 
Name Type Default Description
Window wxWindow An object with a wxWindow as its prototype.
Option Integer 0 Option is used together with wxBoxSizer. 0 means that the size of the control is not allowed to change in the main orientation of the sizer. 1 means that the size of the control may grow or shrink in the main orientation of the sizer
Flag Integer 0 This parameter is used to set a number of flags. One main behaviour of a flag is to set a border around the window. Another behaviour is to determine the child window's behaviour when the size of the sizer changes. You can use the constants of wxDirection and wxStretch.
Border Integer 0 The border width. Use this when you used a border(wxDirection) flag.
add(Sizer, 
    Option = 0, 
    Flag = 0, 
    Border = 0)
 
Name Type Default Description
Sizer wxSizer An object with a wxWindow as its prototype. An object which prototype is wxSizer.
Option Integer 0 Option is used together with wxBoxSizer. 0 means that the size of the control is not allowed to change in the main orientation of the sizer. 1 means that the size of the control may grow or shrink in the main orientation of the sizer
Flag Integer 0 This parameter is used to set a number of flags. One main behaviour of a flag is to set a border around the window. Another behaviour is to determine the child window's behaviour when the size of the sizer changes. You can use the constants of wxDirection and wxStretch.
Border Integer 0 The border width. Use this when you used a border flag (see wxDirection).
add(Width, 
    Height, 
    Option = 0, 
    Flag = 0, 
    Border = 0)
 
Name Type Default Description
Width Integer The width of the spacer.
Height Integer The height of the spacer.
Option Integer 0 Option is used together with wxBoxSizer. 0 means that the size of the control is not allowed to change in the main orientation of the sizer. 1 means that the size of the control may grow or shrink in the main orientation of the sizer
Flag Integer 0 This parameter is used to set a number of flags. One main behaviour of a flag is to set a border around the window. Another behaviour is to determine the child window's behaviour when the size of the sizer changes. You can use the constants of wxDirection and wxStretch.
Border Integer 0 The border width. Use this when you used a border flag (see wxDirection).

Adds a window, another sizer or a spacer to the sizer.

addSpacer

addSpacer(Size) : wxSizerItem
 
Name Type Default Description
Size Integer

Adds non-stretchable space to the sizer.

addStretchSpacer

addStretchSpacer(Prop = 1) : wxSizerItem
 
Name Type Default Description
Prop Integer 1

Adds stretchable space to the sizer.

calcMin

calcMin() : wxSize
 

clear

clear(Delete = Boolean)
 
Name Type Default Description
Delete Boolean Boolean

Detaches all children from the sizer. If Delete is true then child windows will also be deleted.

detach

detach(Window) : Boolean
 
Name Type Default Description
Window wxWindow
detach(Window) : Boolean
 
Name Type Default Description
Window wxSizer
detach(Window) : Boolean
 
Name Type Default Description
Window int

Detach a child from the sizer without destroying it. window is the window to be detached, sizer is the equivalent sizer and index is the position of the child in the sizer, typically 0 for the first item. This method does not cause any layout or resizing to take place, call layout to update the layout 'on screen' after detaching a child from the sizer. Returns true if the child item was found and detached, false otherwise.

fit

fit(Window) : wxSize
 
Name Type Default Description
Window wxWindow

Tell the sizer to resize the window to match the sizer's minimal size.

fitInside

fitInside(Window)
 
Name Type Default Description
Window wxWindow

Tell the sizer to resize the virtual size of the window to match the sizer's minimal size. This will not alter the on screen size of the window, but may cause the addition/removal/alteration of scrollbars required to view the virtual area in windows which manage it.

getItem

getItem(Window, 
        Recursive = false) : wxSizerItem
 
Name Type Default Description
Window wxWindow
Recursive Boolean false
getItem(Window, 
        Recursive = false) : wxSizerItem
 
Name Type Default Description
Window wxSizer
Recursive Boolean false
getItem(Window) : wxSizerItem
 
Name Type Default Description
Window int

Finds item of the sizer which holds given window, sizer or is located in sizer at position index. Use parameter recursive to search in subsizers too.

hide

hide(Window, 
     Recursive = false) : Boolean
 
Name Type Default Description
Window wxWindow
Recursive Boolean false
hide(Window, 
     Recursive = false) : Boolean
 
Name Type Default Description
Window wxSizer
Recursive Boolean false
hide(Window) : Boolean
 
Name Type Default Description
Window int

Hides the window, sizer, or item at index. To make a sizer item disappear, use hide followed by layout. Use parameter recursive to hide elements found in subsizers.

insert

insert(Index, 
       Window, 
       Flags) : wxSizerItem
 
Name Type Default Description
Index Integer
Window wxWindow An object with a wxWindow as its prototype.
Flags wxSizerFlags
insert(Index, 
       Window, 
       Option = 0, 
       Flag = 0, 
       Border = 0) : wxSizerItem
 
Name Type Default Description
Index Integer
Window wxWindow An object with a wxWindow as its prototype.
Option Integer 0 Option is used together with wxBoxSizer. 0 means that the size of the control is not allowed to change in the main orientation of the sizer. 1 means that the size of the control may grow or shrink in the main orientation of the sizer
Flag Integer 0 This parameter is used to set a number of flags. One main behaviour of a flag is to set a border around the window. Another behaviour is to determine the child window's behaviour when the size of the sizer changes. You can use the constants of wxDirection and wxStretch.
Border Integer 0 The border width. Use this when you used a border(wxDirection) flag.
insert(Index, 
       Sizer, 
       Option = 0, 
       Flag = 0, 
       Border = 0)
 
Name Type Default Description
Index Integer
Sizer wxSizer An object with a wxWindow as its prototype. An object which prototype is wxSizer.
Option Integer 0 Option is used together with wxBoxSizer. 0 means that the size of the control is not allowed to change in the main orientation of the sizer. 1 means that the size of the control may grow or shrink in the main orientation of the sizer
Flag Integer 0 This parameter is used to set a number of flags. One main behaviour of a flag is to set a border around the window. Another behaviour is to determine the child window's behaviour when the size of the sizer changes. You can use the constants of wxDirection and wxStretch.
Border Integer 0 The border width. Use this when you used a border flag (see wxDirection).
insert(Index, 
       Width, 
       Height, 
       Option = 0, 
       Flag = 0, 
       Border = 0)
 
Name Type Default Description
Index Integer
Width Integer The width of the spacer.
Height Integer The height of the spacer.
Option Integer 0 Option is used together with wxBoxSizer. 0 means that the size of the control is not allowed to change in the main orientation of the sizer. 1 means that the size of the control may grow or shrink in the main orientation of the sizer
Flag Integer 0 This parameter is used to set a number of flags. One main behaviour of a flag is to set a border around the window. Another behaviour is to determine the child window's behaviour when the size of the sizer changes. You can use the constants of wxDirection and wxStretch.
Border Integer 0 The border width. Use this when you used a border flag (see wxDirection).

Insert a child into the sizer before any existing item at index.

insertSpacer

insertSpacer(Index, 
             Size) : wxSizerItem
 
Name Type Default Description
Index Integer
Size Integer

Inserts non-stretchable space to the sizer.

insertStretchSpacer

insertStretchSpacer(Index, 
                    Size) : wxSizerItem
 
Name Type Default Description
Index Integer
Size Integer

Inserts stretchable space to the sizer.

isShown

isShown(Window) : Boolean
 
Name Type Default Description
Window wxWindow
isShown(Window) : Boolean
 
Name Type Default Description
Window wxSizer
isShown(Window) : Boolean
 
Name Type Default Description
Window int

Returns true if the window, sizer, or item at index is shown.

layout

layout()
 

Call this to force layout of the children.

prepend

prepend(Window, 
        Flags)
 
Name Type Default Description
Window wxWindow An object with a wxWindow as its prototype.
Flags wxSizerFlags
prepend(Window, 
        Option = 0, 
        Flag = 0, 
        Border = 0)
 
Name Type Default Description
Window wxWindow An object with a wxWindow as its prototype.
Option Integer 0 Option is used together with wxBoxSizer. 0 means that the size of the control is not allowed to change in the main orientation of the sizer. 1 means that the size of the control may grow or shrink in the main orientation of the sizer
Flag Integer 0 This parameter is used to set a number of flags. One main behaviour of a flag is to set a border around the window. Another behaviour is to determine the child window's behaviour when the size of the sizer changes. You can use the constants of wxDirection and wxStretch.
Border Integer 0 The border width. Use this when you used a border(wxDirection) flag.
prepend(Sizer, 
        Flags)
 
Name Type Default Description
Sizer wxSizer An object with a wxWindow as its prototype. An object which prototype is wxSizer.
Flags wxSizerFlags
prepend(Sizer, 
        Option = 0, 
        Flag = 0, 
        Border = 0)
 
Name Type Default Description
Sizer wxSizer An object with a wxWindow as its prototype. An object which prototype is wxSizer.
Option Integer 0 Option is used together with wxBoxSizer. 0 means that the size of the control is not allowed to change in the main orientation of the sizer. 1 means that the size of the control may grow or shrink in the main orientation of the sizer
Flag Integer 0 This parameter is used to set a number of flags. One main behaviour of a flag is to set a border around the window. Another behaviour is to determine the child window's behaviour when the size of the sizer changes. You can use the constants of wxDirection and wxStretch.
Border Integer 0 The border width. Use this when you used a border(wxDirection) flag.
prepend(Width, 
        Height, 
        Option = 0, 
        Flag = 0, 
        Border = 0)
 
Name Type Default Description
Width Integer The width of the spacer.
Height Integer The height of the spacer.
Option Integer 0 Option is used together with wxBoxSizer. 0 means that the size of the control is not allowed to change in the main orientation of the sizer. 1 means that the size of the control may grow or shrink in the main orientation of the sizer
Flag Integer 0 This parameter is used to set a number of flags. One main behaviour of a flag is to set a border around the window. Another behaviour is to determine the child window's behaviour when the size of the sizer changes. You can use the constants of wxDirection and wxStretch.
Border Integer 0 The border width. Use this when you used a border(wxDirection) flag.

Prepends a window, another sizer or a spacer to the beginning of the list of items owned by this sizer. See add.

prependSpacer

prependSpacer(Size) : wxSizerItem
 
Name Type Default Description
Size Integer

Prepends non-stretchable space to the sizer.

prependStretchSpacer

prependStretchSpacer(Prop = 1) : wxSizerItem
 
Name Type Default Description
Prop Integer 1

Prepends stretchable space to the sizer.

remove

remove(Index) : Boolean
 
Name Type Default Description
Index Integer The index of the item to remove from the sizer.
remove(Sizer)
 
Name Type Default Description
Sizer wxSizer Sizer to remove from this sizer.

Removes the item from the sizer. Call layout to update the screen.

replace

replace(OldIndex, 
        Item) : Boolean
 
Name Type Default Description
OldIndex Integer
Item wxSizerItem
replace(OldSizer, 
        NewSizer, 
        Recursive = false) : Boolean
 
Name Type Default Description
OldSizer wxSizer
NewSizer wxSizer
Recursive Boolean false
replace(OldWindow, 
        NewWindow, 
        Recursive = false) : Boolean
 
Name Type Default Description
OldWindow wxWindow
NewWindow wxWindow
Recursive Boolean false

Removes the item from the sizer. Call layout to update the screen.

setDimension

setDimension(x, 
             y, 
             width, 
             height)
 
Name Type Default Description
x Integer
y Integer
width Integer
height Integer

Call this to force the sizer to take the given dimension and thus force the items owned by the sizer to resize themselves according to the rules defined by the parameters in the add and prepend methods.

setItemMinSize

setItemMinSize(Window, 
               Width, 
               Height)
 
Name Type Default Description
Window wxWindow
Width Integer
Height Integer
setItemMinSize(Sizer, 
               Width, 
               Height)
 
Name Type Default Description
Sizer wxSizer
Width Integer
Height Integer
setItemMinSize(Item, 
               Width, 
               Height)
 
Name Type Default Description
Item Integer
Width Integer
Height Integer

Sets an item minimal size.

setMinSize

setMinSize(Width, 
           Height)
 
Name Type Default Description
Width Integer
Height Integer

Sets the minimal size of the sizer. See minSize.

setSizeHints

setSizeHints(Window)
 
Name Type Default Description
Window wxWindow

This method first calls fit and then setSizeHints on the window passed to it. This only makes sense when window is actually a wxTopLevelWindow such as a wxFrame or a wxDialog, since setSizeHints only has any effect in these classes. It does nothing in normal windows or controls.

setVirtualSizeHints

setVirtualSizeHints(Window)
 
Name Type Default Description
Window wxWindow

Tell the sizer to set the minimal size of the window virtual area to match the sizer's minimal size. For windows with managed scrollbars this will set them appropriately.

show

show(Show)
 
Name Type Default Description
Show Boolean
show(Window, 
     Show = true, 
     Recursive = false) : Boolean
 
Name Type Default Description
Window wxWindow
Show Boolean true
Recursive Boolean false
show(Window, 
     Show = true, 
     Recursive = false) : Boolean
 
Name Type Default Description
Window wxSizer
Show Boolean true
Recursive Boolean false
show(Window, 
     Show = true) : Boolean
 
Name Type Default Description
Window int
Show Boolean true

Hides the window, sizer, or item at index. To make a sizer item disappear, use hide followed by layout. Use parameter recursive to hide elements found in subsizers.




Design downloaded from Zeroweb.org: Free website templates, layouts, and tools.