Version: 3.2.5
wxSizerFlags Class Reference

#include <wx/sizer.h>

Detailed Description

Container for sizer items flags providing readable names for them.

Normally, when you add an item to a sizer via wxSizer::Add, you have to specify a lot of flags and parameters which can be unwieldy. This is where wxSizerFlags comes in: it allows you to specify all parameters using the named methods instead. For example, instead of

sizer->Add(ctrl, 0, wxEXPAND | wxALL, 10);
@ wxEXPAND
Definition: defs.h:115
@ wxALL
Definition: defs.h:57

you can now write

sizer->Add(ctrl, wxSizerFlags().Expand().Border(wxALL, 10));
wxSizerFlags & Border(int direction, int borderinpixels)
Sets the wxSizerFlags to have a border of a number of pixels specified by borderinpixels with the dir...
wxSizerFlags(int proportion=0)
Creates the wxSizer with the proportion specified by proportion.
wxSizerFlags & Expand()
Sets the object of the wxSizerFlags to expand to fill as much area as it can.

This is more readable and also allows you to create wxSizerFlags objects which can be reused for several sizer items.

wxSizerFlags flagsExpand(1);
flagsExpand.Expand().Border(wxALL, 10);
sizer->Add(ctrl1, flagsExpand);
sizer->Add(ctrl2, flagsExpand);
Container for sizer items flags providing readable names for them.
Definition: sizer.h:1402

Note that by specification, all methods of wxSizerFlags return the wxSizerFlags object itself to allowing chaining multiple methods calls like in the examples above.

Library:  wxCore
Category:  Window Layout
See also
wxSizer

Public Member Functions

 wxSizerFlags (int proportion=0)
 Creates the wxSizer with the proportion specified by proportion. More...
 
wxSizerFlagsAlign (int alignment)
 Sets the alignment of this wxSizerFlags to align. More...
 
wxSizerFlagsBorder (int direction, int borderinpixels)
 Sets the wxSizerFlags to have a border of a number of pixels specified by borderinpixels with the directions specified by direction. More...
 
wxSizerFlagsBorder (int direction=wxALL)
 Sets the wxSizerFlags to have a border with size as returned by GetDefaultBorder(). More...
 
wxSizerFlagsBottom ()
 Aligns the object to the bottom, similar for Align(wxALIGN_BOTTOM). More...
 
wxSizerFlagsCenter ()
 Sets the object of the wxSizerFlags to center itself in the area it is given. More...
 
wxSizerFlagsCentre ()
 Center() for people with the other dialect of English. More...
 
wxSizerFlagsCenterHorizontal ()
 Same as CentreHorizontal(). More...
 
wxSizerFlagsCenterVertical ()
 Same as CentreVertical(). More...
 
wxSizerFlagsCentreHorizontal ()
 Center an item only in horizontal direction. More...
 
wxSizerFlagsCentreVertical ()
 Center an item only in vertical direction. More...
 
wxSizerFlagsDoubleBorder (int direction=wxALL)
 Sets the border in the given direction having twice the default border size. More...
 
wxSizerFlagsHorzBorder ()
 Sets the border in left and right directions having the default border size. More...
 
wxSizerFlagsDoubleHorzBorder ()
 Sets the border in left and right directions having twice the default border size. More...
 
wxSizerFlagsExpand ()
 Sets the object of the wxSizerFlags to expand to fill as much area as it can. More...
 
wxSizerFlagsFixedMinSize ()
 Set the wxFIXED_MINSIZE flag which indicates that the initial size of the window should be also set as its minimal size. More...
 
wxSizerFlagsReserveSpaceEvenIfHidden ()
 Set the wxRESERVE_SPACE_EVEN_IF_HIDDEN flag. More...
 
wxSizerFlagsLeft ()
 Aligns the object to the left, similar for Align(wxALIGN_LEFT). More...
 
wxSizerFlagsProportion (int proportion)
 Sets the proportion of this wxSizerFlags to proportion. More...
 
