Toolbar
Toolbar has become standard in the recent GUI applications,
which have a set of common-use buttons, or so.
On Gtk, the toolbar is a kind of the container widget, and it can
place the buttons with icon and/or the other optional widgets,
vertically or horizontally.
A sample of the toolbar
Here is a tiny sample of the toolbar. (Excuse its a-bit-small scale ;-)
Program toolbar.rb:
require 'gtk'
window = Gtk::Window.new(Gtk::WINDOW_TOPLEVEL)
window.realize
pix, mask = Gdk::Pixmap::create_from_xpm(window.window,
nil,
"test.xpm")
toolbar = Gtk::Toolbar.new(Gtk::ORIENTATION_HORIZONTAL, Gtk::TOOLBAR_BOTH)
toolbar.append_item('Open', 'Open File', nil,
Gtk::Pixmap::new(pix, mask), nil) {}
toolbar.append_item('Borders', 'Show Borders', nil,
Gtk::Pixmap::new(pix, mask), nil) {
toolbar.set_button_relief(Gtk::RELIEF_NORMAL)
}
toolbar.append_item('Borderless', 'Hide Borders', nil,
Gtk::Pixmap::new(pix, mask), nil) {
toolbar.set_button_relief(Gtk::RELIEF_NONE)
}
window.add toolbar
toolbar.show
window.show
Gtk.main
Execution result:
Illustration of the program above:
pix, mask = Gdk::Pixmap::create_from_xpm(window.window, nil, "test.xpm")
It generates an icon (pixmap) put on the button of the toolbar.
Only one icon is generated here and is common with all buttons,
but actually they each wants their own icons.
toolbar = Gtk::Toolbar.new(Gtk::ORIENTATION_HORIZONTAL, Gtk::TOOLBAR_BOTH)
It generates a toolbar widget.
First argument desinates the orientation of the toolbar widget.
Either of the two below will be chosen:
- Gtk::ORIENTATION_HORIZONTAL (...horizontal)
- Gtk::ORIENTATION_VERTICAL (...vertical)
Second argument specifies the style of the button,
and is either of the followings:
- Gtk::TOOLBAR_TEXT (...only text)
- Gtk::TOOLBAR_ICONS (...only icons)
- Gtk::TOOLBAR_BOTH (...both)
This style is applied to the button made by following `append_item'.
[Example] The case to designate Gtk::TOOLBAR_TEXT
toolbar.append_item('Open', 'Open File', nil, Gtk::Pixmap::new(pix, mask), nil) {}
It appends an item to the toolbar.
Button is the item at here.
Each of the arguments (many) have a following role; from the head,
- text on the button,
- string displayed as tooltips,
- discriminator (string) used on the tooltip;
although `nil' should be OK,
- `pixmap' used for the icon,
- and callback `proc' at the time the button is pushed.
`append_item' is a iterator (but it doesn't forced to iterate...),
and it can give the callback closure as the block (it cannot skip).
The first item `Open' is empty,
so nothing happens when the button is pushed.
Rest two buttons can be made in the same way, while this time
the following sentence is written in the block.
toolbar.set_button_relief(Gtk::RELIEF_NORMAL)
`set_button_relief' is a method of the toolbar widget,
and change its relief style of the button on the item.
- Gtk::RELIEF_NORMAL (same as the normal button; default)
- Gtk::RELIEF_NONE (no relief)
Push the button `Borders' or `Borderles', and
the relief style of the item of the toolbar changes.
[Example] push `Borderless' button:
Other methods
prepend_item
(text, tooltip_text, tooltip_private_text, icon, callback)
insert_item
(text, tooltip_text, tooltip_private_text, icon, callback, pos)
-
`prepend_item' is almost the same as `append_item',
but it appends the item before the location.
`insert_item' appends it on the location specified by `pos'.
set_orientation
(orientation)
-
It designates the orientation of the toolbar.
orientation
The argument is either of the followings:
- Gtk::ORIENTATION_HORIZONTAL (...horizontal)
- Gtk::ORIENTATION_VERTICAL (...vertical)
This designation will be promptly reflected on the toolbar.
set_style
(style)
-
Specify the style of the items (buttons).
The argument is either of the followings:
- Gtk::TOOLBAR_TEXT (...only text)
- Gtk::TOOLBAR_ICONS (...only icons)
- Gtk::TOOLBAR_BOTH (...both)
Each of these designations will be promptly reflected on the toolbar.
set_tooltips
(enable)
-
It designates whether tooltips should be effective or not.
The argument is either `true' or `false'.
This designation will be promptly reflected on the toolbar.
append_space
prepend_space
insert_space
(pos)
-
Each of them inserts the space as a pause of the items, where
`append_space': before; `prepend_space': after;
`insert_space': on the specified, location.
set_space_size
(space_size)
-
It designates the size of the space by integer value.
This designation will be promptly reflected on the toolbar.
set_space_style
(style)
-
Specify the style of the spaces.
- Gtk::Toolbar::SPACE_EMPTY (...empty at all)
- Gtk::Toolbar::SPACE_LINE (...lined)
append_widget
(widget, tooltips_text, tooltips_private_text)
prepend_widget
(widget, tooltips_text, tooltips_private_text)
insert_widget
(widget, tooltips_text, tooltips_private_text, pos)
-
Add an arbitrary widget (not an item).
Next
[TOP]
Written by
akaishi@ruby.freak.ne.jp