Class: Wx::Sizer
- Defined in:
- lib/wx/doc/gen/sizer.rb,
lib/wx/doc/sizer.rb
Overview
Sizer is the abstract base class used for laying out subwindows in a window.
You cannot use Sizer directly; instead, you will have to use one of the sizer classes derived from it. Currently there are BoxSizer, StaticBoxSizer, GridSizer, FlexGridSizer, WrapSizer and GridBagSizer. The layout algorithm used by sizers in wxWidgets is closely related to layout in other GUI toolkits, such as Java’s AWT, the GTK toolkit or the Qt toolkit. It is based upon the idea of the individual subwindows reporting their minimal required size and their ability to get stretched if the size of the parent window has changed. This will most often mean that the programmer does not set the original size of a dialog in the beginning, rather the dialog will be assigned a sizer and this sizer will be queried about the recommended size. The sizer in turn will query its children, which can be normal windows, empty space or other sizers, so that a hierarchy of sizers can be constructed. Note that Sizer does not derive from Window and thus does not interfere with tab ordering and requires very little resources compared to a real window on screen. What makes sizers so well fitted for use in wxWidgets is the fact that every control reports its own minimal size and the algorithm can handle differences in font sizes or different window (dialog item) sizes on different platforms without problems. If e.g. the standard font as well as the overall design of Motif widgets requires more space than on Windows, the initial dialog size will automatically be bigger on Motif than on Windows. Sizers may also be used to control the layout of custom drawn items on the window. The #add, #insert, and #prepend functions return a pointer to the newly added SizerItem. Just add empty space of the desired size and attributes, and then use the Wx::SizerItem#get_rect method to determine where the drawing operations should take place. Please notice that sizers, like child windows, are owned by the library and will be deleted by it which implies that they must be allocated on the heap. However if you create a sizer and do not add it to another sizer or window, the library wouldn’t be able to delete such an orphan sizer and in this, and only this, case it should be deleted explicitly.
wxSizer flags
The “flag” argument accepted by SizerItem constructors and other functions, e.g. #add, is an OR-combination of the following flags. Two main behaviours are defined using these flags. One is the border around a window: the border parameter determines the border width whereas the flags given here determine which side(s) of the item that the border will be added. The other flags determine how the sizer item behaves when the space allotted to the sizer changes, and is somewhat dependent on the specific kind of sizer used.
Direction::ALL These flags are used to specify which side(s) of the sizer item the border width will apply to.
Wx::Stretch::EXPAND The item will be expanded to fill the space assigned to the item. When used for the items of BoxSizer, the expansion only happens in the transversal direction of the sizer as only the item proportion governs its behaviour in the principal sizer direction. But when it is used for the items of GridSizer, this flag can be combined with the alignment flags which override it in the corresponding direction if specified, e.g. Wx::Stretch::EXPAND | Alignment::ALIGN_CENTRE_VERTICAL would expand the item only horizontally but center it vertically. Notice that this doesn’t work for the default left/top alignment and Wx::Stretch::EXPAND still applies in both directions if it is combined with Alignment::ALIGN_LEFT or Alignment::ALIGN_TOP.
Wx::Stretch::SHAPED The item will be expanded as much as possible while also maintaining its aspect ratio.
Wx::SizerFlagBits::FIXED_MINSIZE Normally sizers use the “best”, i.e. most appropriate, size of the window to determine what the minimal size of window items should be. This allows layouts to adjust correctly when the item contents, and hence its best size, changes. If this behaviour is unwanted, Wx::SizerFlagBits::FIXED_MINSIZE can be used to fix minimal size of the window to its initial value and not change it any more in the future. Note that the same thing can be accomplished by calling Window#set_min_size explicitly as well.
Wx::SizerFlagBits::RESERVE_SPACE_EVEN_IF_HIDDEN Normally Sizers 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. (Available since 2.8.8.)
Alignment::ALIGN_CENTER_VERTICAL
Alignment::ALIGN_CENTRE_VERTICAL
Alignment::ALIGN_CENTER_HORIZONTAL
Alignment::ALIGN_CENTRE_HORIZONTAL The wxALIGN_*
flags allow you to specify the alignment of the item within the space allotted to it by the sizer, adjusted for the border if any.
Category: Window Layout
Instance Method Summary collapse
- #add(*args) ⇒ Object
-
#add_spacer(size) ⇒ Wx::SizerItem
This base function adds non-stretchable space to both the horizontal and vertical orientation of the sizer.
-
#add_stretch_spacer(prop = 1) ⇒ Wx::SizerItem
Adds stretchable space to the sizer.
-
#calc_min ⇒ Wx::Size
This method is abstract and has to be overwritten by any derived class.
-
#clear(delete_windows = false) ⇒ void
Detaches all children from the sizer.
-
#compute_fitting_client_size(window) ⇒ Wx::Size
Computes client area size for window so that it matches the sizer’s minimal size.
-
#compute_fitting_window_size(window) ⇒ Wx::Size
Like #compute_fitting_client_size, but converts the result into window size.
- #detach(*args) ⇒ Object
-
#each_child {|child| ... } ⇒ Object, Enumerator
Yield each child item to the given block.
-
#fit(window) ⇒ Wx::Size
Tell the sizer to resize the window so that its client area matches the sizer’s minimal size (#compute_fitting_client_size is called to determine it).
-
#fit_inside(window) ⇒ void
Tell the sizer to resize the virtual size of the window to match the sizer’s minimal size.
-
#get_children ⇒ Wx::SizerItemList
(also: #children)
Returns the list of the items in this sizer.
-
#get_containing_window ⇒ Wx::Window
(also: #containing_window)
Returns the window this sizer is used in or NULL if none.
- #get_item(*args) ⇒ Object (also: #item)
-
#get_item_by_id(id, recursive = false) ⇒ Wx::SizerItem
(also: #item_by_id)
Finds the item in the sizer which has the given id.
-
#get_item_count ⇒ Integer
(also: #item_count)
Returns the number of items in the sizer.
-
#get_min_size ⇒ Wx::Size
(also: #min_size)
Returns the minimal size of the sizer.
-
#get_position ⇒ Wx::Point
(also: #position)
Returns the current position of the sizer.
-
#get_size ⇒ Wx::Size
(also: #size)
Returns the current size of the sizer.
- #hide(*args) ⇒ Object
-
#inform_first_direction(direction, size, availableOtherDir) ⇒ Boolean
Inform sizer about the first direction that has been decided (by parent item).
-
#initialize ⇒ Wx::Sizer
constructor
The constructor.
- #insert(*args) ⇒ Object
-
#insert_spacer(index, size) ⇒ Wx::SizerItem
Inserts non-stretchable space to the sizer.
-
#insert_stretch_spacer(index, prop = 1) ⇒ Wx::SizerItem
Inserts stretchable space to the sizer.
-
#is_empty ⇒ Boolean
(also: #empty?)
Return true if the sizer has no elements.
-
#layout ⇒ void
Call this to force layout of the children anew, e.g.
- #prepend(*args) ⇒ Object
-
#prepend_spacer(size) ⇒ Wx::SizerItem
Prepends non-stretchable space to the sizer.
-
#prepend_stretch_spacer(prop = 1) ⇒ Wx::SizerItem
Prepends stretchable space to the sizer.
- #remove(*args) ⇒ Object
- #replace(*args) ⇒ Object
-
#reposition_children(minSize) ⇒ void
Method which must be overridden in the derived sizer classes.
-
#set_containing_window(window) ⇒ void
(also: #containing_window=)
Set the window this sizer is used in.
- #set_dimension(*args) ⇒ Object
- #set_item_min_size(*args) ⇒ Object
- #set_min_size(*args) ⇒ Object (also: #min_size=)
-
#set_size_hints(window) ⇒ void
(also: #size_hints=)
This method first calls #fit and then TopLevelWindow#set_size_hints on the window passed to it.
- #show(*args) ⇒ Object
-
#show_items(show) ⇒ void
Show or hide all items managed by the sizer.
Methods inherited from Object
#clone, #dup, #is_same_as, #un_share
Constructor Details
Instance Method Details
#add(window, flags) ⇒ Wx::SizerItem #add(window, proportion = 0, flag = 0, border = 0, userData = nil) ⇒ Wx::SizerItem #add(sizer, flags) ⇒ Wx::SizerItem #add(sizer, proportion = 0, flag = 0, border = 0, userData = nil) ⇒ Wx::SizerItem #add(width, height, proportion = 0, flag = 0, border = 0, userData = nil) ⇒ Wx::SizerItem #add(width, height, flags) ⇒ Wx::SizerItem
228 |
# File 'lib/wx/doc/gen/sizer.rb', line 228 def add(*args) end |
#add_spacer(size) ⇒ Wx::SizerItem
239 |
# File 'lib/wx/doc/gen/sizer.rb', line 239 def add_spacer(size) end |
#add_stretch_spacer(prop = 1) ⇒ Wx::SizerItem
249 |
# File 'lib/wx/doc/gen/sizer.rb', line 249 def add_stretch_spacer(prop=1) end |
#calc_min ⇒ Wx::Size
This method is abstract and has to be overwritten by any derived class.
Here, the sizer will do the actual calculation of its children’s minimal sizes.
255 |
# File 'lib/wx/doc/gen/sizer.rb', line 255 def calc_min; end |
#clear(delete_windows = false) ⇒ void
This method returns an undefined value.
Detaches all children from the sizer.
If delete_windows is true then child windows will also be deleted. Notice that child sizers are always deleted, as a general consequence of the principle that sizers own their sizer children, but don’t own their window children (because they are already owned by their parent windows).
263 |
# File 'lib/wx/doc/gen/sizer.rb', line 263 def clear(delete_windows=false) end |
#compute_fitting_client_size(window) ⇒ Wx::Size
Computes client area size for window so that it matches the sizer’s minimal size.
Unlike #get_min_size, this method accounts for other constraints imposed on window, namely display’s size (returned size will never be too large for the display) and maximum window size if previously set by Window#set_max_size. The returned value is suitable for passing to Window#set_client_size or Window#set_min_client_size.
273 |
# File 'lib/wx/doc/gen/sizer.rb', line 273 def compute_fitting_client_size(window) end |
#compute_fitting_window_size(window) ⇒ Wx::Size
Like #compute_fitting_client_size, but converts the result into window size.
The returned value is suitable for passing to Window#set_size or Window#set_min_size.
282 |
# File 'lib/wx/doc/gen/sizer.rb', line 282 def compute_fitting_window_size(window) end |
#detach(window) ⇒ Boolean #detach(sizer) ⇒ Boolean #detach(index) ⇒ Boolean
307 |
# File 'lib/wx/doc/gen/sizer.rb', line 307 def detach(*args) end |
#each_child {|child| ... } ⇒ Object, Enumerator
Yield each child item to the given block. Returns an Enumerator if no block given.
16 |
# File 'lib/wx/doc/sizer.rb', line 16 def each_child; end |
#fit(window) ⇒ Wx::Size
Tell the sizer to resize the window so that its client area matches the sizer’s minimal size (#compute_fitting_client_size is called to determine it).
This is commonly done in the constructor of the window itself, see sample in the description of BoxSizer. The new window size.
317 |
# File 'lib/wx/doc/gen/sizer.rb', line 317 def fit(window) end |
#fit_inside(window) ⇒ void
This method returns an undefined value.
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.
326 |
# File 'lib/wx/doc/gen/sizer.rb', line 326 def fit_inside(window) end |
#get_children ⇒ Wx::SizerItemList Also known as: children
Returns the list of the items in this sizer.
The elements of type-safe List Wx::SizerItemList are pointers to objects of type Wx::SizerItem.
96 |
# File 'lib/wx/doc/gen/sizer.rb', line 96 def get_children; end |
#get_containing_window ⇒ Wx::Window Also known as: containing_window
Returns the window this sizer is used in or NULL if none.
339 |
# File 'lib/wx/doc/gen/sizer.rb', line 339 def get_containing_window; end |
#get_item(window, recursive = false) ⇒ Wx::SizerItem #get_item(sizer, recursive = false) ⇒ Wx::SizerItem #get_item(index) ⇒ Wx::SizerItem Also known as: item
377 |
# File 'lib/wx/doc/gen/sizer.rb', line 377 def get_item(*args) end |
#get_item_by_id(id, recursive = false) ⇒ Wx::SizerItem Also known as: item_by_id
Finds the item in the sizer which has the given id.
This id is not the window id but the id of the Wx::SizerItem itself. This is mainly useful for retrieving the sizers created from XRC resources. Use parameter recursive to search in subsizers too. Pointer to item or NULL if no item has that id.
387 |
# File 'lib/wx/doc/gen/sizer.rb', line 387 def get_item_by_id(id, recursive=false) end |
#get_item_count ⇒ Integer Also known as: item_count
Returns the number of items in the sizer.
If you just need to test whether the sizer is empty or not you can also use the #is_empty function.
352 |
# File 'lib/wx/doc/gen/sizer.rb', line 352 def get_item_count; end |
#get_min_size ⇒ Wx::Size Also known as: min_size
Returns the minimal size of the sizer.
This is either the combined minimal size of all the children and their borders or the minimal size set by #set_min_size, depending on which is bigger. Note that the returned value is client size, not window size. In particular, if you use the value to set toplevel window’s minimal or actual size, use Window#set_min_client_size or Window#set_client_size, not Window#set_min_size or Window#set_size.
394 |
# File 'lib/wx/doc/gen/sizer.rb', line 394 def get_min_size; end |
#get_position ⇒ Wx::Point Also known as: position
Returns the current position of the sizer.
399 |
# File 'lib/wx/doc/gen/sizer.rb', line 399 def get_position; end |
#get_size ⇒ Wx::Size Also known as: size
Returns the current size of the sizer.
404 |
# File 'lib/wx/doc/gen/sizer.rb', line 404 def get_size; end |
#hide(window, recursive = false) ⇒ Boolean #hide(sizer, recursive = false) ⇒ Boolean #hide(index) ⇒ Boolean
436 |
# File 'lib/wx/doc/gen/sizer.rb', line 436 def hide(*args) end |
#inform_first_direction(direction, size, availableOtherDir) ⇒ Boolean
Inform sizer about the first direction that has been decided (by parent item).
Returns true if it made use of the information (and recalculated min size).
335 |
# File 'lib/wx/doc/gen/sizer.rb', line 335 def inform_first_direction(direction, size, availableOtherDir) end |
#insert(index, window, flags) ⇒ Wx::SizerItem #insert(index, window, proportion = 0, flag = 0, border = 0, userData = nil) ⇒ Wx::SizerItem #insert(index, sizer, flags) ⇒ Wx::SizerItem #insert(index, sizer, proportion = 0, flag = 0, border = 0, userData = nil) ⇒ Wx::SizerItem #insert(index, width, height, proportion = 0, flag = 0, border = 0, userData = nil) ⇒ Wx::SizerItem #insert(index, width, height, flags) ⇒ Wx::SizerItem
497 |
# File 'lib/wx/doc/gen/sizer.rb', line 497 def insert(*args) end |
#insert_spacer(index, size) ⇒ Wx::SizerItem
Inserts non-stretchable space to the sizer.
More readable way of calling #insert(index,size,size).
505 |
# File 'lib/wx/doc/gen/sizer.rb', line 505 def insert_spacer(index, size) end |
#insert_stretch_spacer(index, prop = 1) ⇒ Wx::SizerItem
Inserts stretchable space to the sizer.
More readable way of calling #insert(0,0,prop).
513 |
# File 'lib/wx/doc/gen/sizer.rb', line 513 def insert_stretch_spacer(index, prop=1) end |
#is_empty ⇒ Boolean Also known as: empty?
Return true if the sizer has no elements.
520 |
# File 'lib/wx/doc/gen/sizer.rb', line 520 def is_empty; end |
#layout ⇒ void
This method returns an undefined value.
Call this to force layout of the children anew, e.g. after having added a child to or removed a child (window, other sizer or space) from the sizer while keeping the current dimension.
525 |
# File 'lib/wx/doc/gen/sizer.rb', line 525 def layout; end |
#prepend(window, flags) ⇒ Wx::SizerItem #prepend(window, proportion = 0, flag = 0, border = 0, userData = nil) ⇒ Wx::SizerItem #prepend(sizer, flags) ⇒ Wx::SizerItem #prepend(sizer, proportion = 0, flag = 0, border = 0, userData = nil) ⇒ Wx::SizerItem #prepend(width, height, proportion = 0, flag = 0, border = 0, userData = nil) ⇒ Wx::SizerItem #prepend(width, height, flags) ⇒ Wx::SizerItem
568 |
# File 'lib/wx/doc/gen/sizer.rb', line 568 def prepend(*args) end |
#prepend_spacer(size) ⇒ Wx::SizerItem
Prepends non-stretchable space to the sizer.
More readable way of calling #prepend(size,size,0).
575 |
# File 'lib/wx/doc/gen/sizer.rb', line 575 def prepend_spacer(size) end |
#prepend_stretch_spacer(prop = 1) ⇒ Wx::SizerItem
Prepends stretchable space to the sizer.
More readable way of calling #prepend(0,0,prop).
582 |
# File 'lib/wx/doc/gen/sizer.rb', line 582 def prepend_stretch_spacer(prop=1) end |
#remove(sizer) ⇒ Boolean #remove(index) ⇒ Boolean
616 |
# File 'lib/wx/doc/gen/sizer.rb', line 616 def remove(*args) end |
#replace(oldwin, newwin, recursive = false) ⇒ Boolean #replace(oldsz, newsz, recursive = false) ⇒ Boolean #replace(index, newitem) ⇒ Boolean
649 |
# File 'lib/wx/doc/gen/sizer.rb', line 649 def replace(*args) end |
#reposition_children(minSize) ⇒ void
This method returns an undefined value.
Method which must be overridden in the derived sizer classes.
The implementation should reposition the children using the current total size available to the sizer (m_size) and the size computed by the last call to #calc_min. Note that you should never call this method directly, call #layout instead if you need to manually update the sizer elements positions. This method is only called by wxWidgets itself.
590 |
# File 'lib/wx/doc/gen/sizer.rb', line 590 def reposition_children(minSize) end |
#set_containing_window(window) ⇒ void Also known as: containing_window=
This method returns an undefined value.
Set the window this sizer is used in.
345 |
# File 'lib/wx/doc/gen/sizer.rb', line 345 def set_containing_window(window) end |
#set_dimension(x, y, width, height) ⇒ void #set_dimension(pos, size) ⇒ void
663 |
# File 'lib/wx/doc/gen/sizer.rb', line 663 def set_dimension(*args) end |
#set_item_min_size(window, width, height) ⇒ Boolean #set_item_min_size(window, size) ⇒ Boolean #set_item_min_size(sizer, width, height) ⇒ Boolean #set_item_min_size(sizer, size) ⇒ Boolean #set_item_min_size(index, width, height) ⇒ Boolean #set_item_min_size(index, size) ⇒ Boolean
168 |
# File 'lib/wx/doc/gen/sizer.rb', line 168 def set_item_min_size(*args) end |
#set_min_size(size) ⇒ void #set_min_size(width, height) ⇒ void Also known as: min_size=
676 |
# File 'lib/wx/doc/gen/sizer.rb', line 676 def set_min_size(*args) end |
#set_size_hints(window) ⇒ void Also known as: size_hints=
This method returns an undefined value.
This method first calls #fit and then TopLevelWindow#set_size_hints on the window passed to it.
This function is only when window is actually a TopLevelWindow such as a Frame or a Dialog, since SetSizeHints only has any effect in these classes. It does nothing in normal windows or controls. Note that window does not need to be the window using this sizer and it is, in fact, common to call this function on the sizer associated with the panel covering the client area of a frame passing it the frame pointer, as this has the desired effect of adjusting the frame size to the size fitting the panel, e.g.:
class MyFrame < Wx::Frame
def initialize(...)
super
panel = Wx::Panel.new(self)
sizer = Wx::BoxSizer.new(Wx::VERTICAL)
sizer.add(...)
sizer.add(...)
panel.set_sizer(sizer)
# Use the panel sizer to set the initial and minimal size of the
# frame to fit its contents.
sizer.set_size_hints(this)
end
This function is also used by Window#set_sizer_and_fit which is commonly invoked in the constructor of Dialog-derived classes, which don’t need to use an intermediate panel, see the example in wxBoxSizer overview.
702 |
# File 'lib/wx/doc/gen/sizer.rb', line 702 def set_size_hints(window) end |
#show(window, show = true, recursive = false) ⇒ Boolean #show(sizer, show = true, recursive = false) ⇒ Boolean #show(index, show = true) ⇒ Boolean
739 |
# File 'lib/wx/doc/gen/sizer.rb', line 739 def show(*args) end |
#show_items(show) ⇒ void
This method returns an undefined value.
Show or hide all items managed by the sizer.
744 |
# File 'lib/wx/doc/gen/sizer.rb', line 744 def show_items(show) end |