wxSizerFlagsRight ()
 Aligns the object to the right, similar for Align(wxALIGN_RIGHT). More...
 
wxSizerFlagsShaped ()
 Set the wx_SHAPED flag which indicates that the elements should always keep the fixed width to height ratio equal to its original value. More...
 
wxSizerFlagsTop ()
 Aligns the object to the top, similar for Align(wxALIGN_TOP). More...
 
wxSizerFlagsTripleBorder (int direction=wxALL)
 Sets the border in the given direction having thrice the default border size. More...
 

Static Public Member Functions

static void DisableConsistencyChecks ()
 Globally disable checks for sizer flag consistency in debug builds. More...
 
static int GetDefaultBorder ()
 Returns the border used by default in Border() method. More...
 
static float GetDefaultBorderFractional ()
 Returns the border used by default, with fractional precision. More...
 

Constructor & Destructor Documentation

◆ wxSizerFlags()

wxSizerFlags::wxSizerFlags ( int  proportion = 0)

Creates the wxSizer with the proportion specified by proportion.

Member Function Documentation

◆ Align()

wxSizerFlags& wxSizerFlags::Align ( int  alignment)

Sets the alignment of this wxSizerFlags to align.

This method replaces the previously set alignment with the specified one.

Parameters
alignmentCombination of wxALIGN_XXX bit masks.
See also
Top(), Left(), Right(), Bottom(), Centre()

◆ Border() [1/2]

wxSizerFlags& wxSizerFlags::Border ( int  direction,
int  borderinpixels 
)

Sets the wxSizerFlags to have a border of a number of pixels specified by borderinpixels with the directions specified by direction.

Prefer to use the overload below or DoubleBorder() or TripleBorder() versions instead of hard-coding the border value in pixels to avoid too small borders on devices with high DPI displays.

◆ Border() [2/2]

wxSizerFlags& wxSizerFlags::Border ( int  direction = wxALL)

Sets the wxSizerFlags to have a border with size as returned by GetDefaultBorder().

Parameters
directionDirection(s) to apply the border in.

◆ Bottom()

wxSizerFlags& wxSizerFlags::Bottom ( )

Aligns the object to the bottom, similar for Align(wxALIGN_BOTTOM).

Unlike Align(), this method doesn't change the horizontal alignment of the item.

◆ Center()

wxSizerFlags& wxSizerFlags::Center ( )

Sets the object of the wxSizerFlags to center itself in the area it is given.

◆ CenterHorizontal()

wxSizerFlags& wxSizerFlags::CenterHorizontal ( )

Same as CentreHorizontal().

Since
3.1.0

◆ CenterVertical()

wxSizerFlags& wxSizerFlags::CenterVertical ( )

Same as CentreVertical().

Since
3.1.0

◆ Centre()

wxSizerFlags& wxSizerFlags::Centre ( )

Center() for people with the other dialect of English.

◆ CentreHorizontal()

wxSizerFlags& wxSizerFlags::CentreHorizontal ( )

Center an item only in horizontal direction.

This is mostly useful for 2D sizers as for the 1D ones it is shorter to just use Centre() as the alignment is only used in one direction with them anyhow. For 2D sizers, centering an item in one direction is quite different from centering it in both directions however.

Note that, unlike Align(), this method doesn't change the vertical alignment.

See also
CentreVertical()
Since
3.1.0

◆ CentreVertical()

wxSizerFlags& wxSizerFlags::CentreVertical ( )

Center an item only in vertical direction.

The remarks in CentreHorizontal() documentation also apply to this function.

Note that, unlike Align(), this method doesn't change the horizontal alignment.

Since
3.1.0

◆ DisableConsistencyChecks()

static void wxSizerFlags::DisableConsistencyChecks ( )
static

Globally disable checks for sizer flag consistency in debug builds.

