Expand description
Rust GTK 3 bindings
Rust bindings and wrappers for GTK 3, part of gtk3-rs, a multi-platform GUI toolkit. It is a part of gtk-rs.
GTK 3.22.30 is the lowest supported version for the underlying library.
Minimum supported Rust version
Currently, the minimum supported Rust version is 1.63.0
.
Building
gtk expects GTK, GLib and Cairo development files to be installed on your system. See the GTK installation page.
Using
We recommend using crates from crates.io, as demonstrated here.
If you want to track the bleeding edge, use the git dependency instead:
[dependencies]
gtk = { git = "https://github.com/gtk-rs/gtk3-rs.git" }
Avoid mixing versioned and git crates like this:
[dependencies]
gtk = "0.13"
gtk = { git = "https://github.com/gtk-rs/gtk3-rs.git" }
“Hello, World!” example program
//!
GTK needs to be initialized before use by calling init
. Creating an
Application
will call init
for you.
use gtk::prelude::*;
use gtk::{Application, ApplicationWindow};
fn main() {
let app = Application::builder()
.application_id("org.example.HelloWorld")
.build();
app.connect_activate(|app| {
// We create the main window.
let win = ApplicationWindow::builder()
.application(app)
.default_width(320)
.default_height(200)
.title("Hello, World!")
.build();
// Don't forget to make all widgets visible.
win.show_all();
});
app.run();
}
The main loop
In a typical GTK application you set up the UI, assign signal handlers and run the main event loop.
use gtk::prelude::*;
use gtk::{Application, ApplicationWindow, Button};
fn main() {
let application = Application::builder()
.application_id("com.example.FirstGtkApp")
.build();
application.connect_activate(|app| {
let window = ApplicationWindow::builder()
.application(app)
.title("First GTK Program")
.default_width(350)
.default_height(70)
.build();
let button = Button::with_label("Click me!");
button.connect_clicked(|_| {
eprintln!("Clicked!");
});
window.add(&button);
window.show_all();
});
application.run();
}
Threads
GTK is not thread-safe. Accordingly, none of this crate’s structs implement
Send
or Sync
.
The thread where init
was called is considered the main thread. OS X has
its own notion of the main thread and init
must be called on that thread.
After successful initialization, calling any gtk
or gdk
functions
(including init
) from other threads will panic
.
Any thread can schedule a closure to be run by the main loop on the main
thread via glib::idle_add
or glib::timeout_add
. While
working with GTK you might need the glib::idle_add_local
or glib::timeout_add_local
version without the
Send
bound. Those may only be called from the main thread.
Panics
The gtk
and gdk
crates have some run-time safety and contract checks.
-
Any constructor or free function will panic if called before
init
or on a non-main thread. -
Any
&str
or&Path
parameter with an interior null (\0
) character will cause a panic. -
Some functions will panic if supplied out-of-range integer parameters. All such cases will be documented individually but they are not yet.
-
A panic in a closure that handles signals or in any other closure passed to a
gtk
function will abort the process.
Features
Library versions
By default this crate provides only GTK 3.22.30 APIs. You can access additional
functionality by selecting one of the v3_24
, etc. features.
Cargo.toml
example:
[dependencies.gtk]
version = "0.x.y"
features = ["v3_24"]
Take care when choosing the version to target: some of your users might not have easy access to the latest ones. The higher the version, the fewer users will have it installed.
Documentation
Most of this documentation is generated from the C API.
Until all parts of the documentation have been reviewed there will be incongruities with the actual Rust API.
Generate the docs:
> cargo doc --features dox
(if the installed GTK+ version is lower than 3.16, adjust the feature name accordingly).
Contribute
Contributor you’re welcome!
See the general bindings documentation.
Most of the bindings (src/auto
) are generated by gir using this configuration file. After editing Gir.toml
the sources can be regenerated with
> make gir
When opening a PR please put the changes to the src/auto
directory in a separate commit.
You may also wish to run cargo clippy -- -D warnings
and check that you’re clean because
otherwise you may be surprised when CI fails.
See Also
But also:
License
gtk is available under the MIT License, please refer to it.
Re-exports
pub use ffi;
pub use atk;
pub use cairo;
pub use gdk;
pub use gdk_pixbuf;
pub use gio;
pub use glib;
pub use pango;
Modules
Structs
About
option from the Help
menu.
All parts of the dialog are optional.AccelGroupExtManual::connect_accel_group()
.AccelGroup
represents a group of keyboard accelerators,
typically attached to a toplevel Window
(with
GtkWindowExt::add_accel_group()
). Usually you won’t need to create a
AccelGroup
directly; instead, when using GtkUIManager
, GTK+
automatically sets up the accelerators for your menus in the ui
manager’s AccelGroup
.AccelLabel
widget is a subclass of Label
that also displays an
accelerator key on the right of the label text, e.g. “Ctrl+S”.
It is commonly used in menus to show the keyboard short-cuts for commands.ApplicationWindow
or Application
.Adjustment
object represents a value which has an associated lower
and upper bound, together with step and page increments, and a page size.
It is used within several GTK+ widgets, including SpinButton
, Viewport
,
and Range
(which is a base class for Scrollbar
and Scale
).cairo_rectangle_int_t
.AppChooser
is an interface that can be implemented by widgets which
allow the user to choose an application (typically for the purpose of
opening a file). The main objects that implement this interface are
AppChooserWidget
, AppChooserDialog
and AppChooserButton
.AppChooserButton
is a widget that lets the user select
an application. It implements the AppChooser
interface.AppChooserWidget
is a widget for selecting applications.
It is the main building block for AppChooserDialog
. Most
applications only need to use the latter; but you can use
this widget as part of a larger widget if you have special needs.Application
is a class that handles many important aspects
of a GTK+ application in a convenient fashion, without enforcing
a one-size-fits-all application model.GtkApplicationExt::inhibit()
.ApplicationWindow
is a Window
subclass that offers some
extra functionality for better integration with Application
features. Notably, it can handle both the application menu as well
as the menubar. See GtkApplicationExt::set_app_menu()
and
GtkApplicationExt::set_menubar()
.AspectFrame
is useful when you want
pack a widget so that it can resize but always retains
the same aspect ratio. For instance, one might be
drawing a small preview of a larger image. AspectFrame
derives from Frame
, so it can draw a label and
a frame around the child. The frame will be
“shrink-wrapped” to the size of the child.Assistant
is a widget used to represent a generally complex
operation splitted in several steps, guiding the user through its
pages and controlling the page flow to collect the necessary data.Bin
widget is a container with just one child.
It is not very useful itself, but it is useful for deriving subclasses,
since it provides common code needed for handling a single child widget.property::Orientable::orientation
property. Within
the other dimension, all children are allocated the same size. Of course,
the property::Widget::halign
and property::Widget::valign
properties can be used on
the children to influence their allocation.gtk_builder_new_from_file()
, from_resource()
or
from_string()
.Button
widget is generally used to trigger a callback function that is
called when the button is pressed. The various signals and how to use them
are outlined below.Calendar
.CellArea
is an abstract class for CellLayout
widgets
(also referred to as “layouting widgets”) to interface with an
arbitrary number of GtkCellRenderers
and interact with the user
for a given TreeModel
row.CellAreaBox
renders cell renderers into a row or a column
depending on its Orientation
.CellAreaContext
object is created by a given CellArea
implementation via its GtkCellAreaClass.create_context()
virtual
method and is used to store cell sizes and alignments for a series of
TreeModel
rows that are requested and rendered in the same context.CellEditable
interface must be implemented for widgets to be usable
to edit the contents of a TreeView
cell. It provides a way to specify how
temporary widgets should be configured for editing, get the new value, etc.CellLayout
is an interface to be implemented by all objects which
want to provide a TreeViewColumn
like API for packing cells,
setting attributes and data funcs.CellRenderer
is a base class of a set of objects used for
rendering a cell to a cairo::Context
. These objects are used primarily by
the TreeView
widget, though they aren’t tied to them in any
specific way. It is worth noting that CellRenderer
is not a
Widget
and cannot be treated as such.CellRendererAccel
displays a keyboard accelerator (i.e. a key
combination like Control + a
). If the cell renderer is editable,
the accelerator can be changed by simply typing the new combination.CellRendererCombo
renders text in a cell like CellRendererText
from
which it is derived. But while CellRendererText
offers a simple entry to
edit the text, CellRendererCombo
offers a ComboBox
widget to edit the text. The values to display in the combo box are taken from
the tree model specified in the property::CellRendererCombo::model
property.CellRendererPixbuf
can be used to render an image in a cell. It allows
to render either a given gdk_pixbuf::Pixbuf
(set via the
property::CellRendererPixbuf::pixbuf
property) or a named icon (set via the
property::CellRendererPixbuf::icon-name
property).CellRendererProgress
renders a numeric value as a progress par in a cell.
Additionally, it can display a text on top of the progress bar.CellRendererSpin
renders text in a cell like CellRendererText
from
which it is derived. But while CellRendererText
offers a simple entry to
edit the text, CellRendererSpin
offers a SpinButton
widget. Of course,
that means that the text has to be parseable as a floating point number.Spinner
. It can often be used as an alternative
to a CellRendererProgress
for displaying indefinite activity,
instead of actual progress.CellRendererText
renders a given text in its cell, using the font, color and
style information provided by its properties. The text will be ellipsized if it is
too long and the property::CellRendererText::ellipsize
property allows it.CellRendererToggle
renders a toggle button in a cell. The
button is drawn as a radio or a checkbutton, depending on the
property::CellRendererToggle::radio
property.
When activated, it emits the signal::CellRendererToggle::toggled
signal.CellView
displays a single row of a TreeModel
using a CellArea
and CellAreaContext
. A CellAreaContext
can be provided to the
CellView
at construction time in order to keep the cellview in context
of a group of cell views, this ensures that the renderers displayed will
be properly aligned with eachother (like the aligned cells in the menus
of ComboBox
).CheckButton
places a discrete ToggleButton
next to a widget,
(usually a Label
). See the section on ToggleButton
widgets for
more information about toggle/check buttons.CheckMenuItem
is a menu item that maintains the state of a boolean
value in addition to a MenuItem
usual role in activating application
code.Clipboard
object represents a clipboard of data shared
between different processes or between different widgets in
the same process. Each clipboard is identified by a name encoded as a
gdk::Atom
. (Conversion to and from strings can be done with
gdk::Atom::intern()
and gdk::Atom::name()
.) The default clipboard
corresponds to the “CLIPBOARD” atom; another commonly used clipboard
is the “PRIMARY” clipboard, which, in X, traditionally contains
the currently selected text.ColorButton
is a button which displays the currently selected
color and allows to open a color selection dialog to change the color.
It is suitable widget for selecting a color in a preference dialog.ColorChooser
is an interface that is implemented by widgets
for choosing colors. Depending on the situation, colors may be
allowed to have alpha (translucency).ColorChooserDialog
widget is a dialog for choosing
a color. It implements the ColorChooser
interface.ColorChooserWidget
widget lets the user select a
color. By default, the chooser presents a predefined palette
of colors, plus a small number of settable custom colors.
It is also possible to select a different color with the
single-color editor. To enter the single-color editing mode,
use the context menu of any color of the palette, or use the
‘+’ button to add a new custom color.ComboBox
that hides
the model-view complexity for simple text-only use cases.Window
containing a Frame
containing a Label
. If you wanted an image instead
of a textual label inside the frame, you might replace the Label
widget
with a Image
widget.StyleProvider
interface.
It is able to parse [CSS-like][css-overview] input in order to style widgets.parent()
to get the
containing region.DestDefaults
enumeration specifies the various
types of action that will be taken on behalf
of the user for a drag destination site.DrawingArea
widget is used for creating custom user interface
elements. It’s essentially a blank widget; you can draw on it. After
creating a drawing area, the application may want to connect to:Editable
interface is an interface which should be implemented by
text editing widgets, such as Entry
and SpinButton
. It contains functions
for generically manipulating an editable widget, a large number of action
signals used for key bindings, and several signals that an application can
connect to to modify the behavior of a widget.Entry
widget is a single line text entry
widget. A fairly large set of key bindings are supported
by default. If the entered text is longer than the allocation
of the widget, the widget will scroll so that the cursor
position is visible.EntryBuffer
class contains the actual text displayed in a
Entry
widget.EntryCompletion
is an auxiliary object to be used in conjunction with
Entry
to provide the completion functionality. It implements the
CellLayout
interface, to allow the user to add extra cells to the
TreeView
with completion matches.EventController
is a base, low-level implementation for event
controllers. Those react to a series of GdkEvents
, and possibly trigger
actions as a consequence of those.v3_24
EventControllerKey
is an event controller meant for situations
where you need access to key events.EventControllerMotion
is an event controller meant for situations
where you need to track the position of the pointer.EventControllerScroll
is an event controller meant to handle
scroll events from mice and touchpads. It is capable of handling
both discrete and continuous scroll events, abstracting them both
on the signal::EventControllerScroll::scroll
signal (deltas in the
discrete case are multiples of 1).EventControllerScroll
.FileChooser
is an interface that can be implemented by file
selection widgets. In GTK+, the main objects that implement this
interface are FileChooserWidget
, FileChooserDialog
, and
FileChooserButton
. You do not need to write an object that
implements the FileChooser
interface unless you are trying to
adapt an existing file selector to expose a standard programming
interface.FileChooserButton
is a widget that lets the user select a
file. It implements the FileChooser
interface. Visually, it is a
file name with a button to bring up a FileChooserDialog
.
The user can then use that dialog to change the file associated with
that button. This widget does not support setting the
property::FileChooser::select-multiple
property to true
.FileChooserDialog
is a dialog box suitable for use with
“File/Open” or “File/Save as” commands. This widget works by
putting a FileChooserWidget
inside a Dialog
. It exposes
the FileChooser
interface, so you can use all of the
FileChooser
functions on the file chooser dialog as well as
those for Dialog
.FileChooserNative
is an abstraction of a dialog box suitable
for use with “File/Open” or “File/Save as” commands. By default, this
just uses a FileChooserDialog
to implement the actual dialog.
However, on certain platforms, such as Windows and macOS, the native platform
file chooser is used instead. When the application is running in a
sandboxed environment without direct filesystem access (such as Flatpak),
FileChooserNative
may call the proper APIs (portals) to let the user
choose a file and make it available to the application.FileChooserWidget
is a widget for choosing files.
It exposes the FileChooser
interface, and you should
use the methods of this interface to interact with the
widget.v3_24_30
FileChooser
. Files can be filtered based on their name (with
add_pattern()
), on their mime type (with
add_mime_type()
), or by a custom filter function
(with add_custom()
).FileFilterInfo
struct
are filled or need to be filled.FileFilterInfo
-struct is used to pass information about the
tested file to FileFilter::filter()
.FontButton
is a button which displays the currently selected
font an allows to open a font chooser dialog to change the font.
It is suitable widget for selecting a font in a preference dialog.FontChooser
is an interface that can be implemented by widgets
displaying the list of fonts. In GTK+, the main objects
that implement this interface are FontChooserWidget
,
FontChooserDialog
and FontButton
. The GtkFontChooser interface
has been introducted in GTK+ 3.2.FontChooserDialog
widget is a dialog for selecting a font.
It implements the FontChooser
interface.v3_24
FontChooserWidget
widget lists the available fonts,
styles and sizes, allowing the user to select a font. It is
used in the FontChooserDialog
widget to provide a
dialog box for selecting fonts.FrameExt::set_label_align()
.Gesture
is the base object for gesture recognition, although this
object is quite generalized to serve as a base for multi-touch gestures,
it is suitable to implement single-touch and pointer-based gestures (using
the special None
gdk::EventSequence
value for these).GestureDrag
is a Gesture
implementation that recognizes drag
operations. The drag operation itself can be tracked throught the
signal::GestureDrag::drag-begin
, signal::GestureDrag::drag-update
and
signal::GestureDrag::drag-end
signals, or the relevant coordinates be
extracted through GestureDragExt::offset()
and
GestureDragExt::start_point()
.GestureLongPress
is a Gesture
implementation able to recognize
long presses, triggering the signal::GestureLongPress::pressed
after the
timeout is exceeded.GestureMultiPress
is a Gesture
implementation able to recognize
multiple clicks on a nearby zone, which can be listened for through the
signal::GestureMultiPress::pressed
signal. Whenever time or distance between
clicks exceed the GTK+ defaults, signal::GestureMultiPress::stopped
is emitted,
and the click counter is reset.GesturePan
is a Gesture
implementation able to recognize
pan gestures, those are drags that are locked to happen along one
axis. The axis that a GesturePan
handles is defined at
construct time, and can be changed through
set_orientation()
.GestureRotate
is a Gesture
implementation able to recognize
2-finger rotations, whenever the angle between both handled sequences
changes, the signal::GestureRotate::angle-changed
signal is emitted.GestureSingle
is a subclass of Gesture
, optimized (although
not restricted) for dealing with mouse and single-touch gestures. Under
interaction, these gestures stick to the first interacting sequence, which
is accessible through GestureSingleExt::current_sequence()
while the
gesture is being interacted with.v3_24
GestureStylus
is a Gesture
implementation specific to stylus
input. The provided signals just provide the basic informationGestureSwipe
is a Gesture
implementation able to recognize
swipes, after a press/move/…/move/release sequence happens, the
signal::GestureSwipe::swipe
signal will be emitted, providing the velocity
and directionality of the sequence at the time it was lifted.GestureZoom
is a Gesture
implementation able to recognize
pinch/zoom gestures, whenever the distance between both tracked
sequences changes, the signal::GestureZoom::scale-changed
signal is
emitted to report the scale factor.Box
. It allows children to
be placed at the start or the end. In addition, it allows a title and
subtitle to be displayed. The title will be centered with respect to
the width of the box, even if the children at either side take up
different amounts of space. The height of the titlebar will be
set to provide sufficient space for the subtitle, even if none is
currently set. If a subtitle is not needed, the space reservation
can be turned off with HeaderBarExt::set_has_subtitle()
.v3_24_11
IconThemeExt::lookup_icon()
IconTheme
provides a facility for looking up icons by name
and size. The main reason for using a name rather than simply
providing a filename is to allow different icons to be used
depending on what “icon theme” is selected
by the user. The operation of icon themes on Linux and Unix
follows the Icon Theme Specification
There is a fallback icon theme, named hicolor
, where applications
should install their icons, but additional icon themes can be installed
as operating system vendors and users choose.IconView
provides an alternative view on a TreeModel
.
It displays the model as a grid of icons with labels. Like
TreeView
, it allows to select one or multiple items
(depending on the selection mode, see IconViewExt::set_selection_mode()
).
In addition to selection with the arrow keys, IconView
supports
rubberband selection, which is controlled by dragging the pointer.Image
widget displays an image. Various kinds of object
can be displayed as an image; most typically, you would load a
gdk_pixbuf::Pixbuf
(“pixel buffer”) from a file, and then display that.
There’s a convenience function to do this, from_file()
,
used as follows:InputPurpose
of the entry.Invisible
widget is used internally in GTK+, and is probably not
very useful for application developers.Layout
is similar to DrawingArea
in that it’s a “blank slate” and
doesn’t do anything except paint a blank background by default. It’s
different in that it supports scrolling natively due to implementing
Scrollable
, and can contain child widgets since it’s a Container
.LevelBar
is a bar widget that can be used
as a level indicator. Typical use cases are displaying the strength
of a password, or showing the charge level of a battery.Button
with a hyperlink, similar to the one
used by web browsers, which triggers an action when clicked. It is useful
to show quick links to resources.ListStore
object is a list model for use with a TreeView
widget. It implements the TreeModel
interface, and consequentialy,
can use all of the methods available there. It also implements the
TreeSortable
interface so it can be sorted by the view.
Finally, it also implements the tree
[drag and drop][gtk3-GtkTreeView-drag-and-drop]
interfaces.gio::Permission
object. Concrete implementations of gio::Permission
may use
PolicyKit or some other authorization framework. To obtain a PolicyKit-based
gio::Permission
, use polkit_permission_new()
.MenuButton
widget is used to display a popup when clicked on.
This popup can be provided either as a Menu
, a Popover
or an
abstract gio::MenuModel
.MenuItem
widget and the derived widgets are the only valid
children for menus. Their function is to correctly handle highlighting,
alignment, events and submenus.MenuToolButton
is a ToolItem
that contains a button and
a small additional button with an arrow. When clicked, the arrow
button pops up a dropdown menu.MessageDialog
presents a dialog with some message text. It’s simply a
convenience widget; you could construct the equivalent of MessageDialog
from Dialog
without too much effort, but MessageDialog
saves typing.Misc
widget is an abstract widget which is not useful itself, but
is used to derive subclasses which have alignment and padding attributes.GAction
as its model.
In contrast to ToggleButton
or RadioButton
, which can also
be backed by a GAction
via the property::Actionable::action-name
property,
GtkModelButton will adapt its appearance according to the kind of
action it is backed by, and appear either as a plain, check or
radio button.OffscreenWindow
is a toplevel widget you cannot obtain
snapshots of a full window with it since you cannot pack a toplevel
widget in another toplevel.Orientable
interface is implemented by all widgets that can be
oriented horizontally or vertically. Historically, such widgets have been
realized as subclasses of a common base class (e.g Box
/GtkHBox
/GtkVBox
or Scale
/GtkHScale
/GtkVScale
). Orientable
is more flexible in that
it allows the orientation to be changed at runtime, allowing the widgets
to “flip”.property::Widget::halign
and property::Widget::valign
properties. E.g. a widget with both alignments set to Align::Start
will be placed at the top left corner of the GtkOverlay container,
whereas an overlay with halign set to Align::Center
and valign set
to Align::End
will be placed a the bottom edge of the GtkOverlay,
horizontally centered. The position can be adjusted by setting the margin
properties of the child to non-zero values.PadController
is an event controller for the pads found in drawing
tablets (The collection of buttons and tactile sensors often found around
the stylus-sensitive area).PrintOperation
when printing.
The benefit of splitting this out of the PrintSettings
is that
these affect the actual layout of the page, and thus need to be set
long before user prints.Paned
has two panes, arranged either
horizontally or vertically. The division between
the two panes is adjustable by the user by dragging
a handle.PlacesSidebar::set_open_flags()
using these flags as a bitmask. This tells the sidebar that the application is able to open
folders selected from the sidebar in various ways, for example, in new tabs or in new windows in
addition to the normal mode.PlacesSidebar
is a widget that displays a list of frequently-used places in the
file system: the user’s home directory, the user’s bookmarks, and volumes and drives.
This widget is used as a sidebar in FileChooser
and may be used by file managers
and similar programs.gdk_backend="x11"
Socket
, Plug
provides the ability to embed
widgets from one process into another process in a fashion that is
transparent to the user. One process creates a Socket
widget
and passes the ID of that widget’s window to the other process,
which then creates a Plug
with that window ID. Any widgets
contained in the Plug
then will appear inside the first
application’s window.gdk_backend="x11"
and v3_24_30
new()
,
or updated afterwards through PopoverExt::set_relative_to()
, by
default they will point to the whole widget area, although this
behavior can be changed through PopoverExt::set_pointing_to()
.Popover
that treats its
children like menus and allows switching between them. It is
meant to be used primarily together with ModelButton
, but
any widget can be used, such as SpinButton
or Scale
.
In this respect, GtkPopoverMenu is more flexible than popovers
that are created from a gio::MenuModel
with Popover::from_model()
.pango::Layout
and pango::Context
objects that match the font metrics
of the cairo surface.FileChooser
, since some platforms don’t expose enough
infrastructure to implement a good print dialog. On such
platforms, GtkPrintOperation uses the native print dialog.
On platforms which do not provide a native print dialog, GTK+
uses its own, see GtkPrintUnixDialog
.ProgressBar
is typically used to display the progress of a long
running operation. It provides a visual clue that processing is underway.
The GtkProgressBar can be used in two different modes: percentage mode
and activity mode.CheckButton
,
as its position in the object hierarchy reflects. It is only when multiple
radio buttons are grouped together that they become a different user
interface component in their own right.RadioToolButton
is a ToolItem
that contains a radio button,
that is, a button that is part of a group of toggle buttons where only
one button can be active at a time.RecentChooser
is an interface that can be implemented by widgets
displaying the list of recently used files. In GTK+, the main objects
that implement this interface are RecentChooserWidget
,
RecentChooserDialog
and RecentChooserMenu
.RecentChooserDialog
is a dialog box suitable for displaying the recently
used documents. This widgets works by putting a RecentChooserWidget
inside
a Dialog
. It exposes the GtkRecentChooserIface
interface, so you can use
all the RecentChooser
functions on the recent chooser dialog as well as
those for Dialog
.RecentChooserMenu
is a widget suitable for displaying recently used files
inside a menu. It can be used to set a sub-menu of a MenuItem
using
GtkMenuItemExt::set_submenu()
, or as the menu of a MenuToolButton
.RecentChooserWidget
is a widget suitable for selecting recently used
files. It is the main building block of a RecentChooserDialog
. Most
applications will only need to use the latter; you can use
RecentChooserWidget
as part of a larger window if you have special needs.RecentManagerExt::add_full()
when
registering a recently used resource.RecentFilter
can be used to restrict the files being shown
in a RecentChooser
. Files can be filtered based on their name
(with add_pattern()
), on their mime type (with
FileFilter::add_mime_type()
), on the application that has
registered them (with add_application()
), or by
a custom filter function (with gtk_recent_filter_add_custom()
).GtkRecentFilterInfo
struct
are filled or need to be filled.RecentInfo
-struct contains private data only, and should
be accessed using the provided API.RecentManager
provides a facility for adding, removing and
looking up recently used files. Each recently used file is
identified by its URI, and has meta-data associated to it, like
the names and command lines of the applications that have
registered it, the number of time each application has registered
the same file, the mime type of the file and whether the file
should be displayed only by the applications that have
registered it.cairo_rectangle_int_t
.Requisition
-struct represents the desired size of a widget. See
[GtkWidget’s geometry management section][geometry-management] for
more information.Range
, in addition to the methods for GtkScale itself.
To set the value of a scale, you would normally use RangeExt::set_value()
.
To detect changes to the value, you would normally use the
signal::Range::value-changed
signal.ScaleButton
provides a button which pops up a scale widget.
This kind of widget is commonly used for volume controls in multimedia
applications, and GTK+ provides a VolumeButton
subclass that
is tailored for this use case.Scrollable
is an interface that is implemented by widgets with native
scrolling ability.Scrollbar
widget is a horizontal or vertical scrollbar,
depending on the value of the property::Orientable::orientation
property.SearchBar
is a container made to have a search entry (possibly
with additional connex widgets, such as drop-down menus, or buttons)
built-in. The search bar would appear when a search is started through
typing on the keyboard, or the application’s search mode is toggled on.SearchEntry
is a subclass of Entry
that has been
tailored for use as a search entry.property::Orientable::orientation
property, used to group the widgets
within a window. It displays a line with a shadow to make it appear sunken
into the interface.SeparatorMenuItem
is a separator used to group
items within a menu. It displays a horizontal line with a shadow to
make it appear sunken into the interface.SeparatorToolItem
is a ToolItem
that separates groups of other
GtkToolItems
. Depending on the theme, a SeparatorToolItem
will
often look like a vertical line on horizontally docked toolbars.ShortcutLabel
is a widget that represents a single keyboard shortcut or gesture
in the user interface.property::ShortcutsSection::section-name
and
a property::ShortcutsSection::title
that can be shown in the section selector of
the GtkShortcutsWindow.ShortcutsWindow
.gdk_backend="x11"
Plug
, Socket
provides the ability to embed
widgets from one process into another process in a fashion that
is transparent to the user. One process creates a Socket
widget
and passes that widget’s window ID to the other process, which then
creates a Plug
with that window ID. Any widgets contained in the
Plug
then will appear inside the first application’s window.gdk_backend="x11"
and v3_24_30
SpinButton
is an ideal way to allow the user to set the value of
some attribute. Rather than having to directly type a number into a
Entry
, GtkSpinButton allows the user to click on one of two arrows
to increment or decrement the displayed value. A value can still be
typed in, with the bonus that it can be checked to ensure it is in a
given range.ProgressBar
for
displaying indefinite activity, instead of actual progress.StackSwitcher
widget can be
used with GtkStack to provide this functionality.Stack
; it shows a row of buttons to switch between
the various pages of the associated stack widget.Statusbar
is usually placed along the bottom of an application’s
main Window
. It may provide a regular commentary of the application’s
status (as is usually the case in a web browser, for example), or may be
used to simply output a message when the status changes, (when an upload
is complete in an FTP client, for example).StyleContext
is an object that stores styling information affecting
a widget defined by WidgetPath
.StyleContextExt::to_string()
.
New values may be added to this enumeration.StyleContext
and other StyleProvider
implementations.StyleContext
.
See StyleContextExt::add_provider()
and StyleContext::add_provider_for_screen()
.Switch
is a widget that has two states: on or off. The user can control
which state should be active by clicking the empty area, or by dragging the
handle.TargetEntry
represents a single type of
data than can be supplied for by a widget for a selection
or for supplied or received during drag-and-drop.TargetFlags
enumeration is used to specify
constraints on a TargetEntry
.TargetList
-struct is a reference counted list
of GtkTargetPair
and should be treated as
opaque.TextAttributes
directly should rarely be necessary.
It’s primarily useful with TextIter::is_attributes()
.
As with most GTK+ structs, the fields in this struct should only
be read, never modified directly.TextChildAnchor
is a spot in the buffer where child widgets can
be “anchored” (inserted inline, as if they were characters). The anchor
can have multiple widgets anchored, to allow for multiple views.ToggleButton
is a Button
which will remain “pressed-in” when
clicked. Clicking again will cause the toggle button to return to its
normal state.ToggleToolButton
is a ToolItem
that contains a toggle
button.GtkToolButtons
are GtkToolItems
containing buttons.GtkToolItems
are widgets that can appear on a toolbar. To
create a toolbar item that contain something else than a button, use
new()
. Use ContainerExt::add()
to add a child
widget to the tool item.ToolItemGroup
is used together with ToolPalette
to add
GtkToolItems
to a palette like container with different
categories and drag and drop support.ToolPalette
allows you to add GtkToolItems
to a palette-like
container with different categories and drag and drop support.WidgetExt::set_tooltip_text()
or WidgetExt::set_tooltip_markup()
without any explicit tooltip object.TreeModel
interface defines a generic tree interface for
use by the TreeView
widget. It is an abstract interface, and
is designed to be usable with any appropriate data structure. The
programmer just has to implement this interface on their own data
type for it to be viewable by a TreeView
widget.TreeModelFilter
is a tree model which wraps another tree model,
and can do the following things:TreeModel
.TreeModelSort
is a model which implements the TreeSortable
interface. It does not hold any data itself, but rather is created with
a child model and proxies its data. It has identical column types to
this child model, and the changes in the child are propagated. The
primary purpose of this model is to provide a way to sort a different
model without modifying it. Note that the sort function used by
TreeModelSort
is not guaranteed to be stable.TreeSelection
object is a helper object to manage the selection
for a TreeView
widget. The TreeSelection
object is
automatically created when a new TreeView
widget is created, and
cannot exist independently of this widget. The primary reason the
TreeSelection
objects exists is for cleanliness of code and API.
That is, there is no conceptual reason all these functions could not be
methods on the TreeView
widget instead of a separate function.TreeSortable
is an interface to be implemented by tree models which
support sorting. The TreeView
uses the methods provided by this interface
to sort the model.TreeStore
object is a list model for use with a TreeView
widget. It implements the TreeModel
interface, and consequentially,
can use all of the methods available there. It also implements the
TreeSortable
interface so it can be sorted by the view. Finally,
it also implements the tree
[drag and drop][gtk3-GtkTreeView-drag-and-drop]
interfaces.TreeView
widget.
It allows to set properties of the column header, and functions as a holding pen for
the cell renderers which determine how the data in the column is displayed.VolumeButton
is a subclass of ScaleButton
that has
been tailored for use as a volume control widget with suitable
icons, tooltips and accessible labels.StyleContext
on behalf of the real
widget in order to query style information.WindowGroup
restricts the effect of grabs to windows
in the same group, thereby making window groups almost behave
like separate applications.Enums
Assistant
. It’s
used to handle buttons sensitivity and visibility.BaselinePosition
to select where to put the baseline inside the
extra availible space.Builder
.ButtonBox
uses to layout the buttons it
contains.ModelButton
.None
then call DialogExtManual::add_buttons()
.ScrolledWindow
. This is effectively the opposite of where the scroll
bars are placed.GTK_CSS_PROVIDER_ERROR
.signal::Entry::delete-from-cursor
.signal::Widget::drag-failed
signal.gdk::EventSequence
in a Gesture
.FileChooser
is being used to open existing files
or to save to a possibly new file.signal::FileChooser::confirm-overwrite
signal of a FileChooser
. This
value determines whether the file chooser will present the stock
confirmation dialog, accept the user’s choice of a filename, or
let the user choose another filename.FileChooser
functions.Image
. If you
want to get the image from the widget, you can only get the
currently-stored representation. e.g. if the
ImageExt::storage_type()
returns Pixbuf
, then you can
call ImageExt::pixbuf()
but not gtk_image_get_stock()
. For empty
images, you can request any storage type (call any of the “get”
functions), but they will all return None
values.Label
widget. (See also
GtkAlignment
).LevelBar
contents should be rendered.
Note that this enumeration could be extended with additional modes
in the future.Toolbar
or
GesturePan
.gtk_print_job_set_page_set()
.GesturePan
PrintSettings::set_duplex()
.action
parameter to PrintOperationExt::run()
determines what action the print operation should perform.PrintOperationExt::run()
.gtk_print_job_set_pages()
PrintSettings::set_quality()
.EventController
.RecentChooser
functions.RecentManager
operationsButton
.DialogExt::add_button()
.
All predefined values are negative; GTK+ leaves values of 0 or greater for
application-defined response ids.Revealer
widget is shown or hidden.Frame
.SpinButtonExt::set_update_policy()
.SpinButtonExt::spin()
.Stack
widget.signal::TextView::extend-selection
signal to customize the selection.TextView
for the purpose of customized
drawing with the ::draw_layer vfunc.TextView
.Toolbar
. Note that
setting the toolbar style overrides the user’s preferences
for the default toolbar style. Note that if the button has only
a label set and GTK_TOOLBAR_ICONS is used, the label will be
visible, and vice versa.Autosize
are inefficient for large views, and
can make columns appear choppy.PrintSettings::set_paper_width()
.CenterAlways
is almost always a bad idea.
It won’t necessarily work well with all window managers or on all windowing systems.Window
can be one of these types. Most things you’d consider a
“window” should have type Toplevel
; windows with this type
are managed by the window manager and have a frame by default (call
GtkWindowExt::set_decorated()
to toggle the frame). Windows with type
Popup
are ignored by the window manager; window manager
keybindings won’t work on them, the window manager won’t decorate the
window with a frame, many GTK+ features that rely on the window
manager will not work (e.g. resize grips and
maximization/minimization). Popup
is used to implement
widgets such as Menu
or tooltips that you normally don’t think of
as windows per se. Nearly all windows should be Toplevel
.
In particular, do not use Popup
just to turn off
the window borders; use GtkWindowExt::set_decorated()
for that.Constants
StyleProvider
for application-specific style information.Settings
.XDG_CONFIG_HOME/gtk-3.0/gtk.css
.Statics
LevelBar
.LevelBar
.LevelBar
.Frame
or the scrolled window frame around the
scrollable area.Paned
.Paned
.gdk::RGBA
.cairo_pattern_t
.gdk::RGBA
.gint
.BorderStyle
.Border
. The border is the intermediary spacing property of the
padding/border/margin series.gdk::RGBA
.pango::FontDescription
.Border
. The
padding is defined as the spacing between the inner part of the element border
and its child. It’s the innermost spacing property of the padding/border/margin
series.Traits
Functions
AccelGroup
attached
to object
that matches accel_key
and accel_mods
, and
activates that accelerator.object
.accelerator_get_label()
, but handling
keycodes.accelerator_parse()
. For example, if you pass in
GDK_KEY_q
and gdk::ModifierType::CONTROL_MASK
, this function returns “<Control>
q”.accelerator_parse_with_keycode()
,
similarly to accelerator_name()
but handling keycodes.
This is only useful for system-level components, applications
should use accelerator_parse()
instead.<Control>
a” or “<Shift>``<Alt>
F1” or “<Release>
z” (the last one is
for key release).accelerator_parse()
but handles keycodes as well. This is only
useful for system-level components, applications should use
accelerator_parse()
instead.gdk::ModifierType::CONTROL_MASK
| gdk::ModifierType::SHIFT_MASK
|
gdk::ModifierType::MOD1_MASK
| gdk::ModifierType::SUPER_MASK
| gdk::ModifierType::HYPER_MASK
| gdk::ModifierType::META_MASK
.
In other words, Control, Shift, Alt, Super, Hyper and Meta. Other
modifiers will by default be ignored by AccelGroup
.GDK_KEY_a
keyval
plus gdk::ModifierType::CONTROL_MASK
is valid - this is a “Ctrl+a” accelerator.
But, you can’t, for instance, use the GDK_KEY_Control_L
keyval
as an accelerator.libtool
when building the GTK+ library the process is running against.
If libtool
means nothing to you, don’t
worry about it.keyval
and modifiers
and activate the
binding on object
.object
to find one matching
event
, and if one was found, activate it.signal::Widget::draw
implementations for widgets that support multiple windows.
cr
must be untransformed from invoking of the draw function.
This function will return true
if the contents of the given
window
are supposed to be drawn and false
otherwise. Note
that when the drawing was not initiated by the windowing
system this function will return true
for all windows, so
you need to draw the bottommost window first. Also, do not
use “else if” statements to check which window should be drawn.cr
that from widget
-relative
coordinates to window
-relative coordinates.
If the widget
’s window is not an ancestor of window
, no
modification will be applied.GTK_MAJOR_VERSION
, GTK_MINOR_VERSION
, GTK_MICRO_VERSION
as the three arguments to this function; that produces
a check that the library in use is compatible with
the version of GTK+ the application or module was compiled
against.None
.GDK_CURRENT_TIME
.pango::Language
for the default language currently in
effect. (Note that this can change over the life of an
application.) The default language is derived from the current
locale. It determines, for example, whether GTK+ uses the
right-to-left or left-to-right text direction.device
, so all the events on device
and its
associated pointer or keyboard (if any) are delivered to widget
.
If the block_others
parameter is true
, any other devices will be
unable to interact with widget
during the grab.gtk_init()
, gtk_init_check()
, gtk_init_with_args()
and
gtk_parse_args()
from automatically
calling setlocale (LC_ALL, "")
. You would
want to use this function if you wanted to set the locale for
your program to something other than the user’s locale, or if
you wanted to set different values for different locale categories.libtool
when building the GTK+ library the process is running against.
If libtool
means nothing to you, don’t
worry about it.true
if GTK has been initialized.true
if GTK has been initialized and this is the main thread.gtk_main_quit()
is called.blocking
.page_setup
. If the user cancels the dialog, the returned PageSetup
is identical to the passed in page_setup
, otherwise it contains the
modifications done in the dialog.page_setup
.Spinner
).
The state StateFlags::CHECKED
determines whether there is
activity going on.angle
.render_background()
for the given context
and
rectangle.CheckButton
).TreeView
and Expander
) in the area
defined by x
, y
, width
, height
. The state StateFlags::CHECKED
determines whether the expander is collapsed or expanded.Notebook
tab) in the rectangle
defined by x
, y
, width
, height
. The side where the extension
connects to is defined by gap_side
.x
, y
, width
, height
.x
, y
, width
, height
.x
, y
, width
, height
),
leaving a gap on one side. xy0_gap
and xy1_gap
will mean X coordinates
for PositionType::Top
and PositionType::Bottom
gap sides, and Y coordinates for
PositionType::Left
and PositionType::Right
.pixbuf
at the specified x
and y
coordinates.surface
at the specified x
and y
coordinates.cr
at the specified index of layout
.layout
on the coordinates x
, y
RadioButton
), the StateFlags::CHECKED
state will determine whether the option is on or off, and
StateFlags::INCONSISTENT
whether it should be marked as undefined.Scale
) in the rectangle defined by x
, y
,
width
, height
. orientation
defines whether the slider is vertical
or horizontal.widget
is None
, release ownership of the selection.widget
is None
, release ownership of the selection.targets
can be used to
provide a gdk_pixbuf::Pixbuf
.targets
can be used to
provide rich text.targets
can be used to
provide text.targets
can be used to
provide an uri list.widget
and all its descendants for a GtkLabel
widget with a text string matching label_pattern
.
The label_pattern
may contain asterisks “*” and question marks “?” as
placeholders, g_pattern_match()
is used for the matching.
Note that locales other than “C“ tend to alter (translate” label strings,
so this function is genrally only useful in test programs with
predetermined locales, see gtk_test_init()
for more details.base_widget
and siblings of its
ancestors for all widgets matching widget_type
.
Of the matching widgets, the one that is geometrically closest to
base_widget
will be returned.
The general purpose of this function is to find the most likely “action”
widget, relative to another labeling widget. Such as finding a
button or text entry widget, given its corresponding label widget.widget
for a widget
of type widget_type
that has a label matching label_pattern
next
to it. This is most useful for automated GUI testing, e.g. to find
the “OK” button in a dialog and synthesize clicks on it.
However see test_find_label()
, test_find_sibling()
and
gtk_test_widget_click()
for possible caveats involving the search of
such widgets and synthesizing widget events.g_type_from_name()
after calling this function.widget
.
For windowless widgets like Button
(which returns false
from
WidgetExt::has_window()
), this will often be an
input-only event window. For other widgets, this is usually widget->window.
Certain caveats should be considered when using this function, in
particular because the mouse pointer is warped to the key press
location, see gdk_test_simulate_key()
for details.widget
to be “drawn”. In this
context that means it waits for the frame clock of widget
to have
run a full styling, layout and drawing cycle.tree_model
and path
from selection data of target type
GTK_TREE_MODEL_ROW
. Normally called from a drag_data_received handler.
This function can only be used if selection_data
originates from the same
process that’s calling this function, because a pointer to the tree model
is being passed around. If you aren’t in the same process, then you’ll
get memory corruption. In the TreeDragDest
drag_data_received handler,
you can assume that selection data of type GTK_TREE_MODEL_ROW
is
in from the current process. The returned path must be freed with
gtk_tree_path_free()
.GTK_TREE_MODEL_ROW
. Normally used
in a drag_data_get handler.