-
Notifications
You must be signed in to change notification settings - Fork 7
HowTo : StaticBox widget
This wxRuby guide demonstrates how to use the Wx::StaticBox widget with it’s various styles, features and functions. A complete list of options will be included here together with code examples for your convenience.
Unlike most widgets, the StaticBox needs to be handled a bit differently. The recommended way to use a StaticBox to group widgets, is to make the widgets children of the StaticBox.
This is similar to how we make widgets children of the Frame itself or the Panel in the window.
The syntax for creating a StaticBox widget in wxRuby is as follows:
sb = Wx::StaticBox.new(parent, id, pos, size, style, name)
Parameter descriptions:
-
parent : Wx::Window
the parent window (widget) such as a Wx::Panel. -
id : Integer
Button ID.Wx::ID_ANY
indicates a default value. -
label : String
Optional text which appears on the widget. Empty by default. -
pos : Array(Integer,Integer) or Wx::Point
Optional coordinates for the position of the topleft corner of the widget. Default isWx::DEFAULT_POSITION
. -
size : Array(Integer,Integer) or Wx::Size
Optional dimensions of the widget. Default isWx::DEFAULT_SIZE
. -
style : Integer
Optional styling mask for the button (such as alignment). Default is 0. There are no StaticBox-specific styles, but genericWx::Alignment::ALIGN_LEFT
,Wx::Alignment::ALIGN_CENTRE_HORIZONTAL
andWx::Alignment::ALIGN_RIGHT
can be used here to change the position of the static box label when using WXGTK (these styles are ignored under the other platforms currently). -
name : String
Optional window name. Default isWx::STATIC_BOX_NAME_STR
.
Note: As with all windows, keyword constructor alternatives for all arguments but the 'parent' argument are available. See here for more information.
In the below example we have created a simple StaticBox widget, and two other basic wxRuby widgets. We then assign each of those widgets the StaticBox widget as the parent, hence they will appear in it.
Remember to give the StaticBox a size, otherwise the widgets will not appear.
require 'wx'
class MyWindow < Wx::Frame
def initialize(title)
super(nil, title: title, size: [400, 300])
@panel = Wx::Panel.new(self)
box = Wx::StaticBox.new(@panel, label: 'StaticBox', size: [200, 200], pos: [20, 20])
text = Wx::StaticText.new(box, label: 'Hello World', pos: [50, 50])
button = Wx::Button.new(box, label: 'Press Me', pos: [50, 100])
centre
end
end
Wx::App.run do
window = MyWindow.new("wxRuby StaticBox Guide")
window.show
end
The output of the above code:
-
-
Basic Guides
-
Widget Guides
-
Drawing Guides
-
Event Guides
-