By default, sizer classes such as wxBoxSizer and wxFlexGridSizer assert when passed invalid flags, even though doing this usually doesn't result in any catastrophic consequences and the invalid flags are simply ignored later. Due to this, and the fact that these checks were only added in wxWidgets 3.1, existing code may run into multiple asserts warning about incorrect sizer flags use. Using this function provides a temporary solution for avoiding such asserts when upgrading to wxWidgets 3.1 from a previous version and will prevent such checks from being done.

Please do note that correcting the code by removing the invalid flags remains a much better solution as these asserts may be very helpful to understand why some code using sizer flags doesn't work as expected, so using this function, especially permanently, rather than a temporary workaround, is not recommended.

Notice that the same effect as calling this function can be achieved by setting the environment variable WXSUPPRESS_SIZER_FLAGS_CHECK to any value.

Since
3.1.6

◆ DoubleBorder()

wxSizerFlags& wxSizerFlags::DoubleBorder ( int  direction = wxALL)

Sets the border in the given direction having twice the default border size.

◆ DoubleHorzBorder()

wxSizerFlags& wxSizerFlags::DoubleHorzBorder ( )

Sets the border in left and right directions having twice the default border size.

◆ Expand()

wxSizerFlags& wxSizerFlags::Expand ( )

Sets the object of the wxSizerFlags to expand to fill as much area as it can.

◆ FixedMinSize()

wxSizerFlags& wxSizerFlags::FixedMinSize ( )

Set the wxFIXED_MINSIZE flag which indicates that the initial size of the window should be also set as its minimal size.

◆ GetDefaultBorder()

static int wxSizerFlags::GetDefaultBorder ( )
static

Returns the border used by default in Border() method.

This value is scaled appropriately for the current DPI on the systems where physical pixel values are used for the control positions and sizes, i.e. not with wxGTK or wxOSX.

See also
GetDefaultBorderFractional()

◆ GetDefaultBorderFractional()

static float wxSizerFlags::GetDefaultBorderFractional ( )
static

Returns the border used by default, with fractional precision.

For example when the border is scaled to a non-integer DPI.

See also
GetDefaultBorder()
Since
3.1.4

◆ HorzBorder()

wxSizerFlags& wxSizerFlags::HorzBorder ( )

Sets the border in left and right directions having the default border size.

◆ Left()

wxSizerFlags& wxSizerFlags::Left ( )

Aligns the object to the left, similar for Align(wxALIGN_LEFT).

Unlike Align(), this method doesn't change the vertical alignment of the item.

◆ Proportion()

wxSizerFlags& wxSizerFlags::Proportion ( int  proportion)

Sets the proportion of this wxSizerFlags to proportion.

◆ ReserveSpaceEvenIfHidden()

wxSizerFlags& wxSizerFlags::ReserveSpaceEvenIfHidden ( )

Set the wxRESERVE_SPACE_EVEN_IF_HIDDEN flag.

Normally wxSizers don't allocate space for hidden windows or other items. This flag overrides this behaviour so that sufficient space is allocated for the window even if it isn't visible. This makes it possible to dynamically show and hide controls without resizing parent dialog, for example.

Since
2.8.8

◆ Right()

wxSizerFlags& wxSizerFlags::Right ( )

Aligns the object to the right, similar for Align(wxALIGN_RIGHT).

Unlike Align(), this method doesn't change the vertical alignment of the item.

◆ Shaped()

wxSizerFlags& wxSizerFlags::Shaped ( )

Set the wx_SHAPED flag which indicates that the elements should always keep the fixed width to height ratio equal to its original value.

◆ Top()

wxSizerFlags& wxSizerFlags::Top ( )

Aligns the object to the top, similar for Align(wxALIGN_TOP).

Unlike Align(), this method doesn't change the horizontal alignment of the item.

◆ TripleBorder()

wxSizerFlags& wxSizerFlags::TripleBorder ( int  direction = wxALL)

Sets the border in the given direction having thrice the default border size.