Protocols
The following protocols are available globally.
-
GtkApplication
is a high-level API for writing applications.It supports many aspects of writing a GTK application in a convenient fashion, without enforcing a one-size-fits-all model.
Currently,
GtkApplication
handles GTK initialization, application uniqueness, session management, provides some basic scriptability and desktop shell integration by exporting actions and menus and manages a list of toplevel windows whose life-cycle is automatically tied to the life-cycle of your application.While
GtkApplication
works fine with plain [classGtk.Window
]s, it is recommended to use it together with [classGtk.ApplicationWindow
].Automatic resources
GtkApplication
will automatically load menus from theGtkBuilder
resource located at “gtk/menus.ui”, relative to the application’s resource base path (seeg_application_set_resource_base_path()
). The menu with the ID “menubar” is taken as the application’s menubar. Additional menus (most interesting submenus) can be named and accessed via [methodGtk.Application.get_menu_by_id
] which allows for dynamic population of a part of the menu structure.It is also possible to provide the menubar manually using [method
Gtk.Application.set_menubar
].GtkApplication
will also automatically setup an icon search path for the default icon theme by appending “icons” to the resource base path. This allows your application to easily store its icons as resources. See [methodGtk.IconTheme.add_resource_path
] for more information.If there is a resource located at “gtk/help-overlay.ui” which defines a [class
Gtk.ShortcutsWindow
] with ID “help_overlay” thenGtkApplication
associates an instance of this shortcuts window with each [classGtk.ApplicationWindow
] and sets up the keyboard accelerator <kbd>Control</kbd>+<kbd>?</kbd> to open it. To create a menu item that displays the shortcuts window, associate the item with the actionwin.show-help-overlay
.A simple application
A simple example is available in the GTK source code repository
GtkApplication
optionally registers with a session manager of the users session (if you set the [propertyGtk.Application:register-session
] property) and offers various functionality related to the session life-cycle.An application can block various ways to end the session with the [method
Gtk.Application.inhibit
] function. Typical use cases for this kind of inhibiting are long-running, uninterruptible operations, such as burning a CD or performing a disk backup. The session manager may not honor the inhibitor, but it can be expected to inform the user about the negative consequences of ending the session while inhibitors are present.See Also
HowDoI: Using GtkApplication, Getting Started with GTK: Basics
The
See moreApplicationProtocol
protocol exposes the methods and properties of an underlyingGtkApplication
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeApplication
. Alternatively, useApplicationRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ApplicationProtocol : ApplicationProtocol
-
The
GtkBox
widget arranges child widgets into a single row or column.Whether it is a row or column depends on the value of its [property
Gtk.Orientable:orientation
] property. Within the other dimension, all children are allocated the same size. Of course, the [propertyGtk.Widget:halign
] and [propertyGtk.Widget:valign
] properties can be used on the children to influence their allocation.Use repeated calls to [method
Gtk.Box.append
] to pack widgets into aGtkBox
from start to end. Use [methodGtk.Box.remove
] to remove widgets from theGtkBox
. [methodGtk.Box.insert_child_after
] can be used to add a child at a particular position.Use [method
Gtk.Box.set_homogeneous
] to specify whether or not all children of theGtkBox
are forced to get the same amount of space.Use [method
Gtk.Box.set_spacing
] to determine how much space will be minimally placed between all children in theGtkBox
. Note that spacing is added between the children.Use [method
Gtk.Box.reorder_child_after
] to move a child to a different place in the box.CSS nodes
GtkBox
uses a single CSS node with name box.Accessibility
GtkBox
uses theGTK_ACCESSIBLE_ROLE_GROUP
role.The
See moreBoxProtocol
protocol exposes the methods and properties of an underlyingGtkBox
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeBox
. Alternatively, useBoxRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol BoxProtocol : OrientableProtocol, WidgetProtocol
-
GtkCssProvider
is an object implementing theGtkStyleProvider
interface for CSS.It is able to parse CSS-like input in order to style widgets.
An application can make GTK parse a specific CSS style sheet by calling [method
Gtk.CssProvider.load_from_file
] or [methodGtk.CssProvider.load_from_resource
] and adding the provider with [methodGtk.StyleContext.add_provider
] or [funcGtk.StyleContext.add_provider_for_display
].In addition, certain files will be read when GTK is initialized. First, the file
$XDG_CONFIG_HOME/gtk-4.0/gtk.css
is loaded if it exists. Then, GTK loads the first existing file amongXDG_DATA_HOME/themes/THEME/gtk-VERSION/gtk-VARIANT.css
,$HOME/.themes/THEME/gtk-VERSION/gtk-VARIANT.css
,$XDG_DATA_DIRS/themes/THEME/gtk-VERSION/gtk-VARIANT.css
andDATADIR/share/themes/THEME/gtk-VERSION/gtk-VARIANT.css
, whereTHEME
is the name of the current theme (see the [propertyGtk.Settings:gtk-theme-name
] setting),VARIANT
is the variant to load (see the [propertyGtk.Settings:gtk-application-prefer-dark-theme
] setting),DATADIR
is the prefix configured when GTK was compiled (unless overridden by theGTK_DATA_PREFIX
environment variable), andVERSION
is the GTK version number. If no file is found for the current version, GTK tries older versions all the way back to 4.0.To track errors while loading CSS, connect to the [signal
Gtk.CssProvider::parsing-error
] signal.The
See moreCssProviderProtocol
protocol exposes the methods and properties of an underlyingGtkCssProvider
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeCssProvider
. Alternatively, useCssProviderRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol CssProviderProtocol : ObjectProtocol, StyleProviderProtocol
-
GtkDrawingArea
is a widget that allows drawing with cairo.It’s essentially a blank widget; you can draw on it. After creating a drawing area, the application may want to connect to:
The [signal
Gtk.Widget::realize
] signal to take any necessary actions when the widget is instantiated on a particular display. (Create GDK resources in response to this signal.)The [signal
Gtk.DrawingArea::resize
] signal to take any necessary actions when the widget changes size.Call [method
Gtk.DrawingArea.set_draw_func
] to handle redrawing the contents of the widget.
The following code portion demonstrates using a drawing area to display a circle in the normal widget foreground color.
Simple GtkDrawingArea usage
static void draw_function (GtkDrawingArea *area, cairo_t *cr, int width, int height, gpointer data) { GdkRGBA color; GtkStyleContext *context; context = gtk_widget_get_style_context (GTK_WIDGET (area)); cairo_arc (cr, width / 2.0, height / 2.0, MIN (width, height) / 2.0, 0, 2 * G_PI); gtk_style_context_get_color (context, &color); gdk_cairo_set_source_rgba (cr, &color); cairo_fill (cr); } int main (int argc, char **argv) { gtk_init (); GtkWidget *area = gtk_drawing_area_new (); gtk_drawing_area_set_content_width (GTK_DRAWING_AREA (area), 100); gtk_drawing_area_set_content_height (GTK_DRAWING_AREA (area), 100); gtk_drawing_area_set_draw_func (GTK_DRAWING_AREA (area), draw_function, NULL, NULL); return 0; }
The draw function is normally called when a drawing area first comes onscreen, or when it’s covered by another window and then uncovered. You can also force a redraw by adding to the “damage region” of the drawing area’s window using [method
Gtk.Widget.queue_draw
]. This will cause the drawing area to call the draw function again.The available routines for drawing are documented on the GDK Drawing Primitives page and the cairo documentation.
To receive mouse events on a drawing area, you will need to use event controllers. To receive keyboard events, you will need to set the “can-focus” property on the drawing area, and you should probably draw some user-visible indication that the drawing area is focused.
If you need more complex control over your widget, you should consider creating your own
GtkWidget
subclass.The
See moreDrawingAreaProtocol
protocol exposes the methods and properties of an underlyingGtkDrawingArea
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeDrawingArea
. Alternatively, useDrawingAreaRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol DrawingAreaProtocol : WidgetProtocol
-
GtkATContext
is an abstract class provided by GTK to communicate to platform-specific assistive technologies API.Each platform supported by GTK implements a
GtkATContext
subclass, and is responsible for updating the accessible state in response to state changes inGtkAccessible
.The
See moreATContextProtocol
protocol exposes the methods and properties of an underlyingGtkATContext
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeATContext
. Alternatively, useATContextRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ATContextProtocol : ObjectProtocol
-
The
GtkAboutDialog
offers a simple way to display information about a program.The shown information includes the programs’ logo, name, copyright, website and license. It is also possible to give credits to the authors, documenters, translators and artists who have worked on the program.
An about dialog is typically opened when the user selects the
About
option from theHelp
menu. All parts of the dialog are optional.About dialogs often contain links and email addresses.
GtkAboutDialog
displays these as clickable links. By default, it calls [funcGtk.show_uri
] when a user clicks one. The behaviour can be overridden with the [signalGtk.AboutDialog::activate-link
] signal.To specify a person with an email address, use a string like
Edgar Allan Poe <edgar
poe.com>
. To specify a website with a title, use a string likeGTK team https://www.gtk.org
.To make constructing a
GtkAboutDialog
as convenient as possible, you can use the function [funcGtk.show_about_dialog
] which constructs and shows a dialog and keeps it around so that it can be shown again.Note that GTK sets a default title of
_("About %s")
on the dialog window (wheres
is replaced by the name of the application, but in order to ensure proper translation of the title, applications should set the title property explicitly when constructing aGtkAboutDialog
, as shown in the following example:GFile *logo_file = g_file_new_for_path ("./logo.png"); GdkTexture *example_logo = gdk_texture_new_from_file (logo_file, NULL); g_object_unref (logo_file); gtk_show_about_dialog (NULL, "program-name", "ExampleCode", "logo", example_logo, "title", `_("About ExampleCode")`, NULL);
CSS nodes
GtkAboutDialog
has a single CSS node with the namewindow
and style class.aboutdialog
.The
See moreAboutDialogProtocol
protocol exposes the methods and properties of an underlyingGtkAboutDialog
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeAboutDialog
. Alternatively, useAboutDialogRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol AboutDialogProtocol : WindowProtocol
-
GtkActionBar
is designed to present contextual actions.It is expected to be displayed below the content and expand horizontally to fill the area.
It allows placing children at the start or the end. In addition, it contains an internal centered box which is centered with respect to the full width of the box, even if the children at either side take up different amounts of space.
CSS nodes
actionbar ╰── revealer ╰── box ├── box.start │ ╰── [start children] ├── [center widget] ╰── box.end ╰── [end children]
A
GtkActionBar
‘s CSS node is calledactionbar
. It contains arevealer
subnode, which contains abox
subnode, which contains twobox
subnodes at the start and end of the action bar, withstart
and `end style classes respectively, as well as a center node that represents the center child.Each of the boxes contains children packed for that side.
The
See moreActionBarProtocol
protocol exposes the methods and properties of an underlyingGtkActionBar
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeActionBar
. Alternatively, useActionBarRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ActionBarProtocol : WidgetProtocol
-
A
GtkShortcutAction
that callsgtk_widget_activate()
.The
See moreActivateActionProtocol
protocol exposes the methods and properties of an underlyingGtkActivateAction
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeActivateAction
. Alternatively, useActivateActionRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ActivateActionProtocol : ShortcutActionProtocol
-
GtkAdjustment
is a model for a numeric value.The `GtkAdjustment has an associated lower and upper bound. It also contains step and page increments, and a page size.
Adjustments are used within several GTK widgets, including [class
Gtk.SpinButton
], [classGtk.Viewport
], [classGtk.Scrollbar
] and [classGtk.Scale
].The
GtkAdjustment
object does not update the value itself. Instead it is left up to the owner of theGtkAdjustment
to control the value.The
See moreAdjustmentProtocol
protocol exposes the methods and properties of an underlyingGtkAdjustment
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeAdjustment
. Alternatively, useAdjustmentRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol AdjustmentProtocol : InitiallyUnownedProtocol
-
A
GtkShortcutTrigger
that combines two triggers.The
GtkAlternativeTrigger
triggers when either of two trigger.This can be cascaded to combine more than two triggers.
The
See moreAlternativeTriggerProtocol
protocol exposes the methods and properties of an underlyingGtkAlternativeTrigger
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeAlternativeTrigger
. Alternatively, useAlternativeTriggerRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol AlternativeTriggerProtocol : ShortcutTriggerProtocol
-
GtkAnyFilter
matches an item when at least one of its filters matches.To add filters to a
GtkAnyFilter
, use [methodGtk.MultiFilter.append
].The
See moreAnyFilterProtocol
protocol exposes the methods and properties of an underlyingGtkAnyFilter
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeAnyFilter
. Alternatively, useAnyFilterRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol AnyFilterProtocol : MultiFilterProtocol
-
The
GtkAppChooserButton
lets the user select an application.Initially, a
GtkAppChooserButton
selects the first application in its list, which will either be the most-recently used application or, if [propertyGtk.AppChooserButton:show-default-item
] istrue
, the default application.The list of applications shown in a
GtkAppChooserButton
includes the recommended applications for the given content type. When [propertyGtk.AppChooserButton:show-default-item
] is set, the default application is also included. To let the user chooser other applications, you can set the [propertyGtk.AppChooserButton:show-dialog-item
] property, which allows to open a full [classGtk.AppChooserDialog
].It is possible to add custom items to the list, using [method
Gtk.AppChooserButton.append_custom_item
]. These items cause the [signalGtk.AppChooserButton::custom-item-activated
] signal to be emitted when they are selected.To track changes in the selected application, use the [signal
Gtk.AppChooserButton::changed
] signal.CSS nodes
GtkAppChooserButton
has a single CSS node with the name “appchooserbutton”.The
See moreAppChooserButtonProtocol
protocol exposes the methods and properties of an underlyingGtkAppChooserButton
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeAppChooserButton
. Alternatively, useAppChooserButtonRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol AppChooserButtonProtocol : AppChooserProtocol
-
GtkAppChooserDialog
shows aGtkAppChooserWidget
inside aGtkDialog
.Note that
GtkAppChooserDialog
does not have any interesting methods of its own. Instead, you should get the embeddedGtkAppChooserWidget
using [methodGtk.AppChooserDialog.get_widget
] and call its methods if the generic [ifaceGtk.AppChooser
] interface is not sufficient for your needs.To set the heading that is shown above the
GtkAppChooserWidget
, use [methodGtk.AppChooserDialog.set_heading
].The
See moreAppChooserDialogProtocol
protocol exposes the methods and properties of an underlyingGtkAppChooserDialog
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeAppChooserDialog
. Alternatively, useAppChooserDialogRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol AppChooserDialogProtocol : AppChooserProtocol, DialogProtocol
-
GtkAppChooserWidget
is a widget for selecting applications.It is the main building block for [class
Gtk.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.GtkAppChooserWidget
offers detailed control over what applications are shown, using the [propertyGtk.AppChooserWidget:show-default
], [propertyGtk.AppChooserWidget:show-recommended
], [propertyGtk.AppChooserWidget:show-fallback
], [propertyGtk.AppChooserWidget:show-other
] and [propertyGtk.AppChooserWidget:show-all
] properties. See the [ifaceGtk.AppChooser
] documentation for more information about these groups of applications.To keep track of the selected application, use the [signal
Gtk.AppChooserWidget::application-selected
] and [signalGtk.AppChooserWidget::application-activated
] signals.CSS nodes
GtkAppChooserWidget
has a single CSS node with name appchooser.The
See moreAppChooserWidgetProtocol
protocol exposes the methods and properties of an underlyingGtkAppChooserWidget
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeAppChooserWidget
. Alternatively, useAppChooserWidgetRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol AppChooserWidgetProtocol : AppChooserProtocol
-
GtkApplicationWindow
is aGtkWindow
subclass that integrates withGtkApplication
.Notably,
GtkApplicationWindow
can handle an application menubar.This class implements the
GActionGroup
andGActionMap
interfaces, to let you add window-specific actions that will be exported by the associated [classGtk.Application
], together with its application-wide actions. Window-specific actions are prefixed with the “win.” prefix and application-wide actions are prefixed with the “app.” prefix. Actions must be addressed with the prefixed name when referring to them from aGMenuModel
.Note that widgets that are placed inside a
GtkApplicationWindow
can also activate these actions, if they implement the [ifaceGtk.Actionable
] interface.The settings [property
Gtk.Settings:gtk-shell-shows-app-menu
] and [propertyGtk.Settings:gtk-shell-shows-menubar
] tell GTK whether the desktop environment is showing the application menu and menubar models outside the application as part of the desktop shell. For instance, on OS X, both menus will be displayed remotely; on Windows neither will be.If the desktop environment does not display the menubar, then
GtkApplicationWindow
will automatically show a menubar for it. This behaviour can be overridden with the [propertyGtk.ApplicationWindow:show-menubar
] property. If the desktop environment does not display the application menu, then it will automatically be included in the menubar or in the windows client-side decorations.See [class
Gtk.PopoverMenu
] for information about the XML language used byGtkBuilder
for menu models.See also: [method
Gtk.Application.set_menubar
].A GtkApplicationWindow with a menubar
The code sample below shows how to set up a
GtkApplicationWindow
with a menu bar defined on the [classGtk.Application
]:GtkApplication *app = gtk_application_new ("org.gtk.test", 0); GtkBuilder *builder = gtk_builder_new_from_string ( "<interface>" " <menu id='menubar'>" " <submenu>" " <attribute name='label' translatable='yes'>_Edit</attribute>" " <item>" " <attribute name='label' translatable='yes'>_Copy</attribute>" " <attribute name='action'>win.copy</attribute>" " </item>" " <item>" " <attribute name='label' translatable='yes'>_Paste</attribute>" " <attribute name='action'>win.paste</attribute>" " </item>" " </submenu>" " </menu>" "</interface>", -1); GMenuModel *menubar = G_MENU_MODEL (gtk_builder_get_object (builder, "menubar")); gtk_application_set_menubar (GTK_APPLICATION (app), menubar); g_object_unref (builder); // ... GtkWidget *window = gtk_application_window_new (app);
The
See moreApplicationWindowProtocol
protocol exposes the methods and properties of an underlyingGtkApplicationWindow
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeApplicationWindow
. Alternatively, useApplicationWindowRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ApplicationWindowProtocol : ActionGroupProtocol, ActionMapProtocol, WindowProtocol
-
GtkAspectFrame
preserves the aspect ratio of its child.The frame can respect the aspect ratio of the child widget, or use its own aspect ratio.
CSS nodes
GtkAspectFrame
uses a CSS node with nameframe
.The
See moreAspectFrameProtocol
protocol exposes the methods and properties of an underlyingGtkAspectFrame
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeAspectFrame
. Alternatively, useAspectFrameRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol AspectFrameProtocol : WidgetProtocol
-
GtkAssistant
is used to represent a complex as a series of steps.Each step consists of one or more pages.
GtkAssistant
guides the user through the pages, and controls the page flow to collect the data needed for the operation.GtkAssistant
handles which buttons to show and to make sensitive based on page sequence knowledge and the [enumGtk.AssistantPageType
] of each page in addition to state information like the completed and committed page statuses.If you have a case that doesn’t quite fit in
GtkAssistant
s way of handling buttons, you can use theGTK_ASSISTANT_PAGE_CUSTOM
page type and handle buttons yourself.GtkAssistant
maintains aGtkAssistantPage
object for each added child, which holds additional per-child properties. You obtain theGtkAssistantPage
for a child with [methodGtk.Assistant.get_page
].GtkAssistant as GtkBuildable
The
GtkAssistant
implementation of theGtkBuildable
interface exposes theaction_area
as internal children with the name “action_area”.To add pages to an assistant in
GtkBuilder
, simply add it as a child to theGtkAssistant
object. If you need to set per-object properties, create aGtkAssistantPage
object explicitly, and set the child widget as a property on it.CSS nodes
GtkAssistant
has a single CSS node with the name window and style class .assistant.The
See moreAssistantProtocol
protocol exposes the methods and properties of an underlyingGtkAssistant
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeAssistant
. Alternatively, useAssistantRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol AssistantProtocol : WindowProtocol
-
GtkAssistantPage
is an auxiliary object used by `GtkAssistant.The
See moreAssistantPageProtocol
protocol exposes the methods and properties of an underlyingGtkAssistantPage
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeAssistantPage
. Alternatively, useAssistantPageRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol AssistantPageProtocol : ObjectProtocol
-
GtkBinLayout
is aGtkLayoutManager
subclass useful for create “bins” of widgets.GtkBinLayout
will stack each child of a widget on top of each other, using the [propertyGtk.Widget:hexpand
], [propertyGtk.Widget:vexpand
], [propertyGtk.Widget:halign
], and [propertyGtk.Widget:valign
] properties of each child to determine where they should be positioned.The
See moreBinLayoutProtocol
protocol exposes the methods and properties of an underlyingGtkBinLayout
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeBinLayout
. Alternatively, useBinLayoutRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol BinLayoutProtocol : LayoutManagerProtocol
-
The
See moreATContextClassProtocol
protocol exposes the methods and properties of an underlyingGtkATContextClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeATContextClass
. Alternatively, useATContextClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ATContextClassProtocol
-
The
See moreAccessibleInterfaceProtocol
protocol exposes the methods and properties of an underlyingGtkAccessibleInterface
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeAccessibleInterface
. Alternatively, useAccessibleInterfaceRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol AccessibleInterfaceProtocol
-
The interface vtable for
GtkActionable
.The
See moreActionableInterfaceProtocol
protocol exposes the methods and properties of an underlyingGtkActionableInterface
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeActionableInterface
. Alternatively, useActionableInterfaceRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ActionableInterfaceProtocol
-
The
See moreActivateActionClassProtocol
protocol exposes the methods and properties of an underlyingGtkActivateActionClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeActivateActionClass
. Alternatively, useActivateActionClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ActivateActionClassProtocol
-
The
See moreAdjustmentClassProtocol
protocol exposes the methods and properties of an underlyingGtkAdjustmentClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeAdjustmentClass
. Alternatively, useAdjustmentClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol AdjustmentClassProtocol
-
The
See moreAlternativeTriggerClassProtocol
protocol exposes the methods and properties of an underlyingGtkAlternativeTriggerClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeAlternativeTriggerClass
. Alternatively, useAlternativeTriggerClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol AlternativeTriggerClassProtocol
-
The
See moreAnyFilterClassProtocol
protocol exposes the methods and properties of an underlyingGtkAnyFilterClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeAnyFilterClass
. Alternatively, useAnyFilterClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol AnyFilterClassProtocol
-
The
See moreApplicationClassProtocol
protocol exposes the methods and properties of an underlyingGtkApplicationClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeApplicationClass
. Alternatively, useApplicationClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ApplicationClassProtocol
-
The
See moreApplicationWindowClassProtocol
protocol exposes the methods and properties of an underlyingGtkApplicationWindowClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeApplicationWindowClass
. Alternatively, useApplicationWindowClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ApplicationWindowClassProtocol
-
The
See moreBinLayoutClassProtocol
protocol exposes the methods and properties of an underlyingGtkBinLayoutClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeBinLayoutClass
. Alternatively, useBinLayoutClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol BinLayoutClassProtocol
-
GtkAccessible
is an interface for describing UI elements for Assistive Technologies.Every accessible implementation has:
- a “role”, represented by a value of the [enum
Gtk.AccessibleRole
] enumeration - an “attribute”, represented by a set of [enum
Gtk.AccessibleState
], [enumGtk.AccessibleProperty
] and [enumGtk.AccessibleRelation
] values
The role cannot be changed after instantiating a
GtkAccessible
implementation.The attributes are updated every time a UI element’s state changes in a way that should be reflected by assistive technologies. For instance, if a
GtkWidget
visibility changes, theGTK_ACCESSIBLE_STATE_HIDDEN
state will also change to reflect the [propertyGtk.Widget:visible
] property.The
See moreAccessibleProtocol
protocol exposes the methods and properties of an underlyingGtkAccessible
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeAccessible
. Alternatively, useAccessibleRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol AccessibleProtocol
- a “role”, represented by a value of the [enum
-
The
GtkActionable
interface provides a convenient way of asscociating widgets with actions.It primarily consists of two properties: [property
Gtk.Actionable:action-name
] and [propertyGtk.Actionable:action-target
]. There are also some convenience APIs for setting these properties.The action will be looked up in action groups that are found among the widgets ancestors. Most commonly, these will be the actions with the “win.” or “app.” prefix that are associated with the
GtkApplicationWindow
orGtkApplication
, but other action groups that are added with [methodGtk.Widget.insert_action_group
] will be consulted as well.The
See moreActionableProtocol
protocol exposes the methods and properties of an underlyingGtkActionable
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeActionable
. Alternatively, useActionableRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ActionableProtocol : WidgetProtocol
-
GtkAppChooser
is an interface for widgets which allow the user to choose an application.The main objects that implement this interface are [class
Gtk.AppChooserWidget
], [classGtk.AppChooserDialog
] and [classGtk.AppChooserButton
].Applications are represented by GIO
GAppInfo
objects here. GIO has a concept of recommended and fallback applications for a given content type. Recommended applications are those that claim to handle the content type itself, while fallback also includes applications that handle a more generic content type. GIO also knows the default and last-used application for a given content type. TheGtkAppChooserWidget
provides detailed control over whether the shown list of applications should include default, recommended or fallback applications.To obtain the application that has been selected in a
GtkAppChooser
, use [methodGtk.AppChooser.get_app_info
].The
See moreAppChooserProtocol
protocol exposes the methods and properties of an underlyingGtkAppChooser
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeAppChooser
. Alternatively, useAppChooserRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol AppChooserProtocol : WidgetProtocol
-
GtkBuildable
allows objects to extend and customize their deserialization from ui files.The interface includes methods for setting names and properties of objects, parsing custom tags and constructing child objects.
The
GtkBuildable
interface is implemented by all widgets and many of the non-widget objects that are provided by GTK. The main user of this interface is [classGtk.Builder
]. There should be very little need for applications to call any of these functions directly.An object only needs to implement this interface if it needs to extend the
GtkBuilder
XML format or run any extra routines at deserialization time.The
See moreBuildableProtocol
protocol exposes the methods and properties of an underlyingGtkBuildable
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeBuildable
. Alternatively, useBuildableRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol BuildableProtocol
-
A
GtkBitset
represents a set of unsigned integers.Another name for this data structure is “bitmap”.
The current implementation is based on roaring bitmaps.
A bitset allows adding a set of integers and provides support for set operations like unions, intersections and checks for equality or if a value is contained in the set.
GtkBitset
also contains various functions to query metadata about the bitset, such as the minimum or maximum values or its size.The fastest way to iterate values in a bitset is [struct
Gtk.BitsetIter
].The main use case for
GtkBitset
is implementing complex selections for [ifaceGtk.SelectionModel
].The
See moreBitsetProtocol
protocol exposes the methods and properties of an underlyingGtkBitset
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeBitset
. Alternatively, useBitsetRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol BitsetProtocol
-
An opaque, stack-allocated struct for iterating over the elements of a
GtkBitset
.Before a
GtkBitsetIter
can be used, it needs to be initialized with [funcGtk.BitsetIter.init_first
], [funcGtk.BitsetIter.init_last
] or [funcGtk.BitsetIter.init_at
].The
See moreBitsetIterProtocol
protocol exposes the methods and properties of an underlyingGtkBitsetIter
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeBitsetIter
. Alternatively, useBitsetIterRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol BitsetIterProtocol
-
The
See moreBookmarkListClassProtocol
protocol exposes the methods and properties of an underlyingGtkBookmarkListClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeBookmarkListClass
. Alternatively, useBookmarkListClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol BookmarkListClassProtocol
-
The
See moreBoolFilterClassProtocol
protocol exposes the methods and properties of an underlyingGtkBoolFilterClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeBoolFilterClass
. Alternatively, useBoolFilterClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol BoolFilterClassProtocol
-
A struct that specifies a border around a rectangular area.
Each side can have different width.
The
See moreBorderProtocol
protocol exposes the methods and properties of an underlyingGtkBorder
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeBorder
. Alternatively, useBorderRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol BorderProtocol
-
The
See moreBoxClassProtocol
protocol exposes the methods and properties of an underlyingGtkBoxClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeBoxClass
. Alternatively, useBoxClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol BoxClassProtocol
-
The
See moreBoxLayoutClassProtocol
protocol exposes the methods and properties of an underlyingGtkBoxLayoutClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeBoxLayoutClass
. Alternatively, useBoxLayoutClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol BoxLayoutClassProtocol
-
The
GtkBuildableIface
interface contains methods that are necessary to allowGtkBuilder
to construct an object from aGtkBuilder
UI definition.The
See moreBuildableIfaceProtocol
protocol exposes the methods and properties of an underlyingGtkBuildableIface
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeBuildableIface
. Alternatively, useBuildableIfaceRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol BuildableIfaceProtocol
-
An opaque context struct for
GtkBuildableParser
.The
See moreBuildableParseContextProtocol
protocol exposes the methods and properties of an underlyingGtkBuildableParseContext
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeBuildableParseContext
. Alternatively, useBuildableParseContextRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol BuildableParseContextProtocol
-
A sub-parser for
GtkBuildable
implementations.The
See moreBuildableParserProtocol
protocol exposes the methods and properties of an underlyingGtkBuildableParser
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeBuildableParser
. Alternatively, useBuildableParserRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol BuildableParserProtocol
-
The
See moreBuilderCScopeClassProtocol
protocol exposes the methods and properties of an underlyingGtkBuilderCScopeClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeBuilderCScopeClass
. Alternatively, useBuilderCScopeClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol BuilderCScopeClassProtocol
-
The
See moreBuilderClassProtocol
protocol exposes the methods and properties of an underlyingGtkBuilderClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeBuilderClass
. Alternatively, useBuilderClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol BuilderClassProtocol
-
The
See moreBuilderListItemFactoryClassProtocol
protocol exposes the methods and properties of an underlyingGtkBuilderListItemFactoryClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeBuilderListItemFactoryClass
. Alternatively, useBuilderListItemFactoryClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol BuilderListItemFactoryClassProtocol
-
The virtual function table to implement for
GtkBuilderScope
implementations. Default implementations for each function do exist, but they usually just fail, so it is suggested that implementations implement all of them.The
See moreBuilderScopeInterfaceProtocol
protocol exposes the methods and properties of an underlyingGtkBuilderScopeInterface
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeBuilderScopeInterface
. Alternatively, useBuilderScopeInterfaceRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol BuilderScopeInterfaceProtocol
-
The
See moreButtonClassProtocol
protocol exposes the methods and properties of an underlyingGtkButtonClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeButtonClass
. Alternatively, useButtonClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ButtonClassProtocol
-
The
See moreCallbackActionClassProtocol
protocol exposes the methods and properties of an underlyingGtkCallbackActionClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeCallbackActionClass
. Alternatively, useCallbackActionClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol CallbackActionClassProtocol
-
GtkBookmarkList
is a list model that wrapsGBookmarkFile
.It presents a
GListModel
and fills it asynchronously with theGFileInfo
s returned from that function.The
GFileInfo
s in the list have some attributes in the recent namespace added:recent
private`(boolean) and
recent:applications` (stringv).The
See moreBookmarkListProtocol
protocol exposes the methods and properties of an underlyingGtkBookmarkList
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeBookmarkList
. Alternatively, useBookmarkListRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol BookmarkListProtocol : ListModelProtocol, ObjectProtocol
-
GtkBoolFilter
evaluates a booleanGtkExpression
to determine whether to include items.The
See moreBoolFilterProtocol
protocol exposes the methods and properties of an underlyingGtkBoolFilter
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeBoolFilter
. Alternatively, useBoolFilterRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol BoolFilterProtocol : FilterProtocol
-
GtkBoxLayout
is a layout manager that arranges children in a single row or column.Whether it is a row or column depends on the value of its [property
Gtk.Orientable:orientation
] property. Within the other dimension all children all allocated the same size. TheGtkBoxLayout
will respect the [propertyGtk.Widget:halign
] and [propertyGtk.Widget:valign
] properties of each child widget.If you want all children to be assigned the same size, you can use the [property
Gtk.BoxLayout:homogeneous
] property.If you want to specify the amount of space placed between each child, you can use the [property
Gtk.BoxLayout:spacing
] property.The
See moreBoxLayoutProtocol
protocol exposes the methods and properties of an underlyingGtkBoxLayout
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeBoxLayout
. Alternatively, useBoxLayoutRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol BoxLayoutProtocol : LayoutManagerProtocol, OrientableProtocol
-
A
GtkBuilder
reads XML descriptions of a user interface and instantiates the described objects.To create a
GtkBuilder
from a user interface description, call [ctorGtk.Builder.new_from_file
], [ctorGtk.Builder.new_from_resource
] or [ctorGtk.Builder.new_from_string
].In the (unusual) case that you want to add user interface descriptions from multiple sources to the same
GtkBuilder
you can call [ctorGtk.Builder.new
] to get an empty builder and populate it by (multiple) calls to [methodGtk.Builder.add_from_file
], [methodGtk.Builder.add_from_resource
] or [methodGtk.Builder.add_from_string
].A
GtkBuilder
holds a reference to all objects that it has constructed and drops these references when it is finalized. This finalization can cause the destruction of non-widget objects or widgets which are not contained in a toplevel window. For toplevel windows constructed by a builder, it is the responsibility of the user to call [methodGtk.Window.destroy
] to get rid of them and all the widgets they contain.The functions [method
Gtk.Builder.get_object
] and [methodGtk.Builder.get_objects
] can be used to access the widgets in the interface by the names assigned to them inside the UI description. Toplevel windows returned by these functions will stay around until the user explicitly destroys them with [methodGtk.Window.destroy
]. Other widgets will either be part of a larger hierarchy constructed by the builder (in which case you should not have to worry about their lifecycle), or without a parent, in which case they have to be added to some container to make use of them. Non-widget objects need to be reffed withg_object_ref()
to keep them beyond the lifespan of the builder.GtkBuilder UI Definitions
GtkBuilder
parses textual descriptions of user interfaces which are specified in XML format. We refer to these descriptions as “GtkBuilder UI definitions” or just “UI definitions” if the context is clear.The toplevel element is
<interface>
. It optionally takes a “domain” attribute, which will make the builder look for translated strings usingdgettext()
in the domain specified. This can also be done by calling [methodGtk.Builder.set_translation_domain
] on the builder.Objects are described by
<object>
elements, which can contain<property>
elements to set properties,<signal>
elements which connect signals to handlers, and<child>
elements, which describe child objects (most often widgets inside a container, but also e.g. actions in an action group, or columns in a tree model). A<child>
element contains an<object>
element which describes the child object.The target toolkit
version(s)
are described by<requires>
elements, the “lib” attribute specifies the widget library in question (currently the only supported value is “gtk”) and the “version” attribute specifies the target version in the form “<major>
.<minor>
”.GtkBuilder
will error out if the version requirements are not met.Typically, the specific kind of object represented by an
<object>
element is specified by the “class” attribute. If the type has not been loaded yet, GTK tries to find theget_type()
function from the class name by applying heuristics. This works in most cases, but if necessary, it is possible to specify the name of theget_type()
function explicitly with the “type-func” attribute.Objects may be given a name with the “id” attribute, which allows the application to retrieve them from the builder with [method
Gtk.Builder.get_object
]. An id is also necessary to use the object as property value in other parts of the UI definition. GTK reserves ids starting and ending with___
(three consecutive underscores) for its own purposes.Setting properties of objects is pretty straightforward with the
<property>
element: the “name” attribute specifies the name of the property, and the content of the element specifies the value. If the “translatable” attribute is set to a true value, GTK usesgettext()
(ordgettext()
if the builder has a translation domain set) to find a translation for the value. This happens before the value is parsed, so it can be used for properties of any type, but it is probably most useful for string properties. It is also possible to specify a context to disambiguate short strings, and comments which may help the translators.GtkBuilder
can parse textual representations for the most common property types: characters, strings, integers, floating-point numbers, booleans (strings like “TRUE”, “t”, “yes”, “y”, “1” are interpreted astrue
, strings like “FALSE”, “f”, “no”, “n”, “0” are interpreted asfalse
), enumerations (can be specified by their name, nick or integer value), flags (can be specified by their name, nick, integer value, optionally combined with “|”, e.g. “GTK_INPUT_HINT_EMOJI|GTK_INPUT_HINT_LOWERCASE”) and colors (in a format understood by [methodGdk.RGBA.parse
]).GVariant
s can be specified in the format understood byg_variant_parse()
, and pixbufs can be specified as a filename of an image file to load.Objects can be referred to by their name and by default refer to objects declared in the local XML fragment and objects exposed via [method
Gtk.Builder.expose_object
]. In general,GtkBuilder
allows forward references to objects — declared in the local XML; an object doesn’t have to be constructed before it can be referred to. The exception to this rule is that an object has to be constructed before it can be used as the value of a construct-only property.It is also possible to bind a property value to another object’s property value using the attributes “bind-source” to specify the source object of the binding, and optionally, “bind-property” and “bind-flags” to specify the source property and source binding flags respectively. Internally,
GtkBuilder
implements this usingGBinding
objects. For more information seeg_object_bind_property()
.Sometimes it is necessary to refer to widgets which have implicitly been constructed by GTK as part of a composite widget, to set properties on them or to add further children (e.g. the content area of a
GtkDialog
). This can be achieved by setting the “internal-child” property of the<child>
element to a true value. Note thatGtkBuilder
still requires an<object>
element for the internal child, even if it has already been constructed.A number of widgets have different places where a child can be added (e.g. tabs vs. page content in notebooks). This can be reflected in a UI definition by specifying the “type” attribute on a
<child>
The possible values for the “type” attribute are described in the sections describing the widget-specific portions of UI definitions.Signal handlers and function pointers
Signal handlers are set up with the
<signal>
element. The “name” attribute specifies the name of the signal, and the “handler” attribute specifies the function to connect to the signal. The remaining attributes, “after”, “swapped” and “object”, have the same meaning as the corresponding parameters of theg_signal_connect_object()
org_signal_connect_data()
functions. A “last_modification_time” attribute is also allowed, but it does not have a meaning to the builder.If you rely on
GModule
support to lookup callbacks in the symbol table, the following details should be noted:When compiling applications for Windows, you must declare signal callbacks with
G_MODULE_EXPORT
, or they will not be put in the symbol table. On Linux and Unix, this is not necessary; applications should instead be compiled with the -Wl,–export-dynamicCFLAGS
, and linked againstgmodule-export-2.0
.A GtkBuilder UI Definition
<interface> <object class="GtkDialog" id="dialog1"> <child internal-child="content_area"> <object class="GtkBox" id="vbox1"> <child internal-child="action_area"> <object class="GtkBox" id="hbuttonbox1"> <child> <object class="GtkButton" id="ok_button"> <property name="label" translatable="yes">_Ok</property> <property name="use-underline">True</property> <signal name="clicked" handler="ok_button_clicked"/> </object> </child> </object> </child> </object> </child> </object> </interface>
Beyond this general structure, several object classes define their own XML DTD fragments for filling in the ANY placeholders in the DTD above. Note that a custom element in a <child> element gets parsed by the custom tag handler of the parent object, while a custom element in an <object> element gets parsed by the custom tag handler of the object.
These XML fragments are explained in the documentation of the respective objects.
A
<template>
tag can be used to define a widget class’s components. See the GtkWidget documentation for details.The
See moreBuilderProtocol
protocol exposes the methods and properties of an underlyingGtkBuilder
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeBuilder
. Alternatively, useBuilderRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol BuilderProtocol : ObjectProtocol
-
A
GtkBuilderScope
implementation for the C language.GtkBuilderCScope
instances use symbols explicitly added tobuilder
with prior calls to [methodGtk.BuilderCScope.add_callback_symbol
]. If developers want to do that, they are encouraged to create their own scopes for that purpose.In the case that symbols are not explicitly added; GTK will uses
GModule
’s introspective features (by opening the modulenil
) to look at the application’s symbol table. From here it tries to match the signal function names given in the interface description with symbols in the application.Note that unless [method
Gtk.BuilderCScope.add_callback_symbol
] is called for all signal callbacks which are referenced by the loaded XML, this functionality will require thatGModule
be supported on the platform.The
See moreBuilderCScopeProtocol
protocol exposes the methods and properties of an underlyingGtkBuilderCScope
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeBuilderCScope
. Alternatively, useBuilderCScopeRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol BuilderCScopeProtocol : ObjectProtocol, BuilderScopeProtocol
-
GtkBuilderListItemFactory
is aGtkListItemFactory
that creates widgets by instantiatingGtkBuilder
UI templates.The templates must be extending
GtkListItem
, and typically useGtkExpression
s to obtain data from the items in the model.Example:
<interface> <template class="GtkListItem"> <property name="child"> <object class="GtkLabel"> <property name="xalign">0</property> <binding name="label"> <lookup name="name" type="SettingsKey"> <lookup name="item">GtkListItem</lookup> </lookup> </binding> </object> </property> </template> </interface>
The
See moreBuilderListItemFactoryProtocol
protocol exposes the methods and properties of an underlyingGtkBuilderListItemFactory
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeBuilderListItemFactory
. Alternatively, useBuilderListItemFactoryRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol BuilderListItemFactoryProtocol : ListItemFactoryProtocol
-
The
GtkButton
widget is generally used to trigger a callback function that is called when the button is pressed.The
GtkButton
widget can hold any valid child widget. That is, it can hold almost any other standardGtkWidget
. The most commonly used child is theGtkLabel
.CSS nodes
GtkButton
has a single CSS node with name button. The node will get the style classes .image-button or .text-button, if the content is just an image or label, respectively. It may also receive the .flat style class. When activating a button via the keyboard, the button will temporarily gain the .keyboard-activating style class.Other style classes that are commonly used with
GtkButton
include .suggested-action and .destructive-action. In special cases, buttons can be made round by adding the .circular style class.Button-like widgets like [class
Gtk.ToggleButton
], [classGtk.MenuButton
], [classGtk.VolumeButton
], [classGtk.LockButton
], [classGtk.ColorButton
] or [classGtk.FontButton
] use style classes such as .toggle, .popup, .scale, .lock, .color on the button node to differentiate themselves from a plainGtkButton
.Accessibility
GtkButton
uses theGTK_ACCESSIBLE_ROLE_BUTTON
role.The
See moreButtonProtocol
protocol exposes the methods and properties of an underlyingGtkButton
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeButton
. Alternatively, useButtonRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ButtonProtocol : ActionableProtocol
-
A variant of
GtkClosureExpression
using a C closure.The
See moreCClosureExpressionProtocol
protocol exposes the methods and properties of an underlyingGtkCClosureExpression
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeCClosureExpression
. Alternatively, useCClosureExpressionRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol CClosureExpressionProtocol : ExpressionProtocol
-
GtkBuilderScope
is an interface to provide language binding support toGtkBuilder
.The goal of
GtkBuilderScope
is to look up programming-language-specific values for strings that are given in aGtkBuilder
UI file.The primary intended audience is bindings that want to provide deeper integration of
GtkBuilder
into the language.A
GtkBuilderScope
instance may be used with multipleGtkBuilder
objects, even at once.By default, GTK will use its own implementation of
GtkBuilderScope
for the C language which can be created via [ctorGtk.BuilderCScope.new
].The
See moreBuilderScopeProtocol
protocol exposes the methods and properties of an underlyingGtkBuilderScope
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeBuilderScope
. Alternatively, useBuilderScopeRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol BuilderScopeProtocol
-
Interface for widgets that can be used for editing cells
The
GtkCellEditable
interface must be implemented for widgets to be usable to edit the contents of aGtkTreeView
cell. It provides a way to specify how temporary widgets should be configured for editing, get the new value, etc.The
See moreCellEditableProtocol
protocol exposes the methods and properties of an underlyingGtkCellEditable
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeCellEditable
. Alternatively, useCellEditableRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol CellEditableProtocol : WidgetProtocol
-
GtkCalendar
is a widget that displays a Gregorian calendar, one month at a time.A
GtkCalendar
can be created with [ctorGtk.Calendar.new
].The date that is currently displayed can be altered with [method
Gtk.Calendar.select_day
].To place a visual marker on a particular day, use [method
Gtk.Calendar.mark_day
] and to remove the marker, [methodGtk.Calendar.unmark_day
]. Alternative, all marks can be cleared with [methodGtk.Calendar.clear_marks
].The selected date can be retrieved from a
GtkCalendar
using [methodGtk.Calendar.get_date
].Users should be aware that, although the Gregorian calendar is the legal calendar in most countries, it was adopted progressively between 1582 and 1929. Display before these dates is likely to be historically incorrect.
CSS nodes
calendar.view ├── header │ ├── button │ ├── stack.month │ ├── button │ ├── button │ ├── label.year │ ╰── button ╰── grid ╰── label[.day-name][.week-number][.day-number][.other-month][.today]
GtkCalendar
has a main node with name calendar. It contains a subnode called header containing the widgets for switching between years and months.The grid subnode contains all day labels, including week numbers on the left (marked with the .week-number css class) and day names on top (marked with the .day-name css class).
Day labels that belong to the previous or next month get the .other-month style class. The label of the current day get the .today style class.
Marked day labels get the :selected state assigned.
The
See moreCalendarProtocol
protocol exposes the methods and properties of an underlyingGtkCalendar
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeCalendar
. Alternatively, useCalendarRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol CalendarProtocol : WidgetProtocol
-
A
GtkShortcutAction
that invokes a callback.The
See moreCallbackActionProtocol
protocol exposes the methods and properties of an underlyingGtkCallbackAction
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeCallbackAction
. Alternatively, useCallbackActionRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol CallbackActionProtocol : ShortcutActionProtocol
-
An abstract class for laying out GtkCellRenderers
The
GtkCellArea
is an abstract class forGtkCellLayout
widgets (also referred to as “layouting widgets”) to interface with an arbitrary number ofGtkCellRenderer
s and interact with the user for a givenGtkTreeModel
row.The cell area handles events, focus navigation, drawing and size requests and allocations for a given row of data.
Usually users dont have to interact with the
GtkCellArea
directly unless they are implementing a cell-layouting widget themselves.Requesting area sizes
As outlined in GtkWidget’s geometry management section, GTK uses a height-for-width geometry management system to compute the sizes of widgets and user interfaces.
GtkCellArea
uses the same semantics to calculate the size of an area for an arbitrary number ofGtkTreeModel
rows.When requesting the size of a cell area one needs to calculate the size for a handful of rows, and this will be done differently by different layouting widgets. For instance a
GtkTreeViewColumn
always lines up the areas from top to bottom while aGtkIconView
on the other hand might enforce that all areas received the same width and wrap the areas around, requesting height for more cell areas when allocated less width.It’s also important for areas to maintain some cell alignments with areas rendered for adjacent rows (cells can appear “columnized” inside an area even when the size of cells are different in each row). For this reason the
GtkCellArea
uses aGtkCellArea
Context object to store the alignments and sizes along the way (as well as the overall largest minimum and natural size for all the rows which have been calculated with the said context).The
GtkCellArea
Context is an opaque object specific to theGtkCellArea
which created it (seegtk_cell_area_create_context()
). The owning cell-layouting widget can create as many contexts as it wishes to calculate sizes of rows which should receive the same size in at least one orientation (horizontally or vertically), However, it’s important that the sameGtkCellArea
Context which was used to request the sizes for a givenGtkTreeModel
row be used when rendering or processing events for that row.In order to request the width of all the rows at the root level of a
GtkTreeModel
one would do the following:(C Language Example):
GtkTreeIter iter; int minimum_width; int natural_width; valid = gtk_tree_model_get_iter_first (model, &iter); while (valid) { gtk_cell_area_apply_attributes (area, model, &iter, FALSE, FALSE); gtk_cell_area_get_preferred_width (area, context, widget, NULL, NULL); valid = gtk_tree_model_iter_next (model, &iter); } gtk_cell_area_context_get_preferred_width (context, &minimum_width, &natural_width);
Note that in this example it’s not important to observe the returned minimum and natural width of the area for each row unless the cell-layouting object is actually interested in the widths of individual rows. The overall width is however stored in the accompanying
GtkCellArea
Context object and can be consulted at any time.This can be useful since
GtkCellLayout
widgets usually have to support requesting and rendering rows in treemodels with an exceedingly large amount of rows. TheGtkCellLayout
widget in that case would calculate the required width of the rows in an idle or timeout source (seeg_timeout_add()
) and when the widget is requested its actual width in [vfuncGtk.Widget.measure
] it can simply consult the width accumulated so far in theGtkCellArea
Context object.A simple example where rows are rendered from top to bottom and take up the full width of the layouting widget would look like:
(C Language Example):
static void foo_get_preferred_width (GtkWidget *widget, int *minimum_size, int *natural_size) { Foo *foo = FOO (widget); FooPrivate *priv = foo->priv; foo_ensure_at_least_one_handfull_of_rows_have_been_requested (foo); gtk_cell_area_context_get_preferred_width (priv->context, minimum_size, natural_size); }
In the above example the Foo widget has to make sure that some row sizes have been calculated (the amount of rows that Foo judged was appropriate to request space for in a single timeout iteration) before simply returning the amount of space required by the area via the
GtkCellArea
Context.Requesting the height for width (or width for height) of an area is a similar task except in this case the
GtkCellArea
Context does not store the data (actually, it does not know how much space the layouting widget plans to allocate it for every row. It’s up to the layouting widget to render each row of data with the appropriate height and width which was requested by theGtkCellArea
).In order to request the height for width of all the rows at the root level of a
GtkTreeModel
one would do the following:(C Language Example):
GtkTreeIter iter; int minimum_height; int natural_height; int full_minimum_height = 0; int full_natural_height = 0; valid = gtk_tree_model_get_iter_first (model, &iter); while (valid) { gtk_cell_area_apply_attributes (area, model, &iter, FALSE, FALSE); gtk_cell_area_get_preferred_height_for_width (area, context, widget, width, &minimum_height, &natural_height); if (width_is_for_allocation) cache_row_height (&iter, minimum_height, natural_height); full_minimum_height += minimum_height; full_natural_height += natural_height; valid = gtk_tree_model_iter_next (model, &iter); }
Note that in the above example we would need to cache the heights returned for each row so that we would know what sizes to render the areas for each row. However we would only want to really cache the heights if the request is intended for the layouting widgets real allocation.
In some cases the layouting widget is requested the height for an arbitrary for_width, this is a special case for layouting widgets who need to request size for tens of thousands of rows. For this case it’s only important that the layouting widget calculate one reasonably sized chunk of rows and return that height synchronously. The reasoning here is that any layouting widget is at least capable of synchronously calculating enough height to fill the screen height (or scrolled window height) in response to a single call to [vfunc
Gtk.Widget.measure
]. Returning a perfect height for width that is larger than the screen area is inconsequential since after the layouting receives an allocation from a scrolled window it simply continues to drive the scrollbar values while more and more height is required for the row heights that are calculated in the background.Rendering Areas
Once area sizes have been acquired at least for the rows in the visible area of the layouting widget they can be rendered at [vfunc
Gtk.Widget.snapshot
] time.A crude example of how to render all the rows at the root level runs as follows:
(C Language Example):
GtkAllocation allocation; GdkRectangle cell_area = { 0, }; GtkTreeIter iter; int minimum_width; int natural_width; gtk_widget_get_allocation (widget, &allocation); cell_area.width = allocation.width; valid = gtk_tree_model_get_iter_first (model, &iter); while (valid) { cell_area.height = get_cached_height_for_row (&iter); gtk_cell_area_apply_attributes (area, model, &iter, FALSE, FALSE); gtk_cell_area_render (area, context, widget, cr, &cell_area, &cell_area, state_flags, FALSE); cell_area.y += cell_area.height; valid = gtk_tree_model_iter_next (model, &iter); }
Note that the cached height in this example really depends on how the layouting widget works. The layouting widget might decide to give every row its minimum or natural height or, if the model content is expected to fit inside the layouting widget without scrolling, it would make sense to calculate the allocation for each row at the time the widget is allocated using
gtk_distribute_natural_allocation()
.Handling Events and Driving Keyboard Focus
Passing events to the area is as simple as handling events on any normal widget and then passing them to the
gtk_cell_area_event()
API as they come in. UsuallyGtkCellArea
is only interested in button events, however some customized derived areas can be implemented who are interested in handling other events. Handling an event can trigger theGtkCellArea
focus-changed
signal to fire; as well asGtkCellArea
add-editable
in the case that an editable cell was clicked and needs to start editing. You can callgtk_cell_area_stop_editing()
at any time to cancel any cell editing that is currently in progress.The
GtkCellArea
drives keyboard focus from cell to cell in a way similar toGtkWidget
. For layouting widgets that support giving focus to cells it’s important to remember to passGTK_CELL_RENDERER_FOCUSED
to the area functions for the row that has focus and to tell the area to paint the focus at render time.Layouting widgets that accept focus on cells should implement the [vfunc
Gtk.Widget.focus
] virtual method. The layouting widget is always responsible for knowing whereGtkTreeModel
rows are rendered inside the widget, so at [vfuncGtk.Widget.focus
] time the layouting widget should use theGtkCellArea
methods to navigate focus inside the area and then observe the GtkDirectionType to pass the focus to adjacent rows and areas.A basic example of how the [vfunc
Gtk.Widget.focus
] virtual method should be implemented:(C Language Example):
static gboolean foo_focus (GtkWidget *widget, GtkDirectionType direction) { Foo *foo = FOO (widget); FooPrivate *priv = foo->priv; int focus_row; gboolean have_focus = FALSE; focus_row = priv->focus_row; if (!gtk_widget_has_focus (widget)) gtk_widget_grab_focus (widget); valid = gtk_tree_model_iter_nth_child (priv->model, &iter, NULL, priv->focus_row); while (valid) { gtk_cell_area_apply_attributes (priv->area, priv->model, &iter, FALSE, FALSE); if (gtk_cell_area_focus (priv->area, direction)) { priv->focus_row = focus_row; have_focus = TRUE; break; } else { if (direction == GTK_DIR_RIGHT || direction == GTK_DIR_LEFT) break; else if (direction == GTK_DIR_UP || direction == GTK_DIR_TAB_BACKWARD) { if (focus_row == 0) break; else { focus_row--; valid = gtk_tree_model_iter_nth_child (priv->model, &iter, NULL, focus_row); } } else { if (focus_row == last_row) break; else { focus_row++; valid = gtk_tree_model_iter_next (priv->model, &iter); } } } } return have_focus; }
Note that the layouting widget is responsible for matching the GtkDirectionType values to the way it lays out its cells.
Cell Properties
The
GtkCellArea
introduces cell properties forGtkCellRenderer
s. This provides some general interfaces for defining the relationship cell areas have with their cells. For instance in aGtkCellArea
Box a cell might “expand” and receive extra space when the area is allocated more than its full natural request, or a cell might be configured to “align” with adjacent rows which were requested and rendered with the sameGtkCellArea
Context.Use
gtk_cell_area_class_install_cell_property()
to install cell properties for a cell area class andgtk_cell_area_class_find_cell_property()
orgtk_cell_area_class_list_cell_properties()
to get information about existing cell properties.To set the value of a cell property, use
gtk_cell_area_cell_set_property()
,gtk_cell_area_cell_set()
orgtk_cell_area_cell_set_valist()
. To obtain the value of a cell property, usegtk_cell_area_cell_get_property()
,gtk_cell_area_cell_get()
orgtk_cell_area_cell_get_valist()
.The
See moreCellAreaProtocol
protocol exposes the methods and properties of an underlyingGtkCellArea
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeCellArea
. Alternatively, useCellAreaRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol CellAreaProtocol : InitiallyUnownedProtocol, BuildableProtocol, CellLayoutProtocol
-
A cell area that renders GtkCellRenderers into a row or a column
The
GtkCellAreaBox
renders cell renderers into a row or a column depending on itsGtkOrientation
.GtkCellAreaBox uses a notion of packing. Packing refers to adding cell renderers with reference to a particular position in a
GtkCellAreaBox
. There are two reference positions: the start and the end of the box. When theGtkCellAreaBox
is oriented in theGTK_ORIENTATION_VERTICAL
orientation, the start is defined as the top of the box and the end is defined as the bottom. In theGTK_ORIENTATION_HORIZONTAL
orientation start is defined as the left side and the end is defined as the right side.Alignments of
GtkCellRenderer
s rendered in adjacent rows can be configured by configuring theGtkCellAreaBox
align child cell property withgtk_cell_area_cell_set_property()
or by specifying the “align” argument togtk_cell_area_box_pack_start()
andgtk_cell_area_box_pack_end()
.The
See moreCellAreaBoxProtocol
protocol exposes the methods and properties of an underlyingGtkCellAreaBox
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeCellAreaBox
. Alternatively, useCellAreaBoxRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol CellAreaBoxProtocol : CellAreaProtocol, OrientableProtocol
-
Stores geometrical information for a series of rows in a GtkCellArea
The
GtkCellAreaContext
object is created by a givenGtkCellArea
implementation via itsGtkCellAreaClass.create_context()
virtual method and is used to store cell sizes and alignments for a series ofGtkTreeModel
rows that are requested and rendered in the same context.GtkCellLayout
widgets can create any number of contexts in which to request and render groups of data rows. However, it’s important that the same context which was used to request sizes for a givenGtkTreeModel
row also be used for the same row when calling otherGtkCellArea
APIs such asgtk_cell_area_render()
andgtk_cell_area_event()
.The
See moreCellAreaContextProtocol
protocol exposes the methods and properties of an underlyingGtkCellAreaContext
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeCellAreaContext
. Alternatively, useCellAreaContextRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol CellAreaContextProtocol : ObjectProtocol
-
An object for rendering a single cell
The
GtkCellRenderer
is a base class of a set of objects used for rendering a cell to acairo_t
. These objects are used primarily by theGtkTreeView
widget, though they aren’t tied to them in any specific way. It is worth noting thatGtkCellRenderer
is not aGtkWidget
and cannot be treated as such.The primary use of a
GtkCellRenderer
is for drawing a certain graphical elements on acairo_t
. Typically, one cell renderer is used to draw many cells on the screen. To this extent, it isn’t expected that a CellRenderer keep any permanent state around. Instead, any state is set just prior to use usingGObject
s property system. Then, the cell is measured usinggtk_cell_renderer_get_preferred_size()
. Finally, the cell is rendered in the correct location usinggtk_cell_renderer_snapshot()
.There are a number of rules that must be followed when writing a new
GtkCellRenderer
. First and foremost, it’s important that a certain set of properties will always yield a cell renderer of the same size, barring a style change. TheGtkCellRenderer
also has a number of generic properties that are expected to be honored by all children.Beyond merely rendering a cell, cell renderers can optionally provide active user interface elements. A cell renderer can be “activatable” like
GtkCellRenderer
Toggle, which toggles when it gets activated by a mouse click, or it can be “editable” likeGtkCellRenderer
Text, which allows the user to edit the text using a widget implementing theGtkCellEditable
interface, e.g.GtkEntry
. To make a cell renderer activatable or editable, you have to implement theGtkCellRenderer
Class.activate orGtkCellRenderer
Class.start_editing virtual functions, respectively.Many properties of
GtkCellRenderer
and its subclasses have a corresponding “set” property, e.g. “cell-background-set” corresponds to “cell-background”. These “set” properties reflect whether a property has been set or not. You should not set them independently.The
See moreCellRendererProtocol
protocol exposes the methods and properties of an underlyingGtkCellRenderer
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeCellRenderer
. Alternatively, useCellRendererRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol CellRendererProtocol : InitiallyUnownedProtocol
-
Renders a keyboard accelerator in a cell
GtkCellRendererAccel
displays a keyboard accelerator (i.e. a key combination likeControl + a
). If the cell renderer is editable, the accelerator can be changed by simply typing the new combination.The
See moreCellRendererAccelProtocol
protocol exposes the methods and properties of an underlyingGtkCellRendererAccel
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeCellRendererAccel
. Alternatively, useCellRendererAccelRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol CellRendererAccelProtocol : CellRendererTextProtocol
-
Renders a combobox in a cell
GtkCellRendererCombo
renders text in a cell likeGtkCellRendererText
from which it is derived. But whileGtkCellRendererText
offers a simple entry to edit the text,GtkCellRendererCombo
offers aGtkComboBox
widget to edit the text. The values to display in the combo box are taken from the tree model specified in theGtkCellRendererCombo
:model property.The combo cell renderer takes care of adding a text cell renderer to the combo box and sets it to display the column specified by its
GtkCellRendererCombo
:text-column property. Further properties of the combo box can be set in a handler for theGtkCellRenderer
editing-started`` signal.The
See moreCellRendererComboProtocol
protocol exposes the methods and properties of an underlyingGtkCellRendererCombo
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeCellRendererCombo
. Alternatively, useCellRendererComboRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol CellRendererComboProtocol : CellRendererTextProtocol
-
Renders a pixbuf in a cell
A
GtkCellRendererPixbuf
can be used to render an image in a cell. It allows to render either a givenGdkPixbuf
(set via theGtkCellRendererPixbuf:pixbuf
property) or a named icon (set via theGtkCellRendererPixbuf:icon-name
property).To support the tree view,
GtkCellRendererPixbuf
also supports rendering two alternative pixbufs, when theGtkCellRenderer:is-expander
property istrue
. If theGtkCellRenderer:is-expanded property
istrue
and theGtkCellRendererPixbuf:pixbuf-expander-open
property is set to a pixbuf, it renders that pixbuf, if theGtkCellRenderer:is-expanded
property isfalse
and theGtkCellRendererPixbuf:pixbuf-expander-closed
property is set to a pixbuf, it renders that one.The
See moreCellRendererPixbufProtocol
protocol exposes the methods and properties of an underlyingGtkCellRendererPixbuf
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeCellRendererPixbuf
. Alternatively, useCellRendererPixbufRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol CellRendererPixbufProtocol : CellRendererProtocol
-
Renders numbers as progress bars
GtkCellRendererProgress
renders a numeric value as a progress par in a cell. Additionally, it can display a text on top of the progress bar.The
See moreCellRendererProgressProtocol
protocol exposes the methods and properties of an underlyingGtkCellRendererProgress
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeCellRendererProgress
. Alternatively, useCellRendererProgressRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol CellRendererProgressProtocol : CellRendererProtocol, OrientableProtocol
-
Renders a spin button in a cell
GtkCellRendererSpin
renders text in a cell likeGtkCellRendererText
from which it is derived. But whileGtkCellRendererText
offers a simple entry to edit the text,GtkCellRendererSpin
offers aGtkSpinButton
widget. Of course, that means that the text has to be parseable as a floating point number.The range of the spinbutton is taken from the adjustment property of the cell renderer, which can be set explicitly or mapped to a column in the tree model, like all properties of cell renders.
GtkCellRendererSpin
also has properties for theGtkCellRendererSpin:climb-rate
and the number ofGtkCellRendererSpin:digits
to display. OtherGtkSpinButton
properties can be set in a handler for theGtkCellRenderer
editing-started`` signal.The
GtkCellRendererSpin
cell renderer was added in GTK 2.10.The
See moreCellRendererSpinProtocol
protocol exposes the methods and properties of an underlyingGtkCellRendererSpin
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeCellRendererSpin
. Alternatively, useCellRendererSpinRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol CellRendererSpinProtocol : CellRendererTextProtocol
-
Renders a spinning animation in a cell
GtkCellRendererSpinner
renders a spinning animation in a cell, very similar toGtkSpinner
. It can often be used as an alternative to aGtkCellRendererProgress
for displaying indefinite activity, instead of actual progress.To start the animation in a cell, set the
GtkCellRendererSpinner:active
property totrue
and increment theGtkCellRendererSpinner:pulse
property at regular intervals. The usual way to set the cell renderer properties for each cell is to bind them to columns in your tree model using e.g.gtk_tree_view_column_add_attribute()
.The
See moreCellRendererSpinnerProtocol
protocol exposes the methods and properties of an underlyingGtkCellRendererSpinner
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeCellRendererSpinner
. Alternatively, useCellRendererSpinnerRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol CellRendererSpinnerProtocol : CellRendererProtocol
-
Renders text in a cell
A
GtkCellRendererText
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 theGtkCellRendererText:ellipsize
property allows it.If the
GtkCellRenderer:mode
isGTK_CELL_RENDERER_MODE_EDITABLE
, theGtkCellRendererText
allows to edit its text using an entry.The
See moreCellRendererTextProtocol
protocol exposes the methods and properties of an underlyingGtkCellRendererText
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeCellRendererText
. Alternatively, useCellRendererTextRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol CellRendererTextProtocol : CellRendererProtocol
-
Renders a toggle button in a cell
GtkCellRendererToggle
renders a toggle button in a cell. The button is drawn as a radio or a checkbutton, depending on theGtkCellRendererToggle:radio
property. When activated, it emits theGtkCellRendererToggle
toggled`` signal.The
See moreCellRendererToggleProtocol
protocol exposes the methods and properties of an underlyingGtkCellRendererToggle
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeCellRendererToggle
. Alternatively, useCellRendererToggleRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol CellRendererToggleProtocol : CellRendererProtocol
-
A widget displaying a single row of a GtkTreeModel
A
GtkCellView
displays a single row of aGtkTreeModel
using aGtkCellArea
andGtkCellAreaContext
. AGtkCellAreaContext
can be provided to theGtkCellView
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 each other (like the aligned cells in the menus ofGtkComboBox
).GtkCellView
isGtkOrientable
in order to decide in which orientation the underlyingGtkCellAreaContext
should be allocated. Taking theGtkComboBox
menu as an example, cellviews should be oriented horizontally if the menus are listed top-to-bottom and thus all share the same width but may have separate individual heights (left-to-right menus should be allocated vertically since they all share the same height but may have variable widths).CSS nodes
GtkCellView has a single CSS node with name cellview.
The
See moreCellViewProtocol
protocol exposes the methods and properties of an underlyingGtkCellView
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeCellView
. Alternatively, useCellViewRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol CellViewProtocol : CellLayoutProtocol, OrientableProtocol, WidgetProtocol
-
GtkCenterBox
arranges three children in a row, keeping the middle child centered as well as possible.To add children to
GtkCenterBox
, use [methodGtk.CenterBox.set_start_widget
], [methodGtk.CenterBox.set_center_widget
] and [methodGtk.CenterBox.set_end_widget
].The sizing and positioning of children can be influenced with the align and expand properties of the children.
GtkCenterBox as GtkBuildable
The
GtkCenterBox
implementation of theGtkBuildable
interface supports placing children in the 3 positions by specifying “start”, “center” or “end” as the “type” attribute of a <child> element.CSS nodes
GtkCenterBox
uses a single CSS node with the name “box”,The first child of the
GtkCenterBox
will be allocated depending on the text direction, i.e. in left-to-right layouts it will be allocated on the left and in right-to-left layouts on the right.In vertical orientation, the nodes of the children are arranged from top to bottom.
Accessibility
GtkCenterBox
uses theGTK_ACCESSIBLE_ROLE_GROUP
role.The
See moreCenterBoxProtocol
protocol exposes the methods and properties of an underlyingGtkCenterBox
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeCenterBox
. Alternatively, useCenterBoxRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol CenterBoxProtocol : OrientableProtocol, WidgetProtocol
-
GtkCenterLayout
is a layout manager that manages up to three children.The start widget is allocated at the start of the layout (left in left-to-right locales and right in right-to-left ones), and the end widget at the end.
The center widget is centered regarding the full width of the layout’s.
The
See moreCenterLayoutProtocol
protocol exposes the methods and properties of an underlyingGtkCenterLayout
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeCenterLayout
. Alternatively, useCenterLayoutRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol CenterLayoutProtocol : LayoutManagerProtocol
-
A
GtkCheckButton
places a label next to an indicator.A
GtkCheckButton
is created by calling either [ctorGtk.CheckButton.new
] or [ctorGtk.CheckButton.new_with_label
].The state of a
GtkCheckButton
can be set specifically using [methodGtk.CheckButton.set_active
], and retrieved using [methodGtk.CheckButton.get_active
].Inconsistent state
In addition to “on” and “off”, check buttons can be an “in between” state that is neither on nor off. This can be used e.g. when the user has selected a range of elements (such as some text or spreadsheet cells) that are affected by a check button, and the current values in that range are inconsistent.
To set a
GtkCheckButton
to inconsistent state, use [methodGtk.CheckButton.set_inconsistent
].Grouping
Check buttons can be grouped together, to form mutually exclusive groups - only one of the buttons can be toggled at a time, and toggling another one will switch the currently toggled one off.
Grouped check buttons use a different indicator, and are commonly referred to as radio buttons.
To add a
GtkCheckButton
to a group, use [methodGtk.CheckButton.set_group
].CSS nodes
checkbutton[.text-button] ├── check ╰── [label]
A
GtkCheckButton
has a main node with name checkbutton. If the [propertyGtk.CheckButton:label
] property is set, it contains a label child. The indicator node is named check when no group is set, and radio if the checkbutton is grouped together with other checkbuttons.Accessibility
GtkCheckButton
uses theGTK_ACCESSIBLE_ROLE_CHECKBOX
role.The
See moreCheckButtonProtocol
protocol exposes the methods and properties of an underlyingGtkCheckButton
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeCheckButton
. Alternatively, useCheckButtonRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol CheckButtonProtocol : ActionableProtocol
-
An expression using a custom
GClosure
to compute the value from its parameters.The
See moreClosureExpressionProtocol
protocol exposes the methods and properties of an underlyingGtkClosureExpression
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeClosureExpression
. Alternatively, useClosureExpressionRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ClosureExpressionProtocol : ExpressionProtocol
-
The
GtkColorButton
allows to open a color chooser dialog to change the color.It is suitable widget for selecting a color in a preference dialog.
CSS nodes
colorbutton ╰── button.color ╰── [content]
GtkColorButton
has a single CSS node with name colorbutton which contains a button node. To differentiate it from a plainGtkButton
, it gets the .color style class.The
See moreColorButtonProtocol
protocol exposes the methods and properties of an underlyingGtkColorButton
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeColorButton
. Alternatively, useColorButtonRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ColorButtonProtocol : ColorChooserProtocol, WidgetProtocol
-
A dialog for choosing a color.
GtkColorChooserDialog
implements the [ifaceGtk.ColorChooser
] interface and does not provide much API of its own.To create a
GtkColorChooserDialog
, use [ctorGtk.ColorChooserDialog.new
].To change the initially selected color, use [method
Gtk.ColorChooser.set_rgba
]. To get the selected color use [methodGtk.ColorChooser.get_rgba
].The
See moreColorChooserDialogProtocol
protocol exposes the methods and properties of an underlyingGtkColorChooserDialog
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeColorChooserDialog
. Alternatively, useColorChooserDialogRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ColorChooserDialogProtocol : ColorChooserProtocol, DialogProtocol
-
The
GtkColorChooserWidget
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.
The chooser automatically remembers the last selection, as well as custom colors.
To create a
GtkColorChooserWidget
, use [ctorGtk.ColorChooserWidget.new
].To change the initially selected color, use [method
Gtk.ColorChooser.set_rgba
]. To get the selected color use [methodGtk.ColorChooser.get_rgba
].The
GtkColorChooserWidget
is used in the [classGtk.ColorChooserDialog
] to provide a dialog for selecting colors.CSS names
GtkColorChooserWidget
has a single CSS node with name colorchooser.The
See moreColorChooserWidgetProtocol
protocol exposes the methods and properties of an underlyingGtkColorChooserWidget
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeColorChooserWidget
. Alternatively, useColorChooserWidgetRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ColorChooserWidgetProtocol : ColorChooserProtocol, WidgetProtocol
-
GtkColumnView
presents a large dynamic list of items using multiple columns with headers.GtkColumnView
uses the factories of its columns to generate a cell widget for each column, for each visible item and displays them together as the row for this item.The [property
Gtk.ColumnView:show-row-separators
] and [propertyGtk.ColumnView:show-column-separators
] properties offer a simple way to display separators between the rows or columns.GtkColumnView
allows the user to select items according to the selection characteristics of the model. For models that allow multiple selected items, it is possible to turn on rubberband selection, using [propertyGtk.ColumnView:enable-rubberband
].The column view supports sorting that can be customized by the user by clicking on column headers. To set this up, the
GtkSorter
returned by [methodGtk.ColumnView.get_sorter
] must be attached to a sort model for the data that the view is showing, and the columns must have sorters attached to them by calling [methodGtk.ColumnViewColumn.set_sorter
]. The initial sort order can be set with [methodGtk.ColumnView.sort_by_column
].The column view also supports interactive resizing and reordering of columns, via Drag-and-Drop of the column headers. This can be enabled or disabled with the [property
Gtk.ColumnView:reorderable
] and [propertyGtk.ColumnViewColumn:resizable
] properties.To learn more about the list widget framework, see the overview.
CSS nodes
columnview[.column-separators][.rich-list][.navigation-sidebar][.data-table] ├── header │ ├── <column header> ┊ ┊ │ ╰── <column header> │ ├── listview │ ┊ ╰── [rubberband]
GtkColumnView
uses a single CSS node named columnview. It may carry the .column-separators style class, when [propertyGtk.ColumnView:show-column-separators
] property is set. Header widgets appear below a node with name header. The rows are contained in aGtkListView
widget, so there is a listview node with the same structure as for a standaloneGtkListView
widget. If [propertyGtk.ColumnView:show-row-separators
] is set, it will be passed on to the list view, causing its CSS node to carry the .separators style class. For rubberband selection, a node with name rubberband is used.The main columnview node may also carry style classes to select the style of list presentation: .rich-list, .navigation-sidebar or .data-table.
Accessibility
GtkColumnView
uses theGTK_ACCESSIBLE_ROLE_TREE_GRID
role, header title widgets are using theGTK_ACCESSIBLE_ROLE_COLUMN_HEADER
role. The row widgets are using theGTK_ACCESSIBLE_ROLE_ROW
role, and individual cells are using theGTK_ACCESSIBLE_ROLE_GRID_CELL
roleThe
See moreColumnViewProtocol
protocol exposes the methods and properties of an underlyingGtkColumnView
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeColumnView
. Alternatively, useColumnViewRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ColumnViewProtocol : ScrollableProtocol, WidgetProtocol
-
GtkColumnViewColumn
represents the columns being added toGtkColumnView
.The main ingredient for a
GtkColumnViewColumn
is theGtkListItemFactory
that tells the columnview how to create cells for this column from items in the model.Columns have a title, and can optionally have a header menu set with [method
Gtk.ColumnViewColumn.set_header_menu
].A sorter can be associated with a column using [method
Gtk.ColumnViewColumn.set_sorter
], to let users influence sorting by clicking on the column header.The
See moreColumnViewColumnProtocol
protocol exposes the methods and properties of an underlyingGtkColumnViewColumn
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeColumnViewColumn
. Alternatively, useColumnViewColumnRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ColumnViewColumnProtocol : ObjectProtocol
-
A
GtkComboBox
is a widget that allows the user to choose from a list of valid choices.The
GtkComboBox
displays the selected choice; when activated, theGtkComboBox
displays a popup which allows the user to make a new choice.The
GtkComboBox
uses the model-view pattern; the list of valid choices is specified in the form of a tree model, and the display of the choices can be adapted to the data in the model by using cell renderers, as you would in a tree view. This is possible sinceGtkComboBox
implements the [ifaceGtk.CellLayout
] interface. The tree model holding the valid choices is not restricted to a flat list, it can be a real tree, and the popup will reflect the tree structure.To allow the user to enter values not in the model, the [property
Gtk.ComboBox:has-entry
] property allows theGtkComboBox
to contain a [classGtk.Entry
]. This entry can be accessed by calling [methodGtk.ComboBox.get_child
] on the combo box.For a simple list of textual choices, the model-view API of
GtkComboBox
can be a bit overwhelming. In this case, [classGtk.ComboBoxText
] offers a simple alternative. BothGtkComboBox
andGtkComboBoxText
can contain an entry.CSS nodes
combobox ├── box.linked │ ╰── button.combo │ ╰── box │ ├── cellview │ ╰── arrow ╰── window.popup
A normal combobox contains a box with the .linked class, a button with the .combo class and inside those buttons, there are a cellview and an arrow.
combobox ├── box.linked │ ├── entry.combo │ ╰── button.combo │ ╰── box │ ╰── arrow ╰── window.popup
A
GtkComboBox
with an entry has a single CSS node with name combobox. It contains a box with the .linked class. That box contains an entry and a button, both with the .combo class added. The button also contains another node with name arrow.Accessibility
GtkComboBox
uses theGTK_ACCESSIBLE_ROLE_COMBO_BOX
role.The
See moreComboBoxProtocol
protocol exposes the methods and properties of an underlyingGtkComboBox
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeComboBox
. Alternatively, useComboBoxRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ComboBoxProtocol : CellEditableProtocol, CellLayoutProtocol
-
A
GtkComboBoxText
is a simple variant ofGtkComboBox
for text-only use cases.GtkComboBoxText
hides the model-view complexity ofGtkComboBox
.To create a
GtkComboBoxText
, use [ctorGtk.ComboBoxText.new
] or [ctorGtk.ComboBoxText.new_with_entry
].You can add items to a
GtkComboBoxText
with [methodGtk.ComboBoxText.append_text
], [methodGtk.ComboBoxText.insert_text
] or [methodGtk.ComboBoxText.prepend_text
] and remove options with [methodGtk.ComboBoxText.remove
].If the
GtkComboBoxText
contains an entry (via the [propertyGtk.ComboBox:has-entry
] property), its contents can be retrieved using [methodGtk.ComboBoxText.get_active_text
].You should not call [method
Gtk.ComboBox.set_model
] or attempt to pack more cells into this combo box via its [ifaceGtk.CellLayout
] interface.GtkComboBoxText as GtkBuildable
The
GtkComboBoxText
implementation of theGtkBuildable
interface supports adding items directly using the <items> element and specifying <item> elements for each item. Each <item> element can specify the “id” corresponding to the appended text and also supports the regular translation attributes “translatable”, “context” and “comments”.Here is a UI definition fragment specifying
GtkComboBoxText
items:<object class="GtkComboBoxText"> <items> <item translatable="yes" id="factory">Factory</item> <item translatable="yes" id="home">Home</item> <item translatable="yes" id="subway">Subway</item> </items> </object>
CSS nodes
combobox ╰── box.linked ├── entry.combo ├── button.combo ╰── window.popup
GtkComboBoxText
has a single CSS node with name combobox. It adds the style class .combo to the main CSS nodes of its entry and button children, and the .linked class to the node of its internal box.The
See moreComboBoxTextProtocol
protocol exposes the methods and properties of an underlyingGtkComboBoxText
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeComboBoxText
. Alternatively, useComboBoxTextRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ComboBoxTextProtocol : ComboBoxProtocol
-
A constant value in a
GtkExpression
.The
See moreConstantExpressionProtocol
protocol exposes the methods and properties of an underlyingGtkConstantExpression
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeConstantExpression
. Alternatively, useConstantExpressionRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ConstantExpressionProtocol : ExpressionProtocol
-
GtkConstraint
describes a constraint between attributes of two widgets, expressed as a linear equation.The typical equation for a constraint is:
target.target_attr = source.source_attr × multiplier + constant
Each
GtkConstraint
is part of a system that will be solved by a [classGtk.ConstraintLayout
] in order to allocate and position each child widget or guide.The source and target, as well as their attributes, of a
GtkConstraint
instance are immutable after creation.The
See moreConstraintProtocol
protocol exposes the methods and properties of an underlyingGtkConstraint
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeConstraint
. Alternatively, useConstraintRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ConstraintProtocol : ObjectProtocol
-
A
GtkConstraintGuide
is an invisible layout element in aGtkConstraintLayout
.The
GtkConstraintLayout
treats guides like widgets. They can be used as the source or target of aGtkConstraint
.Guides have a minimum, maximum and natural size. Depending on the constraints that are applied, they can act like a guideline that widgets can be aligned to, or like flexible space.
Unlike a
GtkWidget
, aGtkConstraintGuide
will not be drawn.The
See moreConstraintGuideProtocol
protocol exposes the methods and properties of an underlyingGtkConstraintGuide
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeConstraintGuide
. Alternatively, useConstraintGuideRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ConstraintGuideProtocol : ObjectProtocol, ConstraintTargetProtocol
-
A layout manager using constraints to describe relations between widgets.
GtkConstraintLayout
is a layout manager that uses relations between widget attributes, expressed via [classGtk.Constraint
] instances, to measure and allocate widgets.How do constraints work
Constraints are objects defining the relationship between attributes of a widget; you can read the description of the [class
Gtk.Constraint
] class to have a more in depth definition.By taking multiple constraints and applying them to the children of a widget using
GtkConstraintLayout
, it’s possible to describe complex layout policies; each constraint applied to a child or to the parent widgets contributes to the full description of the layout, in terms of parameters for resolving the value of each attribute.It is important to note that a layout is defined by the totality of constraints; removing a child, or a constraint, from an existing layout without changing the remaining constraints may result in an unstable or unsolvable layout.
Constraints have an implicit “reading order”; you should start describing each edge of each child, as well as their relationship with the parent container, from the top left (or top right, in RTL languages), horizontally first, and then vertically.
A constraint-based layout with too few constraints can become “unstable”, that is: have more than one solution. The behavior of an unstable layout is undefined.
A constraint-based layout with conflicting constraints may be unsolvable, and lead to an unstable layout. You can use the [property
Gtk.Constraint:strength
] property of [classGtk.Constraint
] to “nudge” the layout towards a solution.GtkConstraintLayout as GtkBuildable
GtkConstraintLayout
implements the [ifaceGtk.Buildable
] interface and has a custom “constraints” element which allows describing constraints in a [classGtk.Builder
] UI file.An example of a UI definition fragment specifying a constraint:
<object class="GtkConstraintLayout"> <constraints> <constraint target="button" target-attribute="start" relation="eq" source="super" source-attribute="start" constant="12" strength="required" /> <constraint target="button" target-attribute="width" relation="ge" constant="250" strength="strong" /> </constraints> </object>
The definition above will add two constraints to the GtkConstraintLayout:
- a required constraint between the leading edge of “button” and the leading edge of the widget using the constraint layout, plus 12 pixels
- a strong, constant constraint making the width of “button” greater than, or equal to 250 pixels
The “target” and “target-attribute” attributes are required.
The “source” and “source-attribute” attributes of the “constraint” element are optional; if they are not specified, the constraint is assumed to be a constant.
The “relation” attribute is optional; if not specified, the constraint is assumed to be an equality.
The “strength” attribute is optional; if not specified, the constraint is assumed to be required.
The “source” and “target” attributes can be set to “super” to indicate that the constraint target is the widget using the GtkConstraintLayout.
There can be “constant” and “multiplier” attributes.
Additionally, the “constraints” element can also contain a description of the
GtkConstraintGuides
used by the layout:<constraints> <guide min-width="100" max-width="500" name="hspace"/> <guide min-height="64" nat-height="128" name="vspace" strength="strong"/> </constraints>
The “guide” element has the following optional attributes:
- “min-width”, “nat-width”, and “max-width”, describe the minimum, natural, and maximum width of the guide, respectively
- “min-height”, “nat-height”, and “max-height”, describe the minimum, natural, and maximum height of the guide, respectively
- “strength” describes the strength of the constraint on the natural size of the guide; if not specified, the constraint is assumed to have a medium strength
- “name” describes a name for the guide, useful when debugging
Using the Visual Format Language
Complex constraints can be described using a compact syntax called VFL, or Visual Format Language.
The Visual Format Language describes all the constraints on a row or column, typically starting from the leading edge towards the trailing one. Each element of the layout is composed by “views”, which identify a [iface
Gtk.ConstraintTarget
].For instance:
[button]-[textField]
Describes a constraint that binds the trailing edge of “button” to the leading edge of “textField”, leaving a default space between the two.
Using VFL is also possible to specify predicates that describe constraints on attributes like width and height:
// Width must be greater than, or equal to 50 [`button(>=50)`] // Width of button1 must be equal to width of button2 [`button1(==button2)`]
The default orientation for a VFL description is horizontal, unless otherwise specified:
// horizontal orientation, default attribute: width H:[`button(>=150)`] // vertical orientation, default attribute: height V:[`button1(==button2)`]
It’s also possible to specify multiple predicates, as well as their strength:
// minimum width of button must be 150 // natural width of button can be 250 [`button(>=150@required, ==250@medium)`]
Finally, it’s also possible to use simple arithmetic operators:
// width of button1 must be equal to width of button2 // divided by 2 plus 12 [`button1(button2 / 2 + 12)`]
The
See moreConstraintLayoutProtocol
protocol exposes the methods and properties of an underlyingGtkConstraintLayout
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeConstraintLayout
. Alternatively, useConstraintLayoutRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ConstraintLayoutProtocol : BuildableProtocol, LayoutManagerProtocol
-
GtkLayoutChild
subclass for children in aGtkConstraintLayout
.The
See moreConstraintLayoutChildProtocol
protocol exposes the methods and properties of an underlyingGtkConstraintLayoutChild
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeConstraintLayoutChild
. Alternatively, useConstraintLayoutChildRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ConstraintLayoutChildProtocol : LayoutChildProtocol
-
GtkCustomFilter
determines whether to include items with a callback.The
See moreCustomFilterProtocol
protocol exposes the methods and properties of an underlyingGtkCustomFilter
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeCustomFilter
. Alternatively, useCustomFilterRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol CustomFilterProtocol : FilterProtocol
-
GtkCustomLayout
uses closures for size negotiation.A
GtkCustomLayout
uses closures matching to the oldGtkWidget
virtual functions for size negotiation, as a convenience API to ease the porting towards the corresponding `GtkLayoutManager virtual functions.The
See moreCustomLayoutProtocol
protocol exposes the methods and properties of an underlyingGtkCustomLayout
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeCustomLayout
. Alternatively, useCustomLayoutRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol CustomLayoutProtocol : LayoutManagerProtocol
-
GtkCustomSorter
is aGtkSorter
implementation that sorts via a callback function.The
See moreCustomSorterProtocol
protocol exposes the methods and properties of an underlyingGtkCustomSorter
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeCustomSorter
. Alternatively, useCustomSorterRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol CustomSorterProtocol : SorterProtocol
-
Dialogs are a convenient way to prompt the user for a small amount of input.
Typical uses are to display a message, ask a question, or anything else that does not require extensive effort on the user’s part.
The main area of a
GtkDialog
is called the “content area”, and is yours to populate with widgets such aGtkLabel
orGtkEntry
, to present your information, questions, or tasks to the user.In addition, dialogs allow you to add “action widgets”. Most commonly, action widgets are buttons. Depending on the platform, action widgets may be presented in the header bar at the top of the window, or at the bottom of the window. To add action widgets, create your
GtkDialog
using [ctorGtk.Dialog.new_with_buttons
], or use [methodGtk.Dialog.add_button
], [methodGtk.Dialog.add_buttons
], or [methodGtk.Dialog.add_action_widget
].GtkDialogs
uses some heuristics to decide whether to add a close button to the window decorations. If any of the action buttons use the response IDGTK_RESPONSE_CLOSE
orGTK_RESPONSE_CANCEL
, the close button is omitted.Clicking a button that was added as an action widget will emit the [signal
Gtk.Dialog::response
] signal with a response ID that you specified. GTK will never assign a meaning to positive response IDs; these are entirely user-defined. But for convenience, you can use the response IDs in the [enumGtk.ResponseType
] enumeration (these all have values less than zero). If a dialog receives a delete event, the [signalGtk.Dialog::response
] signal will be emitted with theGTK_RESPONSE_DELETE_EVENT
response ID.Dialogs are created with a call to [ctor
Gtk.Dialog.new
] or [ctorGtk.Dialog.new_with_buttons
]. The latter is recommended; it allows you to set the dialog title, some convenient flags, and add buttons.A “modal” dialog (that is, one which freezes the rest of the application from user input), can be created by calling [method
Gtk.Window.set_modal
] on the dialog. When using [ctorGtk.Dialog.new_with_buttons
], you can also pass theGTK_DIALOG_MODAL
flag to make a dialog modal.For the simple dialog in the following example, a [class
Gtk.MessageDialog
] would save some effort. But you’d need to create the dialog contents manually if you had more than a simple message in the dialog.An example for simple
GtkDialog
usage:// Function to open a dialog box with a message void quick_message (GtkWindow *parent, char *message) { GtkWidget *dialog, *label, *content_area; GtkDialogFlags flags; // Create the widgets flags = GTK_DIALOG_DESTROY_WITH_PARENT; dialog = gtk_dialog_new_with_buttons ("Message", parent, flags, `_("_OK")`, GTK_RESPONSE_NONE, NULL); content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog)); label = gtk_label_new (message); // Ensure that the dialog box is destroyed when the user responds g_signal_connect_swapped (dialog, "response", G_CALLBACK (gtk_window_destroy), dialog); // Add the label, and show everything we’ve added gtk_box_append (GTK_BOX (content_area), label); gtk_widget_show (dialog); }
GtkDialog as GtkBuildable
The
GtkDialog
implementation of theGtkBuildable
interface exposes thecontent_area
as an internal child with the name “content_area”.GtkDialog
supports a custom<action-widgets>
element, which can contain multiple<action-widget>
elements. The “response” attribute specifies a numeric response, and the content of the element is the id of widget (which should be a child of the dialogsaction_area
). To mark a response as default, set the “default” attribute of the<action-widget>
element to true.GtkDialog
supports adding action widgets by specifying “action” as the “type” attribute of a<child>
element. The widget will be added either to the action area or the headerbar of the dialog, depending on the “use-header-bar” property. The response id has to be associated with the action widget using the<action-widgets>
element.An example of a
GtkDialog
UI definition fragment:<object class="GtkDialog" id="dialog1"> <child type="action"> <object class="GtkButton" id="button_cancel"/> </child> <child type="action"> <object class="GtkButton" id="button_ok"> </object> </child> <action-widgets> <action-widget response="cancel">button_cancel</action-widget> <action-widget response="ok" default="true">button_ok</action-widget> </action-widgets> </object>
Accessibility
GtkDialog
uses theGTK_ACCESSIBLE_ROLE_DIALOG
role.The
See moreDialogProtocol
protocol exposes the methods and properties of an underlyingGtkDialog
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeDialog
. Alternatively, useDialogRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol DialogProtocol : WindowProtocol
-
The
See moreCellAreaClassProtocol
protocol exposes the methods and properties of an underlyingGtkCellAreaClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeCellAreaClass
. Alternatively, useCellAreaClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol CellAreaClassProtocol
-
The
See moreCellAreaContextClassProtocol
protocol exposes the methods and properties of an underlyingGtkCellAreaContextClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeCellAreaContextClass
. Alternatively, useCellAreaContextClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol CellAreaContextClassProtocol
-
The
See moreCellEditableIfaceProtocol
protocol exposes the methods and properties of an underlyingGtkCellEditableIface
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeCellEditableIface
. Alternatively, useCellEditableIfaceRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol CellEditableIfaceProtocol
-
The
See moreCellLayoutIfaceProtocol
protocol exposes the methods and properties of an underlyingGtkCellLayoutIface
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeCellLayoutIface
. Alternatively, useCellLayoutIfaceRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol CellLayoutIfaceProtocol
-
The
See moreCellRendererClassProtocol
protocol exposes the methods and properties of an underlyingGtkCellRendererClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeCellRendererClass
. Alternatively, useCellRendererClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol CellRendererClassProtocol
-
The
See moreCellRendererClassPrivateProtocol
protocol exposes the methods and properties of an underlyingGtkCellRendererClassPrivate
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeCellRendererClassPrivate
. Alternatively, useCellRendererClassPrivateRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol CellRendererClassPrivateProtocol
-
The
See moreCellRendererTextClassProtocol
protocol exposes the methods and properties of an underlyingGtkCellRendererTextClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeCellRendererTextClass
. Alternatively, useCellRendererTextClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol CellRendererTextClassProtocol
-
The
See moreCenterBoxClassProtocol
protocol exposes the methods and properties of an underlyingGtkCenterBoxClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeCenterBoxClass
. Alternatively, useCenterBoxClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol CenterBoxClassProtocol
-
The
See moreCenterLayoutClassProtocol
protocol exposes the methods and properties of an underlyingGtkCenterLayoutClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeCenterLayoutClass
. Alternatively, useCenterLayoutClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol CenterLayoutClassProtocol
-
The
See moreCheckButtonClassProtocol
protocol exposes the methods and properties of an underlyingGtkCheckButtonClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeCheckButtonClass
. Alternatively, useCheckButtonClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol CheckButtonClassProtocol
-
The
See moreColorChooserInterfaceProtocol
protocol exposes the methods and properties of an underlyingGtkColorChooserInterface
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeColorChooserInterface
. Alternatively, useColorChooserInterfaceRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ColorChooserInterfaceProtocol
-
The
See moreColumnViewClassProtocol
protocol exposes the methods and properties of an underlyingGtkColumnViewClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeColumnViewClass
. Alternatively, useColumnViewClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ColumnViewClassProtocol
-
The
See moreColumnViewColumnClassProtocol
protocol exposes the methods and properties of an underlyingGtkColumnViewColumnClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeColumnViewColumnClass
. Alternatively, useColumnViewColumnClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ColumnViewColumnClassProtocol
-
The
See moreComboBoxClassProtocol
protocol exposes the methods and properties of an underlyingGtkComboBoxClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeComboBoxClass
. Alternatively, useComboBoxClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ComboBoxClassProtocol
-
The
See moreConstraintClassProtocol
protocol exposes the methods and properties of an underlyingGtkConstraintClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeConstraintClass
. Alternatively, useConstraintClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ConstraintClassProtocol
-
The
See moreConstraintGuideClassProtocol
protocol exposes the methods and properties of an underlyingGtkConstraintGuideClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeConstraintGuideClass
. Alternatively, useConstraintGuideClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ConstraintGuideClassProtocol
-
The
See moreConstraintLayoutChildClassProtocol
protocol exposes the methods and properties of an underlyingGtkConstraintLayoutChildClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeConstraintLayoutChildClass
. Alternatively, useConstraintLayoutChildClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ConstraintLayoutChildClassProtocol
-
The
See moreConstraintLayoutClassProtocol
protocol exposes the methods and properties of an underlyingGtkConstraintLayoutClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeConstraintLayoutClass
. Alternatively, useConstraintLayoutClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ConstraintLayoutClassProtocol
-
The
See moreConstraintTargetInterfaceProtocol
protocol exposes the methods and properties of an underlyingGtkConstraintTargetInterface
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeConstraintTargetInterface
. Alternatively, useConstraintTargetInterfaceRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ConstraintTargetInterfaceProtocol
-
Represents a location in a file or other source of data parsed by the CSS engine.
The
bytes
andline_bytes
offsets are meant to be used to programmatically match data. Thelines
andline_chars
offsets can be used for printing the location in a file.Note that the
lines
parameter starts from 0 and is increased whenever a CSS line break is encountered. (CSS defines the C character sequences “\r\n”, “\r”, “\n” and “\f” as newlines.) If your document uses different rules for line breaking, you might want run into problems here.The
See moreCssLocationProtocol
protocol exposes the methods and properties of an underlyingGtkCssLocation
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeCssLocation
. Alternatively, useCssLocationRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol CssLocationProtocol
-
The
See moreCssProviderClassProtocol
protocol exposes the methods and properties of an underlyingGtkCssProviderClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeCssProviderClass
. Alternatively, useCssProviderClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol CssProviderClassProtocol
-
Defines a part of a CSS document.
Because sections are nested into one another, you can use
gtk_css_section_get_parent()
to get the containing region.The
See moreCssSectionProtocol
protocol exposes the methods and properties of an underlyingGtkCssSection
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeCssSection
. Alternatively, useCssSectionRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol CssSectionProtocol
-
The
See moreCssStyleChangeProtocol
protocol exposes the methods and properties of an underlyingGtkCssStyleChange
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeCssStyleChange
. Alternatively, useCssStyleChangeRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol CssStyleChangeProtocol
-
The
See moreCustomFilterClassProtocol
protocol exposes the methods and properties of an underlyingGtkCustomFilterClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeCustomFilterClass
. Alternatively, useCustomFilterClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol CustomFilterClassProtocol
-
The
See moreCustomLayoutClassProtocol
protocol exposes the methods and properties of an underlyingGtkCustomLayoutClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeCustomLayoutClass
. Alternatively, useCustomLayoutClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol CustomLayoutClassProtocol
-
The
See moreCustomSorterClassProtocol
protocol exposes the methods and properties of an underlyingGtkCustomSorterClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeCustomSorterClass
. Alternatively, useCustomSorterClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol CustomSorterClassProtocol
-
The
See moreDialogClassProtocol
protocol exposes the methods and properties of an underlyingGtkDialogClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeDialogClass
. Alternatively, useDialogClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol DialogClassProtocol
-
An interface for packing cells
GtkCellLayout
is an interface to be implemented by all objects which want to provide aGtkTreeViewColumn
like API for packing cells, setting attributes and data funcs.One of the notable features provided by implementations of
GtkCellLayout
are attributes. Attributes let you set the properties in flexible ways. They can just be set to constant values like regular properties. But they can also be mapped to a column of the underlying tree model withgtk_cell_layout_set_attributes()
, which means that the value of the attribute can change from cell to cell as they are rendered by the cell renderer. Finally, it is possible to specify a function withgtk_cell_layout_set_cell_data_func()
that is called to determine the value of the attribute for each cell that is rendered.GtkCellLayouts as GtkBuildable
Implementations of GtkCellLayout which also implement the GtkBuildable interface (
GtkCellView
,GtkIconView
,GtkComboBox
,GtkEntryCompletion
,GtkTreeViewColumn
) acceptGtkCellRenderer
objects as <child> elements in UI definitions. They support a custom <attributes> element for their children, which can contain multiple <attribute> elements. Each <attribute> element has a name attribute which specifies a property of the cell renderer; the content of the element is the attribute value.This is an example of a UI definition fragment specifying attributes:
<object class="GtkCellView"> <child> <object class="GtkCellRendererText"/> <attributes> <attribute name="text">0</attribute> </attributes> </child>" </object>
Furthermore for implementations of GtkCellLayout that use a
GtkCellArea
to lay out cells (all GtkCellLayouts in GTK use a GtkCellArea) cell properties can also be defined in the format by specifying the custom <cell-packing> attribute which can contain multiple <property> elements defined in the normal way.Here is a UI definition fragment specifying cell properties:
<object class="GtkTreeViewColumn"> <child> <object class="GtkCellRendererText"/> <cell-packing> <property name="align">True</property> <property name="expand">False</property> </cell-packing> </child>" </object>
Subclassing GtkCellLayout implementations
When subclassing a widget that implements
GtkCellLayout
likeGtkIconView
orGtkComboBox
, there are some considerations related to the fact that these widgets internally use aGtkCellArea
. The cell area is exposed as a construct-only property by these widgets. This means that it is possible to e.g. do(C Language Example):
combo = g_object_new (GTK_TYPE_COMBO_BOX, "cell-area", my_cell_area, NULL);
to use a custom cell area with a combo box. But construct properties are only initialized after instance
init()
functions have run, which means that using functions which rely on the existence of the cell area in your subclass’init()
function will cause the default cell area to be instantiated. In this case, a provided construct property value will be ignored (with a warning, to alert you to the problem).(C Language Example):
static void my_combo_box_init (MyComboBox *b) { GtkCellRenderer *cell; cell = gtk_cell_renderer_pixbuf_new (); // The following call causes the default cell area for combo boxes, // a GtkCellAreaBox, to be instantiated gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (b), cell, FALSE); ... } GtkWidget * my_combo_box_new (GtkCellArea *area) { // This call is going to cause a warning about area being ignored return g_object_new (MY_TYPE_COMBO_BOX, "cell-area", area, NULL); }
If supporting alternative cell areas with your derived widget is not important, then this does not have to concern you. If you want to support alternative cell areas, you can do so by moving the problematic calls out of
init()
and into aconstructor()
for your class.The
See moreCellLayoutProtocol
protocol exposes the methods and properties of an underlyingGtkCellLayout
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeCellLayout
. Alternatively, useCellLayoutRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol CellLayoutProtocol
-
GtkColorChooser
is an interface that is implemented by widgets for choosing colors.Depending on the situation, colors may be allowed to have alpha (translucency).
In GTK, the main widgets that implement this interface are [class
Gtk.ColorChooserWidget
], [classGtk.ColorChooserDialog
] and [classGtk.ColorButton
].The
See moreColorChooserProtocol
protocol exposes the methods and properties of an underlyingGtkColorChooser
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeColorChooser
. Alternatively, useColorChooserRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ColorChooserProtocol
-
The
GtkConstraintTarget
interface is implemented by objects that can be used as source or target inGtkConstraint
s.Besides
GtkWidget
, it is also implemented byGtkConstraintGuide
.The
See moreConstraintTargetProtocol
protocol exposes the methods and properties of an underlyingGtkConstraintTarget
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeConstraintTarget
. Alternatively, useConstraintTargetRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ConstraintTargetProtocol
-
GtkEditable
is an interface for text editing widgets.Typical examples of editable widgets are [class
Gtk.Entry
] and [classGtk.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 modify the behavior of a widget.As an example of the latter usage, by connecting the following handler to [signal
Gtk.Editable::insert-text
], an application can convert all entry into a widget into uppercase.Forcing entry to uppercase.
`include` <ctype.h> void insert_text_handler (GtkEditable *editable, const char *text, int length, int *position, gpointer data) { char *result = g_utf8_strup (text, length); g_signal_handlers_block_by_func (editable, (gpointer) insert_text_handler, data); gtk_editable_insert_text (editable, result, length, position); g_signal_handlers_unblock_by_func (editable, (gpointer) insert_text_handler, data); g_signal_stop_emission_by_name (editable, "insert_text"); g_free (result); }
Implementing GtkEditable
The most likely scenario for implementing
GtkEditable
on your own widget is that you will embed aGtkText
inside a complex widget, and want to delegate the editable functionality to that text widget.GtkEditable
provides some utility functions to make this easy.In your class_init function, call [func
Gtk.Editable.install_properties
], passing the first available property ID:static void my_class_init (MyClass *class) { ... g_object_class_install_properties (object_class, NUM_PROPERTIES, props); gtk_editable_install_properties (object_clas, NUM_PROPERTIES); ... }
In your interface_init function for the
GtkEditable
interface, provide an implementation for the get_delegate vfunc that returns your text widget:GtkEditable * get_editable_delegate (GtkEditable *editable) { return GTK_EDITABLE (MY_WIDGET (editable)->text_widget); } static void my_editable_init (GtkEditableInterface *iface) { iface->get_delegate = get_editable_delegate; }
You don’t need to provide any other vfuncs. The default implementations work by forwarding to the delegate that the
GtkEditableInterface.get_delegate()
vfunc returns.In your instance_init function, create your text widget, and then call [method
Gtk.Editable.init_delegate
]:static void my_widget_init (MyWidget *self) { ... self->text_widget = gtk_text_new (); gtk_editable_init_delegate (GTK_EDITABLE (self)); ... }
In your dispose function, call [method
Gtk.Editable.finish_delegate
] before destroying your text widget:static void my_widget_dispose (GObject *object) { ... gtk_editable_finish_delegate (GTK_EDITABLE (self)); g_clear_pointer (&self->text_widget, gtk_widget_unparent); ... }
Finally, use [func
Gtk.Editable.delegate_set_property
] in yourset_property
function (and similar forget_property
), to set the editable properties:... if (gtk_editable_delegate_set_property (object, prop_id, value, pspec)) return; switch (prop_id) ...
It is important to note that if you create a
GtkEditable
that uses a delegate, the low level [signalGtk.Editable::insert-text
] and [signalGtk.Editable::delete-text
] signals will be propagated from the “wrapper” editable to the delegate, but they will not be propagated from the delegate to the “wrapper” editable, as they would cause an infinite recursion. If you wish to connect to the [signalGtk.Editable::insert-text
] and [signalGtk.Editable::delete-text
] signals, you will need to connect to them on the delegate obtained via [methodGtk.Editable.get_delegate
].The
See moreEditableProtocol
protocol exposes the methods and properties of an underlyingGtkEditable
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeEditable
. Alternatively, useEditableRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol EditableProtocol : WidgetProtocol
-
GtkDirectoryList
is a list model that wrapsg_file_enumerate_children_async()
.It presents a
GListModel
and fills it asynchronously with theGFileInfo
s returned from that function.Enumeration will start automatically when a the [property
Gtk.DirectoryList:file
] property is set.While the
GtkDirectoryList
is being filled, the [propertyGtk.DirectoryList:loading
] property will be set totrue
. You can listen to that property if you want to show information like aGtkSpinner
or a “Loading…” text.If loading fails at any point, the [property
Gtk.DirectoryList:error
] property will be set to give more indication about the failure.The
GFileInfo
s returned from aGtkDirectoryList
have the “standardfile
” attribute set to theGFile
they refer to. This way you can get at the file that is referred to in the same way you would viag_file_enumerator_get_child()
. This means you do not need access to theGtkDirectoryList
, but can access theGFile
directly from theGFileInfo
when operating with aGtkListView
or similar.The
See moreDirectoryListProtocol
protocol exposes the methods and properties of an underlyingGtkDirectoryList
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeDirectoryList
. Alternatively, useDirectoryListRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol DirectoryListProtocol : ListModelProtocol, ObjectProtocol
-
GtkDragIcon
is aGtkRoot
implementation for drag icons.A drag icon moves with the pointer during a Drag-and-Drop operation and is destroyed when the drag ends.
To set up a drag icon and associate it with an ongoing drag operation, use [func
Gtk.DragIcon.get_for_drag
] to get the icon for a drag. You can then use it like any other widget and use [methodGtk.DragIcon.set_child
] to set whatever widget should be used for the drag icon.Keep in mind that drag icons do not allow user input.
The
See moreDragIconProtocol
protocol exposes the methods and properties of an underlyingGtkDragIcon
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeDragIcon
. Alternatively, useDragIconRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol DragIconProtocol : RootProtocol
-
GtkDragSource
is an event controller to initiate Drag-And-Drop operations.GtkDragSource
can be set up with the necessary ingredients for a DND operation ahead of time. This includes the source for the data that is being transferred, in the form of a [classGdk.ContentProvider
], the desired action, and the icon to use during the drag operation. After setting it up, the drag source must be added to a widget as an event controller, using [methodGtk.Widget.add_controller
].static void my_widget_init (MyWidget *self) { GtkDragSource *drag_source = gtk_drag_source_new (); g_signal_connect (drag_source, "prepare", G_CALLBACK (on_drag_prepare), self); g_signal_connect (drag_source, "drag-begin", G_CALLBACK (on_drag_begin), self); gtk_widget_add_controller (GTK_WIDGET (self), GTK_EVENT_CONTROLLER (drag_source)); }
Setting up the content provider and icon ahead of time only makes sense when the data does not change. More commonly, you will want to set them up just in time. To do so,
GtkDragSource
has [signalGtk.DragSource::prepare
] and [signalGtk.DragSource::drag-begin
] signals.The
prepare
signal is emitted before a drag is started, and can be used to set the content provider and actions that the drag should be started with.static GdkContentProvider * on_drag_prepare (GtkDragSource *source, double x, double y, MyWidget *self) { // This widget supports two types of content: GFile objects // and GdkPixbuf objects; GTK will handle the serialization // of these types automatically GFile *file = my_widget_get_file (self); GdkPixbuf *pixbuf = my_widget_get_pixbuf (self); return gdk_content_provider_new_union ((GdkContentProvider *[2]) { gdk_content_provider_new_typed (G_TYPE_FILE, file), gdk_content_provider_new_typed (GDK_TYPE_PIXBUF, pixbuf), }, 2); }
The
drag-begin
signal is emitted after theGdkDrag
object has been created, and can be used to set up the drag icon.static void on_drag_begin (GtkDragSource *source, GtkDrag *drag, MyWidget *self) { // Set the widget as the drag icon GdkPaintable *paintable = gtk_widget_paintable_new (GTK_WIDGET (self)); gtk_drag_source_set_icon (source, paintable, 0, 0); g_object_unref (paintable); }
During the DND operation,
GtkDragSource
emits signals that can be used to obtain updates about the status of the operation, but it is not normally necessary to connect to any signals, except for one case: when the supported actions includeGDK_ACTION_MOVE
, you need to listen for the [signalGtk.DragSource::drag-end
] signal and delete the data after it has been transferred.The
See moreDragSourceProtocol
protocol exposes the methods and properties of an underlyingGtkDragSource
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeDragSource
. Alternatively, useDragSourceRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol DragSourceProtocol : GestureSingleProtocol
-
GtkDropControllerMotion
is an event controller tracking the pointer during Drag-and-Drop operations.It is modeled after [class
Gtk.EventControllerMotion
] so if you have used that, this should feel really familiar.This controller is not able to accept drops, use [class
Gtk.DropTarget
] for that purpose.The
See moreDropControllerMotionProtocol
protocol exposes the methods and properties of an underlyingGtkDropControllerMotion
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeDropControllerMotion
. Alternatively, useDropControllerMotionRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol DropControllerMotionProtocol : EventControllerProtocol
-
GtkDropDown
is a widget that allows the user to choose an item from a list of options.The
GtkDropDown
displays the selected choice.The options are given to
GtkDropDown
in the form ofGListModel
and how the individual options are represented is determined by a [classGtk.ListItemFactory
]. The default factory displays simple strings.GtkDropDown
knows how to obtain strings from the items in a [classGtk.StringList
]; for other models, you have to provide an expression to find the strings via [methodGtk.DropDown.set_expression
].GtkDropDown
can optionally allow search in the popup, which is useful if the list of options is long. To enable the search entry, use [methodGtk.DropDown.set_enable_search
].CSS nodes
GtkDropDown
has a single CSS node with name dropdown, with the button and popover nodes as children.Accessibility
GtkDropDown
uses theGTK_ACCESSIBLE_ROLE_COMBO_BOX
role.The
See moreDropDownProtocol
protocol exposes the methods and properties of an underlyingGtkDropDown
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeDropDown
. Alternatively, useDropDownRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol DropDownProtocol : WidgetProtocol
-
GtkDropTarget
is an event controller to receive Drag-and-Drop operations.The most basic way to use a
GtkDropTarget
to receive drops on a widget is to create it via [ctorGtk.DropTarget.new
], passing in theGType
of the data you want to receive and connect to the [signalGtk.DropTarget::drop
] signal to receive the data:static gboolean on_drop (GtkDropTarget *target, const GValue *value, double x, double y, gpointer data) { MyWidget *self = data; // Call the appropriate setter depending on the type of data // that we received if (G_VALUE_HOLDS (value, G_TYPE_FILE)) my_widget_set_file (self, g_value_get_object (value)); else if (G_VALUE_HOLDS (value, GDK_TYPE_PIXBUF)) my_widget_set_pixbuf (self, g_value_get_object (value)); else return FALSE; return TRUE; } static void my_widget_init (MyWidget *self) { GtkDropTarget *target = gtk_drop_target_new (G_TYPE_INVALID, GDK_ACTION_COPY); // This widget accepts two types of drop types: GFile objects // and GdkPixbuf objects gtk_drop_target_set_gtypes (target, (GTypes [2]) { G_TYPE_FILE, GDK_TYPE_PIXBUF, }, 2); gtk_widget_add_controller (GTK_WIDGET (self), GTK_EVENT_CONTROLLER (target)); }
GtkDropTarget
supports more options, such as:- rejecting potential drops via the [signal
Gtk.DropTarget::accept
] signal and the [methodGtk.DropTarget.reject
] function to let other drop targets handle the drop - tracking an ongoing drag operation before the drop via the
[signal
Gtk.DropTarget::enter
], [signalGtk.DropTarget::motion
] and [signalGtk.DropTarget::leave
] signals - configuring how to receive data by setting the
[property
Gtk.DropTarget:preload
] property and listening for its availability via the [propertyGtk.DropTarget:value
] property
However,
GtkDropTarget
is ultimately modeled in a synchronous way and only supports data transferred viaGType
. If you want full control over an ongoing drop, the [classGtk.DropTargetAsync
] object gives you this ability.While a pointer is dragged over the drop target’s widget and the drop has not been rejected, that widget will receive the
GTK_STATE_FLAG_DROP_ACTIVE
state, which can be used to style the widget.If you are not interested in receiving the drop, but just want to update UI state during a Drag-and-Drop operation (e.g. switching tabs), you can use [class
Gtk.DropControllerMotion
].The
See moreDropTargetProtocol
protocol exposes the methods and properties of an underlyingGtkDropTarget
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeDropTarget
. Alternatively, useDropTargetRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol DropTargetProtocol : EventControllerProtocol
- rejecting potential drops via the [signal
-
GtkDropTargetAsync
is an event controller to receive Drag-and-Drop operations, asynchronously.It is the more complete but also more complex method of handling drop operations compared to [class
Gtk.DropTarget
], and you should only use it ifGtkDropTarget
doesn’t provide all the features you need.To use a
GtkDropTargetAsync
to receive drops on a widget, you create aGtkDropTargetAsync
object, configure which data formats and actions you support, connect to its signals, and then attach it to the widget with [methodGtk.Widget.add_controller
].During a drag operation, the first signal that a
GtkDropTargetAsync
emits is [signalGtk.DropTargetAsync::accept
], which is meant to determine whether the target is a possible drop site for the ongoing drop. The default handler for theaccept
signal accepts the drop if it finds a compatible data format and an action that is supported on both sides.If it is, and the widget becomes a target, you will receive a [signal
Gtk.DropTargetAsync::drag-enter
] signal, followed by [signalGtk.DropTargetAsync::drag-motion
] signals as the pointer moves, optionally a [signalGtk.DropTargetAsync::drop
] signal when a drop happens, and finally a [signalGtk.DropTargetAsync::drag-leave
] signal when the pointer moves off the widget.The
drag-enter
anddrag-motion
handler return aGdkDragAction
to update the status of the ongoing operation. Thedrop
handler should decide if it ultimately accepts the drop and if it does, it should initiate the data transfer and finish the operation by calling [methodGdk.Drop.finish
].Between the
drag-enter
anddrag-leave
signals the widget is a current drop target, and will receive theGTK_STATE_FLAG_DROP_ACTIVE
state, which can be used by themes to style the widget as a drop target.The
See moreDropTargetAsyncProtocol
protocol exposes the methods and properties of an underlyingGtkDropTargetAsync
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeDropTargetAsync
. Alternatively, useDropTargetAsyncRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol DropTargetAsyncProtocol : EventControllerProtocol
-
A
GtkEditableLabel
is a label that allows users to edit the text by switching to an “edit mode”.GtkEditableLabel
does not have API of its own, but it implements the [ifaceGtk.Editable
] interface.The default bindings for activating the edit mode is to click or press the Enter key. The default bindings for leaving the edit mode are the Enter key (to save the results) or the Escape key (to cancel the editing).
CSS nodes
editablelabel[.editing] ╰── stack ├── label ╰── text
GtkEditableLabel
has a main node with the name editablelabel. When the entry is in editing mode, it gets the .editing style class.For all the subnodes added to the text node in various situations, see [class
Gtk.Text
].The
See moreEditableLabelProtocol
protocol exposes the methods and properties of an underlyingGtkEditableLabel
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeEditableLabel
. Alternatively, useEditableLabelRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol EditableLabelProtocol : EditableProtocol
-
The
See moreDirectoryListClassProtocol
protocol exposes the methods and properties of an underlyingGtkDirectoryListClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeDirectoryListClass
. Alternatively, useDirectoryListClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol DirectoryListClassProtocol
-
The
See moreDragIconClassProtocol
protocol exposes the methods and properties of an underlyingGtkDragIconClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeDragIconClass
. Alternatively, useDragIconClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol DragIconClassProtocol
-
The
See moreDragSourceClassProtocol
protocol exposes the methods and properties of an underlyingGtkDragSourceClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeDragSourceClass
. Alternatively, useDragSourceClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol DragSourceClassProtocol
-
The
See moreDrawingAreaClassProtocol
protocol exposes the methods and properties of an underlyingGtkDrawingAreaClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeDrawingAreaClass
. Alternatively, useDrawingAreaClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol DrawingAreaClassProtocol
-
The
See moreDropControllerMotionClassProtocol
protocol exposes the methods and properties of an underlyingGtkDropControllerMotionClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeDropControllerMotionClass
. Alternatively, useDropControllerMotionClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol DropControllerMotionClassProtocol
-
The
See moreDropDownClassProtocol
protocol exposes the methods and properties of an underlyingGtkDropDownClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeDropDownClass
. Alternatively, useDropDownClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol DropDownClassProtocol
-
The
See moreDropTargetAsyncClassProtocol
protocol exposes the methods and properties of an underlyingGtkDropTargetAsyncClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeDropTargetAsyncClass
. Alternatively, useDropTargetAsyncClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol DropTargetAsyncClassProtocol
-
The
See moreDropTargetClassProtocol
protocol exposes the methods and properties of an underlyingGtkDropTargetClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeDropTargetClass
. Alternatively, useDropTargetClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol DropTargetClassProtocol
-
The
See moreEditableInterfaceProtocol
protocol exposes the methods and properties of an underlyingGtkEditableInterface
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeEditableInterface
. Alternatively, useEditableInterfaceRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol EditableInterfaceProtocol
-
The
See moreEditableLabelClassProtocol
protocol exposes the methods and properties of an underlyingGtkEditableLabelClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeEditableLabelClass
. Alternatively, useEditableLabelClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol EditableLabelClassProtocol
-
The
See moreEmojiChooserClassProtocol
protocol exposes the methods and properties of an underlyingGtkEmojiChooserClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeEmojiChooserClass
. Alternatively, useEmojiChooserClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol EmojiChooserClassProtocol
-
The
See moreEntryBufferClassProtocol
protocol exposes the methods and properties of an underlyingGtkEntryBufferClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeEntryBufferClass
. Alternatively, useEntryBufferClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol EntryBufferClassProtocol
-
Class structure for
GtkEntry
. All virtual functions have a default implementation. Derived classes may set the virtual function pointers for the signal handlers tonil
, but must keepget_text_area_size
andget_frame_size
non-nil
; either use the default implementation, or provide a custom one.The
See moreEntryClassProtocol
protocol exposes the methods and properties of an underlyingGtkEntryClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeEntryClass
. Alternatively, useEntryClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol EntryClassProtocol
-
The
See moreEventControllerClassProtocol
protocol exposes the methods and properties of an underlyingGtkEventControllerClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeEventControllerClass
. Alternatively, useEventControllerClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol EventControllerClassProtocol
-
The
See moreEventControllerFocusClassProtocol
protocol exposes the methods and properties of an underlyingGtkEventControllerFocusClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeEventControllerFocusClass
. Alternatively, useEventControllerFocusClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol EventControllerFocusClassProtocol
-
The
See moreEventControllerKeyClassProtocol
protocol exposes the methods and properties of an underlyingGtkEventControllerKeyClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeEventControllerKeyClass
. Alternatively, useEventControllerKeyClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol EventControllerKeyClassProtocol
-
The
See moreEventControllerLegacyClassProtocol
protocol exposes the methods and properties of an underlyingGtkEventControllerLegacyClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeEventControllerLegacyClass
. Alternatively, useEventControllerLegacyClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol EventControllerLegacyClassProtocol
-
The
See moreEventControllerMotionClassProtocol
protocol exposes the methods and properties of an underlyingGtkEventControllerMotionClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeEventControllerMotionClass
. Alternatively, useEventControllerMotionClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol EventControllerMotionClassProtocol
-
The
See moreEventControllerScrollClassProtocol
protocol exposes the methods and properties of an underlyingGtkEventControllerScrollClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeEventControllerScrollClass
. Alternatively, useEventControllerScrollClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol EventControllerScrollClassProtocol
-
The
See moreEveryFilterClassProtocol
protocol exposes the methods and properties of an underlyingGtkEveryFilterClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeEveryFilterClass
. Alternatively, useEveryFilterClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol EveryFilterClassProtocol
-
An opaque structure representing a watched
GtkExpression
.The contents of
GtkExpressionWatch
should only be accessed through the provided API.The
See moreExpressionWatchProtocol
protocol exposes the methods and properties of an underlyingGtkExpressionWatch
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeExpressionWatch
. Alternatively, useExpressionWatchRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ExpressionWatchProtocol
-
The
See moreFileChooserNativeClassProtocol
protocol exposes the methods and properties of an underlyingGtkFileChooserNativeClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeFileChooserNativeClass
. Alternatively, useFileChooserNativeClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol FileChooserNativeClassProtocol
-
The
GtkEmojiChooser
is used by text widgets such asGtkEntry
orGtkTextView
to let users insert Emoji characters.GtkEmojiChooser
emits the [signalGtk.EmojiChooser::emoji-picked
] signal when an Emoji is selected.CSS nodes
popover ├── box.emoji-searchbar │ ╰── entry.search ╰── box.emoji-toolbar ├── button.image-button.emoji-section ├── ... ╰── button.image-button.emoji-section
Every
GtkEmojiChooser
consists of a main node called popover. The contents of the popover are largely implementation defined and supposed to inherit general styles. The top searchbar used to search emoji and gets the .emoji-searchbar style class itself. The bottom toolbar used to switch between different emoji categories consists of buttons with the .emoji-section style class and gets the .emoji-toolbar style class itself.The
See moreEmojiChooserProtocol
protocol exposes the methods and properties of an underlyingGtkEmojiChooser
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeEmojiChooser
. Alternatively, useEmojiChooserRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol EmojiChooserProtocol : PopoverProtocol
-
GtkEntry
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.
When using an entry for passwords and other sensitive information, it can be put into “password mode” using [method
Gtk.Entry.set_visibility
]. In this mode, entered text is displayed using a “invisible” character. By default, GTK picks the best invisible character that is available in the current font, but it can be changed with [methodGtk.Entry.set_invisible_char
].GtkEntry
has the ability to display progress or activity information behind the text. To make an entry display such information, use [methodGtk.Entry.set_progress_fraction
] or [methodGtk.Entry.set_progress_pulse_step
].Additionally,
GtkEntry
can show icons at either side of the entry. These icons can be activatable by clicking, can be set up as drag source and can have tooltips. To add an icon, use [methodGtk.Entry.set_icon_from_gicon
] or one of the various other functions that set an icon from an icon name or a paintable. To trigger an action when the user clicks an icon, connect to the [signalGtk.Entry::icon-press
] signal. To allow DND operations from an icon, use [methodGtk.Entry.set_icon_drag_source
]. To set a tooltip on an icon, use [methodGtk.Entry.set_icon_tooltip_text
] or the corresponding function for markup.Note that functionality or information that is only available by clicking on an icon in an entry may not be accessible at all to users which are not able to use a mouse or other pointing device. It is therefore recommended that any such functionality should also be available by other means, e.g. via the context menu of the entry.
CSS nodes
entry[.flat][.warning][.error] ├── text[.readonly] ├── image.left ├── image.right ╰── [progress[.pulse]]
GtkEntry
has a main node with the name entry. Depending on the properties of the entry, the style classes .read-only and .flat may appear. The style classes .warning and .error may also be used with entries.When the entry shows icons, it adds subnodes with the name image and the style class .left or .right, depending on where the icon appears.
When the entry shows progress, it adds a subnode with the name progress. The node has the style class .pulse when the shown progress is pulsing.
For all the subnodes added to the text node in various situations, see [class
Gtk.Text
].GtkEntry as GtkBuildable
The
GtkEntry
implementation of theGtkBuildable
interface supports a custom <attributes> element, which supports any number of <attribute> elements. The <attribute> element has attributes named “name“, “value“, “start“ and “end“ and allows you to specifyPangoAttribute
values for this label.An example of a UI definition fragment specifying Pango attributes:
<object class="GtkEntry"> <attributes> <attribute name="weight" value="PANGO_WEIGHT_BOLD"/> <attribute name="background" value="red" start="5" end="10"/> </attributes> </object>
The start and end attributes specify the range of characters to which the Pango attribute applies. If start and end are not specified, the attribute is applied to the whole text. Note that specifying ranges does not make much sense with translatable attributes. Use markup embedded in the translatable content instead.
Accessibility
GtkEntry
uses theGTK_ACCESSIBLE_ROLE_TEXT_BOX
role.The
See moreEntryProtocol
protocol exposes the methods and properties of an underlyingGtkEntry
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeEntry
. Alternatively, useEntryRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol EntryProtocol : CellEditableProtocol, EditableProtocol
-
A
GtkEntryBuffer
hold the text displayed in aGtkText
widget.A single
GtkEntryBuffer
object can be shared by multiple widgets which will then share the same text content, but not the cursor position, visibility attributes, icon etc.GtkEntryBuffer
may be derived from. Such a derived class might allow text to be stored in an alternate location, such as non-pageable memory, useful in the case of important passwords. Or a derived class could integrate with an application’s concept of undo/redo.The
See moreEntryBufferProtocol
protocol exposes the methods and properties of an underlyingGtkEntryBuffer
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeEntryBuffer
. Alternatively, useEntryBufferRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol EntryBufferProtocol : ObjectProtocol
-
GtkEntryCompletion
is an auxiliary object to provide completion functionality forGtkEntry
.It implements the [iface
Gtk.CellLayout
] interface, to allow the user to add extra cells to theGtkTreeView
with completion matches.“Completion functionality” means that when the user modifies the text in the entry,
GtkEntryCompletion
checks which rows in the model match the current content of the entry, and displays a list of matches. By default, the matching is done by comparing the entry text case-insensitively against the text column of the model (see [methodGtk.EntryCompletion.set_text_column
]), but this can be overridden with a custom match function (see [methodGtk.EntryCompletion.set_match_func
]).When the user selects a completion, the content of the entry is updated. By default, the content of the entry is replaced by the text column of the model, but this can be overridden by connecting to the [signal
Gtk.EntryCompletion::match-selected
] signal and updating the entry in the signal handler. Note that you should returntrue
from the signal handler to suppress the default behaviour.To add completion functionality to an entry, use [method
Gtk.Entry.set_completion
].GtkEntryCompletion
uses a [classGtk.TreeModelFilter
] model to represent the subset of the entire model that is currently matching. While theGtkEntryCompletion
signals [signalGtk.EntryCompletion::match-selected
] and [signalGtk.EntryCompletion::cursor-on-match
] take the original model and an iter pointing to that model as arguments, other callbacks and signals (such asGtkCellLayoutDataFunc
or [signalGtk.CellArea::apply-attributes
)] will generally take the filter model as argument. As long as you are only calling [methodGtk.TreeModel.get
], this will make no difference to you. If for some reason, you need the original model, use [methodGtk.TreeModelFilter.get_model
]. Don’t forget to use [methodGtk.TreeModelFilter.convert_iter_to_child_iter
] to obtain a matching iter.The
See moreEntryCompletionProtocol
protocol exposes the methods and properties of an underlyingGtkEntryCompletion
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeEntryCompletion
. Alternatively, useEntryCompletionRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol EntryCompletionProtocol : ObjectProtocol, BuildableProtocol, CellLayoutProtocol
-
GtkEventController
is the base class for event controllers.These are ancillary objects associated to widgets, which react to
GdkEvents
, and possibly trigger actions as a consequence.Event controllers are added to a widget with [method
Gtk.Widget.add_controller
]. It is rarely necessary to explicitly remove a controller with [methodGtk.Widget.remove_controller
].See the chapter on input handling for an overview of the basic concepts, such as the capture and bubble phases of even propagation.
The
See moreEventControllerProtocol
protocol exposes the methods and properties of an underlyingGtkEventController
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeEventController
. Alternatively, useEventControllerRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol EventControllerProtocol : ObjectProtocol
-
GtkEventControllerFocus
is an event controller to keep track of keyboard focus.The event controller offers [signal
Gtk.EventControllerFocus::enter
] and [signalGtk.EventControllerFocus::leave
] signals, as well as [propertyGtk.EventControllerFocus:is-focus
] and [propertyGtk.EventControllerFocus:contains-focus
] properties which are updated to reflect focus changes inside the widget hierarchy that is rooted at the controllers widget.The
See moreEventControllerFocusProtocol
protocol exposes the methods and properties of an underlyingGtkEventControllerFocus
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeEventControllerFocus
. Alternatively, useEventControllerFocusRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol EventControllerFocusProtocol : EventControllerProtocol
-
GtkEventControllerKey
is an event controller that provides access to key events.The
See moreEventControllerKeyProtocol
protocol exposes the methods and properties of an underlyingGtkEventControllerKey
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeEventControllerKey
. Alternatively, useEventControllerKeyRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol EventControllerKeyProtocol : EventControllerProtocol
-
GtkEventControllerLegacy
is an event controller that provides raw access to the event stream.It should only be used as a last resort if none of the other event controllers or gestures do the job.
The
See moreEventControllerLegacyProtocol
protocol exposes the methods and properties of an underlyingGtkEventControllerLegacy
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeEventControllerLegacy
. Alternatively, useEventControllerLegacyRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol EventControllerLegacyProtocol : EventControllerProtocol
-
GtkEventControllerMotion
is an event controller tracking the pointer position.The event controller offers [signal
Gtk.EventControllerMotion::enter
] and [signalGtk.EventControllerMotion::leave
] signals, as well as [propertyGtk.EventControllerMotion:is-pointer
] and [propertyGtk.EventControllerMotion:contains-pointer
] properties which are updated to reflect changes in the pointer position as it moves over the widget.The
See moreEventControllerMotionProtocol
protocol exposes the methods and properties of an underlyingGtkEventControllerMotion
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeEventControllerMotion
. Alternatively, useEventControllerMotionRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol EventControllerMotionProtocol : EventControllerProtocol
-
GtkEventControllerScroll
is an event controller that handles scroll events.It is capable of handling both discrete and continuous scroll events from mice or touchpads, abstracting them both with the [signal
Gtk.EventControllerScroll::scroll
] signal. Deltas in the discrete case are multiples of 1.In the case of continuous scroll events,
GtkEventControllerScroll
encloses all [signalGtk.EventControllerScroll::scroll
] emissions between two [signalGtk.EventControllerScroll::scroll-begin
] and [signalGtk.EventControllerScroll::scroll-end
] signals.The behavior of the event controller can be modified by the flags given at creation time, or modified at a later point through method
Gtk.EventControllerScroll.set_flags
.The controller can be set up to emit motion for either/both vertical and horizontal scroll events through
GTK_EVENT_CONTROLLER_SCROLL_VERTICAL
,GTK_EVENT_CONTROLLER_SCROLL_HORIZONTAL
andGTK_EVENT_CONTROLLER_SCROLL_BOTH_AXES
. If any axis is disabled, the respective [signalGtk.EventControllerScroll::scroll
] delta will be 0. Vertical scroll events will be translated to horizontal motion for the devices incapable of horizontal scrolling.The event controller can also be forced to emit discrete events on all devices through
GTK_EVENT_CONTROLLER_SCROLL_DISCRETE
. This can be used to implement discrete actions triggered through scroll events (e.g. switching across combobox options).The
GTK_EVENT_CONTROLLER_SCROLL_KINETIC
flag toggles the emission of the [signalGtk.EventControllerScroll::decelerate
] signal, emitted at the end of scrolling with two X/Y velocity arguments that are consistent with the motion that was received.The
See moreEventControllerScrollProtocol
protocol exposes the methods and properties of an underlyingGtkEventControllerScroll
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeEventControllerScroll
. Alternatively, useEventControllerScrollRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol EventControllerScrollProtocol : EventControllerProtocol
-
GtkEveryFilter
matches an item when each of its filters matches.To add filters to a
GtkEveryFilter
, use [methodGtk.MultiFilter.append
].The
See moreEveryFilterProtocol
protocol exposes the methods and properties of an underlyingGtkEveryFilter
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeEveryFilter
. Alternatively, useEveryFilterRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol EveryFilterProtocol : MultiFilterProtocol
-
GtkExpander
allows the user to reveal its child by clicking on an expander triangle.This is similar to the triangles used in a
GtkTreeView
.Normally you use an expander as you would use a frame; you create the child widget and use [method
Gtk.Expander.set_child
] to add it to the expander. When the expander is toggled, it will take care of showing and hiding the child automatically.Special Usage
There are situations in which you may prefer to show and hide the expanded widget yourself, such as when you want to actually create the widget at expansion time. In this case, create a
GtkExpander
but do not add a child to it. The expander widget has an [propertyGtk.Expander:expanded
[ property which can be used to monitor its expansion state. You should watch this property with a signal connection as follows:static void expander_callback (GObject *object, GParamSpec *param_spec, gpointer user_data) { GtkExpander *expander; expander = GTK_EXPANDER (object); if (gtk_expander_get_expanded (expander)) { // Show or create widgets } else { // Hide or destroy widgets } } static void create_expander (void) { GtkWidget *expander = gtk_expander_new_with_mnemonic ("_More Options"); g_signal_connect (expander, "notify`expanded`", G_CALLBACK (expander_callback), NULL); // ... }
GtkExpander as GtkBuildable
The
GtkExpander
implementation of theGtkBuildable
interface supports placing a child in the label position by specifying “label” as the “type” attribute of a <child> element. A normal content child can be specified without specifying a <child> type attribute.An example of a UI definition fragment with GtkExpander:
<object class="GtkExpander"> <child type="label"> <object class="GtkLabel" id="expander-label"/> </child> <child> <object class="GtkEntry" id="expander-content"/> </child> </object>
CSS nodes
expander ╰── box ├── title │ ├── arrow │ ╰── <label widget> ╰── <child>
GtkExpander
has three CSS nodes, the main node with the name expander, a subnode with name title and node below it with name arrow. The arrow of an expander that is showing its child gets the :checked pseudoclass added to it.Accessibility
GtkExpander
uses theGTK_ACCESSIBLE_ROLE_BUTTON
role.The
See moreExpanderProtocol
protocol exposes the methods and properties of an underlyingGtkExpander
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeExpander
. Alternatively, useExpanderRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ExpanderProtocol : WidgetProtocol
-
GtkExpression
provides a way to describe references to values.An important aspect of expressions is that the value can be obtained from a source that is several steps away. For example, an expression may describe ‘the value of property A of
object1
, which is itself the value of a property ofobject2
’. Andobject1
may not even exist yet at the time that the expression is created. This is contrast toGObject
property bindings, which can only create direct connections between the properties of two objects that must both exist for the duration of the binding.An expression needs to be “evaluated” to obtain the value that it currently refers to. An evaluation always happens in the context of a current object called
this
(it mirrors the behavior of object-oriented languages), which may or may not influence the result of the evaluation. Use [methodGtk.Expression.evaluate
] for evaluating an expression.Various methods for defining expressions exist, from simple constants via [ctor
Gtk.ConstantExpression.new
] to looking up properties in aGObject
(even recursively) via [ctorGtk.PropertyExpression.new
] or providing custom functions to transform and combine expressions via [ctorGtk.ClosureExpression.new
].Here is an example of a complex expression:
color_expr = gtk_property_expression_new (GTK_TYPE_LIST_ITEM, NULL, "item"); expression = gtk_property_expression_new (GTK_TYPE_COLOR, color_expr, "name");
when evaluated with
this
being aGtkListItem
, it will obtain the “item” property from theGtkListItem
, and then obtain the “name” property from the resulting object (which is assumed to be of typeGTK_TYPE_COLOR
).A more concise way to describe this would be
this->item->name
The most likely place where you will encounter expressions is in the context of list models and list widgets using them. For example,
GtkDropDown
is evaluating aGtkExpression
to obtain strings from the items in its model that it can then use to match against the contents of its search entry.GtkStringFilter
is using aGtkExpression
for similar reasons.By default, expressions are not paying attention to changes and evaluation is just a snapshot of the current state at a given time. To get informed about changes, an expression needs to be “watched” via a [struct
Gtk.ExpressionWatch
], which will cause a callback to be called whenever the value of the expression may have changed; [methodGtk.Expression.watch
] starts watching an expression, and [methodGtk.ExpressionWatch.unwatch
] stops.Watches can be created for automatically updating the property of an object, similar to GObject’s
GBinding
mechanism, by using [methodGtk.Expression.bind
].GtkExpression in GObject properties
In order to use a
GtkExpression
as aGObject
property, you must use the [idgtk_param_spec_expression
] when creating aGParamSpec
to install in theGObject
class being defined; for instance:obj_props[PROP_EXPRESSION] = gtk_param_spec_expression ("expression", "Expression", "The expression used by the widget", G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
When implementing the
GObjectClass.set_property
andGObjectClass.get_property
virtual functions, you must use [idgtk_value_get_expression
], to retrieve the storedGtkExpression
from theGValue
container, and [idgtk_value_set_expression
], to store theGtkExpression
into theGValue
; for instance:// in `set_property()`... case PROP_EXPRESSION: foo_widget_set_expression (foo, gtk_value_get_expression (value)); break; // in `get_property()`... case PROP_EXPRESSION: gtk_value_set_expression (value, foo->expression); break;
GtkExpression in .ui files
GtkBuilder
has support for creating expressions. The syntax here can be used where aGtkExpression
object is needed like in a<property>
tag for an expression property, or in a<binding>
tag to bind a property to an expression.To create an property expression, use the
<lookup>
element. It can have atype
attribute to specify the object type, and aname
attribute to specify the property to look up. The content of<lookup>
can either be an element specfiying the expression to use the object, or a string that specifies the name of the object to use.Example:
<lookup name='search'>string_filter</lookup>
To create a constant expression, use the
<constant>
element. If the type attribute is specified, the element content is interpreted as a value of that type. Otherwise, it is assumed to be an object. For instance:<constant>string_filter</constant> <constant type='gchararray'>Hello, world</constant>
To create a closure expression, use the
<closure>
element. Thetype
andfunction
attributes specify what function to use for the closure, the content of the element contains the expressions for the parameters. For instance:<closure type='gchararray' function='combine_args_somehow'> <constant type='gchararray'>File size:</constant> <lookup type='GFile' name='size'>myfile</lookup> </closure>
The
See moreExpressionProtocol
protocol exposes the methods and properties of an underlyingGtkExpression
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeExpression
. Alternatively, useExpressionRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ExpressionProtocol
-
GtkFileChooserDialog
is a dialog suitable for use with “File Open” or “File Save” commands.This widget works by putting a [class
Gtk.FileChooserWidget
] inside a [classGtk.Dialog
]. It exposes the [ifaceGtk.FileChooser
] interface, so you can use all of the [ifaceGtk.FileChooser
] functions on the file chooser dialog as well as those for [classGtk.Dialog
].Note that
GtkFileChooserDialog
does not have any methods of its own. Instead, you should use the functions that work on a [ifaceGtk.FileChooser
].If you want to integrate well with the platform you should use the [class
Gtk.FileChooserNative
] API, which will use a platform-specific dialog if available and fall back toGtkFileChooserDialog
otherwise.Typical usage
In the simplest of cases, you can the following code to use
GtkFileChooserDialog
to select a file for opening:static void on_open_response (GtkDialog *dialog, int response) { if (response == GTK_RESPONSE_ACCEPT) { GtkFileChooser *chooser = GTK_FILE_CHOOSER (dialog); `g_autoptr(GFile)` file = gtk_file_chooser_get_file (chooser); open_file (file); } gtk_window_destroy (GTK_WINDOW (dialog)); } // ... GtkWidget *dialog; GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN; dialog = gtk_file_chooser_dialog_new ("Open File", parent_window, action, `_("_Cancel")`, GTK_RESPONSE_CANCEL, `_("_Open")`, GTK_RESPONSE_ACCEPT, NULL); gtk_widget_show (dialog); g_signal_connect (dialog, "response", G_CALLBACK (on_open_response), NULL);
To use a dialog for saving, you can use this:
static void on_save_response (GtkDialog *dialog, int response) { if (response == GTK_RESPONSE_ACCEPT) { GtkFileChooser *chooser = GTK_FILE_CHOOSER (dialog); `g_autoptr(GFile)` file = gtk_file_chooser_get_file (chooser); save_to_file (file); } gtk_window_destroy (GTK_WINDOW (dialog)); } // ... GtkWidget *dialog; GtkFileChooser *chooser; GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_SAVE; dialog = gtk_file_chooser_dialog_new ("Save File", parent_window, action, `_("_Cancel")`, GTK_RESPONSE_CANCEL, `_("_Save")`, GTK_RESPONSE_ACCEPT, NULL); chooser = GTK_FILE_CHOOSER (dialog); if (user_edited_a_new_document) gtk_file_chooser_set_current_name (chooser, `_("Untitled document")`); else gtk_file_chooser_set_file (chooser, existing_filename); gtk_widget_show (dialog); g_signal_connect (dialog, "response", G_CALLBACK (on_save_response), NULL);
Setting up a file chooser dialog
There are various cases in which you may need to use a
GtkFileChooserDialog
:To select a file for opening, use
GTK_FILE_CHOOSER_ACTION_OPEN
.To save a file for the first time, use
GTK_FILE_CHOOSER_ACTION_SAVE
, and suggest a name such as “Untitled” with [methodGtk.FileChooser.set_current_name
].To save a file under a different name, use
GTK_FILE_CHOOSER_ACTION_SAVE
, and set the existing file with [methodGtk.FileChooser.set_file
].To choose a folder instead of a filem use
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER
.
In general, you should only cause the file chooser to show a specific folder when it is appropriate to use [method
Gtk.FileChooser.set_file
], i.e. when you are doing a “Save As” command and you already have a file saved somewhere.Response Codes
GtkFileChooserDialog
inherits from [classGtk.Dialog
], so buttons that go in its action area have response codes such asGTK_RESPONSE_ACCEPT
andGTK_RESPONSE_CANCEL
. For example, you could call [ctorGtk.FileChooserDialog.new
] as follows:GtkWidget *dialog; GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN; dialog = gtk_file_chooser_dialog_new ("Open File", parent_window, action, `_("_Cancel")`, GTK_RESPONSE_CANCEL, `_("_Open")`, GTK_RESPONSE_ACCEPT, NULL);
This will create buttons for “Cancel” and “Open” that use predefined response identifiers from [enum
Gtk.ResponseType
]. For most dialog boxes you can use your own custom response codes rather than the ones in [enumGtk.ResponseType
], butGtkFileChooserDialog
assumes that its “accept”-type action, e.g. an “Open” or “Save” button, will have one of the following response codes:GTK_RESPONSE_ACCEPT
GTK_RESPONSE_OK
GTK_RESPONSE_YES
GTK_RESPONSE_APPLY
This is because
GtkFileChooserDialog
must intercept responses and switch to folders if appropriate, rather than letting the dialog terminate — the implementation uses these known response codes to know which responses can be blocked if appropriate.To summarize, make sure you use a predefined response code when you use
GtkFileChooserDialog
to ensure proper operation.The
See moreFileChooserDialogProtocol
protocol exposes the methods and properties of an underlyingGtkFileChooserDialog
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeFileChooserDialog
. Alternatively, useFileChooserDialogRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol FileChooserDialogProtocol : DialogProtocol, FileChooserProtocol
-
GtkFileChooser
is an interface that can be implemented by file selection widgets.In GTK, the main objects that implement this interface are [class
Gtk.FileChooserWidget
] and [classGtk.FileChooserDialog
].You do not need to write an object that implements the
GtkFileChooser
interface unless you are trying to adapt an existing file selector to expose a standard programming interface.GtkFileChooser
allows for shortcuts to various places in the filesystem. In the default implementation these are displayed in the left pane. It may be a bit confusing at first that these shortcuts come from various sources and in various flavours, so lets explain the terminology here:Bookmarks: are created by the user, by dragging folders from the right pane to the left pane, or by using the “Add”. Bookmarks can be renamed and deleted by the user.
Shortcuts: can be provided by the application. For example, a Paint program may want to add a shortcut for a Clipart folder. Shortcuts cannot be modified by the user.
Volumes: are provided by the underlying filesystem abstraction. They are the “roots” of the filesystem.
File Names and Encodings
When the user is finished selecting files in a
GtkFileChooser
, your program can get the selected filenames asGFile
s.Adding options
You can add extra widgets to a file chooser to provide options that are not present in the default design, by using [method
Gtk.FileChooser.add_choice
]. Each choice has an identifier and a user visible label; additionally, each choice can have multiple options. If a choice has no option, it will be rendered as a check button with the given label; if a choice has options, it will be rendered as a combo box.The
See moreFileChooserProtocol
protocol exposes the methods and properties of an underlyingGtkFileChooser
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeFileChooser
. Alternatively, useFileChooserRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol FileChooserProtocol
-
GtkFontChooser
is an interface that can be implemented by widgets for choosing fonts.In GTK, the main objects that implement this interface are [class
Gtk.FontChooserWidget
], [classGtk.FontChooserDialog
] and [classGtk.FontButton
].The
See moreFontChooserProtocol
protocol exposes the methods and properties of an underlyingGtkFontChooser
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeFontChooser
. Alternatively, useFontChooserRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol FontChooserProtocol
-
GtkNative
is the interface implemented by all widgets that have their ownGdkSurface
.The obvious example of a
GtkNative
isGtkWindow
.Every widget that is not itself a
GtkNative
is contained in one, and you can get it with [methodGtk.Widget.get_native
].To get the surface of a
GtkNative
, use [methodGtk.Native.get_surface
]. It is also possible to find theGtkNative
to which a surface belongs, with [funcGtk.Native.get_for_surface
].In addition to a [class
Gdk.Surface
], aGtkNative
also provides a [classGsk.Renderer
] for rendering on that surface. To get the renderer, use [methodGtk.Native.get_renderer
].The
See moreNativeProtocol
protocol exposes the methods and properties of an underlyingGtkNative
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeNative
. Alternatively, useNativeRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol NativeProtocol : WidgetProtocol
-
GtkFileChooserNative
is an abstraction of a dialog suitable for use with “File Open” or “File Save as” commands.By default, this just uses a
GtkFileChooserDialog
to implement the actual dialog. However, on some 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),GtkFileChooserNative
may call the proper APIs (portals) to let the user choose a file and make it available to the application.While the API of
GtkFileChooserNative
closely mirrorsGtkFileChooserDialog
, the main difference is that there is no access to anyGtkWindow
orGtkWidget
for the dialog. This is required, as there may not be one in the case of a platform native dialog.Showing, hiding and running the dialog is handled by the [class
Gtk.NativeDialog
] functions.Note that unlike
GtkFileChooserDialog
,GtkFileChooserNative
objects are not toplevel widgets, and GTK does not keep them alive. It is your responsibility to keep a reference until you are done with the object.Typical usage
In the simplest of cases, you can the following code to use
GtkFileChooserNative
to select a file for opening:static void on_response (GtkNativeDialog *native, int response) { if (response == GTK_RESPONSE_ACCEPT) { GtkFileChooser *chooser = GTK_FILE_CHOOSER (native); GFile *file = gtk_file_chooser_get_file (chooser); open_file (file); g_object_unref (file); } g_object_unref (native); } // ... GtkFileChooserNative *native; GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN; native = gtk_file_chooser_native_new ("Open File", parent_window, action, "_Open", "_Cancel"); g_signal_connect (native, "response", G_CALLBACK (on_response), NULL); gtk_native_dialog_show (GTK_NATIVE_DIALOG (native));
To use a
GtkFileChooserNative
for saving, you can use this:static void on_response (GtkNativeDialog *native, int response) { if (response == GTK_RESPONSE_ACCEPT) { GtkFileChooser *chooser = GTK_FILE_CHOOSER (native); GFile *file = gtk_file_chooser_get_file (chooser); save_to_file (file); g_object_unref (file); } g_object_unref (native); } // ... GtkFileChooserNative *native; GtkFileChooser *chooser; GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_SAVE; native = gtk_file_chooser_native_new ("Save File", parent_window, action, "_Save", "_Cancel"); chooser = GTK_FILE_CHOOSER (native); if (user_edited_a_new_document) gtk_file_chooser_set_current_name (chooser, `_("Untitled document")`); else gtk_file_chooser_set_file (chooser, existing_file, NULL); g_signal_connect (native, "response", G_CALLBACK (on_response), NULL); gtk_native_dialog_show (GTK_NATIVE_DIALOG (native));
For more information on how to best set up a file dialog, see the [class
Gtk.FileChooserDialog
] documentation.Response Codes
GtkFileChooserNative
inherits from [classGtk.NativeDialog
], which means it will returnGTK_RESPONSE_ACCEPT
if the user accepted, andGTK_RESPONSE_CANCEL
if he pressed cancel. It can also returnGTK_RESPONSE_DELETE_EVENT
if the window was unexpectedly closed.Differences from
GtkFileChooserDialog
There are a few things in the [iface
Gtk.FileChooser
] interface that are not possible to use withGtkFileChooserNative
, as such use would prohibit the use of a native dialog.No operations that change the dialog work while the dialog is visible. Set all the properties that are required before showing the dialog.
Win32 details
On windows the
IFileDialog
implementation (added in Windows Vista) is used. It supports many of the features thatGtkFileChooser
has, but there are some things it does not handle:- Any [class
Gtk.FileFilter
] added using a mimetype
If any of these features are used the regular
GtkFileChooserDialog
will be used in place of the native one.Portal details
When the
org.freedesktop.portal.FileChooser
portal is available on the session bus, it is used to bring up an out-of-process file chooser. Depending on the kind of session the application is running in, this may or may not be a GTK file chooser.macOS details
On macOS the
NSSavePanel
andNSOpenPanel
classes are used to provide native file chooser dialogs. Some features provided byGtkFileChooser
are not supported:- Shortcut folders.
The
See moreFileChooserNativeProtocol
protocol exposes the methods and properties of an underlyingGtkFileChooserNative
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeFileChooserNative
. Alternatively, useFileChooserNativeRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol FileChooserNativeProtocol : FileChooserProtocol, NativeDialogProtocol
- Any [class
-
GtkFileChooserWidget
is a widget for choosing files.It exposes the [iface
Gtk.FileChooser
] interface, and you should use the methods of this interface to interact with the widget.CSS nodes
GtkFileChooserWidget
has a single CSS node with name filechooser.The
See moreFileChooserWidgetProtocol
protocol exposes the methods and properties of an underlyingGtkFileChooserWidget
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeFileChooserWidget
. Alternatively, useFileChooserWidgetRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol FileChooserWidgetProtocol : FileChooserProtocol, WidgetProtocol
-
GtkFileFilter
filters files by name or mime type.GtkFileFilter
can be used to restrict the files being shown in aGtkFileChooser
. Files can be filtered based on their name (with [methodGtk.FileFilter.add_pattern
] or [methodGtk.FileFilter.add_suffix
]) or on their mime type (with [methodGtk.FileFilter.add_mime_type
]).Filtering by mime types handles aliasing and subclassing of mime types; e.g. a filter for text/plain also matches a file with mime type application/rtf, since application/rtf is a subclass of text/plain. Note that
GtkFileFilter
allows wildcards for the subtype of a mime type, so you can e.g. filter for image/*.Normally, file filters are used by adding them to a
GtkFileChooser
(see [methodGtk.FileChooser.add_filter
]), but it is also possible to manually use a file filter on any [classGtk.FilterListModel
] containingGFileInfo
objects.GtkFileFilter as GtkBuildable
The
GtkFileFilter
implementation of theGtkBuildable
interface supports adding rules using the<mime-types>
and<patterns>
and<suffixes>
elements and listing the rules within. Specifying a<mime-type>
or<pattern>
or<suffix>
has the same effect as as calling [methodGtk.FileFilter.add_mime_type
] or [methodGtk.FileFilter.add_pattern
] or [methodGtk.FileFilter.add_suffix
].An example of a UI definition fragment specifying
GtkFileFilter
rules:<object class="GtkFileFilter"> <property name="name" translatable="yes">Text and Images</property> <mime-types> <mime-type>text/plain</mime-type> <mime-type>image/ *</mime-type> </mime-types> <patterns> <pattern>*.txt</pattern> </patterns> <suffixes> <suffix>png</suffix> </suffixes> </object>
The
See moreFileFilterProtocol
protocol exposes the methods and properties of an underlyingGtkFileFilter
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeFileFilter
. Alternatively, useFileFilterRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol FileFilterProtocol : BuildableProtocol, FilterProtocol
-
A
GtkFilter
object describes the filtering to be performed by aGtkFilterListModel
.The model will use the filter to determine if it should include items or not by calling [method
Gtk.Filter.match
] for each item and only keeping the ones that the function returnstrue
for.Filters may change what items they match through their lifetime. In that case, they will emit the [signal
Gtk.Filter::changed
] signal to notify that previous filter results are no longer valid and that items should be checked again via [methodGtk.Filter.match
].GTK provides various pre-made filter implementations for common filtering operations. These filters often include properties that can be linked to various widgets to easily allow searches.
However, in particular for large lists or complex search methods, it is also possible to subclass
GtkFilter
and provide one’s own filter.The
See moreFilterProtocol
protocol exposes the methods and properties of an underlyingGtkFilter
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeFilter
. Alternatively, useFilterRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol FilterProtocol : ObjectProtocol
-
GtkFilterListModel
is a list model that filters the elements of the underlying model according to aGtkFilter
.It hides some elements from the other model according to criteria given by a
GtkFilter
.The model can be set up to do incremental searching, so that filtering long lists doesn’t block the UI. See [method
Gtk.FilterListModel.set_incremental
] for details.The
See moreFilterListModelProtocol
protocol exposes the methods and properties of an underlyingGtkFilterListModel
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeFilterListModel
. Alternatively, useFilterListModelRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol FilterListModelProtocol : ListModelProtocol, ObjectProtocol
-
GtkFixed
places its child widgets at fixed positions and with fixed sizes.GtkFixed
performs no automatic layout management.For most applications, you should not use this container! It keeps you from having to learn about the other GTK containers, but it results in broken applications. With
GtkFixed
, the following things will result in truncated text, overlapping widgets, and other display bugs:Themes, which may change widget sizes.
Fonts other than the one you used to write the app will of course change the size of widgets containing text; keep in mind that users may use a larger font because of difficulty reading the default, or they may be using a different OS that provides different fonts.
Translation of text into other languages changes its size. Also, display of non-English text will use a different font in many cases.
In addition,
GtkFixed
does not pay attention to text direction and thus may produce unwanted results if your app is run under right-to-left languages such as Hebrew or Arabic. That is: normally GTK will order containers appropriately for the text direction, e.g. to put labels to the right of the thing they label when using an RTL language, but it can’t do that withGtkFixed
. So if you need to reorder widgets depending on the text direction, you would need to manually detect it and adjust child positions accordingly.Finally, fixed positioning makes it kind of annoying to add/remove UI elements, since you have to reposition all the other elements. This is a long-term maintenance problem for your application.
If you know none of these things are an issue for your application, and prefer the simplicity of
GtkFixed
, by all means use the widget. But you should be aware of the tradeoffs.The
See moreFixedProtocol
protocol exposes the methods and properties of an underlyingGtkFixed
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeFixed
. Alternatively, useFixedRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol FixedProtocol : WidgetProtocol
-
GtkFixedLayout
is a layout manager which can place child widgets at fixed positions.Most applications should never use this layout manager; fixed positioning and sizing requires constant recalculations on where children need to be positioned and sized. Other layout managers perform this kind of work internally so that application developers don’t need to do it. Specifically, widgets positioned in a fixed layout manager will need to take into account:
Themes, which may change widget sizes.
Fonts other than the one you used to write the app will of course change the size of widgets containing text; keep in mind that users may use a larger font because of difficulty reading the default, or they may be using a different OS that provides different fonts.
Translation of text into other languages changes its size. Also, display of non-English text will use a different font in many cases.
In addition,
GtkFixedLayout
does not pay attention to text direction and thus may produce unwanted results if your app is run under right-to-left languages such as Hebrew or Arabic. That is: normally GTK will order containers appropriately depending on the text direction, e.g. to put labels to the right of the thing they label when using an RTL language;GtkFixedLayout
won’t be able to do that for you.Finally, fixed positioning makes it kind of annoying to add/remove UI elements, since you have to reposition all the other elements. This is a long-term maintenance problem for your application.
The
See moreFixedLayoutProtocol
protocol exposes the methods and properties of an underlyingGtkFixedLayout
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeFixedLayout
. Alternatively, useFixedLayoutRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol FixedLayoutProtocol : LayoutManagerProtocol
-
GtkLayoutChild
subclass for children in aGtkFixedLayout
.The
See moreFixedLayoutChildProtocol
protocol exposes the methods and properties of an underlyingGtkFixedLayoutChild
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeFixedLayoutChild
. Alternatively, useFixedLayoutChildRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol FixedLayoutChildProtocol : LayoutChildProtocol
-
GtkFlattenListModel
is a list model that concatenates other list models.GtkFlattenListModel
takes a list model containing list models, and flattens it into a single model.The
See moreFlattenListModelProtocol
protocol exposes the methods and properties of an underlyingGtkFlattenListModel
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeFlattenListModel
. Alternatively, useFlattenListModelRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol FlattenListModelProtocol : ListModelProtocol, ObjectProtocol
-
A
GtkFlowBox
puts child widgets in reflowing grid.For instance, with the horizontal orientation, the widgets will be arranged from left to right, starting a new row under the previous row when necessary. Reducing the width in this case will require more rows, so a larger height will be requested.
Likewise, with the vertical orientation, the widgets will be arranged from top to bottom, starting a new column to the right when necessary. Reducing the height will require more columns, so a larger width will be requested.
The size request of a
GtkFlowBox
alone may not be what you expect; if you need to be able to shrink it along both axes and dynamically reflow its children, you may have to wrap it in aGtkScrolledWindow
to enable that.The children of a
GtkFlowBox
can be dynamically sorted and filtered.Although a
GtkFlowBox
must have onlyGtkFlowBoxChild
children, you can add any kind of widget to it via [methodGtk.FlowBox.insert
], and aGtkFlowBoxChild
widget will automatically be inserted between the box and the widget.Also see [class
Gtk.ListBox
].CSS nodes
flowbox ├── flowboxchild │ ╰── <child> ├── flowboxchild │ ╰── <child> ┊ ╰── [rubberband]
GtkFlowBox
uses a single CSS node with name flowbox.GtkFlowBoxChild
uses a single CSS node with name flowboxchild. For rubberband selection, a subnode with name rubberband is used.Accessibility
GtkFlowBox
uses theGTK_ACCESSIBLE_ROLE_GRID
role, andGtkFlowBoxChild
uses theGTK_ACCESSIBLE_ROLE_GRID_CELL
role.The
See moreFlowBoxProtocol
protocol exposes the methods and properties of an underlyingGtkFlowBox
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeFlowBox
. Alternatively, useFlowBoxRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol FlowBoxProtocol : OrientableProtocol, WidgetProtocol
-
GtkFlowBoxChild
is the kind of widget that can be added to aGtkFlowBox
.The
See moreFlowBoxChildProtocol
protocol exposes the methods and properties of an underlyingGtkFlowBoxChild
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeFlowBoxChild
. Alternatively, useFlowBoxChildRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol FlowBoxChildProtocol : WidgetProtocol
-
The
GtkFontButton
allows to open a font chooser dialog to change the font.It is suitable widget for selecting a font in a preference dialog.
CSS nodes
fontbutton ╰── button.font ╰── [content]
GtkFontButton
has a single CSS node with name fontbutton which contains a button node with the .font style class.The
See moreFontButtonProtocol
protocol exposes the methods and properties of an underlyingGtkFontButton
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeFontButton
. Alternatively, useFontButtonRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol FontButtonProtocol : FontChooserProtocol, WidgetProtocol
-
The
GtkFontChooserDialog
widget is a dialog for selecting a font.GtkFontChooserDialog
implements the [ifaceGtk.FontChooser
] interface and does not provide much API of its own.To create a
GtkFontChooserDialog
, use [ctorGtk.FontChooserDialog.new
].GtkFontChooserDialog as GtkBuildable
The
GtkFontChooserDialog
implementation of theGtkBuildable
interface exposes the buttons with the names “select_button” and “cancel_button”.The
See moreFontChooserDialogProtocol
protocol exposes the methods and properties of an underlyingGtkFontChooserDialog
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeFontChooserDialog
. Alternatively, useFontChooserDialogRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol FontChooserDialogProtocol : DialogProtocol, FontChooserProtocol
-
The
GtkFontChooserWidget
widget lets the user select a font.It is used in the
GtkFontChooserDialog
widget to provide a dialog for selecting fonts.To set the font which is initially selected, use [method
Gtk.FontChooser.set_font
] or [methodGtk.FontChooser.set_font_desc
].To get the selected font use [method
Gtk.FontChooser.get_font
] or [methodGtk.FontChooser.get_font_desc
].To change the text which is shown in the preview area, use [method
Gtk.FontChooser.set_preview_text
].CSS nodes
GtkFontChooserWidget
has a single CSS node with name fontchooser.The
See moreFontChooserWidgetProtocol
protocol exposes the methods and properties of an underlyingGtkFontChooserWidget
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeFontChooserWidget
. Alternatively, useFontChooserWidgetRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol FontChooserWidgetProtocol : FontChooserProtocol, WidgetProtocol
-
GtkFrame
is a widget that surrounds its child with a decorative frame and an optional label.If present, the label is drawn inside the top edge of the frame. The horizontal position of the label can be controlled with [method
Gtk.Frame.set_label_align
].GtkFrame
clips its child. You can use this to add rounded corners to widgets, but be aware that it also cuts off shadows.GtkFrame as GtkBuildable
The
GtkFrame
implementation of theGtkBuildable
interface supports placing a child in the label position by specifying “label” as the “type” attribute of a <child> element. A normal content child can be specified without specifying a <child> type attribute.An example of a UI definition fragment with GtkFrame:
<object class="GtkFrame"> <child type="label"> <object class="GtkLabel" id="frame_label"/> </child> <child> <object class="GtkEntry" id="frame_content"/> </child> </object>
CSS nodes
frame ├── <label widget> ╰── <child>
GtkFrame
has a main CSS node with name “frame”, which is used to draw the visible border. You can set the appearance of the border using CSS properties like “border-style” on this node.The
See moreFrameProtocol
protocol exposes the methods and properties of an underlyingGtkFrame
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeFrame
. Alternatively, useFrameRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol FrameProtocol : WidgetProtocol
-
GtkGLArea
is a widget that allows drawing with OpenGL.GtkGLArea
sets up its own [classGdk.GLContext
], and creates a custom GL framebuffer that the widget will do GL rendering onto. It also ensures that this framebuffer is the default GL rendering target when rendering.In order to draw, you have to connect to the [signal
Gtk.GLArea::render
] signal, or subclassGtkGLArea
and override the GtkGLAreaClass.render virtual function.The
GtkGLArea
widget ensures that theGdkGLContext
is associated with the widget’s drawing area, and it is kept updated when the size and position of the drawing area changes.Drawing with GtkGLArea
The simplest way to draw using OpenGL commands in a
GtkGLArea
is to create a widget instance and connect to the [signalGtk.GLArea::render
] signal:The
render()
function will be called when theGtkGLArea
is ready for you to draw its content:static gboolean render (GtkGLArea *area, GdkGLContext *context) { // inside this function it's safe to use GL; the given // GdkGLContext has been made current to the drawable // surface used by the `GtkGLArea` and the viewport has // already been set to be the size of the allocation // we can start by clearing the buffer glClearColor (0, 0, 0, 0); glClear (GL_COLOR_BUFFER_BIT); // draw your object // draw_an_object (); // we completed our drawing; the draw commands will be // flushed at the end of the signal emission chain, and // the buffers will be drawn on the window return TRUE; } void setup_glarea (void) { // create a GtkGLArea instance GtkWidget *gl_area = gtk_gl_area_new (); // connect to the "render" signal g_signal_connect (gl_area, "render", G_CALLBACK (render), NULL); }
If you need to initialize OpenGL state, e.g. buffer objects or shaders, you should use the [signal
Gtk.Widget::realize
] signal; you can use the [signalGtk.Widget::unrealize
] signal to clean up. Since theGdkGLContext
creation and initialization may fail, you will need to check for errors, using [methodGtk.GLArea.get_error
].An example of how to safely initialize the GL state is:
static void on_realize (GtkGLarea *area) { // We need to make the context current if we want to // call GL API gtk_gl_area_make_current (area); // If there were errors during the initialization or // when trying to make the context current, this // function will return a GError for you to catch if (gtk_gl_area_get_error (area) != NULL) return; // You can also use `gtk_gl_area_set_error()` in order // to show eventual initialization errors on the // GtkGLArea widget itself GError *internal_error = NULL; init_buffer_objects (&error); if (error != NULL) { gtk_gl_area_set_error (area, error); g_error_free (error); return; } init_shaders (&error); if (error != NULL) { gtk_gl_area_set_error (area, error); g_error_free (error); return; } }
If you need to change the options for creating the
GdkGLContext
you should use the [signalGtk.GLArea::create-context
] signal.The
See moreGLAreaProtocol
protocol exposes the methods and properties of an underlyingGtkGLArea
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeGLArea
. Alternatively, useGLAreaRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol GLAreaProtocol : WidgetProtocol
-
The
See moreFilterClassProtocol
protocol exposes the methods and properties of an underlyingGtkFilterClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeFilterClass
. Alternatively, useFilterClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol FilterClassProtocol
-
The
See moreFilterListModelClassProtocol
protocol exposes the methods and properties of an underlyingGtkFilterListModelClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeFilterListModelClass
. Alternatively, useFilterListModelClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol FilterListModelClassProtocol
-
The
See moreFixedClassProtocol
protocol exposes the methods and properties of an underlyingGtkFixedClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeFixedClass
. Alternatively, useFixedClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol FixedClassProtocol
-
The
See moreFixedLayoutChildClassProtocol
protocol exposes the methods and properties of an underlyingGtkFixedLayoutChildClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeFixedLayoutChildClass
. Alternatively, useFixedLayoutChildClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol FixedLayoutChildClassProtocol
-
The
See moreFixedLayoutClassProtocol
protocol exposes the methods and properties of an underlyingGtkFixedLayoutClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeFixedLayoutClass
. Alternatively, useFixedLayoutClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol FixedLayoutClassProtocol
-
The
See moreFlattenListModelClassProtocol
protocol exposes the methods and properties of an underlyingGtkFlattenListModelClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeFlattenListModelClass
. Alternatively, useFlattenListModelClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol FlattenListModelClassProtocol
-
The
See moreFlowBoxChildClassProtocol
protocol exposes the methods and properties of an underlyingGtkFlowBoxChildClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeFlowBoxChildClass
. Alternatively, useFlowBoxChildClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol FlowBoxChildClassProtocol
-
The
See moreFontChooserIfaceProtocol
protocol exposes the methods and properties of an underlyingGtkFontChooserIface
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeFontChooserIface
. Alternatively, useFontChooserIfaceRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol FontChooserIfaceProtocol
-
The
See moreFrameClassProtocol
protocol exposes the methods and properties of an underlyingGtkFrameClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeFrameClass
. Alternatively, useFrameClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol FrameClassProtocol
-
The
GtkGLAreaClass
structure contains only private data.The
See moreGLAreaClassProtocol
protocol exposes the methods and properties of an underlyingGtkGLAreaClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeGLAreaClass
. Alternatively, useGLAreaClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol GLAreaClassProtocol
-
GtkGesture
is the base class for gesture recognition.Although
GtkGesture
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 specialnil
GdkEventSequence
value for these).The number of touches that a
GtkGesture
need to be recognized is controlled by the [propertyGtk.Gesture:n-points
] property, if a gesture is keeping track of less or more than that number of sequences, it won’t check whether the gesture is recognized.As soon as the gesture has the expected number of touches, it will check regularly if it is recognized, the criteria to consider a gesture as “recognized” is left to
GtkGesture
subclasses.A recognized gesture will then emit the following signals:
- [signal
Gtk.Gesture::begin
] when the gesture is recognized. - [signal
Gtk.Gesture::update
], whenever an input event is processed. - [signal
Gtk.Gesture::end
] when the gesture is no longer recognized.
Event propagation
In order to receive events, a gesture needs to set a propagation phase through [method
Gtk.EventController.set_propagation_phase
].In the capture phase, events are propagated from the toplevel down to the target widget, and gestures that are attached to containers above the widget get a chance to interact with the event before it reaches the target.
In the bubble phase, events are propagated up from the target widget to the toplevel, and gestures that are attached to containers above the widget get a chance to interact with events that have not been handled yet.
States of a sequence
Whenever input interaction happens, a single event may trigger a cascade of
GtkGesture
s, both across the parents of the widget receiving the event and in parallel within an individual widget. It is a responsibility of the widgets using those gestures to set the state of touch sequences accordingly in order to enable cooperation of gestures around theGdkEventSequence
s triggering those.Within a widget, gestures can be grouped through [method
Gtk.Gesture.group
]. Grouped gestures synchronize the state of sequences, so calling [methodGtk.Gesture.set_sequence_state
] on one will effectively propagate the state throughout the group.By default, all sequences start out in the
GTK_EVENT_SEQUENCE_NONE
state, sequences in this state trigger the gesture event handler, but event propagation will continue unstopped by gestures.If a sequence enters into the
GTK_EVENT_SEQUENCE_DENIED
state, the gesture group will effectively ignore the sequence, letting events go unstopped through the gesture, but the “slot” will still remain occupied while the touch is active.If a sequence enters in the
GTK_EVENT_SEQUENCE_CLAIMED
state, the gesture group will grab all interaction on the sequence, by:- Setting the same sequence to
GTK_EVENT_SEQUENCE_DENIED
on every other gesture group within the widget, and every gesture on parent widgets in the propagation chain. - Emitting [signal
Gtk.Gesture::cancel
] on every gesture in widgets underneath in the propagation chain. - Stopping event propagation after the gesture group handles the event.
Note: if a sequence is set early to
GTK_EVENT_SEQUENCE_CLAIMED
onGDK_TOUCH_BEGIN
/GDK_BUTTON_PRESS
(so those events are captured before reaching the event widget, this impliesGTK_PHASE_CAPTURE
), one similar event will emulated if the sequence changes toGTK_EVENT_SEQUENCE_DENIED
. This way event coherence is preserved before event propagation is unstopped again.Sequence states can’t be changed freely. See [method
Gtk.Gesture.set_sequence_state
] to know about the possible lifetimes of aGdkEventSequence
.Touchpad gestures
On the platforms that support it,
GtkGesture
will handle transparently touchpad gesture events. The only precautions users ofGtkGesture
should do to enable this support are:- If the gesture has
GTK_PHASE_NONE
, ensuring events of typeGDK_TOUCHPAD_SWIPE
andGDK_TOUCHPAD_PINCH
are handled by theGtkGesture
The
See moreGestureProtocol
protocol exposes the methods and properties of an underlyingGtkGesture
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeGesture
. Alternatively, useGestureRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol GestureProtocol : EventControllerProtocol
- [signal
-
GtkGestureClick
is aGtkGesture
implementation for clicks.It is able to recognize multiple clicks on a nearby zone, which can be listened for through the [signal
Gtk.GestureClick::pressed
] signal. Whenever time or distance between clicks exceed the GTK defaults, [signalGtk.GestureClick::stopped
] is emitted, and the click counter is reset.The
See moreGestureClickProtocol
protocol exposes the methods and properties of an underlyingGtkGestureClick
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeGestureClick
. Alternatively, useGestureClickRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol GestureClickProtocol : GestureSingleProtocol
-
GtkGestureDrag
is aGtkGesture
implementation for drags.The drag operation itself can be tracked throughout the [signal
Gtk.GestureDrag::drag-begin
], [signalGtk.GestureDrag::drag-update
] and [signalGtk.GestureDrag::drag-end
] signals, and the relevant coordinates can be extracted through [methodGtk.GestureDrag.get_offset
] and [methodGtk.GestureDrag.get_start_point
].The
See moreGestureDragProtocol
protocol exposes the methods and properties of an underlyingGtkGestureDrag
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeGestureDrag
. Alternatively, useGestureDragRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol GestureDragProtocol : GestureSingleProtocol
-
GtkGestureLongPress
is aGtkGesture
for long presses.This gesture is also known as “Press and Hold”.
When the timeout is exceeded, the gesture is triggering the [signal
Gtk.GestureLongPress::pressed
] signal.If the touchpoint is lifted before the timeout passes, or if it drifts too far of the initial press point, the [signal
Gtk.GestureLongPress::cancelled
] signal will be emitted.How long the timeout is before the
pressed
signal gets emitted is determined by the [propertyGtk.Settings:gtk-long-press-time
] setting. It can be modified by the [propertyGtk.GestureLongPress:delay-factor
] property.The
See moreGestureLongPressProtocol
protocol exposes the methods and properties of an underlyingGtkGestureLongPress
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeGestureLongPress
. Alternatively, useGestureLongPressRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol GestureLongPressProtocol : GestureSingleProtocol
-
GtkGesturePan
is aGtkGesture
for pan gestures.These are drags that are locked to happen along one axis. The axis that a
GtkGesturePan
handles is defined at construct time, and can be changed through [methodGtk.GesturePan.set_orientation
].When the gesture starts to be recognized,
GtkGesturePan
will attempt to determine as early as possible whether the sequence is moving in the expected direction, and denying the sequence if this does not happen.Once a panning gesture along the expected axis is recognized, the [signal
Gtk.GesturePan::pan
] signal will be emitted as input events are received, containing the offset in the given axis.The
See moreGesturePanProtocol
protocol exposes the methods and properties of an underlyingGtkGesturePan
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeGesturePan
. Alternatively, useGesturePanRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol GesturePanProtocol : GestureDragProtocol
-
GtkGestureRotate
is aGtkGesture
for 2-finger rotations.Whenever the angle between both handled sequences changes, the [signal
Gtk.GestureRotate::angle-changed
] signal is emitted.The
See moreGestureRotateProtocol
protocol exposes the methods and properties of an underlyingGtkGestureRotate
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeGestureRotate
. Alternatively, useGestureRotateRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol GestureRotateProtocol : GestureProtocol
-
GtkGestureSingle
is aGtkGestures
subclass optimized for singe-touch and mouse gestures.Under interaction, these gestures stick to the first interacting sequence, which is accessible through [method
Gtk.GestureSingle.get_current_sequence
] while the gesture is being interacted with.By default gestures react to both
GDK_BUTTON_PRIMARY
and touch events. [methodGtk.GestureSingle.set_touch_only
] can be used to change the touch behavior. Callers may also specify a different mouse button number to interact with through [methodGtk.GestureSingle.set_button
], or react to any mouse button by setting it to 0. While the gesture is active, the button being currently pressed can be known through [methodGtk.GestureSingle.get_current_button
].The
See moreGestureSingleProtocol
protocol exposes the methods and properties of an underlyingGtkGestureSingle
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeGestureSingle
. Alternatively, useGestureSingleRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol GestureSingleProtocol : GestureProtocol
-
GtkGestureStylus
is aGtkGesture
specific to stylus input.The provided signals just relay the basic information of the stylus events.
The
See moreGestureStylusProtocol
protocol exposes the methods and properties of an underlyingGtkGestureStylus
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeGestureStylus
. Alternatively, useGestureStylusRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol GestureStylusProtocol : GestureSingleProtocol
-
GtkGestureSwipe
is aGtkGesture
for swipe gestures.After a press/move/…/move/release sequence happens, the [signal
Gtk.GestureSwipe::swipe
] signal will be emitted, providing the velocity and directionality of the sequence at the time it was lifted.If the velocity is desired in intermediate points, [method
Gtk.GestureSwipe.get_velocity
] can be called in a [signalGtk.Gesture::update
] handler.All velocities are reported in pixels/sec units.
The
See moreGestureSwipeProtocol
protocol exposes the methods and properties of an underlyingGtkGestureSwipe
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeGestureSwipe
. Alternatively, useGestureSwipeRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol GestureSwipeProtocol : GestureSingleProtocol
-
GtkGestureZoom
is aGtkGesture
for 2-finger pinch/zoom gestures.Whenever the distance between both tracked sequences changes, the [signal
Gtk.GestureZoom::scale-changed
] signal is emitted to report the scale factor.The
See moreGestureZoomProtocol
protocol exposes the methods and properties of an underlyingGtkGestureZoom
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeGestureZoom
. Alternatively, useGestureZoomRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol GestureZoomProtocol : GestureProtocol
-
GtkGrid
is a container which arranges its child widgets in rows and columns.It supports arbitrary positions and horizontal/vertical spans.
Children are added using [method
Gtk.Grid.attach
]. They can span multiple rows or columns. It is also possible to add a child next to an existing child, using [methodGtk.Grid.attach_next_to
]. To remove a child from the grid, use [methodGtk.Grid.remove
].The behaviour of
GtkGrid
when several children occupy the same grid cell is undefined.GtkGrid as GtkBuildable
Every child in a
GtkGrid
has access to a custom [ifaceGtk.Buildable
] element, called<layout>
. It can by used to specify a position in the grid and optionally spans. All properties that can be used in the<layout>
element are implemented by [classGtk.GridLayoutChild
].It is implemented by
GtkWidget
using [classGtk.LayoutManager
].To showcase it, here is a simple example:
<object class="GtkGrid" id="my_grid"> <child> <object class="GtkButton" id="button1"> <property name="label">Button 1</property> <layout> <property name="column">0</property> <property name="row">0</property> </layout> </object> </child> <child> <object class="GtkButton" id="button2"> <property name="label">Button 2</property> <layout> <property name="column">1</property> <property name="row">0</property> </layout> </object> </child> <child> <object class="GtkButton" id="button3"> <property name="label">Button 3</property> <layout> <property name="column">2</property> <property name="row">0</property> <property name="row-span">2</property> </layout> </object> </child> <child> <object class="GtkButton" id="button4"> <property name="label">Button 4</property> <layout> <property name="column">0</property> <property name="row">1</property> <property name="column-span">2</property> </layout> </object> </child> </object>
It organizes the first two buttons side-by-side in one cell each. The third button is in the last column but spans across two rows. This is defined by the
row-span
property. The last button is located in the second row and spans across two columns, which is defined by thecolumn-span
property.CSS nodes
GtkGrid
uses a single CSS node with namegrid
.Accessibility
GtkGrid
uses theGTK_ACCESSIBLE_ROLE_GROUP
role.The
See moreGridProtocol
protocol exposes the methods and properties of an underlyingGtkGrid
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeGrid
. Alternatively, useGridRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol GridProtocol : OrientableProtocol, WidgetProtocol
-
GtkGridLayout
is a layout manager which arranges child widgets in rows and columns.Children have an “attach point” defined by the horizontal and vertical index of the cell they occupy; children can span multiple rows or columns. The layout properties for setting the attach points and spans are set using the [class
Gtk.GridLayoutChild
] associated to each child widget.The behaviour of
GtkGridLayout
when several children occupy the same grid cell is undefined.GtkGridLayout
can be used like aGtkBoxLayout
if all children are attached to the same row or column; however, if you only ever need a single row or column, you should consider usingGtkBoxLayout
.The
See moreGridLayoutProtocol
protocol exposes the methods and properties of an underlyingGtkGridLayout
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeGridLayout
. Alternatively, useGridLayoutRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol GridLayoutProtocol : LayoutManagerProtocol
-
GtkLayoutChild
subclass for children in aGtkGridLayout
.The
See moreGridLayoutChildProtocol
protocol exposes the methods and properties of an underlyingGtkGridLayoutChild
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeGridLayoutChild
. Alternatively, useGridLayoutChildRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol GridLayoutChildProtocol : LayoutChildProtocol
-
GtkGridView
presents a large dynamic grid of items.GtkGridView
uses its factory to generate one child widget for each visible item and shows them in a grid. The orientation of the grid view determines if the grid reflows vertically or horizontally.GtkGridView
allows the user to select items according to the selection characteristics of the model. For models that allow multiple selected items, it is possible to turn on rubberband selection, using [propertyGtk.GridView:enable-rubberband
].To learn more about the list widget framework, see the overview.
CSS nodes
gridview ├── child[.activatable] │ ├── child[.activatable] │ ┊ ╰── [rubberband]
GtkGridView
uses a single CSS node with namegridview
. Each child uses a single CSS node with namechild
. If the [propertyGtk.ListItem:activatable
] property is set, the corresponding row will have the.activatable
style class. For rubberband selection, a subnode with namerubberband
is used.Accessibility
GtkGridView
uses theGTK_ACCESSIBLE_ROLE_GRID
role, and the items use theGTK_ACCESSIBLE_ROLE_GRID_CELL
role.The
See moreGridViewProtocol
protocol exposes the methods and properties of an underlyingGtkGridView
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeGridView
. Alternatively, useGridViewRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol GridViewProtocol : ListBaseProtocol
-
GtkHeaderBar
is a widget for creating custom title bars for windows.GtkHeaderBar
is similar to a horizontalGtkCenterBox
. It allows children to be placed at the start or the end. In addition, it allows the window title 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.GtkHeaderBar
can add typical window frame controls, such as minimize, maximize and close buttons, or the window icon.For these reasons,
GtkHeaderBar
is the natural choice for use as the custom titlebar widget of aGtkWindow (see [method
Gtk.Window.set_titlebar`]), as it gives features typical of titlebars while allowing the addition of child widgets.GtkHeaderBar as GtkBuildable
The
GtkHeaderBar
implementation of theGtkBuildable
interface supports adding children at the start or end sides by specifying “start” or “end” as the “type” attribute of a <child> element, or setting the title widget by specifying “title” value.By default the
GtkHeaderBar
uses aGtkLabel
displaying the title of the window it is contained in as the title widget, equivalent to the following UI definition:<object class="GtkHeaderBar"> <property name="title-widget"> <object class="GtkLabel"> <property name="label" translatable="yes">Label</property> <property name="single-line-mode">True</property> <property name="ellipsize">end</property> <property name="width-chars">5</property> <style> <class name="title"/> </style> </object> </property> </object>
CSS nodes
headerbar ╰── windowhandle ╰── box ├── box.start │ ├── windowcontrols.start │ ╰── [other children] ├── [Title Widget] ╰── box.end ├── [other children] ╰── windowcontrols.end
A
GtkHeaderBar
‘s CSS node is calledheaderbar
. It contains awindowhandle
subnode, which contains abox
subnode, which contains twobox
subnodes at the start and end of the header bar, as well as a center node that represents the title.Each of the boxes contains a
windowcontrols
subnode, see [classGtk.WindowControls
] for details, as well as other children.Accessibility
GtkHeaderBar
uses theGTK_ACCESSIBLE_ROLE_GROUP
role.The
See moreHeaderBarProtocol
protocol exposes the methods and properties of an underlyingGtkHeaderBar
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeHeaderBar
. Alternatively, useHeaderBarRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol HeaderBarProtocol : WidgetProtocol
-
The
See moreGestureClassProtocol
protocol exposes the methods and properties of an underlyingGtkGestureClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeGestureClass
. Alternatively, useGestureClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol GestureClassProtocol
-
The
See moreGestureClickClassProtocol
protocol exposes the methods and properties of an underlyingGtkGestureClickClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeGestureClickClass
. Alternatively, useGestureClickClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol GestureClickClassProtocol
-
The
See moreGestureDragClassProtocol
protocol exposes the methods and properties of an underlyingGtkGestureDragClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeGestureDragClass
. Alternatively, useGestureDragClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol GestureDragClassProtocol
-
The
See moreGestureLongPressClassProtocol
protocol exposes the methods and properties of an underlyingGtkGestureLongPressClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeGestureLongPressClass
. Alternatively, useGestureLongPressClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol GestureLongPressClassProtocol
-
The
See moreGesturePanClassProtocol
protocol exposes the methods and properties of an underlyingGtkGesturePanClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeGesturePanClass
. Alternatively, useGesturePanClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol GesturePanClassProtocol
-
The
See moreGestureRotateClassProtocol
protocol exposes the methods and properties of an underlyingGtkGestureRotateClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeGestureRotateClass
. Alternatively, useGestureRotateClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol GestureRotateClassProtocol
-
The
See moreGestureSingleClassProtocol
protocol exposes the methods and properties of an underlyingGtkGestureSingleClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeGestureSingleClass
. Alternatively, useGestureSingleClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol GestureSingleClassProtocol
-
The
See moreGestureStylusClassProtocol
protocol exposes the methods and properties of an underlyingGtkGestureStylusClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeGestureStylusClass
. Alternatively, useGestureStylusClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol GestureStylusClassProtocol
-
The
See moreGestureSwipeClassProtocol
protocol exposes the methods and properties of an underlyingGtkGestureSwipeClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeGestureSwipeClass
. Alternatively, useGestureSwipeClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol GestureSwipeClassProtocol
-
The
See moreGestureZoomClassProtocol
protocol exposes the methods and properties of an underlyingGtkGestureZoomClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeGestureZoomClass
. Alternatively, useGestureZoomClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol GestureZoomClassProtocol
-
The
See moreGridClassProtocol
protocol exposes the methods and properties of an underlyingGtkGridClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeGridClass
. Alternatively, useGridClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol GridClassProtocol
-
The
See moreGridLayoutChildClassProtocol
protocol exposes the methods and properties of an underlyingGtkGridLayoutChildClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeGridLayoutChildClass
. Alternatively, useGridLayoutChildClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol GridLayoutChildClassProtocol
-
The
See moreGridLayoutClassProtocol
protocol exposes the methods and properties of an underlyingGtkGridLayoutClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeGridLayoutClass
. Alternatively, useGridLayoutClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol GridLayoutClassProtocol
-
The
See moreGridViewClassProtocol
protocol exposes the methods and properties of an underlyingGtkGridViewClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeGridViewClass
. Alternatively, useGridViewClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol GridViewClassProtocol
-
The
See moreIMContextClassProtocol
protocol exposes the methods and properties of an underlyingGtkIMContextClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeIMContextClass
. Alternatively, useIMContextClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol IMContextClassProtocol
-
GtkIMContext
defines the interface for GTK input methods.GtkIMContext
is used by GTK text input widgets likeGtkText
to map from key events to Unicode character strings.An input method may consume multiple key events in sequence before finally outputting the composed result. This is called preediting, and an input method may provide feedback about this process by displaying the intermediate composition states as preedit text. To do so, the
GtkIMContext
will emit [signalGtk.IMContext::preedit-start
], [signalGtk.IMContext::preedit-changed
] and [signalGtk.IMContext::preedit-end
] signals.For instance, the built-in GTK input method [class
Gtk.IMContextSimple
] implements the input of arbitrary Unicode code points by holding down the <kbd>Control</kbd> and <kbd>Shift</kbd> keys and then typing <kbd>u</kbd> followed by the hexadecimal digits of the code point. When releasing the <kbd>Control</kbd> and <kbd>Shift</kbd> keys, preediting ends and the character is inserted as text. For example,Ctrl+Shift+u 2 0 A C
results in the € sign.
Additional input methods can be made available for use by GTK widgets as loadable modules. An input method module is a small shared library which provides a
GIOExtension
for the extension point named “gtk-im-module”.To connect a widget to the users preferred input method, you should use [class
Gtk.IMMulticontext
].The
See moreIMContextProtocol
protocol exposes the methods and properties of an underlyingGtkIMContext
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeIMContext
. Alternatively, useIMContextRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol IMContextProtocol : ObjectProtocol
-
GtkIMContextSimple
is an input method supporting table-based input methods.Compose sequences
GtkIMContextSimple
reads compose sequences from the first of the following files that is found: ~/.config/gtk-4.0/Compose, ~/.XCompose, /usr/share/X11/locale/$locale/Compose (for locales that have a nontrivial Compose file). The syntax of these files is described in theCompose(5)
manual page.If none of these files is found,
GtkIMContextSimple
uses a built-in table of compose sequences that is derived from the X11 Compose files.Note that compose sequences typically start with the Compose_key, which is often not available as a dedicated key on keyboards. Keyboard layouts may map this keysym to other keys, such as the right Control key.
Unicode characters
GtkIMContextSimple
also supports numeric entry of Unicode characters by typing <kbd>Ctrl</kbd>-<kbd>Shift</kbd>-<kbd>u</kbd>, followed by a hexadecimal Unicode codepoint.For example,
Ctrl-Shift-u 1 2 3 Enter
yields U+0123 LATIN SMALL LETTER G WITH CEDILLA, i.e. ģ.
Dead keys
GtkIMContextSimple
supports dead keys. For example, typingdead_acute a
yields U+00E! LATIN SMALL LETTER_A WITH ACUTE, i.e. á. Note that this depends on the keyboard layout including dead keys.
The
See moreIMContextSimpleProtocol
protocol exposes the methods and properties of an underlyingGtkIMContextSimple
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeIMContextSimple
. Alternatively, useIMContextSimpleRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol IMContextSimpleProtocol : IMContextProtocol
-
GtkIMMulticontext
is an input method context supporting multiple, switchable input methods.Text widgets such as
GtkText
orGtkTextView
use aGtkIMMultiContext
to implement theirim-module
property for switching between different input methods.The
See moreIMMulticontextProtocol
protocol exposes the methods and properties of an underlyingGtkIMMulticontext
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeIMMulticontext
. Alternatively, useIMMulticontextRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol IMMulticontextProtocol : IMContextProtocol
-
Contains information found when looking up an icon in
GtkIconTheme
.GtkIconPaintable
implementsGdkPaintable
.The
See moreIconPaintableProtocol
protocol exposes the methods and properties of an underlyingGtkIconPaintable
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeIconPaintable
. Alternatively, useIconPaintableRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol IconPaintableProtocol : ObjectProtocol, PaintableProtocol
-
GtkIconTheme
provides a facility for loading themed icons.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.In many cases, named themes are used indirectly, via [class
Gtk.Image
] rather than directly, but looking up icons directly is also simple. TheGtkIconTheme
object acts as a database of all the icons in the current theme. You can create newGtkIconTheme
objects, but it’s much more efficient to use the standard icon theme of theGtkWidget
so that the icon information is shared with other people looking up icons.GtkIconTheme *icon_theme; GtkIconPaintable *icon; GdkPaintable *paintable; icon_theme = gtk_icon_theme_get_for_display (gtk_widget_get_display (my_widget)); icon = gtk_icon_theme_lookup_icon (icon_theme, "my-icon-name", // icon name 48, // icon size 1, // scale 0, // flags); paintable = GDK_PAINTABLE (icon); // Use the paintable g_object_unref (icon);
The
See moreIconThemeProtocol
protocol exposes the methods and properties of an underlyingGtkIconTheme
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeIconTheme
. Alternatively, useIconThemeRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol IconThemeProtocol : ObjectProtocol
-
GtkIconView
is a widget which displays data in a grid of icons.GtkIconView
provides an alternative view on aGtkTreeModel
. It displays the model as a grid of icons with labels. Like [classGtk.TreeView
], it allows to select one or multiple items (depending on the selection mode, see [methodGtk.IconView.set_selection_mode
]). In addition to selection with the arrow keys,GtkIconView
supports rubberband selection, which is controlled by dragging the pointer.Note that if the tree model is backed by an actual tree store (as opposed to a flat list where the mapping to icons is obvious),
GtkIconView
will only display the first level of the tree and ignore the tree’s branches.CSS nodes
iconview.view ╰── [rubberband]
GtkIconView
has a single CSS node with name iconview and style class .view. For rubberband selection, a subnode with name rubberband is used.The
See moreIconViewProtocol
protocol exposes the methods and properties of an underlyingGtkIconView
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeIconView
. Alternatively, useIconViewRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol IconViewProtocol : CellLayoutProtocol, ScrollableProtocol, WidgetProtocol
-
The
GtkImage
widget displays an image.Various kinds of object can be displayed as an image; most typically, you would load a
GdkTexture
from a file, using the convenience function [ctorGtk.Image.new_from_file
], for instance:GtkWidget *image = gtk_image_new_from_file ("myfile.png");
If the file isn’t loaded successfully, the image will contain a “broken image” icon similar to that used in many web browsers.
If you want to handle errors in loading the file yourself, for example by displaying an error message, then load the image with [ctor
Gdk.Texture.new_from_file
], then create theGtkImage
with [ctorGtk.Image.new_from_paintable
].Sometimes an application will want to avoid depending on external data files, such as image files. See the documentation of
GResource
inside GIO, for details. In this case, [propertyGtk.Image:resource
], [ctorGtk.Image.new_from_resource
], and [methodGtk.Image.set_from_resource
] should be used.GtkImage
displays its image as an icon, with a size that is determined by the application. See [classGtk.Picture
] if you want to show an image at is actual size.CSS nodes
GtkImage
has a single CSS node with the nameimage
. The style classes.normal-icons
or.large-icons
may appear, depending on the [propertyGtk.Image:icon-size
] property.Accessibility
GtkImage
uses theGTK_ACCESSIBLE_ROLE_IMG
role.The
See moreImageProtocol
protocol exposes the methods and properties of an underlyingGtkImage
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeImage
. Alternatively, useImageRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ImageProtocol : WidgetProtocol
-
GtkInfoBar
can be show messages to the user without a dialog.It is often temporarily shown at the top or bottom of a document. In contrast to [class
Gtk.Dialog
], which has an action area at the bottom,GtkInfoBar
has an action area at the side.The API of
GtkInfoBar
is very similar toGtkDialog
, allowing you to add buttons to the action area with [methodGtk.InfoBar.add_button
] or [ctorGtk.InfoBar.new_with_buttons
]. The sensitivity of action widgets can be controlled with [methodGtk.InfoBar.set_response_sensitive
].To add widgets to the main content area of a
GtkInfoBar
, use [methodGtk.InfoBar.add_child
].Similar to [class
Gtk.MessageDialog
], the contents of aGtkInfoBar
can by classified as error message, warning, informational message, etc, by using [methodGtk.InfoBar.set_message_type
]. GTK may use the message type to determine how the message is displayed.A simple example for using a
GtkInfoBar
:GtkWidget *message_label; GtkWidget *widget; GtkWidget *grid; GtkInfoBar *bar; // set up info bar widget = gtk_info_bar_new (); bar = GTK_INFO_BAR (widget); grid = gtk_grid_new (); message_label = gtk_label_new (""); gtk_info_bar_add_child (bar, message_label); gtk_info_bar_add_button (bar, `_("_OK")`, GTK_RESPONSE_OK); g_signal_connect (bar, "response", G_CALLBACK (gtk_widget_hide), NULL); gtk_grid_attach (GTK_GRID (grid), widget, 0, 2, 1, 1); // ... // show an error message gtk_label_set_text (GTK_LABEL (message_label), "An error occurred!"); gtk_info_bar_set_message_type (bar, GTK_MESSAGE_ERROR); gtk_widget_show (bar);
GtkInfoBar as GtkBuildable
GtkInfoBar
supports a custom <action-widgets> element, which can contain multiple <action-widget> elements. The “response” attribute specifies a numeric response, and the content of the element is the id of widget (which should be a child of the dialogsaction_area
).GtkInfoBar
supports adding action widgets by specifying “action” as the “type” attribute of a<child>
element. The widget will be added either to the action area. The response id has to be associated with the action widget using the<action-widgets>
element.CSS nodes
GtkInfoBar
has a single CSS node with name infobar. The node may get one of the style classes .info, .warning, .error or .question, depending on the message type. If the info bar shows a close button, that button will have the .close style class applied.The
See moreInfoBarProtocol
protocol exposes the methods and properties of an underlyingGtkInfoBar
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeInfoBar
. Alternatively, useInfoBarRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol InfoBarProtocol : WidgetProtocol
-
A
GtkShortcutTrigger
that triggers when a specific keyval and modifiers are pressed.The
See moreKeyvalTriggerProtocol
protocol exposes the methods and properties of an underlyingGtkKeyvalTrigger
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeKeyvalTrigger
. Alternatively, useKeyvalTriggerRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol KeyvalTriggerProtocol : ShortcutTriggerProtocol
-
The
See moreIMContextSimpleClassProtocol
protocol exposes the methods and properties of an underlyingGtkIMContextSimpleClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeIMContextSimpleClass
. Alternatively, useIMContextSimpleClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol IMContextSimpleClassProtocol
-
The
See moreIMMulticontextClassProtocol
protocol exposes the methods and properties of an underlyingGtkIMMulticontextClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeIMMulticontextClass
. Alternatively, useIMMulticontextClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol IMMulticontextClassProtocol
-
The
See moreKeyvalTriggerClassProtocol
protocol exposes the methods and properties of an underlyingGtkKeyvalTriggerClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeKeyvalTriggerClass
. Alternatively, useKeyvalTriggerClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol KeyvalTriggerClassProtocol
-
The
GtkLabel
widget displays a small amount of text.As the name implies, most labels are used to label another widget such as a [class
Button
].CSS nodes
label ├── [selection] ├── [link] ┊ ╰── [link]
GtkLabel
has a single CSS node with the name label. A wide variety of style classes may be applied to labels, such as .title, .subtitle, .dim-label, etc. In theGtkShortcutsWindow
, labels are used with the .keycap style class.If the label has a selection, it gets a subnode with name selection.
If the label has links, there is one subnode per link. These subnodes carry the link or visited state depending on whether they have been visited. In this case, label node also gets a .link style class.
GtkLabel as GtkBuildable
The GtkLabel implementation of the GtkBuildable interface supports a custom <attributes> element, which supports any number of <attribute> elements. The <attribute> element has attributes named “name“, “value“, “start“ and “end“ and allows you to specify [struct
Pango.Attribute
] values for this label.An example of a UI definition fragment specifying Pango attributes:
<object class="GtkLabel"> <attributes> <attribute name="weight" value="PANGO_WEIGHT_BOLD"/> <attribute name="background" value="red" start="5" end="10"/> </attributes> </object>
The start and end attributes specify the range of characters to which the Pango attribute applies. If start and end are not specified, the attribute is applied to the whole text. Note that specifying ranges does not make much sense with translatable attributes. Use markup embedded in the translatable content instead.
Accessibility
GtkLabel
uses theGTK_ACCESSIBLE_ROLE_LABEL
role.Mnemonics
Labels may contain “mnemonics”. Mnemonics are underlined characters in the label, used for keyboard navigation. Mnemonics are created by providing a string with an underscore before the mnemonic character, such as
"_File"
, to the functions [ctorGtk.Label.new_with_mnemonic
] or [methodGtk.Label.set_text_with_mnemonic
].Mnemonics automatically activate any activatable widget the label is inside, such as a [class
Gtk.Button
]; if the label is not inside the mnemonic’s target widget, you have to tell the label about the target using [classGtk.Label.set_mnemonic_widget
]. Here’s a simple example where the label is inside a button:// Pressing Alt+H will activate this button GtkWidget *button = gtk_button_new (); GtkWidget *label = gtk_label_new_with_mnemonic ("_Hello"); gtk_button_set_child (GTK_BUTTON (button), label);
There’s a convenience function to create buttons with a mnemonic label already inside:
// Pressing Alt+H will activate this button GtkWidget *button = gtk_button_new_with_mnemonic ("_Hello");
To create a mnemonic for a widget alongside the label, such as a [class
Gtk.Entry
], you have to point the label at the entry with [methodGtk.Label.set_mnemonic_widget
]:// Pressing Alt+H will focus the entry GtkWidget *entry = gtk_entry_new (); GtkWidget *label = gtk_label_new_with_mnemonic ("_Hello"); gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry);
Markup (styled text)
To make it easy to format text in a label (changing colors, fonts, etc.), label text can be provided in a simple markup format:
Here’s how to create a label with a small font:
GtkWidget *label = gtk_label_new (NULL); gtk_label_set_markup (GTK_LABEL (label), "<small>Small text</small>");
(See the Pango manual for complete documentation] of available tags, [func
Pango.parse_markup
])The markup passed to
gtk_label_set_markup()
must be valid; for example, literal <, > and & characters must be escaped as <, >, and &. If you pass text obtained from the user, file, or a network to [methodGtk.Label.set_markup
], you’ll want to escape it withg_markup_escape_text()
org_markup_printf_escaped()
.Markup strings are just a convenient way to set the [struct
Pango.AttrList
] on a label; [methodGtk.Label.set_attributes
] may be a simpler way to set attributes in some cases. Be careful though; [structPango.AttrList
] tends to cause internationalization problems, unless you’re applying attributes to the entire string (i.e. unless you set the range of each attribute to [0,G_MAXINT
)). The reason is that specifying the start_index and end_index for a [structPango.Attribute
] requires knowledge of the exact string being displayed, so translations will cause problems.Selectable labels
Labels can be made selectable with [method
Gtk.Label.set_selectable
]. Selectable labels allow the user to copy the label contents to the clipboard. Only labels that contain useful-to-copy information — such as error messages — should be made selectable.Text layout
A label can contain any number of paragraphs, but will have performance problems if it contains more than a small number. Paragraphs are separated by newlines or other paragraph separators understood by Pango.
Labels can automatically wrap text if you call [method
Gtk.Label.set_wrap
].[method
Gtk.Label.set_justify
] sets how the lines in a label align with one another. If you want to set how the label as a whole aligns in its available space, see the [propertyGtk.Widget:halign
] and [propertyGtk.Widget:valign
] properties.The [property
Gtk.Label:width-chars
] and [propertyGtk.Label:max-width-chars
] properties can be used to control the size allocation of ellipsized or wrapped labels. For ellipsizing labels, if either is specified (and less than the actual text size), it is used as the minimum width, and the actual text size is used as the natural width of the label. For wrapping labels, width-chars is used as the minimum width, if specified, and max-width-chars is used as the natural width. Even if max-width-chars specified, wrapping labels will be rewrapped to use all of the available width.Links
GTK supports markup for clickable hyperlinks in addition to regular Pango markup. The markup for links is borrowed from HTML, using the
<a>
with “href“, “title“ and “class“ attributes. GTK renders links similar to the way they appear in web browsers, with colored, underlined text. The “title“ attribute is displayed as a tooltip on the link. The “class“ attribute is used as style class on the CSS node for the link.An example looks like this:
const char *text = "Go to the" "<a href=\"http://www.gtk.org title=\"<i>Our</i> website\">" "GTK website</a> for more..."; GtkWidget *label = gtk_label_new (NULL); gtk_label_set_markup (GTK_LABEL (label), text);
It is possible to implement custom handling for links and their tooltips with the [signal
Gtk.Label::activate-link
] signal and the [methodGtk.Label.get_current_uri
] function.The
See moreLabelProtocol
protocol exposes the methods and properties of an underlyingGtkLabel
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeLabel
. Alternatively, useLabelRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol LabelProtocol : WidgetProtocol
-
GtkLayoutChild
is the base class for objects that are meant to hold layout properties.If a
GtkLayoutManager
has per-child properties, like their packing type, or the horizontal and vertical span, or the icon name, then the layout manager should use aGtkLayoutChild
implementation to store those properties.A
GtkLayoutChild
instance is only ever valid while a widget is part of a layout.The
See moreLayoutChildProtocol
protocol exposes the methods and properties of an underlyingGtkLayoutChild
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeLayoutChild
. Alternatively, useLayoutChildRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol LayoutChildProtocol : ObjectProtocol
-
Layout managers are delegate classes that handle the preferred size and the allocation of a widget.
You typically subclass
GtkLayoutManager
if you want to implement a layout policy for the children of a widget, or if you want to determine the size of a widget depending on its contents.Each
GtkWidget
can only have aGtkLayoutManager
instance associated to it at any given time; it is possible, though, to replace the layout manager instance using [methodGtk.Widget.set_layout_manager
].Layout properties
A layout manager can expose properties for controlling the layout of each child, by creating an object type derived from [class
Gtk.LayoutChild
] and installing the properties on it as normalGObject
properties.Each
GtkLayoutChild
instance storing the layout properties for a specific child is created through the [methodGtk.LayoutManager.get_layout_child
] method; aGtkLayoutManager
controls the creation of itsGtkLayoutChild
instances by overriding theGtkLayoutManagerClass.create_layout_child()
virtual function. The typical implementation should look like:static GtkLayoutChild * create_layout_child (GtkLayoutManager *manager, GtkWidget *container, GtkWidget *child) { return g_object_new (your_layout_child_get_type (), "layout-manager", manager, "child-widget", child, NULL); }
The [property
Gtk.LayoutChild:layout-manager
] and [propertyGtk.LayoutChild:child-widget
] properties on the newly createdGtkLayoutChild
instance are mandatory. TheGtkLayoutManager
will cache the newly createdGtkLayoutChild
instance until the widget is removed from its parent, or the parent removes the layout manager.Each
GtkLayoutManager
instance creating aGtkLayoutChild
should use [methodGtk.LayoutManager.get_layout_child
] every time it needs to query the layout properties; eachGtkLayoutChild
instance should call [methodGtk.LayoutManager.layout_changed
] every time a property is updated, in order to queue a new size measuring and allocation.The
See moreLayoutManagerProtocol
protocol exposes the methods and properties of an underlyingGtkLayoutManager
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeLayoutManager
. Alternatively, useLayoutManagerRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol LayoutManagerProtocol : ObjectProtocol
-
GtkLevelBar
is a 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.
Use [method
Gtk.LevelBar.set_value
] to set the current value, and [methodGtk.LevelBar.add_offset_value
] to set the value offsets at which the bar will be considered in a different state. GTK will add a few offsets by default on the level bar:GTK_LEVEL_BAR_OFFSET_LOW
,GTK_LEVEL_BAR_OFFSET_HIGH
andGTK_LEVEL_BAR_OFFSET_FULL
, with values 0.25, 0.75 and 1.0 respectively.Note that it is your responsibility to update preexisting offsets when changing the minimum or maximum value. GTK will simply clamp them to the new range.
Adding a custom offset on the bar
static GtkWidget * create_level_bar (void) { GtkWidget *widget; GtkLevelBar *bar; widget = gtk_level_bar_new (); bar = GTK_LEVEL_BAR (widget); // This changes the value of the default low offset gtk_level_bar_add_offset_value (bar, GTK_LEVEL_BAR_OFFSET_LOW, 0.10); // This adds a new offset to the bar; the application will // be able to change its color CSS like this: // // levelbar block.my-offset { // background-color: magenta; // border-style: solid; // border-color: black; // border-style: 1px; // } gtk_level_bar_add_offset_value (bar, "my-offset", 0.60); return widget; }
The default interval of values is between zero and one, but it’s possible to modify the interval using [method
Gtk.LevelBar.set_min_value
] and [methodGtk.LevelBar.set_max_value
]. The value will be always drawn in proportion to the admissible interval, i.e. a value of 15 with a specified interval between 10 and 20 is equivalent to a value of 0.5 with an interval between 0 and 1. WhenGTK_LEVEL_BAR_MODE_DISCRETE
is used, the bar level is rendered as a finite number of separated blocks instead of a single one. The number of blocks that will be rendered is equal to the number of units specified by the admissible interval.For instance, to build a bar rendered with five blocks, it’s sufficient to set the minimum value to 0 and the maximum value to 5 after changing the indicator mode to discrete.
GtkLevelBar as GtkBuildable
The
GtkLevelBar
implementation of theGtkBuildable
interface supports a custom <offsets> element, which can contain any number of <offset> elements, each of which must have name and value attributes.CSS nodes
levelbar[.discrete] ╰── trough ├── block.filled.level-name ┊ ├── block.empty ┊
GtkLevelBar
has a main CSS node with name levelbar and one of the style classes .discrete or .continuous and a subnode with name trough. Below the trough node are a number of nodes with name block and style class .filled or .empty. In continuous mode, there is exactly one node of each, in discrete mode, the number of filled and unfilled nodes corresponds to blocks that are drawn. The block.filled nodes also get a style class .level-name corresponding to the level for the current value.In horizontal orientation, the nodes are always arranged from left to right, regardless of text direction.
Accessibility
GtkLevelBar
uses theGTK_ACCESSIBLE_ROLE_METER
role.The
See moreLevelBarProtocol
protocol exposes the methods and properties of an underlyingGtkLevelBar
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeLevelBar
. Alternatively, useLevelBarRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol LevelBarProtocol : OrientableProtocol, WidgetProtocol
-
A
GtkLinkButton
is a button with a hyperlink.It is useful to show quick links to resources.
A link button is created by calling either [ctor
Gtk.LinkButton.new
] or [ctorGtk.LinkButton.new_with_label
]. If using the former, the URI you pass to the constructor is used as a label for the widget.The URI bound to a
GtkLinkButton
can be set specifically using [methodGtk.LinkButton.set_uri
].By default,
GtkLinkButton
calls [funcGtk.show_uri
] when the button is clicked. This behaviour can be overridden by connecting to the [signalGtk.LinkButton::activate-link
] signal and returningtrue
from the signal handler.CSS nodes
GtkLinkButton
has a single CSS node with name button. To differentiate it from a plainGtkButton
, it gets the .link style class.Accessibility
GtkLinkButton
uses theGTK_ACCESSIBLE_ROLE_LINK
role.The
See moreLinkButtonProtocol
protocol exposes the methods and properties of an underlyingGtkLinkButton
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeLinkButton
. Alternatively, useLinkButtonRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol LinkButtonProtocol : ButtonProtocol
-
GtkListBase
is the abstract base class for GTK’s list widgets.The
See moreListBaseProtocol
protocol exposes the methods and properties of an underlyingGtkListBase
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeListBase
. Alternatively, useListBaseRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ListBaseProtocol : OrientableProtocol, ScrollableProtocol, WidgetProtocol
-
GtkListBox
is a vertical list.A
GtkListBox
only containsGtkListBoxRow
children. These rows can by dynamically sorted and filtered, and headers can be added dynamically depending on the row content. It also allows keyboard and mouse navigation and selection like a typical list.Using
GtkListBox
is often an alternative toGtkTreeView
, especially when the list contents has a more complicated layout than what is allowed by aGtkCellRenderer
, or when the contents is interactive (i.e. has a button in it).Although a
GtkListBox
must have onlyGtkListBoxRow
children, you can add any kind of widget to it via [methodGtk.ListBox.prepend
], [methodGtk.ListBox.append
] and [methodGtk.ListBox.insert
] and aGtkListBoxRow
widget will automatically be inserted between the list and the widget.GtkListBoxRows
can be marked as activatable or selectable. If a row is activatable, [signalGtk.ListBox::row-activated
] will be emitted for it when the user tries to activate it. If it is selectable, the row will be marked as selected when the user tries to select it.GtkListBox as GtkBuildable
The
GtkListBox
implementation of theGtkBuildable
interface supports setting a child as the placeholder by specifying “placeholder” as the “type” attribute of a <child> element. See [methodGtk.ListBox.set_placeholder
] for info.CSS nodes
(plain Language Example):
list[.separators][.rich-list][.navigation-sidebar] ╰── row[.activatable]
GtkListBox
uses a single CSS node named list. It may carry the .separators style class, when the [propertyGtk.ListBox:show-separators
] property is set. EachGtkListBoxRow
uses a single CSS node named row. The row nodes get the .activatable style class added when appropriate.The main list node may also carry style classes to select the style of list presentation: .rich-list, .navigation-sidebar or .data-table.
Accessibility
GtkListBox
uses theGTK_ACCESSIBLE_ROLE_LIST
role andGtkListBoxRow
uses theGTK_ACCESSIBLE_ROLE_LIST_ITEM
role.The
See moreListBoxProtocol
protocol exposes the methods and properties of an underlyingGtkListBox
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeListBox
. Alternatively, useListBoxRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ListBoxProtocol : WidgetProtocol
-
GtkListBoxRow
is the kind of widget that can be added to aGtkListBox
.The
See moreListBoxRowProtocol
protocol exposes the methods and properties of an underlyingGtkListBoxRow
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeListBoxRow
. Alternatively, useListBoxRowRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ListBoxRowProtocol : ActionableProtocol
-
GtkListItem
is used by list widgets to represent items in aGListModel
.The
GtkListItem
s are managed by the list widget (with its factory) and cannot be created by applications, but they need to be populated by application code. This is done by calling [methodGtk.ListItem.set_child
].GtkListItem
s exist in 2 stages:The unbound stage where the listitem is not currently connected to an item in the list. In that case, the [property
Gtk.ListItem:item
] property is set tonil
.The bound stage where the listitem references an item from the list. The [property
Gtk.ListItem:item
] property is notnil
.
The
See moreListItemProtocol
protocol exposes the methods and properties of an underlyingGtkListItem
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeListItem
. Alternatively, useListItemRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ListItemProtocol : ObjectProtocol
-
A
GtkListItemFactory
creates widgets for the items taken from aGListModel
.This is one of the core concepts of handling list widgets such as [class
Gtk.ListView
] or [classGtk.GridView
].The
GtkListItemFactory
is tasked with creating widgets for items taken from the model when the views need them and updating them as the items displayed by the view change.A view is usually only able to display anything after both a factory and a model have been set on the view. So it is important that you do not skip this step when setting up your first view.
Because views do not display the whole list at once but only a few items, they only need to maintain a few widgets at a time. They will instruct the
GtkListItemFactory
to create these widgets and bind them to the items that are currently displayed.As the list model changes or the user scrolls to the list, the items will change and the view will instruct the factory to bind the widgets to those new items.
The actual widgets used for displaying those widgets is provided by you.
When the factory needs widgets created, it will create a
GtkListItem
and hand it to your code to set up a widget for. This list item will provide various properties with information about what item to display and provide you with some opportunities to configure its behavior. See the [classGtk.ListItem
] documentation for further details.Various implementations of
GtkListItemFactory
exist to allow you different ways to provide those widgets. The most common implementations are [classGtk.BuilderListItemFactory
] which takes aGtkBuilder
.ui file and then creates widgets and manages everything automatically from the information in that file and [classGtk.SignalListItemFactory
] which allows you to connect to signals with your own code and retain full control over how the widgets are setup and managed.A
GtkListItemFactory
is supposed to be final - that means its behavior should not change and the first widget created from it should behave the same way as the last widget created from it. If you intend to do changes to the behavior, it is recommended that you create a newGtkListItemFactory
which will allow the views to recreate its widgets.Once you have chosen your factory and created it, you need to set it on the view widget you want to use it with, such as via [method
Gtk.ListView.set_factory
]. Reusing factories across different views is allowed, but very uncommon.The
See moreListItemFactoryProtocol
protocol exposes the methods and properties of an underlyingGtkListItemFactory
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeListItemFactory
. Alternatively, useListItemFactoryRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ListItemFactoryProtocol : ObjectProtocol
-
A list-like data structure that can be used with the GtkTreeView
The
GtkListStore
object is a list model for use with aGtkTreeView
widget. It implements theGtkTreeModel
interface, and consequentialy, can use all of the methods available there. It also implements theGtkTreeSortable
interface so it can be sorted by the view. Finally, it also implements the tree drag and drop interfaces.The
GtkListStore
can accept most GObject types as a column type, though it can’t accept all custom types. Internally, it will keep a copy of data passed in (such as a string or a boxed pointer). Columns that acceptGObject
s are handled a little differently. TheGtkListStore
will keep a reference to the object instead of copying the value. As a result, if the object is modified, it is up to the application writer to callgtk_tree_model_row_changed()
to emit theGtkTreeModel
row_changed
signal. This most commonly affects lists withGdkTexture
s stored.An example for creating a simple list store: (C Language Example):
enum { COLUMN_STRING, COLUMN_INT, COLUMN_BOOLEAN, N_COLUMNS }; { GtkListStore *list_store; GtkTreePath *path; GtkTreeIter iter; int i; list_store = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING, G_TYPE_INT, G_TYPE_BOOLEAN); for (i = 0; i < 10; i++) { char *some_data; some_data = get_some_data (i); // Add a new row to the model gtk_list_store_append (list_store, &iter); gtk_list_store_set (list_store, &iter, COLUMN_STRING, some_data, COLUMN_INT, i, COLUMN_BOOLEAN, FALSE, -1); // As the store will keep a copy of the string internally, // we free some_data. g_free (some_data); } // Modify a particular row path = gtk_tree_path_new_from_string ("4"); gtk_tree_model_get_iter (GTK_TREE_MODEL (list_store), &iter, path); gtk_tree_path_free (path); gtk_list_store_set (list_store, &iter, COLUMN_BOOLEAN, TRUE, -1); }
Performance Considerations
Internally, the
GtkListStore
was originally implemented with a linked list with a tail pointer. As a result, it was fast at data insertion and deletion, and not fast at random data access. TheGtkListStore
sets theGTK_TREE_MODEL_ITERS_PERSIST
flag, which means thatGtkTreeIter
s can be cached while the row exists. Thus, if access to a particular row is needed often and your code is expected to run on older versions of GTK, it is worth keeping the iter around.Atomic Operations
It is important to note that only the methods
gtk_list_store_insert_with_values()
andgtk_list_store_insert_with_valuesv()
are atomic, in the sense that the row is being appended to the store and the values filled in in a single operation with regard toGtkTreeModel
signaling. In contrast, using e.g.gtk_list_store_append()
and thengtk_list_store_set()
will first create a row, which triggers theGtkTreeModel
row-inserted
signal onGtkListStore
. The row, however, is still empty, and any signal handler connecting toGtkTreeModel
row-inserted
on this particular store should be prepared for the situation that the row might be empty. This is especially important if you are wrapping theGtkListStore
inside aGtkTreeModel
Filter and are using aGtkTreeModel
FilterVisibleFunc. Using any of the non-atomic operations to append rows to theGtkListStore
will cause theGtkTreeModel
FilterVisibleFunc to be visited with an empty row first; the function must be prepared for that.GtkListStore as GtkBuildable
The GtkListStore implementation of the GtkBuildable interface allows to specify the model columns with a <columns> element that may contain multiple <column> elements, each specifying one model column. The “type” attribute specifies the data type for the column.
Additionally, it is possible to specify content for the list store in the UI definition, with the <data> element. It can contain multiple <row> elements, each specifying to content for one row of the list model. Inside a <row>, the <col> elements specify the content for individual cells.
Note that it is probably more common to define your models in the code, and one might consider it a layering violation to specify the content of a list store in a UI definition, data, not presentation, and common wisdom is to separate the two, as far as possible.
An example of a UI Definition fragment for a list store: (C Language Example):
<object class="GtkListStore"> <columns> <column type="gchararray"/> <column type="gchararray"/> <column type="gint"/> </columns> <data> <row> <col id="0">John</col> <col id="1">Doe</col> <col id="2">25</col> </row> <row> <col id="0">Johan</col> <col id="1">Dahlin</col> <col id="2">50</col> </row> </data> </object>
The
See moreListStoreProtocol
protocol exposes the methods and properties of an underlyingGtkListStore
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeListStore
. Alternatively, useListStoreRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ListStoreProtocol : ObjectProtocol, BuildableProtocol, TreeDragDestProtocol, TreeDragSourceProtocol, TreeSortableProtocol
-
GtkListView
presents a large dynamic list of items.GtkListView
uses its factory to generate one row widget for each visible item and shows them in a linear display, either vertically or horizontally.The [property
Gtk.ListView:show-separators
] property offers a simple way to display separators between the rows.GtkListView
allows the user to select items according to the selection characteristics of the model. For models that allow multiple selected items, it is possible to turn on rubberband selection, using [propertyGtk.ListView:enable-rubberband
].If you need multiple columns with headers, see [class
Gtk.ColumnView
].To learn more about the list widget framework, see the overview.
An example of using
GtkListView
:static void setup_listitem_cb (GtkListItemFactory *factory, GtkListItem *list_item) { GtkWidget *image; image = gtk_image_new (); gtk_image_set_icon_size (GTK_IMAGE (image), GTK_ICON_SIZE_LARGE); gtk_list_item_set_child (list_item, image); } static void bind_listitem_cb (GtkListItemFactory *factory, GtkListItem *list_item) { GtkWidget *image; GAppInfo *app_info; image = gtk_list_item_get_child (list_item); app_info = gtk_list_item_get_item (list_item); gtk_image_set_from_gicon (GTK_IMAGE (image), g_app_info_get_icon (app_info)); } static void activate_cb (GtkListView *list, guint position, gpointer unused) { GAppInfo *app_info; app_info = g_list_model_get_item (G_LIST_MODEL (gtk_list_view_get_model (list)), position); g_app_info_launch (app_info, NULL, NULL, NULL); g_object_unref (app_info); } ... model = create_application_list (); factory = gtk_signal_list_item_factory_new (); g_signal_connect (factory, "setup", G_CALLBACK (setup_listitem_cb), NULL); g_signal_connect (factory, "bind", G_CALLBACK (bind_listitem_cb), NULL); list = gtk_list_view_new (GTK_SELECTION_MODEL (gtk_single_selection_new (model)), factory); g_signal_connect (list, "activate", G_CALLBACK (activate_cb), NULL); gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), list);
CSS nodes
listview[.separators][.rich-list][.navigation-sidebar][.data-table] ├── row[.activatable] │ ├── row[.activatable] │ ┊ ╰── [rubberband]
GtkListView
uses a single CSS node namedlistview
. It may carry the.separators
style class, when [propertyGtk.ListView:show-separators
] property is set. Each child widget uses a single CSS node namedrow
. If the [propertyGtk.ListItem:activatable
] property is set, the corresponding row will have the.activatable
style class. For rubberband selection, a node with namerubberband
is used.The main listview node may also carry style classes to select the style of list presentation: .rich-list, .navigation-sidebar or .data-table.
Accessibility
GtkListView
uses theGTK_ACCESSIBLE_ROLE_LIST
role, and the list items use theGTK_ACCESSIBLE_ROLE_LIST_ITEM
role.The
See moreListViewProtocol
protocol exposes the methods and properties of an underlyingGtkListView
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeListView
. Alternatively, useListViewRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ListViewProtocol : ListBaseProtocol
-
GtkLockButton
is a widget to obtain and revoke authorizations needed to operate the controls.It is typically used in preference dialogs or control panels.
The required authorization is represented by a
GPermission
object. Concrete implementations ofGPermission
may use PolicyKit or some other authorization framework. To obtain a PolicyKit-basedGPermission
, usepolkit_permission_new()
.If the user is not currently allowed to perform the action, but can obtain the permission, the widget looks like this:
and the user can click the button to request the permission. Depending on the platform, this may pop up an authentication dialog or ask the user to authenticate in some other way. Once the user has obtained the permission, the widget changes to this:
and the permission can be dropped again by clicking the button. If the user is not able to obtain the permission at all, the widget looks like this:
If the user has the permission and cannot drop it, the button is hidden.
The text (and tooltips) that are shown in the various cases can be adjusted with the [property
Gtk.LockButton:text-lock
], [propertyGtk.LockButton:text-unlock
], [propertyGtk.LockButton:tooltip-lock
], [propertyGtk.LockButton:tooltip-unlock
] and [propertyGtk.LockButton:tooltip-not-authorized
] properties.The
See moreLockButtonProtocol
protocol exposes the methods and properties of an underlyingGtkLockButton
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeLockButton
. Alternatively, useLockButtonRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol LockButtonProtocol : ButtonProtocol
-
A
GtkMapListModel
maps the items in a list model to different items.GtkMapListModel
uses a [callbackGtk.MapListModelMapFunc
].Example: Create a list of
GtkEventControllers
static gpointer map_to_controllers (gpointer widget, gpointer data) { gpointer result = gtk_widget_observe_controllers (widget); g_object_unref (widget); return result; } widgets = gtk_widget_observe_children (widget); controllers = gtk_map_list_model_new (G_TYPE_LIST_MODEL, widgets, map_to_controllers, NULL, NULL); model = gtk_flatten_list_model_new (GTK_TYPE_EVENT_CONTROLLER, controllers);
GtkMapListModel
will attempt to discard the mapped objects as soon as they are no longer needed and recreate them if necessary.The
See moreMapListModelProtocol
protocol exposes the methods and properties of an underlyingGtkMapListModel
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeMapListModel
. Alternatively, useMapListModelRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol MapListModelProtocol : ListModelProtocol, ObjectProtocol
-
The
See moreLayoutChildClassProtocol
protocol exposes the methods and properties of an underlyingGtkLayoutChildClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeLayoutChildClass
. Alternatively, useLayoutChildClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol LayoutChildClassProtocol
-
The
GtkLayoutManagerClass
structure contains only private data, and should only be accessed through the provided API, or when subclassingGtkLayoutManager
.The
See moreLayoutManagerClassProtocol
protocol exposes the methods and properties of an underlyingGtkLayoutManagerClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeLayoutManagerClass
. Alternatively, useLayoutManagerClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol LayoutManagerClassProtocol
-
The
See moreListBaseClassProtocol
protocol exposes the methods and properties of an underlyingGtkListBaseClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeListBaseClass
. Alternatively, useListBaseClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ListBaseClassProtocol
-
The
See moreListBoxRowClassProtocol
protocol exposes the methods and properties of an underlyingGtkListBoxRowClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeListBoxRowClass
. Alternatively, useListBoxRowClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ListBoxRowClassProtocol
-
The
See moreListItemClassProtocol
protocol exposes the methods and properties of an underlyingGtkListItemClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeListItemClass
. Alternatively, useListItemClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ListItemClassProtocol
-
The
See moreListItemFactoryClassProtocol
protocol exposes the methods and properties of an underlyingGtkListItemFactoryClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeListItemFactoryClass
. Alternatively, useListItemFactoryClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ListItemFactoryClassProtocol
-
The
See moreListStoreClassProtocol
protocol exposes the methods and properties of an underlyingGtkListStoreClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeListStoreClass
. Alternatively, useListStoreClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ListStoreClassProtocol
-
The
See moreListViewClassProtocol
protocol exposes the methods and properties of an underlyingGtkListViewClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeListViewClass
. Alternatively, useListViewClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ListViewClassProtocol
-
The
See moreMapListModelClassProtocol
protocol exposes the methods and properties of an underlyingGtkMapListModelClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeMapListModelClass
. Alternatively, useMapListModelClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol MapListModelClassProtocol
-
GtkMediaControls
is a widget to show controls for a video.Usually,
GtkMediaControls
is used as part of [classGtk.Video
].The
See moreMediaControlsProtocol
protocol exposes the methods and properties of an underlyingGtkMediaControls
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeMediaControls
. Alternatively, useMediaControlsRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol MediaControlsProtocol : WidgetProtocol
-
GtkMediaFile
implementsGtkMediaStream
for files.This provides a simple way to play back video files with GTK.
GTK provides a GIO extension point for
GtkMediaFile
implementations to allow for external implementations using various media frameworks.GTK itself includes implementations using GStreamer and ffmpeg.
The
See moreMediaFileProtocol
protocol exposes the methods and properties of an underlyingGtkMediaFile
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeMediaFile
. Alternatively, useMediaFileRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol MediaFileProtocol : MediaStreamProtocol
-
GtkMediaStream
is the integration point for media playback inside GTK.GTK provides an implementation of the
GtkMediaStream
interface that is called [classGtk.MediaFile
].Apart from application-facing API for stream playback,
GtkMediaStream
has a number of APIs that are only useful for implementations and should not be used in applications: [methodGtk.MediaStream.prepared
], [methodGtk.MediaStream.unprepared
], [methodGtk.MediaStream.update
], [methodGtk.MediaStream.ended
], [methodGtk.MediaStream.seek_success
], [methodGtk.MediaStream.seek_failed
], [methodGtk.MediaStream.gerror
], [methodGtk.MediaStream.error
], [methodGtk.MediaStream.error_valist
].The
See moreMediaStreamProtocol
protocol exposes the methods and properties of an underlyingGtkMediaStream
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeMediaStream
. Alternatively, useMediaStreamRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol MediaStreamProtocol : ObjectProtocol, PaintableProtocol
-
The
GtkMenuButton
widget is used to display a popup when clicked.This popup can be provided either as a
GtkPopover
or as an abstractGMenuModel
.The
GtkMenuButton
widget can show either an icon (set with the [propertyGtk.MenuButton:icon-name
] property) or a label (set with the [propertyGtk.MenuButton:label
] property). If neither is explicitly set, a [classGtk.Image
] is automatically created, using an arrow image oriented according to [propertyGtk.MenuButton:direction
] or the generic “open-menu-symbolic” icon if the direction is not set.The positioning of the popup is determined by the [property
Gtk.MenuButton:direction
] property of the menu button.For menus, the [property
Gtk.Widget:halign
] and [propertyGtk.Widget:valign
] properties of the menu are also taken into account. For example, when the direction isGTK_ARROW_DOWN
and the horizontal alignment isGTK_ALIGN_START
, the menu will be positioned below the button, with the starting edge (depending on the text direction) of the menu aligned with the starting edge of the button. If there is not enough space below the button, the menu is popped up above the button instead. If the alignment would move part of the menu offscreen, it is “pushed in”.start center end down up left right CSS nodes
menubutton ╰── button.toggle ╰── <content> ╰── [arrow]
GtkMenuButton
has a single CSS node with namemenubutton
which contains abutton
node with a.toggle
style class.If the button contains only an icon or an arrow, it will have the
.image-button
style class, if it contains both, it will have the.arrow-button
style class.Inside the toggle button content, there is an
arrow
node for the indicator, which will carry one of the.none
,.up
,.down
,.left
or.right
style classes to indicate the direction that the menu will appear in. The CSS is expected to provide a suitable image for each of these cases using the-gtk-icon-source
property.Optionally, the
menubutton
node can carry the.circular
style class to request a round appearance.Accessibility
GtkMenuButton
uses theGTK_ACCESSIBLE_ROLE_BUTTON
role.The
See moreMenuButtonProtocol
protocol exposes the methods and properties of an underlyingGtkMenuButton
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeMenuButton
. Alternatively, useMenuButtonRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol MenuButtonProtocol : WidgetProtocol
-
GtkMessageDialog
presents a dialog with some message text.It’s simply a convenience widget; you could construct the equivalent of
GtkMessageDialog
fromGtkDialog
without too much effort, butGtkMessageDialog
saves typing.The easiest way to do a modal message dialog is to use the
GTK_DIALOG_MODAL
flag, which will call [methodGtk.Window.set_modal
] internally. The dialog will prevent interaction with the parent window until it’s hidden or destroyed. You can use the [signalGtk.Dialog::response
] signal to know when the user dismissed the dialog.An example for using a modal dialog:
GtkDialogFlags flags = GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL; dialog = gtk_message_dialog_new (parent_window, flags, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "Error reading “`s`”: `s`", filename, g_strerror (errno)); // Destroy the dialog when the user responds to it // (e.g. clicks a button) g_signal_connect (dialog, "response", G_CALLBACK (gtk_window_destroy), NULL);
You might do a non-modal
GtkMessageDialog
simply by omitting theGTK_DIALOG_MODAL
flag:GtkDialogFlags flags = GTK_DIALOG_DESTROY_WITH_PARENT; dialog = gtk_message_dialog_new (parent_window, flags, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "Error reading “`s`”: `s`", filename, g_strerror (errno)); // Destroy the dialog when the user responds to it // (e.g. clicks a button) g_signal_connect (dialog, "response", G_CALLBACK (gtk_window_destroy), NULL);
GtkMessageDialog as GtkBuildable
The
GtkMessageDialog
implementation of theGtkBuildable
interface exposes the message area as an internal child with the name “message_area”.The
See moreMessageDialogProtocol
protocol exposes the methods and properties of an underlyingGtkMessageDialog
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeMessageDialog
. Alternatively, useMessageDialogRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol MessageDialogProtocol : DialogProtocol
-
A
GtkShortcutAction
that callsgtk_widget_mnemonic_activate()
.The
See moreMnemonicActionProtocol
protocol exposes the methods and properties of an underlyingGtkMnemonicAction
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeMnemonicAction
. Alternatively, useMnemonicActionRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol MnemonicActionProtocol : ShortcutActionProtocol
-
A
GtkShortcutTrigger
that triggers when a specific mnemonic is pressed.Mnemonics require a mnemonic modifier (typically <kbd>Alt</kbd>) to be pressed together with the mnemonic key.
The
See moreMnemonicTriggerProtocol
protocol exposes the methods and properties of an underlyingGtkMnemonicTrigger
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeMnemonicTrigger
. Alternatively, useMnemonicTriggerRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol MnemonicTriggerProtocol : ShortcutTriggerProtocol
-
GtkMountOperation
is an implementation ofGMountOperation
.The functions and objects described here make working with GTK and GIO more convenient.
GtkMountOperation
is needed when mounting volumes: It is an implementation ofGMountOperation
that can be used with GIO functions for mounting volumes such asg_file_mount_enclosing_volume()
,g_file_mount_mountable()
,g_volume_mount()
,g_mount_unmount_with_operation()
and others.When necessary,
GtkMountOperation
shows dialogs to let the user enter passwords, ask questions or show processes blocking unmount.The
See moreMountOperationProtocol
protocol exposes the methods and properties of an underlyingGtkMountOperation
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeMountOperation
. Alternatively, useMountOperationRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol MountOperationProtocol : MountOperationProtocol
-
GtkMultiFilter
is the base class for filters that combine multiple filters.The
See moreMultiFilterProtocol
protocol exposes the methods and properties of an underlyingGtkMultiFilter
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeMultiFilter
. Alternatively, useMultiFilterRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol MultiFilterProtocol : ListModelProtocol, BuildableProtocol, FilterProtocol
-
GtkMultiSelection
is aGtkSelectionModel
that allows selecting multiple elements.The
See moreMultiSelectionProtocol
protocol exposes the methods and properties of an underlyingGtkMultiSelection
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeMultiSelection
. Alternatively, useMultiSelectionRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol MultiSelectionProtocol : ObjectProtocol, SelectionModelProtocol
-
GtkMultiSorter
combines multiple sorters by trying them in turn.If the first sorter compares two items as equal, the second is tried next, and so on.
The
See moreMultiSorterProtocol
protocol exposes the methods and properties of an underlyingGtkMultiSorter
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeMultiSorter
. Alternatively, useMultiSorterRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol MultiSorterProtocol : ListModelProtocol, BuildableProtocol, SorterProtocol
-
A
GtkShortcutAction
that activates an action by name.The
See moreNamedActionProtocol
protocol exposes the methods and properties of an underlyingGtkNamedAction
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeNamedAction
. Alternatively, useNamedActionRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol NamedActionProtocol : ShortcutActionProtocol
-
The
See moreMediaControlsClassProtocol
protocol exposes the methods and properties of an underlyingGtkMediaControlsClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeMediaControlsClass
. Alternatively, useMediaControlsClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol MediaControlsClassProtocol
-
The
See moreMediaFileClassProtocol
protocol exposes the methods and properties of an underlyingGtkMediaFileClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeMediaFileClass
. Alternatively, useMediaFileClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol MediaFileClassProtocol
-
The
See moreMediaStreamClassProtocol
protocol exposes the methods and properties of an underlyingGtkMediaStreamClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeMediaStreamClass
. Alternatively, useMediaStreamClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol MediaStreamClassProtocol
-
The
See moreMessageDialogClassProtocol
protocol exposes the methods and properties of an underlyingGtkMessageDialogClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeMessageDialogClass
. Alternatively, useMessageDialogClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol MessageDialogClassProtocol
-
The
See moreMnemonicActionClassProtocol
protocol exposes the methods and properties of an underlyingGtkMnemonicActionClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeMnemonicActionClass
. Alternatively, useMnemonicActionClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol MnemonicActionClassProtocol
-
The
See moreMnemonicTriggerClassProtocol
protocol exposes the methods and properties of an underlyingGtkMnemonicTriggerClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeMnemonicTriggerClass
. Alternatively, useMnemonicTriggerClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol MnemonicTriggerClassProtocol
-
The
See moreMountOperationClassProtocol
protocol exposes the methods and properties of an underlyingGtkMountOperationClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeMountOperationClass
. Alternatively, useMountOperationClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol MountOperationClassProtocol
-
The
See moreMultiFilterClassProtocol
protocol exposes the methods and properties of an underlyingGtkMultiFilterClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeMultiFilterClass
. Alternatively, useMultiFilterClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol MultiFilterClassProtocol
-
The
See moreMultiSelectionClassProtocol
protocol exposes the methods and properties of an underlyingGtkMultiSelectionClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeMultiSelectionClass
. Alternatively, useMultiSelectionClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol MultiSelectionClassProtocol
-
The
See moreMultiSorterClassProtocol
protocol exposes the methods and properties of an underlyingGtkMultiSorterClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeMultiSorterClass
. Alternatively, useMultiSorterClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol MultiSorterClassProtocol
-
The
See moreNamedActionClassProtocol
protocol exposes the methods and properties of an underlyingGtkNamedActionClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeNamedActionClass
. Alternatively, useNamedActionClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol NamedActionClassProtocol
-
Native dialogs are platform dialogs that don’t use
GtkDialog
.They are used in order to integrate better with a platform, by looking the same as other native applications and supporting platform specific features.
The [class
Gtk.Dialog
] functions cannot be used on such objects, but we need a similar API in order to drive them. TheGtkNativeDialog
object is an API that allows you to do this. It allows you to set various common properties on the dialog, as well as show and hide it and get a [signalGtk.NativeDialog::response
] signal when the user finished with the dialog.Note that unlike
GtkDialog
,GtkNativeDialog
objects are not toplevel widgets, and GTK does not keep them alive. It is your responsibility to keep a reference until you are done with the object.The
See moreNativeDialogProtocol
protocol exposes the methods and properties of an underlyingGtkNativeDialog
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeNativeDialog
. Alternatively, useNativeDialogRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol NativeDialogProtocol : ObjectProtocol
-
A
GtkShortcutTrigger
that never triggers.The
See moreNeverTriggerProtocol
protocol exposes the methods and properties of an underlyingGtkNeverTrigger
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeNeverTrigger
. Alternatively, useNeverTriggerRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol NeverTriggerProtocol : ShortcutTriggerProtocol
-
GtkNoSelection
is aGtkSelectionModel
that does not allow selecting anything.This model is meant to be used as a simple wrapper around a
GListModel
when aGtkSelectionModel
is required.The
See moreNoSelectionProtocol
protocol exposes the methods and properties of an underlyingGtkNoSelection
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeNoSelection
. Alternatively, useNoSelectionRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol NoSelectionProtocol : ObjectProtocol, SelectionModelProtocol
-
GtkNotebook
is a container whose children are pages switched between using tabs.There are many configuration options for
GtkNotebook
. Among other things, you can choose on which edge the tabs appear (see [methodGtk.Notebook.set_tab_pos
]), whether, if there are too many tabs to fit the notebook should be made bigger or scrolling arrows added (see [methodGtk.Notebook.set_scrollable
]), and whether there will be a popup menu allowing the users to switch pages. (see [methodGtk.Notebook.popup_enable
]).GtkNotebook as GtkBuildable
The
GtkNotebook
implementation of theGtkBuildable
interface supports placing children into tabs by specifying “tab” as the “type” attribute of a <child> element. Note that the content of the tab must be created before the tab can be filled. A tab child can be specified without specifying a <child> type attribute.To add a child widget in the notebooks action area, specify “action-start” or “action-end” as the “type” attribute of the <child> element.
An example of a UI definition fragment with
GtkNotebook
:<object class="GtkNotebook"> <child> <object class="GtkLabel" id="notebook-content"> <property name="label">Content</property> </object> </child> <child type="tab"> <object class="GtkLabel" id="notebook-tab"> <property name="label">Tab</property> </object> </child> </object>
CSS nodes
notebook ├── header.top │ ├── [<action widget>] │ ├── tabs │ │ ├── [arrow] │ │ ├── tab │ │ │ ╰── <tab label> ┊ ┊ ┊ │ │ ├── tab[.reorderable-page] │ │ │ ╰── <tab label> │ │ ╰── [arrow] │ ╰── [<action widget>] │ ╰── stack ├── <child> ┊ ╰── <child>
GtkNotebook
has a main CSS node with namenotebook
, a subnode with nameheader
and below that a subnode with nametabs
which contains one subnode per tab with nametab
.If action widgets are present, their CSS nodes are placed next to the
tabs
node. If the notebook is scrollable, CSS nodes with namearrow
are placed as first and last child of thetabs
node.The main node gets the
.frame
style class when the notebook has a border (see [methodGtk.Notebook.set_show_border
]).The header node gets one of the style class
.top
,.bottom
,.left
or.right
, depending on where the tabs are placed. For reorderable pages, the tab node gets the.reorderable-page
class.A
tab
node gets the.dnd
style class while it is moved with drag-and-drop.The nodes are always arranged from left-to-right, regardless of text direction.
Accessibility
GtkNotebook
uses the following roles:GTK_ACCESSIBLE_ROLE_GROUP
for the notebook widgetGTK_ACCESSIBLE_ROLE_TAB_LIST
for the list of tabsGTK_ACCESSIBLE_ROLE_TAB
role for each tabGTK_ACCESSIBLE_ROLE_TAB_PANEL
for each page
The
See moreNotebookProtocol
protocol exposes the methods and properties of an underlyingGtkNotebook
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeNotebook
. Alternatively, useNotebookRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol NotebookProtocol : WidgetProtocol
-
GtkNotebookPage
is an auxiliary object used byGtkNotebook
.The
See moreNotebookPageProtocol
protocol exposes the methods and properties of an underlyingGtkNotebookPage
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeNotebookPage
. Alternatively, useNotebookPageRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol NotebookPageProtocol : ObjectProtocol
-
A
GtkShortcutAction
that does nothing.The
See moreNothingActionProtocol
protocol exposes the methods and properties of an underlyingGtkNothingAction
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeNothingAction
. Alternatively, useNothingActionRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol NothingActionProtocol : ShortcutActionProtocol
-
GtkNumericSorter
is aGtkSorter
that compares numbers.To obtain the numbers to compare, this sorter evaluates a [class
Gtk.Expression
].The
See moreNumericSorterProtocol
protocol exposes the methods and properties of an underlyingGtkNumericSorter
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeNumericSorter
. Alternatively, useNumericSorterRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol NumericSorterProtocol : SorterProtocol
-
A
GObject
value in aGtkExpression
.The
See moreObjectExpressionProtocol
protocol exposes the methods and properties of an underlyingGtkObjectExpression
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeObjectExpression
. Alternatively, useObjectExpressionRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ObjectExpressionProtocol : ExpressionProtocol
-
Class structure for
GtkNativeDialog
.The
See moreNativeDialogClassProtocol
protocol exposes the methods and properties of an underlyingGtkNativeDialogClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeNativeDialogClass
. Alternatively, useNativeDialogClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol NativeDialogClassProtocol
-
The
See moreNativeInterfaceProtocol
protocol exposes the methods and properties of an underlyingGtkNativeInterface
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeNativeInterface
. Alternatively, useNativeInterfaceRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol NativeInterfaceProtocol
-
The
See moreNeverTriggerClassProtocol
protocol exposes the methods and properties of an underlyingGtkNeverTriggerClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeNeverTriggerClass
. Alternatively, useNeverTriggerClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol NeverTriggerClassProtocol
-
The
See moreNoSelectionClassProtocol
protocol exposes the methods and properties of an underlyingGtkNoSelectionClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeNoSelectionClass
. Alternatively, useNoSelectionClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol NoSelectionClassProtocol
-
The
See moreNothingActionClassProtocol
protocol exposes the methods and properties of an underlyingGtkNothingActionClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeNothingActionClass
. Alternatively, useNothingActionClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol NothingActionClassProtocol
-
The
See moreNumericSorterClassProtocol
protocol exposes the methods and properties of an underlyingGtkNumericSorterClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeNumericSorterClass
. Alternatively, useNumericSorterClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol NumericSorterClassProtocol
-
The
See moreOrientableIfaceProtocol
protocol exposes the methods and properties of an underlyingGtkOrientableIface
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeOrientableIface
. Alternatively, useOrientableIfaceRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol OrientableIfaceProtocol
-
The
GtkOrientable
interface is implemented by all widgets that can be oriented horizontally or vertically.GtkOrientable
is more flexible in that it allows the orientation to be changed at runtime, allowing the widgets to “flip”.The
See moreOrientableProtocol
protocol exposes the methods and properties of an underlyingGtkOrientable
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeOrientable
. Alternatively, useOrientableRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol OrientableProtocol
-
GtkPrintOperationPreview
is the interface that is used to implement print preview.A
GtkPrintOperationPreview
object is passed to the [signalGtk.PrintOperation::preview
] signal by [classGtk.PrintOperation
].The
See morePrintOperationPreviewProtocol
protocol exposes the methods and properties of an underlyingGtkPrintOperationPreview
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seePrintOperationPreview
. Alternatively, usePrintOperationPreviewRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol PrintOperationPreviewProtocol
-
GtkOverlay
is a container which contains a single main child, on top of which it can place “overlay” widgets.The position of each overlay widget is determined by its [property
Gtk.Widget:halign
] and [propertyGtk.Widget:valign
] properties. E.g. a widget with both alignments set toGTK_ALIGN_START
will be placed at the top left corner of theGtkOverlay
container, whereas an overlay with halign set toGTK_ALIGN_CENTER
and valign set toGTK_ALIGN_END
will be placed a the bottom edge of theGtkOverlay
, horizontally centered. The position can be adjusted by setting the margin properties of the child to non-zero values.More complicated placement of overlays is possible by connecting to the [signal
Gtk.Overlay::get-child-position
] signal.An overlay’s minimum and natural sizes are those of its main child. The sizes of overlay children are not considered when measuring these preferred sizes.
GtkOverlay as GtkBuildable
The
GtkOverlay
implementation of theGtkBuildable
interface supports placing a child as an overlay by specifying “overlay” as the “type” attribute of a<child>
element.CSS nodes
GtkOverlay
has a single CSS node with the name “overlay”. Overlay children whose alignments cause them to be positioned at an edge get the style classes “.left”, “.right”, “.top”, and/or “.bottom” according to their position.The
See moreOverlayProtocol
protocol exposes the methods and properties of an underlyingGtkOverlay
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeOverlay
. Alternatively, useOverlayRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol OverlayProtocol : WidgetProtocol
-
GtkOverlayLayout
is the layout manager used byGtkOverlay
.It places widgets as overlays on top of the main child.
This is not a reusable layout manager, since it expects its widget to be a
GtkOverlay
. It only listed here so that its layout properties get documented.The
See moreOverlayLayoutProtocol
protocol exposes the methods and properties of an underlyingGtkOverlayLayout
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeOverlayLayout
. Alternatively, useOverlayLayoutRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol OverlayLayoutProtocol : LayoutManagerProtocol
-
GtkLayoutChild
subclass for children in aGtkOverlayLayout
.The
See moreOverlayLayoutChildProtocol
protocol exposes the methods and properties of an underlyingGtkOverlayLayoutChild
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeOverlayLayoutChild
. Alternatively, useOverlayLayoutChildRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol OverlayLayoutChildProtocol : LayoutChildProtocol
-
GtkPadController
is an event controller for the pads found in drawing tablets.Pads are the collection of buttons and tactile sensors often found around the stylus-sensitive area.
These buttons and sensors have no implicit meaning, and by default they perform no action.
GtkPadController
is provided to map those toGAction
objects, thus letting the application give them a more semantic meaning.Buttons and sensors are not constrained to triggering a single action, some
GDK_SOURCE_TABLET_PAD
devices feature multiple “modes”. All these input elements have one current mode, which may determine the final action being triggered.Pad devices often divide buttons and sensors into groups. All elements in a group share the same current mode, but different groups may have different modes. See [method
Gdk.DevicePad.get_n_groups
] and [methodGdk.DevicePad.get_group_n_modes
].Each of the actions that a given button/strip/ring performs for a given mode is defined by a [struct
Gtk.PadActionEntry
]. It contains an action name that will be looked up in the givenGActionGroup
and activated whenever the specified input element and mode are triggered.A simple example of
GtkPadController
usage: Assigning button 1 in all modes and pad devices to an “invert-selection” action:GtkPadActionEntry *pad_actions[] = { { GTK_PAD_ACTION_BUTTON, 1, -1, "Invert selection", "pad-actions.invert-selection" }, … }; … action_group = g_simple_action_group_new (); action = g_simple_action_new ("pad-actions.invert-selection", NULL); g_signal_connect (action, "activate", on_invert_selection_activated, NULL); g_action_map_add_action (G_ACTION_MAP (action_group), action); … pad_controller = gtk_pad_controller_new (action_group, NULL);
The actions belonging to rings/strips will be activated with a parameter of type
G_VARIANT_TYPE_DOUBLE
bearing the value of the given axis, it is required that those are made stateful and accepting thisGVariantType
.The
See morePadControllerProtocol
protocol exposes the methods and properties of an underlyingGtkPadController
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seePadController
. Alternatively, usePadControllerRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol PadControllerProtocol : EventControllerProtocol
-
The
See moreOverlayLayoutChildClassProtocol
protocol exposes the methods and properties of an underlyingGtkOverlayLayoutChildClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeOverlayLayoutChildClass
. Alternatively, useOverlayLayoutChildClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol OverlayLayoutChildClassProtocol
-
The
See moreOverlayLayoutClassProtocol
protocol exposes the methods and properties of an underlyingGtkOverlayLayoutClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeOverlayLayoutClass
. Alternatively, useOverlayLayoutClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol OverlayLayoutClassProtocol
-
Struct defining a pad action entry.
The
See morePadActionEntryProtocol
protocol exposes the methods and properties of an underlyingGtkPadActionEntry
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seePadActionEntry
. Alternatively, usePadActionEntryRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol PadActionEntryProtocol
-
The
See morePadControllerClassProtocol
protocol exposes the methods and properties of an underlyingGtkPadControllerClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seePadControllerClass
. Alternatively, usePadControllerClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol PadControllerClassProtocol
-
A range of pages to print.
See also [method
Gtk.PrintSettings.set_page_ranges
].The
See morePageRangeProtocol
protocol exposes the methods and properties of an underlyingGtkPageRange
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seePageRange
. Alternatively, usePageRangeRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol PageRangeProtocol
-
GtkPaperSize
handles paper sizes.It uses the standard called PWG 5101.1-2002 PWG: Standard for Media Standardized Names to name the paper sizes (and to get the data for the page sizes). In addition to standard paper sizes,
GtkPaperSize
allows to construct custom paper sizes with arbitrary dimensions.The
GtkPaperSize
object stores not only the dimensions (width and height) of a paper size and its name, it also provides default print margins.The
See morePaperSizeProtocol
protocol exposes the methods and properties of an underlyingGtkPaperSize
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seePaperSize
. Alternatively, usePaperSizeRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol PaperSizeProtocol
-
The
See morePasswordEntryBufferClassProtocol
protocol exposes the methods and properties of an underlyingGtkPasswordEntryBufferClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seePasswordEntryBufferClass
. Alternatively, usePasswordEntryBufferClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol PasswordEntryBufferClassProtocol
-
The
See morePasswordEntryClassProtocol
protocol exposes the methods and properties of an underlyingGtkPasswordEntryClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seePasswordEntryClass
. Alternatively, usePasswordEntryClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol PasswordEntryClassProtocol
-
The
See morePictureClassProtocol
protocol exposes the methods and properties of an underlyingGtkPictureClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seePictureClass
. Alternatively, usePictureClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol PictureClassProtocol
-
The
See morePopoverClassProtocol
protocol exposes the methods and properties of an underlyingGtkPopoverClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seePopoverClass
. Alternatively, usePopoverClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol PopoverClassProtocol
-
The
See morePrintBackendProtocol
protocol exposes the methods and properties of an underlyingGtkPrintBackend
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seePrintBackend
. Alternatively, usePrintBackendRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol PrintBackendProtocol
-
The
See morePrintOperationClassProtocol
protocol exposes the methods and properties of an underlyingGtkPrintOperationClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seePrintOperationClass
. Alternatively, usePrintOperationClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol PrintOperationClassProtocol
-
The
See morePrintOperationPreviewIfaceProtocol
protocol exposes the methods and properties of an underlyingGtkPrintOperationPreviewIface
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seePrintOperationPreviewIface
. Alternatively, usePrintOperationPreviewIfaceRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol PrintOperationPreviewIfaceProtocol
-
The
See moreRangeClassProtocol
protocol exposes the methods and properties of an underlyingGtkRangeClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeRangeClass
. Alternatively, useRangeClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol RangeClassProtocol
-
A
GtkPageSetup
object stores the page size, orientation and margins.The idea is that you can get one of these from the page setup dialog and then pass it to the
GtkPrintOperation
when printing. The benefit of splitting this out of theGtkPrintSettings
is that these affect the actual layout of the page, and thus need to be set long before user prints.Margins
The margins specified in this object are the “print margins”, i.e. the parts of the page that the printer cannot print on. These are different from the layout margins that a word processor uses; they are typically used to determine the minimal size for the layout margins.
To obtain a
GtkPageSetup
use [ctorGtk.PageSetup.new
] to get the defaults, or use [funcGtk.print_run_page_setup_dialog
] to show the page setup dialog and receive the resulting page setup.A page setup dialog
static GtkPrintSettings *settings = NULL; static GtkPageSetup *page_setup = NULL; static void do_page_setup (void) { GtkPageSetup *new_page_setup; if (settings == NULL) settings = gtk_print_settings_new (); new_page_setup = gtk_print_run_page_setup_dialog (GTK_WINDOW (main_window), page_setup, settings); if (page_setup) g_object_unref (page_setup); page_setup = new_page_setup; }
The
See morePageSetupProtocol
protocol exposes the methods and properties of an underlyingGtkPageSetup
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seePageSetup
. Alternatively, usePageSetupRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol PageSetupProtocol : ObjectProtocol
-
GtkPageSetupUnixDialog
implements a page setup dialog for platforms which don’t provide a native page setup dialog, like Unix.It can be used very much like any other GTK dialog, at the cost of the portability offered by the high-level printing API in [class
Gtk.PrintOperation
].The
See morePageSetupUnixDialogProtocol
protocol exposes the methods and properties of an underlyingGtkPageSetupUnixDialog
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seePageSetupUnixDialog
. Alternatively, usePageSetupUnixDialogRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol PageSetupUnixDialogProtocol : DialogProtocol
-
GtkPaned
has two panes, arranged either horizontally or vertically.The division between the two panes is adjustable by the user by dragging a handle.
Child widgets are added to the panes of the widget with [method
Gtk.Paned.set_start_child
] and [methodGtk.Paned.set_end_child
]. The division between the two children is set by default from the size requests of the children, but it can be adjusted by the user.A paned widget draws a separator between the two child widgets and a small handle that the user can drag to adjust the division. It does not draw any relief around the children or around the separator. (The space in which the separator is called the gutter.) Often, it is useful to put each child inside a [class
Gtk.Frame
] so that the gutter appears as a ridge. No separator is drawn if one of the children is missing.Each child has two options that can be set,
resize
andshrink
. Ifresize
is true, then when theGtkPaned
is resized, that child will expand or shrink along with the paned widget. Ifshrink
is true, then that child can be made smaller than its requisition by the user. Settingshrink
tofalse
allows the application to set a minimum size. Ifresize
is false for both children, then this is treated as ifresize
is true for both children.The application can set the position of the slider as if it were set by the user, by calling [method
Gtk.Paned.set_position
].CSS nodes
paned ├── <child> ├── separator[.wide] ╰── <child>
GtkPaned
has a main CSS node with name paned, and a subnode for the separator with name separator. The subnode gets a .wide style class when the paned is supposed to be wide.In horizontal orientation, the nodes are arranged based on the text direction, so in left-to-right mode, :first-child will select the leftmost child, while it will select the rightmost child in RTL layouts.
Creating a paned widget with minimum sizes.
GtkWidget *hpaned = gtk_paned_new (GTK_ORIENTATION_HORIZONTAL); GtkWidget *frame1 = gtk_frame_new (NULL); GtkWidget *frame2 = gtk_frame_new (NULL); gtk_widget_set_size_request (hpaned, 200, -1); gtk_paned_set_start_child (GTK_PANED (hpaned), frame1); gtk_paned_set_start_child_resize (GTK_PANED (hpaned), TRUE); gtk_paned_set_start_child_shrink (GTK_PANED (hpaned), FALSE); gtk_widget_set_size_request (frame1, 50, -1); gtk_paned_set_end_child (GTK_PANED (hpaned), frame2); gtk_paned_set_end_child_resize (GTK_PANED (hpaned), FALSE); gtk_paned_set_end_child_shrink (GTK_PANED (hpaned), FALSE); gtk_widget_set_size_request (frame2, 50, -1);
The
See morePanedProtocol
protocol exposes the methods and properties of an underlyingGtkPaned
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seePaned
. Alternatively, usePanedRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol PanedProtocol : OrientableProtocol, WidgetProtocol
-
A
GParamSpec
for properties holding aGtkExpression
.The
See moreParamSpecExpressionProtocol
protocol exposes the methods and properties of an underlyingGtkParamSpecExpression
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeParamSpecExpression
. Alternatively, useParamSpecExpressionRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ParamSpecExpressionProtocol : ParamSpecProtocol
-
GtkPasswordEntry
is an entry that has been tailored for entering secrets.It does not show its contents in clear text, does not allow to copy it to the clipboard, and it shows a warning when Caps Lock is engaged. If the underlying platform allows it,
GtkPasswordEntry
will also place the text in a non-pageable memory area, to avoid it being written out to disk by the operating system.Optionally, it can offer a way to reveal the contents in clear text.
GtkPasswordEntry
provides only minimal API and should be used with the [ifaceGtk.Editable
] API.CSS Nodes
entry.password ╰── text ├── image.caps-lock-indicator ┊
GtkPasswordEntry
has a single CSS node with name entry that carries a .passwordstyle class. The text Css node below it has a child with name image and style class .caps-lock-indicator for the Caps Lock icon, and possibly other children.Accessibility
GtkPasswordEntry
uses theGTK_ACCESSIBLE_ROLE_TEXT_BOX
role.The
See morePasswordEntryProtocol
protocol exposes the methods and properties of an underlyingGtkPasswordEntry
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seePasswordEntry
. Alternatively, usePasswordEntryRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol PasswordEntryProtocol : EditableProtocol
-
A
GtkEntryBuffer
that locks the underlying memory to prevent it from being swapped to disk.GtkPasswordEntry
uses aGtkPasswordEntryBuffer
.The
See morePasswordEntryBufferProtocol
protocol exposes the methods and properties of an underlyingGtkPasswordEntryBuffer
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seePasswordEntryBuffer
. Alternatively, usePasswordEntryBufferRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol PasswordEntryBufferProtocol : EntryBufferProtocol
-
The
GtkPicture
widget displays aGdkPaintable
.Many convenience functions are provided to make pictures simple to use. For example, if you want to load an image from a file, and then display it, there’s a convenience function to do this:
GtkWidget *widget = gtk_picture_new_for_filename ("myfile.png");
If the file isn’t loaded successfully, the picture will contain a “broken image” icon similar to that used in many web browsers. If you want to handle errors in loading the file yourself, for example by displaying an error message, then load the image with [ctor
Gdk.Texture.new_from_file
], then create theGtkPicture
with [ctorGtk.Picture.new_for_paintable
].Sometimes an application will want to avoid depending on external data files, such as image files. See the documentation of
GResource
for details. In this case, [ctorGtk.Picture.new_for_resource
] and [methodGtk.Picture.set_resource
] should be used.GtkPicture
displays an image at its natural size. See [classGtk.Image
] if you want to display a fixed-size image, such as an icon.Sizing the paintable
You can influence how the paintable is displayed inside the
GtkPicture
. By turning off [propertyGtk.Picture:keep-aspect-ratio
] you can allow the paintable to get stretched. [propertyGtk.Picture:can-shrink
] can be unset to make sure that paintables are never made smaller than their ideal size - but be careful if you do not know the size of the paintable in use (like when displaying user-loaded images). This can easily cause the picture to grow larger than the screen. And [propertyGtkWidget:halign
] and [propertyGtkWidget:valign
] can be used to make sure the paintable doesn’t fill all available space but is instead displayed at its original size.CSS nodes
GtkPicture
has a single CSS node with the namepicture
.Accessibility
GtkPicture
uses theGTK_ACCESSIBLE_ROLE_IMG
role.The
See morePictureProtocol
protocol exposes the methods and properties of an underlyingGtkPicture
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seePicture
. Alternatively, usePictureRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol PictureProtocol : WidgetProtocol
-
GtkPopover
is a bubble-like context popup.It is primarily meant to provide context-dependent information or options. Popovers are attached to a parent widget. By default, they point to the whole widget area, although this behavior can be changed with [method
Gtk.Popover.set_pointing_to
].The position of a popover relative to the widget it is attached to can also be changed with [method
Gtk.Popover.set_position
]By default,
GtkPopover
performs a grab, in order to ensure input events get redirected to it while it is shown, and also so the popover is dismissed in the expected situations (clicks outside the popover, or the Escape key being pressed). If no such modal behavior is desired on a popover, [methodGtk.Popover.set_autohide
] may be called on it to tweak its behavior.GtkPopover as menu replacement
GtkPopover
is often used to replace menus. The best was to do this is to use the [classGtk.PopoverMenu
] subclass which supports being populated from aGMenuModel
with [ctorGtk.PopoverMenu.new_from_model
].<section> <attribute name="display-hint">horizontal-buttons</attribute> <item> <attribute name="label">Cut</attribute> <attribute name="action">app.cut</attribute> <attribute name="verb-icon">edit-cut-symbolic</attribute> </item> <item> <attribute name="label">Copy</attribute> <attribute name="action">app.copy</attribute> <attribute name="verb-icon">edit-copy-symbolic</attribute> </item> <item> <attribute name="label">Paste</attribute> <attribute name="action">app.paste</attribute> <attribute name="verb-icon">edit-paste-symbolic</attribute> </item> </section>
CSS nodes
popover[.menu] ├── arrow ╰── contents.background ╰── <child>
The contents child node always gets the .background style class and the popover itself gets the .menu style class if the popover is menu-like (i.e.
GtkPopoverMenu
).Particular uses of
GtkPopover
, such as touch selection popups or magnifiers inGtkEntry
orGtkTextView
get style classes like .touch-selection or .magnifier to differentiate from plain popovers.When styling a popover directly, the popover node should usually not have any background. The visible part of the popover can have a shadow. To specify it in CSS, set the box-shadow of the contents node.
Note that, in order to accomplish appropriate arrow visuals,
GtkPopover
uses custom drawing for the arrow node. This makes it possible for the arrow to change its shape dynamically, but it also limits the possibilities of styling it using CSS. In particular, the arrow gets drawn over the content node’s border and shadow, so they look like one shape, which means that the border width of the content node and the arrow node should be the same. The arrow also does not support any border shape other than solid, no border-radius, only one border width (border-bottom-width is used) and no box-shadow.The
See morePopoverProtocol
protocol exposes the methods and properties of an underlyingGtkPopover
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seePopover
. Alternatively, usePopoverRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol PopoverProtocol : NativeProtocol, ShortcutManagerProtocol
-
GtkPopoverMenu
is a subclass ofGtkPopover
that implements menu behavior.GtkPopoverMenu
treats its children like menus and allows switching between them. It can open submenus as traditional, nested submenus, or in a more touch-friendly sliding fashion.GtkPopoverMenu
is meant to be used primarily with menu models, using [ctorGtk.PopoverMenu.new_from_model
]. If you need to put other widgets such as aGtkSpinButton
or aGtkSwitch
into a popover, you can use [methodGtk.PopoverMenu.add_child
].For more dialog-like behavior, use a plain
GtkPopover
.Menu models
The XML format understood by
GtkBuilder
forGMenuModel
consists of a toplevel<menu>
element, which contains one or more<item>
elements. Each<item>
element contains<attribute>
and<link>
elements with a mandatory name attribute.<link>
elements have the same content model as<menu>
. Instead of<link name="submenu">
or<link name="section">
, you can use<submenu>
or<section>
elements.<menu id='app-menu'> <section> <item> <attribute name='label' translatable='yes'>_New Window</attribute> <attribute name='action'>app.new</attribute> </item> <item> <attribute name='label' translatable='yes'>_About Sunny</attribute> <attribute name='action'>app.about</attribute> </item> <item> <attribute name='label' translatable='yes'>_Quit</attribute> <attribute name='action'>app.quit</attribute> </item> </section> </menu>
Attribute values can be translated using gettext, like other
GtkBuilder
content.<attribute>
elements can be marked for translation with atranslatable="yes"
attribute. It is also possible to specify message context and translator comments, using the context and comments attributes. To make use of this, theGtkBuilder
must have been given the gettext domain to use.The following attributes are used when constructing menu items:
- “label”: a user-visible string to display
- “action”: the prefixed name of the action to trigger
- “target”: the parameter to use when activating the action
- “icon” and “verb-icon”: names of icons that may be displayed
- “submenu-action”: name of an action that may be used to track whether a submenu is open
- “hidden-when”: a string used to determine when the item will be hidden.
Possible values include “action-disabled”, “action-missing”, “macos-menubar”.
This is mainly useful for exported menus, see [method
Gtk.Application.set_menubar
]. - “custom”: a string used to match against the ID of a custom child added with
[method
Gtk.PopoverMenu.add_child
], [methodGtk.PopoverMenuBar.add_child
], or in the ui file with<child type="ID">
.
The following attributes are used when constructing sections:
- “label”: a user-visible string to use as section heading
- “display-hint”: a string used to determine special formatting for the section. Possible values include “horizontal-buttons”, “circular-buttons” and “inline-buttons”. They all indicate that section should be displayed as a horizontal row of buttons.
- “text-direction”: a string used to determine the
GtkTextDirection
to use when “display-hint” is set to “horizontal-buttons”. Possible values include “rtl”, “ltr”, and “none”.
The following attributes are used when constructing submenus:
- “label”: a user-visible string to display
- “icon”: icon name to display
Menu items will also show accelerators, which are usually associated with actions via [method
Gtk.Application.set_accels_for_action
], [idgtk_widget_class_add_binding_action
] or [methodGtk.ShortcutController.add_shortcut
].CSS Nodes
GtkPopoverMenu
is just a subclass ofGtkPopover
that adds custom content to it, therefore it has the same CSS nodes. It is one of the cases that add a .menu style class to the popover’s main node.Accessibility
GtkPopoverMenu
uses theGTK_ACCESSIBLE_ROLE_MENU
role, and its items use theGTK_ACCESSIBLE_ROLE_MENU_ITEM
,GTK_ACCESSIBLE_ROLE_MENU_ITEM_CHECKBOX
orGTK_ACCESSIBLE_ROLE_MENU_ITEM_RADIO
roles, depending on the action they are connected to.The
See morePopoverMenuProtocol
protocol exposes the methods and properties of an underlyingGtkPopoverMenu
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seePopoverMenu
. Alternatively, usePopoverMenuRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol PopoverMenuProtocol : PopoverProtocol
-
GtkPopoverMenuBar
presents a horizontal bar of items that pop up popover menus when clicked.The only way to create instances of
GtkPopoverMenuBar
is from aGMenuModel
.CSS nodes
menubar ├── item[.active] ┊ ╰── popover ╰── item ╰── popover
GtkPopoverMenuBar
has a single CSS node with name menubar, below which each item has its CSS node, and below that the corresponding popover.The item whose popover is currently open gets the .active style class.
Accessibility
GtkPopoverMenuBar
uses theGTK_ACCESSIBLE_ROLE_MENU_BAR
role, the menu items use theGTK_ACCESSIBLE_ROLE_MENU_ITEM
role and the menus use theGTK_ACCESSIBLE_ROLE_MENU
role.The
See morePopoverMenuBarProtocol
protocol exposes the methods and properties of an underlyingGtkPopoverMenuBar
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seePopoverMenuBar
. Alternatively, usePopoverMenuBarRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol PopoverMenuBarProtocol : WidgetProtocol
-
A
GtkPrintContext
encapsulates context information that is required when drawing pages for printing.This includes the cairo context and important parameters like page size and resolution. It also lets you easily create [class
Pango.Layout
] and [classPango.Context
] objects that match the font metrics of the cairo surface.GtkPrintContext
objects get passed to the [signalGtk.PrintOperation::begin-print
], [signalGtk.PrintOperation::end-print
], [signalGtk.PrintOperation::request-page-setup
] and [signalGtk.PrintOperation::draw-page
] signals on the [classGtk.PrintOperation
] object.Using GtkPrintContext in a
draw-page
callbackstatic void draw_page (GtkPrintOperation *operation, GtkPrintContext *context, int page_nr) { cairo_t *cr; PangoLayout *layout; PangoFontDescription *desc; cr = gtk_print_context_get_cairo_context (context); // Draw a red rectangle, as wide as the paper (inside the margins) cairo_set_source_rgb (cr, 1.0, 0, 0); cairo_rectangle (cr, 0, 0, gtk_print_context_get_width (context), 50); cairo_fill (cr); // Draw some lines cairo_move_to (cr, 20, 10); cairo_line_to (cr, 40, 20); cairo_arc (cr, 60, 60, 20, 0, M_PI); cairo_line_to (cr, 80, 20); cairo_set_source_rgb (cr, 0, 0, 0); cairo_set_line_width (cr, 5); cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND); cairo_stroke (cr); // Draw some text layout = gtk_print_context_create_pango_layout (context); pango_layout_set_text (layout, "Hello World! Printing is easy", -1); desc = pango_font_description_from_string ("sans 28"); pango_layout_set_font_description (layout, desc); pango_font_description_free (desc); cairo_move_to (cr, 30, 20); pango_cairo_layout_path (cr, layout); // Font Outline cairo_set_source_rgb (cr, 0.93, 1.0, 0.47); cairo_set_line_width (cr, 0.5); cairo_stroke_preserve (cr); // Font Fill cairo_set_source_rgb (cr, 0, 0.0, 1.0); cairo_fill (cr); g_object_unref (layout); }
The
See morePrintContextProtocol
protocol exposes the methods and properties of an underlyingGtkPrintContext
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seePrintContext
. Alternatively, usePrintContextRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol PrintContextProtocol : ObjectProtocol
-
A
GtkPrintJob
object represents a job that is sent to a printer.You only need to deal directly with print jobs if you use the non-portable [class
Gtk.PrintUnixDialog
] API.Use [method
Gtk.PrintJob.get_surface
] to obtain the cairo surface onto which the pages must be drawn. Use [methodGtk.PrintJob.send
] to send the finished job to the printer. If you don’t use cairoGtkPrintJob
also supports printing of manually generated PostScript, via [methodGtk.PrintJob.set_source_file
].The
See morePrintJobProtocol
protocol exposes the methods and properties of an underlyingGtkPrintJob
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seePrintJob
. Alternatively, usePrintJobRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol PrintJobProtocol : ObjectProtocol
-
GtkPrintOperation
is the high-level, portable printing API.It looks a bit different than other GTK dialogs such as the
GtkFileChooser
, 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 [classGtk.PrintUnixDialog
].The typical way to use the high-level printing API is to create a
GtkPrintOperation
object with [ctorGtk.PrintOperation.new
] when the user selects to print. Then you set some properties on it, e.g. the page size, any [classGtk.PrintSettings
] from previous print operations, the number of pages, the current page, etc.Then you start the print operation by calling [method
Gtk.PrintOperation.run
]. It will then show a dialog, let the user select a printer and options. When the user finished the dialog, various signals will be emitted on theGtkPrintOperation
, the main one being [signalGtk.PrintOperation::draw-page
], which you are supposed to handle and render the page on the provided [classGtk.PrintContext
] using Cairo.The high-level printing API
static GtkPrintSettings *settings = NULL; static void do_print (void) { GtkPrintOperation *print; GtkPrintOperationResult res; print = gtk_print_operation_new (); if (settings != NULL) gtk_print_operation_set_print_settings (print, settings); g_signal_connect (print, "begin_print", G_CALLBACK (begin_print), NULL); g_signal_connect (print, "draw_page", G_CALLBACK (draw_page), NULL); res = gtk_print_operation_run (print, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, GTK_WINDOW (main_window), NULL); if (res == GTK_PRINT_OPERATION_RESULT_APPLY) { if (settings != NULL) g_object_unref (settings); settings = g_object_ref (gtk_print_operation_get_print_settings (print)); } g_object_unref (print); }
By default
GtkPrintOperation
uses an external application to do print preview. To implement a custom print preview, an application must connect to the preview signal. The functions [methodGtk.PrintOperationPreview.render_page
], [methodGtk.PrintOperationPreview.end_preview
] and [methodGtk.PrintOperationPreview.is_selected
] are useful when implementing a print preview.The
See morePrintOperationProtocol
protocol exposes the methods and properties of an underlyingGtkPrintOperation
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seePrintOperation
. Alternatively, usePrintOperationRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol PrintOperationProtocol : ObjectProtocol, PrintOperationPreviewProtocol
-
A
GtkPrintSettings
object represents the settings of a print dialog in a system-independent way.The main use for this object is that once you’ve printed you can get a settings object that represents the settings the user chose, and the next time you print you can pass that object in so that the user doesn’t have to re-set all his settings.
Its also possible to enumerate the settings so that you can easily save the settings for the next time your app runs, or even store them in a document. The predefined keys try to use shared values as much as possible so that moving such a document between systems still works.
The
See morePrintSettingsProtocol
protocol exposes the methods and properties of an underlyingGtkPrintSettings
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seePrintSettings
. Alternatively, usePrintSettingsRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol PrintSettingsProtocol : ObjectProtocol
-
GtkPrintUnixDialog
implements a print dialog for platforms which don’t provide a native print dialog, like Unix.It can be used very much like any other GTK dialog, at the cost of the portability offered by the high-level printing API with [class
Gtk.PrintOperation
].In order to print something with
GtkPrintUnixDialog
, you need to use [methodGtk.PrintUnixDialog.get_selected_printer
] to obtain a [classGtk.Printer
] object and use it to construct a [classGtk.PrintJob
] using [ctorGtk.PrintJob.new
].GtkPrintUnixDialog
uses the following response values:GTK_RESPONSE_OK:
for the “Print” buttonGTK_RESPONSE_APPLY:
for the “Preview” buttonGTK_RESPONSE_CANCEL:
for the “Cancel” button
GtkPrintUnixDialog as GtkBuildable
The
GtkPrintUnixDialog
implementation of theGtkBuildable
interface exposes itsnotebook
internal children with the name “notebook”.An example of a
GtkPrintUnixDialog
UI definition fragment:<object class="GtkPrintUnixDialog" id="dialog1"> <child internal-child="notebook"> <object class="GtkNotebook" id="notebook"> <child> <object type="GtkNotebookPage"> <property name="tab_expand">False</property> <property name="tab_fill">False</property> <property name="tab"> <object class="GtkLabel" id="tablabel"> <property name="label">Tab label</property> </object> </property> <property name="child"> <object class="GtkLabel" id="tabcontent"> <property name="label">Content on notebook tab</property> </object> </property> </object> </child> </object> </child> </object>
CSS nodes
GtkPrintUnixDialog
has a single CSS node with name window. The style classes dialog and print are added.The
See morePrintUnixDialogProtocol
protocol exposes the methods and properties of an underlyingGtkPrintUnixDialog
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seePrintUnixDialog
. Alternatively, usePrintUnixDialogRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol PrintUnixDialogProtocol : DialogProtocol
-
A
GtkPrinter
object represents a printer.You only need to deal directly with printers if you use the non-portable [class
Gtk.PrintUnixDialog
] API.A
GtkPrinter
allows to get status information about the printer, such as its description, its location, the number of queued jobs, etc. Most importantly, aGtkPrinter
object can be used to create a [classGtk.PrintJob
] object, which lets you print to the printer.The
See morePrinterProtocol
protocol exposes the methods and properties of an underlyingGtkPrinter
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seePrinter
. Alternatively, usePrinterRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol PrinterProtocol : ObjectProtocol
-
GtkProgressBar
is typically used to display the progress of a long running operation.It provides a visual clue that processing is underway.
GtkProgressBar
can be used in two different modes: percentage mode and activity mode.When an application can determine how much work needs to take place (e.g. read a fixed number of bytes from a file) and can monitor its progress, it can use the
GtkProgressBar
in percentage mode and the user sees a growing bar indicating the percentage of the work that has been completed. In this mode, the application is required to call [methodGtk.ProgressBar.set_fraction
] periodically to update the progress bar.When an application has no accurate way of knowing the amount of work to do, it can use the
GtkProgressBar
in activity mode, which shows activity by a block moving back and forth within the progress area. In this mode, the application is required to call [methodGtk.ProgressBar.pulse
] periodically to update the progress bar.There is quite a bit of flexibility provided to control the appearance of the
GtkProgressBar
. Functions are provided to control the orientation of the bar, optional text can be displayed along with the bar, and the step size used in activity mode can be set.CSS nodes
progressbar[.osd] ├── [text] ╰── trough[.empty][.full] ╰── progress[.pulse]
GtkProgressBar
has a main CSS node with name progressbar and subnodes with names text and trough, of which the latter has a subnode named progress. The text subnode is only present if text is shown. The progress subnode has the style class .pulse when in activity mode. It gets the style classes .left, .right, .top or .bottom added when the progress ‘touches’ the corresponding end of the GtkProgressBar. The .osd class on the progressbar node is for use in overlays like the one Epiphany has for page loading progress.Accessibility
GtkProgressBar
uses theGTK_ACCESSIBLE_ROLE_PROGRESS_BAR
role.The
See moreProgressBarProtocol
protocol exposes the methods and properties of an underlyingGtkProgressBar
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeProgressBar
. Alternatively, useProgressBarRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ProgressBarProtocol : OrientableProtocol, WidgetProtocol
-
A
GObject
property value in aGtkExpression
.The
See morePropertyExpressionProtocol
protocol exposes the methods and properties of an underlyingGtkPropertyExpression
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seePropertyExpression
. Alternatively, usePropertyExpressionRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol PropertyExpressionProtocol : ExpressionProtocol
-
GtkRange
is the common base class for widgets which visualize an adjustment.Widgets that are derived from
GtkRange
include [classGtk.Scale
] and [classGtk.Scrollbar
].Apart from signals for monitoring the parameters of the adjustment,
GtkRange
provides properties and methods for setting a “fill level” on range widgets. See [methodGtk.Range.set_fill_level
].The
See moreRangeProtocol
protocol exposes the methods and properties of an underlyingGtkRange
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeRange
. Alternatively, useRangeRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol RangeProtocol : OrientableProtocol, WidgetProtocol
-
Meta-data to be passed to
gtk_recent_manager_add_full()
when registering a recently used resource.The
See moreRecentDataProtocol
protocol exposes the methods and properties of an underlyingGtkRecentData
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeRecentData
. Alternatively, useRecentDataRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol RecentDataProtocol
-
GtkRecentInfo
contains the metadata associated with an item in the recently used files list.The
See moreRecentInfoProtocol
protocol exposes the methods and properties of an underlyingGtkRecentInfo
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeRecentInfo
. Alternatively, useRecentInfoRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol RecentInfoProtocol
-
GtkRecentManagerClass
contains only private data.The
See moreRecentManagerClassProtocol
protocol exposes the methods and properties of an underlyingGtkRecentManagerClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeRecentManagerClass
. Alternatively, useRecentManagerClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol RecentManagerClassProtocol
-
Represents a request of a screen object in a given orientation. These are primarily used in container implementations when allocating a natural size for children calling. See
gtk_distribute_natural_allocation()
.The
See moreRequestedSizeProtocol
protocol exposes the methods and properties of an underlyingGtkRequestedSize
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeRequestedSize
. Alternatively, useRequestedSizeRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol RequestedSizeProtocol
-
A
GtkRequisition
represents the desired size of a widget. See GtkWidget’s geometry management section for more information.The
See moreRequisitionProtocol
protocol exposes the methods and properties of an underlyingGtkRequisition
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeRequisition
. Alternatively, useRequisitionRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol RequisitionProtocol
-
The
See moreRootInterfaceProtocol
protocol exposes the methods and properties of an underlyingGtkRootInterface
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeRootInterface
. Alternatively, useRootInterfaceRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol RootInterfaceProtocol
-
The
See moreScaleButtonClassProtocol
protocol exposes the methods and properties of an underlyingGtkScaleButtonClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeScaleButtonClass
. Alternatively, useScaleButtonClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ScaleButtonClassProtocol
-
GtkRecentManager
manages and looks 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.
The recently used files list is per user.
GtkRecentManager
acts like a database of all the recently used files. You can create newGtkRecentManager
objects, but it is more efficient to use the default manager created by GTK.Adding a new recently used file is as simple as:
GtkRecentManager *manager; manager = gtk_recent_manager_get_default (); gtk_recent_manager_add_item (manager, file_uri);
The
GtkRecentManager
will try to gather all the needed information from the file itself through GIO.Looking up the meta-data associated with a recently used file given its URI requires calling [method
Gtk.RecentManager.lookup_item
]:GtkRecentManager *manager; GtkRecentInfo *info; GError *error = NULL; manager = gtk_recent_manager_get_default (); info = gtk_recent_manager_lookup_item (manager, file_uri, &error); if (error) { g_warning ("Could not find the file: `s`", error->message); g_error_free (error); } else { // Use the info object gtk_recent_info_unref (info); }
In order to retrieve the list of recently used files, you can use [method
Gtk.RecentManager.get_items
], which returns a list of [structGtk.RecentInfo
].Note that the maximum age of the recently used files list is controllable through the [property
Gtk.Settings:gtk-recent-files-max-age
] property.The
See moreRecentManagerProtocol
protocol exposes the methods and properties of an underlyingGtkRecentManager
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeRecentManager
. Alternatively, useRecentManagerRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol RecentManagerProtocol : ObjectProtocol
-
A
GtkRevealer
animates the transition of its child from invisible to visible.The style of transition can be controlled with [method
Gtk.Revealer.set_transition_type
].These animations respect the [property
Gtk.Settings:gtk-enable-animations
] setting.CSS nodes
GtkRevealer
has a single CSS node with name revealer. When stylingGtkRevealer
using CSS, remember that it only hides its contents, not itself. That means applied margin, padding and borders will be visible even when the [propertyGtk.Revealer:reveal-child
] property is set tofalse
.Accessibility
GtkRevealer
uses theGTK_ACCESSIBLE_ROLE_GROUP
role.The child of
GtkRevealer
, if set, is always available in the accessibility tree, regardless of the state of the revealer widget.The
See moreRevealerProtocol
protocol exposes the methods and properties of an underlyingGtkRevealer
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeRevealer
. Alternatively, useRevealerRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol RevealerProtocol : WidgetProtocol
-
A
GtkScale
is a slider control used to select a numeric value.To use it, you’ll probably want to investigate the methods on its base class, [class
GtkRange
], in addition to the methods forGtkScale
itself. To set the value of a scale, you would normally use [methodGtk.Range.set_value
]. To detect changes to the value, you would normally use the [signalGtk.Range::value-changed
] signal.Note that using the same upper and lower bounds for the
GtkScale
(through theGtkRange
methods) will hide the slider itself. This is useful for applications that want to show an undeterminate value on the scale, without changing the layout of the application (such as movie or music players).GtkScale as GtkBuildable
GtkScale
supports a custom <marks> element, which can contain multiple <mark> elements. The “value” and “position” attributes have the same meaning as [methodGtk.Scale.add_mark
] parameters of the same name. If the element is not empty, its content is taken as the markup to show at the mark. It can be translated with the usual ”translatable” and “context” attributes.CSS nodes
scale[.fine-tune][.marks-before][.marks-after] ├── [value][.top][.right][.bottom][.left] ├── marks.top │ ├── mark │ ┊ ├── [label] │ ┊ ╰── indicator ┊ ┊ │ ╰── mark ├── marks.bottom │ ├── mark │ ┊ ├── indicator │ ┊ ╰── [label] ┊ ┊ │ ╰── mark ╰── trough ├── [fill] ├── [highlight] ╰── slider
GtkScale
has a main CSS node with name scale and a subnode for its contents, with subnodes named trough and slider.The main node gets the style class .fine-tune added when the scale is in ‘fine-tuning’ mode.
If the scale has an origin (see [method
Gtk.Scale.set_has_origin
]), there is a subnode with name highlight below the trough node that is used for rendering the highlighted part of the trough.If the scale is showing a fill level (see [method
Gtk.Range.set_show_fill_level
]), there is a subnode with name fill below the trough node that is used for rendering the filled in part of the trough.If marks are present, there is a marks subnode before or after the trough node, below which each mark gets a node with name mark. The marks nodes get either the .top or .bottom style class.
The mark node has a subnode named indicator. If the mark has text, it also has a subnode named label. When the mark is either above or left of the scale, the label subnode is the first when present. Otherwise, the indicator subnode is the first.
The main CSS node gets the ‘marks-before’ and/or ‘marks-after’ style classes added depending on what marks are present.
If the scale is displaying the value (see [property
Gtk.Scale:draw-value
]), there is subnode with name value. This node will get the .top or .bottom style classes similar to the marks node.Accessibility
GtkScale
uses theGTK_ACCESSIBLE_ROLE_SLIDER
role.The
See moreScaleProtocol
protocol exposes the methods and properties of an underlyingGtkScale
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeScale
. Alternatively, useScaleRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ScaleProtocol : RangeProtocol
-
GtkRoot
is the interface implemented by all widgets that can act as a toplevel widget.The root widget takes care of providing the connection to the windowing system and manages layout, drawing and event delivery for its widget hierarchy.
The obvious example of a
GtkRoot
isGtkWindow
.To get the display to which a
GtkRoot
belongs, use [methodGtk.Root.get_display
].GtkRoot
also maintains the location of keyboard focus inside its widget hierarchy, with [methodGtk.Root.set_focus
] and [methodGtk.Root.get_focus
].The
See moreRootProtocol
protocol exposes the methods and properties of an underlyingGtkRoot
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeRoot
. Alternatively, useRootRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol RootProtocol : NativeProtocol
-
GtkScrollable
is an interface for widgets with native scrolling ability.To implement this interface you should override the [property
Gtk.Scrollable:hadjustment
] and [propertyGtk.Scrollable:vadjustment
] properties.Creating a scrollable widget
All scrollable widgets should do the following.
When a parent widget sets the scrollable child widget’s adjustments, the widget should populate the adjustments’ [property
Gtk.Adjustment:lower
], [propertyGtk.Adjustment:upper
], [propertyGtk.Adjustment:step-increment
], [propertyGtk.Adjustment:page-increment
] and [propertyGtk.Adjustment:page-size
] properties and connect to the [signalGtk.Adjustment::value-changed
] signal.Because its preferred size is the size for a fully expanded widget, the scrollable widget must be able to cope with underallocations. This means that it must accept any value passed to its [vfunc
Gtk.Widget.size_allocate
] implementation.When the parent allocates space to the scrollable child widget, the widget should update the adjustments’ properties with new values.
When any of the adjustments emits the [signal
Gtk.Adjustment::value-changed
] signal, the scrollable widget should scroll its contents.
The
See moreScrollableProtocol
protocol exposes the methods and properties of an underlyingGtkScrollable
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeScrollable
. Alternatively, useScrollableRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ScrollableProtocol
-
GtkScaleButton
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 [class
Gtk.VolumeButton
] subclass that is tailored for this use case.CSS nodes
GtkScaleButton
has a single CSS node with name button. To differentiate it from a plainGtkButton
, it gets the .scale style class.The
See moreScaleButtonProtocol
protocol exposes the methods and properties of an underlyingGtkScaleButton
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeScaleButton
. Alternatively, useScaleButtonRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ScaleButtonProtocol : OrientableProtocol, WidgetProtocol
-
The
GtkScrollbar
widget is a horizontal or vertical scrollbar.Its position and movement are controlled by the adjustment that is passed to or created by [ctor
Gtk.Scrollbar.new
]. See [classGtk.Adjustment
] for more details. The [propertyGtk.Adjustment:value
] field sets the position of the thumb and must be between [propertyGtk.Adjustment:lower
] and [propertyGtk.Adjustment:upper
] - [propertyGtk.Adjustment:page-size
]. The [propertyGtk.Adjustment:page-size
] represents the size of the visible scrollable area.The fields [property
Gtk.Adjustment:step-increment
] and [propertyGtk.Adjustment:page-increment
] fields are added to or subtracted from the [propertyGtk.Adjustment:value
] when the user asks to move by a step (using e.g. the cursor arrow keys) or by a page (using e.g. the Page Down/Up keys).CSS nodes
scrollbar ╰── range[.fine-tune] ╰── trough ╰── slider
GtkScrollbar
has a main CSS node with name scrollbar and a subnode for its contents. The main node gets the .horizontal or .vertical style classes applied, depending on the scrollbar’s orientation.The range node gets the style class .fine-tune added when the scrollbar is in ‘fine-tuning’ mode.
Other style classes that may be added to scrollbars inside [class
Gtk.ScrolledWindow
] include the positional classes (.left, .right, .top, .bottom) and style classes related to overlay scrolling (.overlay-indicator, .dragging, .hovering).Accessibility
GtkScrollbar
uses theGTK_ACCESSIBLE_ROLE_SCROLLBAR
role.The
See moreScrollbarProtocol
protocol exposes the methods and properties of an underlyingGtkScrollbar
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeScrollbar
. Alternatively, useScrollbarRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ScrollbarProtocol : OrientableProtocol, WidgetProtocol
-
GtkScrolledWindow
is a container that makes its child scrollable.It does so using either internally added scrollbars or externally associated adjustments, and optionally draws a frame around the child.
Widgets with native scrolling support, i.e. those whose classes implement the [iface
Gtk.Scrollable
] interface, are added directly. For other types of widget, the class [classGtk.Viewport
] acts as an adaptor, giving scrollability to other widgets. [methodGtk.ScrolledWindow.set_child
] intelligently accounts for whether or not the added child is aGtkScrollable
. If it isn’t, then it wraps the child in aGtkViewport
. Therefore, you can just add any child widget and not worry about the details.If [method
Gtk.ScrolledWindow.set_child
] has added aGtkViewport
for you, you can remove both your added child widget from theGtkViewport
, and theGtkViewport
from theGtkScrolledWindow
, like this:GtkWidget *scrolled_window = gtk_scrolled_window_new (); GtkWidget *child_widget = gtk_button_new (); // GtkButton is not a GtkScrollable, so GtkScrolledWindow will automatically // add a GtkViewport. gtk_box_append (GTK_BOX (scrolled_window), child_widget); // Either of these will result in child_widget being unparented: gtk_box_remove (GTK_BOX (scrolled_window), child_widget); // or gtk_box_remove (GTK_BOX (scrolled_window), gtk_bin_get_child (GTK_BIN (scrolled_window)));
Unless [property
Gtk.ScrolledWindow:hscrollbar-policy
] and [propertyGtk.ScrolledWindow:vscrollbar-policy
] areGTK_POLICY_NEVER
orGTK_POLICY_EXTERNAL
,GtkScrolledWindow
adds internalGtkScrollbar
widgets around its child. The scroll position of the child, and if applicable the scrollbars, is controlled by the [propertyGtk.ScrolledWindow:hadjustment
] and [propertyGtk.ScrolledWindow:vadjustment
] that are associated with theGtkScrolledWindow
. See the docs on [classGtk.Scrollbar
] for the details, but note that the “step_increment” and “page_increment” fields are only effective if the policy causes scrollbars to be present.If a
GtkScrolledWindow
doesn’t behave quite as you would like, or doesn’t have exactly the right layout, it’s very possible to set up your own scrolling withGtkScrollbar
and for example aGtkGrid
.Touch support
GtkScrolledWindow
has built-in support for touch devices. When a touchscreen is used, swiping will move the scrolled window, and will expose ‘kinetic’ behavior. This can be turned off with the [propertyGtk.ScrolledWindow:kinetic-scrolling
] property if it is undesired.GtkScrolledWindow
also displays visual ‘overshoot’ indication when the content is pulled beyond the end, and this situation can be captured with the [signalGtk.ScrolledWindow::edge-overshot
] signal.If no mouse device is present, the scrollbars will overlaid as narrow, auto-hiding indicators over the content. If traditional scrollbars are desired although no mouse is present, this behaviour can be turned off with the [property
Gtk.ScrolledWindow:overlay-scrolling
] property.CSS nodes
GtkScrolledWindow
has a main CSS node with name scrolledwindow. It gets a .frame style class added when [propertyGtk.ScrolledWindow:has-frame
] istrue
.It uses subnodes with names overshoot and undershoot to draw the overflow and underflow indications. These nodes get the .left, .right, .top or .bottom style class added depending on where the indication is drawn.
GtkScrolledWindow
also sets the positional style classes (.left, .right, .top, .bottom) and style classes related to overlay scrolling (.overlay-indicator, .dragging, .hovering) on its scrollbars.If both scrollbars are visible, the area where they meet is drawn with a subnode named junction.
Accessibility
GtkScrolledWindow
uses theGTK_ACCESSIBLE_ROLE_GROUP
role.The
See moreScrolledWindowProtocol
protocol exposes the methods and properties of an underlyingGtkScrolledWindow
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeScrolledWindow
. Alternatively, useScrolledWindowRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ScrolledWindowProtocol : WidgetProtocol
-
GtkSearchBar
is a container made to have a search entry.It can also contain additional widgets, such as drop-down menus, or buttons. The search bar would appear when a search is started through typing on the keyboard, or the application’s search mode is toggled on.
For keyboard presses to start a search, the search bar must be told of a widget to capture key events from through [method
Gtk.SearchBar.set_key_capture_widget
]. This widget will typically be the top-level window, or a parent container of the search bar. Common shortcuts such as Ctrl+F should be handled as an application action, or through the menu items.You will also need to tell the search bar about which entry you are using as your search entry using [method
Gtk.SearchBar.connect_entry
].Creating a search bar
The following example shows you how to create a more complex search entry.
CSS nodes
searchbar ╰── revealer ╰── box ├── [child] ╰── [button.close]
GtkSearchBar
has a main CSS node with name searchbar. It has a child node with name revealer that contains a node with name box. The box node contains both the CSS node of the child widget as well as an optional button node which gets the .close style class applied.Accessibility
GtkSearchBar
uses theGTK_ACCESSIBLE_ROLE_SEARCH
role.The
See moreSearchBarProtocol
protocol exposes the methods and properties of an underlyingGtkSearchBar
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeSearchBar
. Alternatively, useSearchBarRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol SearchBarProtocol : WidgetProtocol
-
GtkSearchEntry
is an entry widget that has been tailored for use as a search entry.The main API for interacting with a
GtkSearchEntry
as entry is theGtkEditable
interface.It will show an inactive symbolic “find” icon when the search entry is empty, and a symbolic “clear” icon when there is text. Clicking on the “clear” icon will empty the search entry.
To make filtering appear more reactive, it is a good idea to not react to every change in the entry text immediately, but only after a short delay. To support this,
GtkSearchEntry
emits the [signalGtk.SearchEntry::search-changed
] signal which can be used instead of the [signalGtk.Editable::changed
] signal.The [signal
Gtk.SearchEntry::previous-match
], [signalGtk.SearchEntry::next-match
] and [signalGtk.SearchEntry::stop-search
] signals can be used to implement moving between search results and ending the search.Often,
GtkSearchEntry
will be fed events by means of being placed inside a [classGtk.SearchBar
]. If that is not the case, you can use [methodGtk.SearchEntry.set_key_capture_widget
] to let it capture key input from another widget.GtkSearchEntry
provides only minimal API and should be used with the [ifaceGtk.Editable
] API.CSS Nodes
entry.search ╰── text
GtkSearchEntry
has a single CSS node with name entry that carries a.search
style class, and the text node is a child of that.Accessibility
GtkSearchEntry
uses theGTK_ACCESSIBLE_ROLE_SEARCH_BOX
role.The
See moreSearchEntryProtocol
protocol exposes the methods and properties of an underlyingGtkSearchEntry
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeSearchEntry
. Alternatively, useSearchEntryRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol SearchEntryProtocol : EditableProtocol
-
GtkSelectionFilterModel
is a list model that presents the selection from aGtkSelectionModel
.The
See moreSelectionFilterModelProtocol
protocol exposes the methods and properties of an underlyingGtkSelectionFilterModel
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeSelectionFilterModel
. Alternatively, useSelectionFilterModelRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol SelectionFilterModelProtocol : ListModelProtocol, ObjectProtocol
-
GtkSeparator
is a horizontal or vertical separator widget.A
GtkSeparator
can be used to group the widgets within a window. It displays a line with a shadow to make it appear sunken into the interface.CSS nodes
GtkSeparator
has a single CSS node with name separator. The node gets one of the .horizontal or .vertical style classes.Accessibility
GtkSeparator
uses theGTK_ACCESSIBLE_ROLE_SEPARATOR
role.The
See moreSeparatorProtocol
protocol exposes the methods and properties of an underlyingGtkSeparator
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeSeparator
. Alternatively, useSeparatorRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol SeparatorProtocol : OrientableProtocol, WidgetProtocol
-
GtkSettings
provides a mechanism to share global settings between applications.On the X window system, this sharing is realized by an XSettings manager that is usually part of the desktop environment, along with utilities that let the user change these settings.
On Wayland, the settings are obtained either via a settings portal, or by reading desktop settings from DConf.
In the absence of these sharing mechanisms, GTK reads default values for settings from
settings.ini
files in/etc/gtk-4.0
,$XDG_CONFIG_DIRS/gtk-4.0
and$XDG_CONFIG_HOME/gtk-4.0
. These files must be valid key files (seeGKeyFile
), and have a section called Settings. Themes can also provide default values for settings by installing asettings.ini
file next to theirgtk.css
file.Applications can override system-wide settings by setting the property of the
GtkSettings
object withg_object_set()
. This should be restricted to special cases though;GtkSettings
are not meant as an application configuration facility.There is one
GtkSettings
instance per display. It can be obtained with [funcGtk.Settings.get_for_display
], but in many cases, it is more convenient to use [methodGtk.Widget.get_settings
].The
See moreSettingsProtocol
protocol exposes the methods and properties of an underlyingGtkSettings
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeSettings
. Alternatively, useSettingsRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol SettingsProtocol : ObjectProtocol, StyleProviderProtocol
-
A
GtkShortcut
describes a keyboard shortcut.It contains a description of how to trigger the shortcut via a [class
Gtk.ShortcutTrigger
] and a way to activate the shortcut on a widget via a [classGtk.ShortcutAction
].The actual work is usually done via [class
Gtk.ShortcutController
], which decides if and when to activate a shortcut. Using that controller directly however is rarely necessary as various higher level convenience APIs exist onGtkWidget
s that make it easier to use shortcuts in GTK.GtkShortcut
does provide functionality to make it easy for users to work with shortcuts, either by providing informational strings for display purposes or by allowing shortcuts to be configured.The
See moreShortcutProtocol
protocol exposes the methods and properties of an underlyingGtkShortcut
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeShortcut
. Alternatively, useShortcutRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ShortcutProtocol : ObjectProtocol
-
GtkShortcutAction
encodes an action that can be triggered by a keyboard shortcut.GtkShortcutActions
contain functions that allow easy presentation to end users as well as being printed for debugging.All
GtkShortcutActions
are immutable, you can only specify their properties during construction. If you want to change a action, you have to replace it with a new one. If you need to pass arguments to an action, these are specified by the higher-levelGtkShortcut
object.To activate a
GtkShortcutAction
manually, [methodGtk.ShortcutAction.activate
] can be called.GTK provides various actions:
- [class
Gtk.MnemonicAction
]: a shortcut action that callsgtk_widget_mnemonic_activate()
- [class
Gtk.CallbackAction
]: a shortcut action that invokes a given callback - [class
Gtk.SignalAction
]: a shortcut action that emits a given signal - [class
Gtk.ActivateAction
]: a shortcut action that callsgtk_widget_activate()
- [class
Gtk.NamedAction
]: a shortcut action that callsgtk_widget_activate_action()
- [class
Gtk.NothingAction
]: a shortcut action that does nothing
The
See moreShortcutActionProtocol
protocol exposes the methods and properties of an underlyingGtkShortcutAction
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeShortcutAction
. Alternatively, useShortcutActionRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ShortcutActionProtocol : ObjectProtocol
- [class
-
GtkShortcutController
is an event controller that manages shortcuts.Most common shortcuts are using this controller implicitly, e.g. by adding a mnemonic underline to a
GtkLabel
, or by installing a key binding using [methodGtk.WidgetClass.add_binding
], or by adding accelerators to global actions using [methodGtk.Application.set_accels_for_action
].But it is possible to create your own shortcut controller, and add shortcuts to it.
GtkShortcutController
implementsGListModel
for querying the shortcuts that have been added to it.GtkShortcutController as a GtkBuildable
GtkShortcutControllers
can be creates in ui files to set up shortcuts in the same place as the widgets.An example of a UI definition fragment with
GtkShortcutController
:<object class='GtkButton'> <child> <object class='GtkShortcutController'> <property name='scope'>managed</property> <child> <object class='GtkShortcut'> <property name='trigger'><Control>k</property> <property name='action'>activate</property> </object> </child> </object> </child> </object>
This example creates a [class
Gtk.ActivateAction
] for triggering theactivate
signal of theGtkButton
. See [ctorGtk.ShortcutAction.parse_string
] for the syntax for other kinds ofGtkShortcutAction
. See [ctorGtk.ShortcutTrigger.parse_string
] to learn more about the syntax for triggers.The
See moreShortcutControllerProtocol
protocol exposes the methods and properties of an underlyingGtkShortcutController
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeShortcutController
. Alternatively, useShortcutControllerRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ShortcutControllerProtocol : ListModelProtocol, BuildableProtocol, EventControllerProtocol
-
GtkShortcutLabel
displays a single keyboard shortcut or gesture.The main use case for
GtkShortcutLabel
is inside a [classGtk.ShortcutsWindow
].The
See moreShortcutLabelProtocol
protocol exposes the methods and properties of an underlyingGtkShortcutLabel
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeShortcutLabel
. Alternatively, useShortcutLabelRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ShortcutLabelProtocol : WidgetProtocol
-
GtkShortcutTrigger
tracks how aGtkShortcut
should be activated.To find out if a
GtkShortcutTrigger
triggers, you can call [methodGtk.ShortcutTrigger.trigger
] on aGdkEvent
.GtkShortcutTriggers
contain functions that allow easy presentation to end users as well as being printed for debugging.All
GtkShortcutTriggers
are immutable, you can only specify their properties during construction. If you want to change a trigger, you have to replace it with a new one.The
See moreShortcutTriggerProtocol
protocol exposes the methods and properties of an underlyingGtkShortcutTrigger
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeShortcutTrigger
. Alternatively, useShortcutTriggerRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ShortcutTriggerProtocol : ObjectProtocol
-
A
GtkShortcutsGroup
represents a group of related keyboard shortcuts or gestures.The group has a title. It may optionally be associated with a view of the application, which can be used to show only relevant shortcuts depending on the application context.
This widget is only meant to be used with [class
Gtk.ShortcutsWindow
].The
See moreShortcutsGroupProtocol
protocol exposes the methods and properties of an underlyingGtkShortcutsGroup
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeShortcutsGroup
. Alternatively, useShortcutsGroupRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ShortcutsGroupProtocol : BoxProtocol
-
A
GtkShortcutsSection
collects all the keyboard shortcuts and gestures for a major application mode.If your application needs multiple sections, you should give each section a unique [property
Gtk.ShortcutsSection:section-name
] and a [propertyGtk.ShortcutsSection:title
] that can be shown in the section selector of the [classGtk.ShortcutsWindow
].The [property
Gtk.ShortcutsSection:max-height
] property can be used to influence how the groups in the section are distributed over pages and columns.This widget is only meant to be used with [class
Gtk.ShortcutsWindow
].The
See moreShortcutsSectionProtocol
protocol exposes the methods and properties of an underlyingGtkShortcutsSection
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeShortcutsSection
. Alternatively, useShortcutsSectionRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ShortcutsSectionProtocol : BoxProtocol
-
A
GtkShortcutsShortcut
represents a single keyboard shortcut or gesture with a short text.This widget is only meant to be used with
GtkShortcutsWindow
.The
See moreShortcutsShortcutProtocol
protocol exposes the methods and properties of an underlyingGtkShortcutsShortcut
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeShortcutsShortcut
. Alternatively, useShortcutsShortcutRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ShortcutsShortcutProtocol : WidgetProtocol
-
A
GtkShortcutsWindow
shows information about the keyboard shortcuts and gestures of an application.The shortcuts can be grouped, and you can have multiple sections in this window, corresponding to the major modes of your application.
Additionally, the shortcuts can be filtered by the current view, to avoid showing information that is not relevant in the current application context.
The recommended way to construct a
GtkShortcutsWindow
is with [classGtk.Builder
], by populating aGtkShortcutsWindow
with one or moreGtkShortcutsSection
objects, which containGtkShortcutsGroups
that in turn contain objects of classGtkShortcutsShortcut
.A simple example:
This example has as single section. As you can see, the shortcut groups are arranged in columns, and spread across several pages if there are too many to find on a single page.
The .ui file for this example can be found here.
An example with multiple views:
This example shows a
GtkShortcutsWindow
that has been configured to show only the shortcuts relevant to the “stopwatch” view.The .ui file for this example can be found here.
An example with multiple sections:
This example shows a
GtkShortcutsWindow
with two sections, “Editor Shortcuts” and “Terminal Shortcuts”.The .ui file for this example can be found here.
The
See moreShortcutsWindowProtocol
protocol exposes the methods and properties of an underlyingGtkShortcutsWindow
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeShortcutsWindow
. Alternatively, useShortcutsWindowRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ShortcutsWindowProtocol : WindowProtocol
-
A
GtkShortcut
Action that emits a signal.Signals that are used in this way are referred to as keybinding signals, and they are expected to be defined with the
G_SIGNAL_ACTION
flag.The
See moreSignalActionProtocol
protocol exposes the methods and properties of an underlyingGtkSignalAction
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeSignalAction
. Alternatively, useSignalActionRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol SignalActionProtocol : ShortcutActionProtocol
-
GtkSignalListItemFactory
is aGtkListItemFactory
that emits signals to to manage listitems.Signals are emitted for every listitem in the same order:
[signal
Gtk.SignalListItemFactory::setup
] is emitted to set up permanent things on the listitem. This usually means constructing the widgets used in the row and adding them to the listitem.[signal
Gtk.SignalListItemFactory::bind
] is emitted to bind the item passed via [propertyGtk.ListItem:item
] to the widgets that have been created in step 1 or to add item-specific widgets. Signals are connected to listen to changes - both to changes in the item to update the widgets or to changes in the widgets to update the item. After this signal has been called, the listitem may be shown in a list widget.[signal
Gtk.SignalListItemFactory::unbind
] is emitted to undo everything done in step 2. Usually this means disconnecting signal handlers. Once this signal has been called, the listitem will no longer be used in a list widget.[signal
Gtk.SignalListItemFactory::bind
] and [signalGtk.SignalListItemFactory::unbind
] may be emitted multiple times again to bind the listitem for use with new items. By reusing listitems, potentially costly setup can be avoided. However, it means code needs to make sure to properly clean up the listitem in step 3 so that no information from the previous use leaks into the next use.- [signal
Gtk.SignalListItemFactory::teardown
] is emitted to allow undoing the effects of [signalGtk.SignalListItemFactory::setup
]. After this signal was emitted on a listitem, the listitem will be destroyed and not be used again.
- [signal
Note that during the signal emissions, changing properties on the
GtkListItem
s passed will not trigger notify signals as the listitem’s notifications are frozen. Seeg_object_freeze_notify()
for details.For tracking changes in other properties in the
GtkListItem
, thenotify
signal is recommended. The signal can be connected in the [signalGtk.SignalListItemFactory::setup
] signal and removed again during [signalGtk.SignalListItemFactory::teardown
].The
See moreSignalListItemFactoryProtocol
protocol exposes the methods and properties of an underlyingGtkSignalListItemFactory
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeSignalListItemFactory
. Alternatively, useSignalListItemFactoryRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol SignalListItemFactoryProtocol : ListItemFactoryProtocol
-
GtkSingleSelection
is aGtkSelectionModel
that allows selecting a single item.Note that the selection is persistent – if the selected item is removed and re-added in the same
items-changed
emission, it stays selected. In particular, this means that changing the sort order of an underlying sort model will preserve the selection.The
See moreSingleSelectionProtocol
protocol exposes the methods and properties of an underlyingGtkSingleSelection
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeSingleSelection
. Alternatively, useSingleSelectionRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol SingleSelectionProtocol : ObjectProtocol, SelectionModelProtocol
-
GtkSizeGroup
groups widgets together so they all request the same size.This is typically useful when you want a column of widgets to have the same size, but you can’t use a
GtkGrid
.In detail, the size requested for each widget in a
GtkSizeGroup
is the maximum of the sizes that would have been requested for each widget in the size group if they were not in the size group. The mode of the size group (see [methodGtk.SizeGroup.set_mode
]) determines whether this applies to the horizontal size, the vertical size, or both sizes.Note that size groups only affect the amount of space requested, not the size that the widgets finally receive. If you want the widgets in a
GtkSizeGroup
to actually be the same size, you need to pack them in such a way that they get the size they request and not more.GtkSizeGroup
objects are referenced by each widget in the size group, so once you have added all widgets to aGtkSizeGroup
, you can drop the initial reference to the size group withg_object_unref()
. If the widgets in the size group are subsequently destroyed, then they will be removed from the size group and drop their references on the size group; when all widgets have been removed, the size group will be freed.Widgets can be part of multiple size groups; GTK will compute the horizontal size of a widget from the horizontal requisition of all widgets that can be reached from the widget by a chain of size groups of type
GTK_SIZE_GROUP_HORIZONTAL
orGTK_SIZE_GROUP_BOTH
, and the vertical size from the vertical requisition of all widgets that can be reached from the widget by a chain of size groups of typeGTK_SIZE_GROUP_VERTICAL
orGTK_SIZE_GROUP_BOTH
.Note that only non-contextual sizes of every widget are ever consulted by size groups (since size groups have no knowledge of what size a widget will be allocated in one dimension, it cannot derive how much height a widget will receive for a given width). When grouping widgets that trade height for width in mode
GTK_SIZE_GROUP_VERTICAL
orGTK_SIZE_GROUP_BOTH:
the height for the minimum width will be the requested height for all widgets in the group. The same is of course true when horizontally grouping width for height widgets.Widgets that trade height-for-width should set a reasonably large minimum width by way of [property
Gtk.Label:width-chars
] for instance. Widgets with static sizes as well as widgets that grow (such as ellipsizing text) need no such considerations.GtkSizeGroup as GtkBuildable
Size groups can be specified in a UI definition by placing an <object> element with
class="GtkSizeGroup"
somewhere in the UI definition. The widgets that belong to the size group are specified by a <widgets> element that may contain multiple <widget> elements, one for each member of the size group. The ”name” attribute gives the id of the widget.An example of a UI definition fragment with
GtkSizeGroup
:<object class="GtkSizeGroup"> <property name="mode">horizontal</property> <widgets> <widget name="radio1"/> <widget name="radio2"/> </widgets> </object>
The
See moreSizeGroupProtocol
protocol exposes the methods and properties of an underlyingGtkSizeGroup
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeSizeGroup
. Alternatively, useSizeGroupRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol SizeGroupProtocol : ObjectProtocol, BuildableProtocol
-
GtkSliceListModel
is a list model that presents a slice of another model.This is useful when implementing paging by setting the size to the number of elements per page and updating the offset whenever a different page is opened.
The
See moreSliceListModelProtocol
protocol exposes the methods and properties of an underlyingGtkSliceListModel
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeSliceListModel
. Alternatively, useSliceListModelRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol SliceListModelProtocol : ListModelProtocol, ObjectProtocol
-
GtkSnapshot
assists in creatingGskRenderNodes
for widgets.It functions in a similar way to a cairo context, and maintains a stack of render nodes and their associated transformations.
The node at the top of the stack is the the one that gtk_snapshot_append_… functions operate on. Use the gtk_snapshot_push_… functions and
gtk_snapshot_pop()
to change the current node.The typical way to obtain a
GtkSnapshot
object is as an argument to the [vfuncGtk.Widget.snapshot
] vfunc. If you need to create your ownGtkSnapshot
, use [ctorGtk.Snapshot.new
].The
See moreSnapshotProtocol
protocol exposes the methods and properties of an underlyingGtkSnapshot
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeSnapshot
. Alternatively, useSnapshotRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol SnapshotProtocol : SnapshotProtocol
-
A
GListModel
that sorts the elements of an underlying model according to aGtkSorter
.The model can be set up to do incremental sorting, so that sorting long lists doesn’t block the UI. See [method
Gtk.SortListModel.set_incremental
] for details.GtkSortListModel
is a generic model and because of that it cannot take advantage of any external knowledge when sorting. If you run into performance issues withGtkSortListModel
, it is strongly recommended that you write your own sorting list model.The
See moreSortListModelProtocol
protocol exposes the methods and properties of an underlyingGtkSortListModel
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeSortListModel
. Alternatively, useSortListModelRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol SortListModelProtocol : ListModelProtocol, ObjectProtocol
-
GtkSorter
is an object to describe sorting criteria.Its primary user is [class
Gtk.SortListModel
]The model will use a sorter to determine the order in which its items should appear by calling [method
Gtk.Sorter.compare
] for pairs of items.Sorters may change their sorting behavior through their lifetime. In that case, they will emit the [signal
Gtk.Sorter::changed
] signal to notify that the sort order is no longer valid and should be updated by callinggtk_sorter_compare()
again.GTK provides various pre-made sorter implementations for common sorting operations. [class
Gtk.ColumnView
] has built-in support for sorting lists via the [propertyGtk.ColumnViewColumn:sorter
] property, where the user can change the sorting by clicking on list headers.Of course, in particular for large lists, it is also possible to subclass
GtkSorter
and provide one’s own sorter.The
See moreSorterProtocol
protocol exposes the methods and properties of an underlyingGtkSorter
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeSorter
. Alternatively, useSorterRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol SorterProtocol : ObjectProtocol
-
A
GtkSpinButton
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
GtkEntry
,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.The main properties of a
GtkSpinButton
are through an adjustment. See the [classGtk.Adjustment
] documentation for more details about an adjustment’s properties.Note that
GtkSpinButton
will by default make its entry large enough to accommodate the lower and upper bounds of the adjustment. If this is not desired, the automatic sizing can be turned off by explicitly setting [propertyGtk.Editable:width-chars
] to a value != -1.Using a GtkSpinButton to get an integer
// Provides a function to retrieve an integer value from a GtkSpinButton // and creates a spin button to model percentage values. int grab_int_value (GtkSpinButton *button, gpointer user_data) { return gtk_spin_button_get_value_as_int (button); } void create_integer_spin_button (void) { GtkWidget *window, *button; GtkAdjustment *adjustment; adjustment = gtk_adjustment_new (50.0, 0.0, 100.0, 1.0, 5.0, 0.0); window = gtk_window_new (); // creates the spinbutton, with no decimal places button = gtk_spin_button_new (adjustment, 1.0, 0); gtk_window_set_child (GTK_WINDOW (window), button); gtk_widget_show (window); }
Using a GtkSpinButton to get a floating point value
// Provides a function to retrieve a floating point value from a // GtkSpinButton, and creates a high precision spin button. float grab_float_value (GtkSpinButton *button, gpointer user_data) { return gtk_spin_button_get_value (button); } void create_floating_spin_button (void) { GtkWidget *window, *button; GtkAdjustment *adjustment; adjustment = gtk_adjustment_new (2.500, 0.0, 5.0, 0.001, 0.1, 0.0); window = gtk_window_new (); // creates the spinbutton, with three decimal places button = gtk_spin_button_new (adjustment, 0.001, 3); gtk_window_set_child (GTK_WINDOW (window), button); gtk_widget_show (window); }
CSS nodes
spinbutton.horizontal ├── text │ ├── undershoot.left │ ╰── undershoot.right ├── button.down ╰── button.up
spinbutton.vertical ├── button.up ├── text │ ├── undershoot.left │ ╰── undershoot.right ╰── button.down
GtkSpinButton
s main CSS node has the name spinbutton. It creates subnodes for the entry and the two buttons, with these names. The button nodes have the style classes .up and .down. TheGtkText
subnodes (if present) are put below the text node. The orientation of the spin button is reflected in the .vertical or .horizontal style class on the main node.Accessiblity
GtkSpinButton
uses theGTK_ACCESSIBLE_ROLE_SPIN_BUTTON
role.The
See moreSpinButtonProtocol
protocol exposes the methods and properties of an underlyingGtkSpinButton
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeSpinButton
. Alternatively, useSpinButtonRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol SpinButtonProtocol : CellEditableProtocol, EditableProtocol, OrientableProtocol
-
A
GtkSpinner
widget displays an icon-size spinning animation.It is often used as an alternative to a [class
Gtk.ProgressBar
] for displaying indefinite activity, instead of actual progress.To start the animation, use [method
Gtk.Spinner.start
], to stop it use [methodGtk.Spinner.stop
].CSS nodes
GtkSpinner
has a single CSS node with the name spinner. When the animation is active, the :checked pseudoclass is added to this node.The
See moreSpinnerProtocol
protocol exposes the methods and properties of an underlyingGtkSpinner
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeSpinner
. Alternatively, useSpinnerRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol SpinnerProtocol : WidgetProtocol
-
GtkStack
is a container which only shows one of its children at a time.In contrast to
GtkNotebook
,GtkStack
does not provide a means for users to change the visible child. Instead, a separate widget such as [classGtk.StackSwitcher
] or [classGtk.StackSidebar
] can be used withGtkStack
to provide this functionality.Transitions between pages can be animated as slides or fades. This can be controlled with [method
Gtk.Stack.set_transition_type
]. These animations respect the [propertyGtk.Settings:gtk-enable-animations
] setting.GtkStack
maintains a [classGtk.StackPage
] object for each added child, which holds additional per-child properties. You obtain theGtkStackPage
for a child with [methodGtk.Stack.get_page
] and you can obtain aGtkSelectionModel
containing all the pages with [methodGtk.Stack.get_pages
].GtkStack as GtkBuildable
To set child-specific properties in a .ui file, create
GtkStackPage
objects explicitly, and set the child widget as a property on it:<object class="GtkStack" id="stack"> <child> <object class="GtkStackPage"> <property name="name">page1</property> <property name="title">In the beginning…</property> <property name="child"> <object class="GtkLabel"> <property name="label">It was dark</property> </object> </property> </object> </child>
CSS nodes
GtkStack
has a single CSS node named stack.Accessibility
GtkStack
uses theGTK_ACCESSIBLE_ROLE_TAB_PANEL
for the stack pages, which are the accessible parent objects of the child widgets.The
See moreStackProtocol
protocol exposes the methods and properties of an underlyingGtkStack
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeStack
. Alternatively, useStackRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol StackProtocol : WidgetProtocol
-
GtkStackPage
is an auxiliary class used byGtkStack
.The
See moreStackPageProtocol
protocol exposes the methods and properties of an underlyingGtkStackPage
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeStackPage
. Alternatively, useStackPageRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol StackPageProtocol : ObjectProtocol, AccessibleProtocol
-
A
GtkStackSidebar
uses a sidebar to switch betweenGtkStack
pages.In order to use a
GtkStackSidebar
, you simply use aGtkStack
to organize your UI flow, and add the sidebar to your sidebar area. You can use [methodGtk.StackSidebar.set_stack
] to connect theGtkStackSidebar
to theGtkStack
.CSS nodes
GtkStackSidebar
has a single CSS node with name stacksidebar and style class .sidebar.When circumstances require it,
GtkStackSidebar
adds the .needs-attention style class to the widgets representing the stack pages.The
See moreStackSidebarProtocol
protocol exposes the methods and properties of an underlyingGtkStackSidebar
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeStackSidebar
. Alternatively, useStackSidebarRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol StackSidebarProtocol : WidgetProtocol
-
The
GtkStackSwitcher
shows a row of buttons to switch betweenGtkStack
pages.It acts as a controller for the associated
GtkStack
.All the content for the buttons comes from the properties of the stacks [class
Gtk.StackPage
] objects; the button visibility in aGtkStackSwitcher
widget is controlled by the visibility of the child in theGtkStack
.It is possible to associate multiple
GtkStackSwitcher
widgets with the sameGtkStack
widget.CSS nodes
GtkStackSwitcher
has a single CSS node named stackswitcher and style class .stack-switcher.When circumstances require it,
GtkStackSwitcher
adds the .needs-attention style class to the widgets representing the stack pages.Accessibility
GtkStackSwitcher
uses theGTK_ACCESSIBLE_ROLE_TAB_LIST
role and uses theGTK_ACCESSIBLE_ROLE_TAB
for its buttons.Orientable
Since GTK 4.4,
GtkStackSwitcher
implementsGtkOrientable
allowing the stack switcher to be made vertical withgtk_orientable_set_orientation()
.The
See moreStackSwitcherProtocol
protocol exposes the methods and properties of an underlyingGtkStackSwitcher
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeStackSwitcher
. Alternatively, useStackSwitcherRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol StackSwitcherProtocol : OrientableProtocol, WidgetProtocol
-
A
GtkStatusbar
widget is usually placed along the bottom of an application’s main [classGtk.Window
].A
GtkStatusBar
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).Status bars in GTK maintain a stack of messages. The message at the top of the each bar’s stack is the one that will currently be displayed.
Any messages added to a statusbar’s stack must specify a context id that is used to uniquely identify the source of a message. This context id can be generated by [method
Gtk.Statusbar.get_context_id
], given a message and the statusbar that it will be added to. Note that messages are stored in a stack, and when choosing which message to display, the stack structure is adhered to, regardless of the context identifier of a message.One could say that a statusbar maintains one stack of messages for display purposes, but allows multiple message producers to maintain sub-stacks of the messages they produced (via context ids).
Status bars are created using [ctor
Gtk.Statusbar.new
].Messages are added to the bar’s stack with [method
Gtk.Statusbar.push
].The message at the top of the stack can be removed using [method
Gtk.Statusbar.pop
]. A message can be removed from anywhere in the stack if its message id was recorded at the time it was added. This is done using [methodGtk.Statusbar.remove
].CSS node
GtkStatusbar
has a single CSS node with namestatusbar
.The
See moreStatusbarProtocol
protocol exposes the methods and properties of an underlyingGtkStatusbar
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeStatusbar
. Alternatively, useStatusbarRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol StatusbarProtocol : WidgetProtocol
-
GtkStringFilter
determines whether to include items by comparing strings to a fixed search term.The strings are obtained from the items by evaluating a
GtkExpression
set with [methodGtk.StringFilter.set_expression
], and they are compared against a search term set with [methodGtk.StringFilter.set_search
].GtkStringFilter
has several different modes of comparison - it can match the whole string, just a prefix, or any substring. Use [methodGtk.StringFilter.set_match_mode
] choose a mode.It is also possible to make case-insensitive comparisons, with [method
Gtk.StringFilter.set_ignore_case
].The
See moreStringFilterProtocol
protocol exposes the methods and properties of an underlyingGtkStringFilter
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeStringFilter
. Alternatively, useStringFilterRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol StringFilterProtocol : FilterProtocol
-
GtkStringList
is a list model that wraps an array of strings.The objects in the model have a “string” property.
GtkStringList
is well-suited for any place where you would typically use achar*[]
, but need a list model.GtkStringList as GtkBuildable
The
GtkStringList
implementation of theGtkBuildable
interface supports adding items directly using the <items> element and specifying <item> elements for each item. Each <item> element supports the regular translation attributes “translatable”, “context” and “comments”.Here is a UI definition fragment specifying a
GtkStringList
<object class="GtkStringList"> <items> <item translatable="yes">Factory</item> <item translatable="yes">Home</item> <item translatable="yes">Subway</item> </items> </object>
The
See moreStringListProtocol
protocol exposes the methods and properties of an underlyingGtkStringList
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeStringList
. Alternatively, useStringListRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol StringListProtocol : ListModelProtocol, ObjectProtocol, BuildableProtocol
-
GtkStringObject
is the type of items in aGtkStringList
.A
GtkStringObject
is a wrapper around aconst char*
; it has a [propertyGtk.StringObject:string
] property.The
See moreStringObjectProtocol
protocol exposes the methods and properties of an underlyingGtkStringObject
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeStringObject
. Alternatively, useStringObjectRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol StringObjectProtocol : ObjectProtocol
-
GtkStringSorter
is aGtkSorter
that compares strings.It does the comparison in a linguistically correct way using the current locale by normalizing Unicode strings and possibly case-folding them before performing the comparison.
To obtain the strings to compare, this sorter evaluates a [class
Gtk.Expression
].The
See moreStringSorterProtocol
protocol exposes the methods and properties of an underlyingGtkStringSorter
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeStringSorter
. Alternatively, useStringSorterRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol StringSorterProtocol : SorterProtocol
-
GtkStyleContext
stores styling information affecting a widget.In order to construct the final style information,
GtkStyleContext
queries information from all attachedGtkStyleProviders
. Style providers can be either attached explicitly to the context through [methodGtk.StyleContext.add_provider
], or to the display through [funcGtk.StyleContext.add_provider_for_display
]. The resulting style is a combination of all providers’ information in priority order.For GTK widgets, any
GtkStyleContext
returned by [methodGtk.Widget.get_style_context
] will already have aGdkDisplay
and RTL/LTR information set. The style context will also be updated automatically if any of these settings change on the widget.Style Classes
Widgets can add style classes to their context, which can be used to associate different styles by class. The documentation for individual widgets lists which style classes it uses itself, and which style classes may be added by applications to affect their appearance.
Custom styling in UI libraries and applications
If you are developing a library with custom widgets that render differently than standard components, you may need to add a
GtkStyleProvider
yourself with theGTK_STYLE_PROVIDER_PRIORITY_FALLBACK
priority, either aGtkCssProvider
or a custom object implementing theGtkStyleProvider
interface. This way themes may still attempt to style your UI elements in a different way if needed so.If you are using custom styling on an applications, you probably want then to make your style information prevail to the theme’s, so you must use a
GtkStyleProvider
with theGTK_STYLE_PROVIDER_PRIORITY_APPLICATION
priority, keep in mind that the user settings inXDG_CONFIG_HOME/gtk-4.0/gtk.css
will still take precedence over your changes, as it uses theGTK_STYLE_PROVIDER_PRIORITY_USER
priority.The
See moreStyleContextProtocol
protocol exposes the methods and properties of an underlyingGtkStyleContext
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeStyleContext
. Alternatively, useStyleContextRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol StyleContextProtocol : ObjectProtocol
-
GtkSwitch
is a “light switch” 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.
GtkSwitch
can also handle situations where the underlying state changes with a delay. See [signalGtkSwitch::state-set
] for details.CSS nodes
switch ├── label ├── label ╰── slider
GtkSwitch
has four css nodes, the main node with the name switch and subnodes for the slider and the on and off labels. Neither of them is using any style classes.Accessibility
GtkSwitch
uses theGTK_ACCESSIBLE_ROLE_SWITCH
role.The
See moreSwitchProtocol
protocol exposes the methods and properties of an underlyingGtkSwitch
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeSwitch
. Alternatively, useSwitchRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol SwitchProtocol : ActionableProtocol
-
The
GtkText
widget is a single-line text entry widget.GtkText
is the common implementation of single-line text editing that is shared betweenGtkEntry
,GtkPasswordEntry
,GtkSpinButton
and other widgets. In all of these,GtkText
is used as the delegate for the [ifaceGtk.Editable
] implementation.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.
When using an entry for passwords and other sensitive information, it can be put into “password mode” using [method
Gtk.Text.set_visibility
]. In this mode, entered text is displayed using a “invisible” character. By default, GTK picks the best invisible character that is available in the current font, but it can be changed with [methodGtk.Text.set_invisible_char
].If you are looking to add icons or progress display in an entry, look at
GtkEntry
. There other alternatives for more specialized use cases, such asGtkSearchEntry
.If you need multi-line editable text, look at
GtkTextView
.CSS nodes
text[.read-only] ├── placeholder ├── undershoot.left ├── undershoot.right ├── [selection] ├── [block-cursor] ╰── [window.popup]
GtkText
has a main node with the name text. Depending on the properties of the widget, the .read-only style class may appear.When the entry has a selection, it adds a subnode with the name selection.
When the entry is in overwrite mode, it adds a subnode with the name block-cursor that determines how the block cursor is drawn.
The CSS node for a context menu is added as a subnode below text as well.
The undershoot nodes are used to draw the underflow indication when content is scrolled out of view. These nodes get the .left and .right style classes added depending on where the indication is drawn.
When touch is used and touch selection handles are shown, they are using CSS nodes with name cursor-handle. They get the .top or .bottom style class depending on where they are shown in relation to the selection. If there is just a single handle for the text cursor, it gets the style class .insertion-cursor.
Accessibility
GtkText
uses theGTK_ACCESSIBLE_ROLE_NONE
role, which causes it to be skipped for accessibility. This is becauseGtkText
is expected to be used as a delegate for aGtkEditable
implementation that will be represented to accessibility.The
See moreTextProtocol
protocol exposes the methods and properties of an underlyingGtkText
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeText
. Alternatively, useTextRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol TextProtocol : EditableProtocol
-
The
See moreScaleClassProtocol
protocol exposes the methods and properties of an underlyingGtkScaleClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeScaleClass
. Alternatively, useScaleClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ScaleClassProtocol
-
The
See moreScrollableInterfaceProtocol
protocol exposes the methods and properties of an underlyingGtkScrollableInterface
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeScrollableInterface
. Alternatively, useScrollableInterfaceRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ScrollableInterfaceProtocol
-
The
See moreSelectionFilterModelClassProtocol
protocol exposes the methods and properties of an underlyingGtkSelectionFilterModelClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeSelectionFilterModelClass
. Alternatively, useSelectionFilterModelClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol SelectionFilterModelClassProtocol
-
The list of virtual functions for the
GtkSelectionModel
interface. No function must be implemented, but unlessGtkSelectionModel
is_selected()
is implemented, it will not be possible to select items in the set.The model does not need to implement any functions to support either selecting or unselecting items. Of course, if the model does not do that, it means that users cannot select or unselect items in a list widget using the model.
All selection functions fall back to
GtkSelectionModel
set_selection()
so it is sufficient to implement just that function for full selection support.The
See moreSelectionModelInterfaceProtocol
protocol exposes the methods and properties of an underlyingGtkSelectionModelInterface
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeSelectionModelInterface
. Alternatively, useSelectionModelInterfaceRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol SelectionModelInterfaceProtocol
-
The
See moreShortcutActionClassProtocol
protocol exposes the methods and properties of an underlyingGtkShortcutActionClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeShortcutActionClass
. Alternatively, useShortcutActionClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ShortcutActionClassProtocol
-
The
See moreShortcutClassProtocol
protocol exposes the methods and properties of an underlyingGtkShortcutClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeShortcutClass
. Alternatively, useShortcutClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ShortcutClassProtocol
-
The
See moreShortcutControllerClassProtocol
protocol exposes the methods and properties of an underlyingGtkShortcutControllerClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeShortcutControllerClass
. Alternatively, useShortcutControllerClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ShortcutControllerClassProtocol
-
The
See moreShortcutLabelClassProtocol
protocol exposes the methods and properties of an underlyingGtkShortcutLabelClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeShortcutLabelClass
. Alternatively, useShortcutLabelClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ShortcutLabelClassProtocol
-
The list of functions that can be implemented for the
GtkShortcutManager
interface.Note that no function is mandatory to implement, the default implementation will work fine.
The
See moreShortcutManagerInterfaceProtocol
protocol exposes the methods and properties of an underlyingGtkShortcutManagerInterface
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeShortcutManagerInterface
. Alternatively, useShortcutManagerInterfaceRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ShortcutManagerInterfaceProtocol
-
The
See moreShortcutTriggerClassProtocol
protocol exposes the methods and properties of an underlyingGtkShortcutTriggerClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeShortcutTriggerClass
. Alternatively, useShortcutTriggerClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ShortcutTriggerClassProtocol
-
The
See moreShortcutsGroupClassProtocol
protocol exposes the methods and properties of an underlyingGtkShortcutsGroupClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeShortcutsGroupClass
. Alternatively, useShortcutsGroupClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ShortcutsGroupClassProtocol
-
The
See moreShortcutsSectionClassProtocol
protocol exposes the methods and properties of an underlyingGtkShortcutsSectionClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeShortcutsSectionClass
. Alternatively, useShortcutsSectionClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ShortcutsSectionClassProtocol
-
The
See moreShortcutsShortcutClassProtocol
protocol exposes the methods and properties of an underlyingGtkShortcutsShortcutClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeShortcutsShortcutClass
. Alternatively, useShortcutsShortcutClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ShortcutsShortcutClassProtocol
-
The
See moreSignalActionClassProtocol
protocol exposes the methods and properties of an underlyingGtkSignalActionClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeSignalActionClass
. Alternatively, useSignalActionClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol SignalActionClassProtocol
-
The
See moreSignalListItemFactoryClassProtocol
protocol exposes the methods and properties of an underlyingGtkSignalListItemFactoryClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeSignalListItemFactoryClass
. Alternatively, useSignalListItemFactoryClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol SignalListItemFactoryClassProtocol
-
The
See moreSingleSelectionClassProtocol
protocol exposes the methods and properties of an underlyingGtkSingleSelectionClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeSingleSelectionClass
. Alternatively, useSingleSelectionClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol SingleSelectionClassProtocol
-
The
See moreSliceListModelClassProtocol
protocol exposes the methods and properties of an underlyingGtkSliceListModelClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeSliceListModelClass
. Alternatively, useSliceListModelClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol SliceListModelClassProtocol
-
The
See moreSnapshotClassProtocol
protocol exposes the methods and properties of an underlyingGtkSnapshotClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeSnapshotClass
. Alternatively, useSnapshotClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol SnapshotClassProtocol
-
The
See moreSortListModelClassProtocol
protocol exposes the methods and properties of an underlyingGtkSortListModelClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeSortListModelClass
. Alternatively, useSortListModelClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol SortListModelClassProtocol
-
The virtual table for
GtkSorter
.The
See moreSorterClassProtocol
protocol exposes the methods and properties of an underlyingGtkSorterClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeSorterClass
. Alternatively, useSorterClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol SorterClassProtocol
-
The
See moreStringFilterClassProtocol
protocol exposes the methods and properties of an underlyingGtkStringFilterClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeStringFilterClass
. Alternatively, useStringFilterClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol StringFilterClassProtocol
-
The
See moreStringListClassProtocol
protocol exposes the methods and properties of an underlyingGtkStringListClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeStringListClass
. Alternatively, useStringListClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol StringListClassProtocol
-
The
See moreStringObjectClassProtocol
protocol exposes the methods and properties of an underlyingGtkStringObjectClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeStringObjectClass
. Alternatively, useStringObjectClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol StringObjectClassProtocol
-
The
See moreStringSorterClassProtocol
protocol exposes the methods and properties of an underlyingGtkStringSorterClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeStringSorterClass
. Alternatively, useStringSorterClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol StringSorterClassProtocol
-
The
See moreStyleContextClassProtocol
protocol exposes the methods and properties of an underlyingGtkStyleContextClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeStyleContextClass
. Alternatively, useStyleContextClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol StyleContextClassProtocol
-
The class structure for
GtkTextBuffer
.The
See moreTextBufferClassProtocol
protocol exposes the methods and properties of an underlyingGtkTextBufferClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeTextBufferClass
. Alternatively, useTextBufferClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol TextBufferClassProtocol
-
GtkSelectionModel
is an interface that add support for selection to list models.This support is then used by widgets using list models to add the ability to select and unselect various items.
GTK provides default implementations of the most common selection modes such as [class
Gtk.SingleSelection
], so you will only need to implement this interface if you want detailed control about how selections should be handled.A
GtkSelectionModel
supports a single boolean per item indicating if an item is selected or not. This can be queried via [methodGtk.SelectionModel.is_selected
]. When the selected state of one or more items changes, the model will emit the [signalGtk.SelectionModel::selection-changed
] signal by calling the [methodGtk.SelectionModel.selection_changed
] function. The positions given in that signal may have their selection state changed, though that is not a requirement. If new items added to the model via theitems-changed
signal are selected or not is up to the implementation.Note that items added via
items-changed
may already be selected and no [Gtk.SelectionModelselection-changed
] will be emitted for them. So to track which items are selected, it is necessary to listen to both signals.Additionally, the interface can expose functionality to select and unselect items. If these functions are implemented, GTK’s list widgets will allow users to select and unselect items. However,
GtkSelectionModel
s are free to only implement them partially or not at all. In that case the widgets will not support the unimplemented operations.When selecting or unselecting is supported by a model, the return values of the selection functions do not indicate if selection or unselection happened. They are only meant to indicate complete failure, like when this mode of selecting is not supported by the model.
Selections may happen asynchronously, so the only reliable way to find out when an item was selected is to listen to the signals that indicate selection.
The
See moreSelectionModelProtocol
protocol exposes the methods and properties of an underlyingGtkSelectionModel
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeSelectionModel
. Alternatively, useSelectionModelRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol SelectionModelProtocol : ListModelProtocol
-
The
GtkShortcutManager
interface is used to implement shortcut scopes.This is important for [iface
Gtk.Native
] widgets that have their own surface, since the event controllers that are used to implement managed and global scopes are limited to the same native.Examples for widgets implementing
GtkShortcutManager
are [classGtk.Window
] and [classGtk.Popover
].Every widget that implements
GtkShortcutManager
will be used as aGTK_SHORTCUT_SCOPE_MANAGED
.The
See moreShortcutManagerProtocol
protocol exposes the methods and properties of an underlyingGtkShortcutManager
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeShortcutManager
. Alternatively, useShortcutManagerRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ShortcutManagerProtocol
-
GtkStyleProvider
is an interface for style information used byGtkStyleContext
.See [method
Gtk.StyleContext.add_provider
] and [funcGtk.StyleContext.add_provider_for_display
] for addingGtkStyleProviders
.GTK uses the
GtkStyleProvider
implementation for CSS in [ifaceGtk.CssProvider
].The
See moreStyleProviderProtocol
protocol exposes the methods and properties of an underlyingGtkStyleProvider
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeStyleProvider
. Alternatively, useStyleProviderRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol StyleProviderProtocol
-
Interface for Drag-and-Drop destinations in
GtkTreeView
.The
See moreTreeDragDestProtocol
protocol exposes the methods and properties of an underlyingGtkTreeDragDest
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeTreeDragDest
. Alternatively, useTreeDragDestRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol TreeDragDestProtocol
-
Stores text and attributes for display in a
GtkTextView
.You may wish to begin by reading the text widget conceptual overview, which gives an overview of all the objects and data types related to the text widget and how they work together.
GtkTextBuffer can support undoing changes to the buffer content, see [method
Gtk.TextBuffer.set_enable_undo
].The
See moreTextBufferProtocol
protocol exposes the methods and properties of an underlyingGtkTextBuffer
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeTextBuffer
. Alternatively, useTextBufferRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol TextBufferProtocol : ObjectProtocol
-
A
GtkTextChildAnchor
is a spot in aGtkTextBuffer
where child widgets can be “anchored”.The anchor can have multiple widgets anchored, to allow for multiple views.
The
See moreTextChildAnchorProtocol
protocol exposes the methods and properties of an underlyingGtkTextChildAnchor
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeTextChildAnchor
. Alternatively, useTextChildAnchorRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol TextChildAnchorProtocol : ObjectProtocol
-
A
GtkTextMark
is a position in aGtkTextbuffer
that is preserved across modifications.You may wish to begin by reading the text widget conceptual overview, which gives an overview of all the objects and data types related to the text widget and how they work together.
A
GtkTextMark
is like a bookmark in a text buffer; it preserves a position in the text. You can convert the mark to an iterator using [methodGtk.TextBuffer.get_iter_at_mark
]. Unlike iterators, marks remain valid across buffer mutations, because their behavior is defined when text is inserted or deleted. When text containing a mark is deleted, the mark remains in the position originally occupied by the deleted text. When text is inserted at a mark, a mark with “left gravity” will be moved to the beginning of the newly-inserted text, and a mark with “right gravity” will be moved to the end.Note that “left” and “right” here refer to logical direction (left is the toward the start of the buffer); in some languages such as Hebrew the logically-leftmost text is not actually on the left when displayed.
Marks are reference counted, but the reference count only controls the validity of the memory; marks can be deleted from the buffer at any time with [method
Gtk.TextBuffer.delete_mark
]. Once deleted from the buffer, a mark is essentially useless.Marks optionally have names; these can be convenient to avoid passing the
GtkTextMark
object around.Marks are typically created using the [method
Gtk.TextBuffer.create_mark
] function.The
See moreTextMarkProtocol
protocol exposes the methods and properties of an underlyingGtkTextMark
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeTextMark
. Alternatively, useTextMarkRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol TextMarkProtocol : ObjectProtocol
-
A tag that can be applied to text contained in a
GtkTextBuffer
.You may wish to begin by reading the text widget conceptual overview, which gives an overview of all the objects and data types related to the text widget and how they work together.
Tags should be in the [class
Gtk.TextTagTable
] for a givenGtkTextBuffer
before using them with that buffer.[method
Gtk.TextBuffer.create_tag
] is the best way to create tags. See “gtk4-demo” for numerous examples.For each property of
GtkTextTag
, there is a “set” property, e.g. “font-set” corresponds to “font”. These “set” properties reflect whether a property has been set or not.They are maintained by GTK and you should not set them independently.
The
See moreTextTagProtocol
protocol exposes the methods and properties of an underlyingGtkTextTag
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeTextTag
. Alternatively, useTextTagRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol TextTagProtocol : ObjectProtocol
-
The collection of tags in a
GtkTextBuffer
You may wish to begin by reading the text widget conceptual overview, which gives an overview of all the objects and data types related to the text widget and how they work together.
GtkTextTagTables as GtkBuildable
The
GtkTextTagTable
implementation of theGtkBuildable
interface supports adding tags by specifying “tag” as the “type” attribute of a <child> element.An example of a UI definition fragment specifying tags:
<object class="GtkTextTagTable"> <child type="tag"> <object class="GtkTextTag"/> </child> </object>
The
See moreTextTagTableProtocol
protocol exposes the methods and properties of an underlyingGtkTextTagTable
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeTextTagTable
. Alternatively, useTextTagTableRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol TextTagTableProtocol : ObjectProtocol, BuildableProtocol
-
A widget that displays the contents of a [class
Gtk.TextBuffer
].You may wish to begin by reading the conceptual overview, which gives an overview of all the objects and data types related to the text widget and how they work together.
CSS nodes
textview.view ├── border.top ├── border.left ├── text │ ╰── [selection] ├── border.right ├── border.bottom ╰── [window.popup]
GtkTextView
has a main css node with name textview and style class .view, and subnodes for each of the border windows, and the main text area, with names border and text, respectively. The border nodes each get one of the style classes .left, .right, .top or .bottom.A node representing the selection will appear below the text node.
If a context menu is opened, the window node will appear as a subnode of the main node.
Accessibility
GtkTextView
uses theGTK_ACCESSIBLE_ROLE_TEXT_BOX
role.The
See moreTextViewProtocol
protocol exposes the methods and properties of an underlyingGtkTextView
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeTextView
. Alternatively, useTextViewRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol TextViewProtocol : ScrollableProtocol, WidgetProtocol
-
A
GtkToggleButton
is a button which remains “pressed-in” when clicked.Clicking again will cause the toggle button to return to its normal state.
A toggle button is created by calling either [ctor
Gtk.ToggleButton.new
] or [ctorGtk.ToggleButton.new_with_label
]. If using the former, it is advisable to pack a widget, (such as aGtkLabel
and/or aGtkImage
), into the toggle button’s container. (See [classGtk.Button
] for more information).The state of a
GtkToggleButton
can be set specifically using [methodGtk.ToggleButton.set_active
], and retrieved using [methodGtk.ToggleButton.get_active
].To simply switch the state of a toggle button, use [method
Gtk.ToggleButton.toggled
].Grouping
Toggle buttons can be grouped together, to form mutually exclusive groups - only one of the buttons can be toggled at a time, and toggling another one will switch the currently toggled one off.
To add a
GtkToggleButton
to a group, use [methodGtk.ToggleButton.set_group
].CSS nodes
GtkToggleButton
has a single CSS node with name button. To differentiate it from a plainGtkButton
, it gets the .toggle style class.Creating two
GtkToggleButton
widgets.static void output_state (GtkToggleButton *source, gpointer user_data) { printf ("Active: `d`\n", gtk_toggle_button_get_active (source)); } void make_toggles (void) { GtkWidget *window, *toggle1, *toggle2; GtkWidget *box; const char *text; window = gtk_window_new (); box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12); text = "Hi, I’m a toggle button."; toggle1 = gtk_toggle_button_new_with_label (text); g_signal_connect (toggle1, "toggled", G_CALLBACK (output_state), NULL); gtk_box_append (GTK_BOX (box), toggle1); text = "Hi, I’m a toggle button."; toggle2 = gtk_toggle_button_new_with_label (text); g_signal_connect (toggle2, "toggled", G_CALLBACK (output_state), NULL); gtk_box_append (GTK_BOX (box), toggle2); gtk_window_set_child (GTK_WINDOW (window), box); gtk_widget_show (window); }
The
See moreToggleButtonProtocol
protocol exposes the methods and properties of an underlyingGtkToggleButton
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeToggleButton
. Alternatively, useToggleButtonRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ToggleButtonProtocol : ButtonProtocol
-
GtkTooltip
is an object representing a widget tooltip.Basic tooltips can be realized simply by using [method
Gtk.Widget.set_tooltip_text
] or [methodGtk.Widget.set_tooltip_markup
] without any explicit tooltip object.When you need a tooltip with a little more fancy contents, like adding an image, or you want the tooltip to have different contents per
GtkTreeView
row or cell, you will have to do a little more work:Set the [property
Gtk.Widget:has-tooltip
] property totrue
. This will make GTK monitor the widget for motion and related events which are needed to determine when and where to show a tooltip.Connect to the [signal
Gtk.Widget::query-tooltip
] signal. This signal will be emitted when a tooltip is supposed to be shown. One of the arguments passed to the signal handler is aGtkTooltip
object. This is the object that we are about to display as a tooltip, and can be manipulated in your callback using functions like [methodGtk.Tooltip.set_icon
]. There are functions for setting the tooltip’s markup, setting an image from a named icon, or even putting in a custom widget.Return
true
from yourquery-tooltip
handler. This causes the tooltip to be show. If you returnfalse
, it will not be shown.
The
See moreTooltipProtocol
protocol exposes the methods and properties of an underlyingGtkTooltip
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeTooltip
. Alternatively, useTooltipRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol TooltipProtocol : ObjectProtocol
-
GtkTreeExpander
is a widget that provides an expander for a list.It is typically placed as a bottommost child into a
GtkListView
to allow users to expand and collapse children in a list with a [classGtk.TreeListModel
].GtkTreeExpander
provides the common UI elements, gestures and keybindings for this purpose.On top of this, the “listitem.expand”, “listitem.collapse” and “listitem.toggle-expand” actions are provided to allow adding custom UI for managing expanded state.
The
GtkTreeListModel
must be set to not be passthrough. Then it will provide [classGtk.TreeListRow
] items which can be set via [methodGtk.TreeExpander.set_list_row
] on the expander. The expander will then watch that row item automatically. [methodGtk.TreeExpander.set_child
] sets the widget that displays the actual row contents.CSS nodes
treeexpander ├── [indent]* ├── [expander] ╰── <child>
GtkTreeExpander
has zero or one CSS nodes with the name “expander” that should display the expander icon. The node will be:checked
when it is expanded. If the node is not expandable, an “indent” node will be displayed instead.For every level of depth, another “indent” node is prepended.
Accessibility
GtkTreeExpander
uses theGTK_ACCESSIBLE_ROLE_GROUP
role. The expander icon is represented as aGTK_ACCESSIBLE_ROLE_BUTTON
, labelled by the expander’s child, and toggling it will change theGTK_ACCESSIBLE_STATE_EXPANDED
state.The
See moreTreeExpanderProtocol
protocol exposes the methods and properties of an underlyingGtkTreeExpander
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeTreeExpander
. Alternatively, useTreeExpanderRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol TreeExpanderProtocol : WidgetProtocol
-
GtkTreeListModel
is a list model that can create child models on demand.The
See moreTreeListModelProtocol
protocol exposes the methods and properties of an underlyingGtkTreeListModel
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeTreeListModel
. Alternatively, useTreeListModelRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol TreeListModelProtocol : ListModelProtocol, ObjectProtocol
-
GtkTreeListRow
is used byGtkTreeListModel
to represent items.It allows navigating the model as a tree and modify the state of rows.
GtkTreeListRow
instances are created by aGtkTreeListModel
only when the [propertyGtk.TreeListModel:passthrough
] property is not set.There are various support objects that can make use of
GtkTreeListRow
objects, such as the [classGtk.TreeExpander
] widget that allows displaying an icon to expand or collapse a row or [classGtk.TreeListRowSorter
] that makes it possible to sort trees properly.The
See moreTreeListRowProtocol
protocol exposes the methods and properties of an underlyingGtkTreeListRow
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeTreeListRow
. Alternatively, useTreeListRowRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol TreeListRowProtocol : ObjectProtocol
-
GtkTreeListRowSorter
is a special-purpose sorter that will apply a given sorter to the levels in a tree.Here is an example for setting up a column view with a tree model and a
GtkTreeListSorter
:column_sorter = gtk_column_view_get_sorter (view); sorter = gtk_tree_list_row_sorter_new (g_object_ref (column_sorter)); sort_model = gtk_sort_list_model_new (tree_model, sorter); selection = gtk_single_selection_new (sort_model); gtk_column_view_set_model (view, G_LIST_MODEL (selection));
The
See moreTreeListRowSorterProtocol
protocol exposes the methods and properties of an underlyingGtkTreeListRowSorter
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeTreeListRowSorter
. Alternatively, useTreeListRowSorterRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol TreeListRowSorterProtocol : SorterProtocol
-
A
GtkTreeModel
which hides parts of an underlying tree modelA
GtkTreeModelFilter
is a tree model which wraps another tree model, and can do the following things:Filter specific rows, based on data from a “visible column”, a column storing booleans indicating whether the row should be filtered or not, or based on the return value of a “visible function”, which gets a model, iter and user_data and returns a boolean indicating whether the row should be filtered or not.
Modify the “appearance” of the model, using a modify function. This is extremely powerful and allows for just changing some values and also for creating a completely different model based on the given child model.
Set a different root node, also known as a “virtual root”. You can pass in a
GtkTreePath
indicating the root node for the filter at construction time.
The basic API is similar to
GtkTreeModelSort
. For an example on its usage, see the section onGtkTreeModelSort
.When using
GtkTreeModelFilter
, it is important to realize thatGtkTreeModelFilter
maintains an internal cache of all nodes which are visible in its clients. The cache is likely to be a subtree of the tree exposed by the child model.GtkTreeModelFilter
will not cache the entire child model when unnecessary to not compromise the caching mechanism that is exposed by the reference counting scheme. If the child model implements reference counting, unnecessary signals may not be emitted because of reference counting rule 3, see theGtkTreeModel
documentation. (Note that e.g.GtkTreeStore
does not implement reference counting and will always emit all signals, even when the receiving node is not visible).Because of this, limitations for possible visible functions do apply. In general, visible functions should only use data or properties from the node for which the visibility state must be determined, its siblings or its parents. Usually, having a dependency on the state of any child node is not possible, unless references are taken on these explicitly. When no such reference exists, no signals may be received for these child nodes (see reference counting rule number 3 in the
GtkTreeModel
section).Determining the visibility state of a given node based on the state of its child nodes is a frequently occurring use case. Therefore,
GtkTreeModelFilter
explicitly supports this. For example, when a node does not have any children, you might not want the node to be visible. As soon as the first row is added to the node’s child level (or the last row removed), the node’s visibility should be updated.This introduces a dependency from the node on its child nodes. In order to accommodate this,
GtkTreeModelFilter
must make sure the necessary signals are received from the child model. This is achieved by building, for all nodes which are exposed as visible nodes toGtkTreeModelFilter
‘s clients, the child level (if any) and take a reference on the first node in this level. Furthermore, for every row-inserted, row-changed or row-deleted signal (also these which were not handled because the node was not cached),GtkTreeModelFilter
will check if the visibility state of any parent node has changed.Beware, however, that this explicit support is limited to these two cases. For example, if you want a node to be visible only if two nodes in a child’s child level (2 levels deeper) are visible, you are on your own. In this case, either rely on
GtkTreeStore
to emit all signals because it does not implement reference counting, or for models that do implement reference counting, obtain references on these child levels yourself.The
See moreTreeModelFilterProtocol
protocol exposes the methods and properties of an underlyingGtkTreeModelFilter
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeTreeModelFilter
. Alternatively, useTreeModelFilterRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol TreeModelFilterProtocol : ObjectProtocol, TreeDragSourceProtocol, TreeModelProtocol
-
A GtkTreeModel which makes an underlying tree model sortable
The
GtkTreeModelSort
is a model which implements theGtkTreeSortable
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 byGtkTreeModelSort
is not guaranteed to be stable.The use of this is best demonstrated through an example. In the following sample code we create two
GtkTreeView
widgets each with a view of the same data. As the model is wrapped here by aGtkTreeModelSort
, the twoGtkTreeView
s can each sort their view of the data without affecting the other. By contrast, if we simply put the same model in each widget, then sorting the first would sort the second.Using a
GtkTreeModelSort
(C Language Example):
{ GtkTreeView *tree_view1; GtkTreeView *tree_view2; GtkTreeModel *sort_model1; GtkTreeModel *sort_model2; GtkTreeModel *child_model; // get the child model child_model = get_my_model (); // Create the first tree sort_model1 = gtk_tree_model_sort_new_with_model (child_model); tree_view1 = gtk_tree_view_new_with_model (sort_model1); // Create the second tree sort_model2 = gtk_tree_model_sort_new_with_model (child_model); tree_view2 = gtk_tree_view_new_with_model (sort_model2); // Now we can sort the two models independently gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (sort_model1), COLUMN_1, GTK_SORT_ASCENDING); gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (sort_model2), COLUMN_1, GTK_SORT_DESCENDING); }
To demonstrate how to access the underlying child model from the sort model, the next example will be a callback for the
GtkTreeSelection
GtkTreeSelection
changed`` signal. In this callback, we get a string from COLUMN_1 of the model. We then modify the string, find the same selected row on the child model, and change the row there.Accessing the child model of in a selection changed callback
(C Language Example):
void selection_changed (GtkTreeSelection *selection, gpointer data) { GtkTreeModel *sort_model = NULL; GtkTreeModel *child_model; GtkTreeIter sort_iter; GtkTreeIter child_iter; char *some_data = NULL; char *modified_data; // Get the current selected row and the model. if (! gtk_tree_selection_get_selected (selection, &sort_model, &sort_iter)) return; // Look up the current value on the selected row and get // a new value to change it to. gtk_tree_model_get (GTK_TREE_MODEL (sort_model), &sort_iter, COLUMN_1, &some_data, -1); modified_data = change_the_data (some_data); g_free (some_data); // Get an iterator on the child model, instead of the sort model. gtk_tree_model_sort_convert_iter_to_child_iter (GTK_TREE_MODEL_SORT (sort_model), &child_iter, &sort_iter); // Get the child model and change the value of the row. In this // example, the child model is a GtkListStore. It could be any other // type of model, though. child_model = gtk_tree_model_sort_get_model (GTK_TREE_MODEL_SORT (sort_model)); gtk_list_store_set (GTK_LIST_STORE (child_model), &child_iter, COLUMN_1, &modified_data, -1); g_free (modified_data); }
The
See moreTreeModelSortProtocol
protocol exposes the methods and properties of an underlyingGtkTreeModelSort
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeTreeModelSort
. Alternatively, useTreeModelSortRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol TreeModelSortProtocol : ObjectProtocol, TreeDragSourceProtocol, TreeSortableProtocol
-
The selection object for GtkTreeView
The
GtkTreeSelection
object is a helper object to manage the selection for aGtkTreeView
widget. TheGtkTreeSelection
object is automatically created when a newGtkTreeView
widget is created, and cannot exist independently of this widget. The primary reason theGtkTreeSelection
objects exists is for cleanliness of code and API. That is, there is no conceptual reason all these functions could not be methods on theGtkTreeView
widget instead of a separate function.The
GtkTreeSelection
object is gotten from aGtkTreeView
by callinggtk_tree_view_get_selection()
. It can be manipulated to check the selection status of the tree, as well as select and deselect individual rows. Selection is done completely view side. As a result, multiple views of the same model can have completely different selections. Additionally, you cannot change the selection of a row on the model that is not currently displayed by the view without expanding its parents first.One of the important things to remember when monitoring the selection of a view is that the
GtkTreeSelection
changed
signal is mostly a hint. That is, it may only emit one signal when a range of rows is selected. Additionally, it may on occasion emit aGtkTreeSelection
changed
signal when nothing has happened (mostly as a result of programmers calling select_row on an already selected row).The
See moreTreeSelectionProtocol
protocol exposes the methods and properties of an underlyingGtkTreeSelection
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeTreeSelection
. Alternatively, useTreeSelectionRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol TreeSelectionProtocol : ObjectProtocol
-
A tree-like data structure that can be used with the GtkTreeView
The
GtkTreeStore
object is a list model for use with aGtkTreeView
widget. It implements theGtkTreeModel
interface, and consequently, can use all of the methods available there. It also implements theGtkTreeSortable
interface so it can be sorted by the view. Finally, it also implements the tree drag and drop interfaces.GtkTreeStore as GtkBuildable
The GtkTreeStore implementation of the
GtkBuildable
interface allows to specify the model columns with a <columns> element that may contain multiple <column> elements, each specifying one model column. The “type” attribute specifies the data type for the column.An example of a UI Definition fragment for a tree store:
<object class="GtkTreeStore"> <columns> <column type="gchararray"/> <column type="gchararray"/> <column type="gint"/> </columns> </object>
The
See moreTreeStoreProtocol
protocol exposes the methods and properties of an underlyingGtkTreeStore
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeTreeStore
. Alternatively, useTreeStoreRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol TreeStoreProtocol : ObjectProtocol, BuildableProtocol, TreeDragDestProtocol, TreeDragSourceProtocol, TreeSortableProtocol
-
A widget for displaying both trees and lists
Widget that displays any object that implements the [iface
Gtk.TreeModel
] interface.Please refer to the tree widget conceptual overview for an overview of all the objects and data types related to the tree widget and how they work together.
Coordinate systems in GtkTreeView API
Several different coordinate systems are exposed in the
GtkTreeView
API. These are:Widget coordinates: Coordinates relative to the widget (usually
widget->window
).Bin window coordinates: Coordinates relative to the window that GtkTreeView renders to.
Tree coordinates: Coordinates relative to the entire scrollable area of GtkTreeView. These coordinates start at (0, 0) for row 0 of the tree.
Several functions are available for converting between the different coordinate systems. The most common translations are between widget and bin window coordinates and between bin window and tree coordinates. For the former you can use method
Gtk.TreeView.convert_widget_to_bin_window_coords
, for the latter methodGtk.TreeView.convert_bin_window_to_tree_coords
.GtkTreeView
asGtkBuildable
The
GtkTreeView
implementation of theGtkBuildable
interface accepts [classGtk.TreeViewColumn
] objects as<child>
elements and exposes the internal [classGtk.TreeSelection
] in UI definitions.An example of a UI definition fragment with
GtkTreeView
:<object class="GtkTreeView" id="treeview"> <property name="model">liststore1</property> <child> <object class="GtkTreeViewColumn" id="test-column"> <property name="title">Test</property> <child> <object class="GtkCellRendererText" id="test-renderer"/> <attributes> <attribute name="text">1</attribute> </attributes> </child> </object> </child> <child internal-child="selection"> <object class="GtkTreeSelection" id="selection"> <signal name="changed" handler="on_treeview_selection_changed"/> </object> </child> </object>
CSS nodes
treeview.view ├── header │ ├── button │ │ ╰── [sort-indicator] ┊ ┊ │ ╰── button │ ╰── [sort-indicator] │ ├── [rubberband] ╰── [dndtarget]
GtkTreeView
has a main CSS node with nametreeview
and style class.view
. It has a subnode with nameheader
, which is the parent for all the column header widgets’ CSS nodes.Each column header consists of a
button
, which among other content, has a child with namesort-indicator
, which carries the.ascending
or.descending
style classes when the column header should show a sort indicator. The CSS is expected to provide a suitable image using the-gtk-icon-source
property.For rubberband selection, a subnode with name
rubberband
is used.For the drop target location during DND, a subnode with name
dndtarget
is used.The
See moreTreeViewProtocol
protocol exposes the methods and properties of an underlyingGtkTreeView
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeTreeView
. Alternatively, useTreeViewRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol TreeViewProtocol : ScrollableProtocol, WidgetProtocol
-
A visible column in a GtkTreeView widget
The GtkTreeViewColumn object represents a visible column in a
GtkTreeView
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.Please refer to the tree widget conceptual overview for an overview of all the objects and data types related to the tree widget and how they work together, and to the
GtkTreeView
documentation for specifics about the CSS node structure for treeviews and their headers.The
See moreTreeViewColumnProtocol
protocol exposes the methods and properties of an underlyingGtkTreeViewColumn
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeTreeViewColumn
. Alternatively, useTreeViewColumnRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol TreeViewColumnProtocol : InitiallyUnownedProtocol, BuildableProtocol, CellLayoutProtocol
-
GtkVideo
is a widget to show aGtkMediaStream
with media controls.The controls are available separately as [class
Gtk.MediaControls
]. If you just want to display a video without controls, you can treat it like any other paintable and for example put it into a [classGtk.Picture
].GtkVideo
aims to cover use cases such as previews, embedded animations, etc. It supports autoplay, looping, and simple media controls. It does not have support for video overlays, multichannel audio, device selection, or input. If you are writing a full-fledged video player, you may want to use the [classGdk.Paintable
] API and a media framework such as Gstreamer directly.The
See moreVideoProtocol
protocol exposes the methods and properties of an underlyingGtkVideo
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeVideo
. Alternatively, useVideoRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol VideoProtocol : WidgetProtocol
-
The
See moreTextChildAnchorClassProtocol
protocol exposes the methods and properties of an underlyingGtkTextChildAnchorClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeTextChildAnchorClass
. Alternatively, useTextChildAnchorClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol TextChildAnchorClassProtocol
-
An iterator for the contents of a
GtkTextBuffer
.You may wish to begin by reading the text widget conceptual overview, which gives an overview of all the objects and data types related to the text widget and how they work together.
The
See moreTextIterProtocol
protocol exposes the methods and properties of an underlyingGtkTextIter
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeTextIter
. Alternatively, useTextIterRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol TextIterProtocol
-
The
See moreTextMarkClassProtocol
protocol exposes the methods and properties of an underlyingGtkTextMarkClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeTextMarkClass
. Alternatively, useTextMarkClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol TextMarkClassProtocol
-
The
See moreTextTagClassProtocol
protocol exposes the methods and properties of an underlyingGtkTextTagClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeTextTagClass
. Alternatively, useTextTagClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol TextTagClassProtocol
-
The
See moreTextViewClassProtocol
protocol exposes the methods and properties of an underlyingGtkTextViewClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeTextViewClass
. Alternatively, useTextViewClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol TextViewClassProtocol
-
The
See moreToggleButtonClassProtocol
protocol exposes the methods and properties of an underlyingGtkToggleButtonClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeToggleButtonClass
. Alternatively, useToggleButtonClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ToggleButtonClassProtocol
-
The
See moreTreeDragDestIfaceProtocol
protocol exposes the methods and properties of an underlyingGtkTreeDragDestIface
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeTreeDragDestIface
. Alternatively, useTreeDragDestIfaceRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol TreeDragDestIfaceProtocol
-
The
See moreTreeDragSourceIfaceProtocol
protocol exposes the methods and properties of an underlyingGtkTreeDragSourceIface
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeTreeDragSourceIface
. Alternatively, useTreeDragSourceIfaceRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol TreeDragSourceIfaceProtocol
-
The
See moreTreeExpanderClassProtocol
protocol exposes the methods and properties of an underlyingGtkTreeExpanderClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeTreeExpanderClass
. Alternatively, useTreeExpanderClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol TreeExpanderClassProtocol
-
The
GtkTreeIter
is the primary structure for accessing aGtkTreeModel
. Models are expected to put a unique integer in thestamp
member, and put model-specific data in the threeuser_data
members.The
See moreTreeIterProtocol
protocol exposes the methods and properties of an underlyingGtkTreeIter
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeTreeIter
. Alternatively, useTreeIterRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol TreeIterProtocol
-
The
See moreTreeListModelClassProtocol
protocol exposes the methods and properties of an underlyingGtkTreeListModelClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeTreeListModelClass
. Alternatively, useTreeListModelClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol TreeListModelClassProtocol
-
The
See moreTreeListRowClassProtocol
protocol exposes the methods and properties of an underlyingGtkTreeListRowClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeTreeListRowClass
. Alternatively, useTreeListRowClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol TreeListRowClassProtocol
-
The
See moreTreeListRowSorterClassProtocol
protocol exposes the methods and properties of an underlyingGtkTreeListRowSorterClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeTreeListRowSorterClass
. Alternatively, useTreeListRowSorterClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol TreeListRowSorterClassProtocol
-
The
See moreTreeModelFilterClassProtocol
protocol exposes the methods and properties of an underlyingGtkTreeModelFilterClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeTreeModelFilterClass
. Alternatively, useTreeModelFilterClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol TreeModelFilterClassProtocol
-
The
See moreTreeModelIfaceProtocol
protocol exposes the methods and properties of an underlyingGtkTreeModelIface
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeTreeModelIface
. Alternatively, useTreeModelIfaceRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol TreeModelIfaceProtocol
-
The
See moreTreeModelSortClassProtocol
protocol exposes the methods and properties of an underlyingGtkTreeModelSortClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeTreeModelSortClass
. Alternatively, useTreeModelSortClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol TreeModelSortClassProtocol
-
An opaque structure representing a path to a row in a model.
The
See moreTreePathProtocol
protocol exposes the methods and properties of an underlyingGtkTreePath
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeTreePath
. Alternatively, useTreePathRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol TreePathProtocol
-
A GtkTreeRowReference tracks model changes so that it always refers to the same row (a
GtkTreePath
refers to a position, not a fixed row). Create a new GtkTreeRowReference withgtk_tree_row_reference_new()
.The
See moreTreeRowReferenceProtocol
protocol exposes the methods and properties of an underlyingGtkTreeRowReference
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeTreeRowReference
. Alternatively, useTreeRowReferenceRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol TreeRowReferenceProtocol
-
The
See moreTreeSortableIfaceProtocol
protocol exposes the methods and properties of an underlyingGtkTreeSortableIface
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeTreeSortableIface
. Alternatively, useTreeSortableIfaceRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol TreeSortableIfaceProtocol
-
The
See moreTreeStoreClassProtocol
protocol exposes the methods and properties of an underlyingGtkTreeStoreClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeTreeStoreClass
. Alternatively, useTreeStoreClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol TreeStoreClassProtocol
-
The
See moreTreeViewClassProtocol
protocol exposes the methods and properties of an underlyingGtkTreeViewClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeTreeViewClass
. Alternatively, useTreeViewClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol TreeViewClassProtocol
-
The
See moreVideoClassProtocol
protocol exposes the methods and properties of an underlyingGtkVideoClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeVideoClass
. Alternatively, useVideoClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol VideoClassProtocol
-
Interface for Drag-and-Drop destinations in
GtkTreeView
.The
See moreTreeDragSourceProtocol
protocol exposes the methods and properties of an underlyingGtkTreeDragSource
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeTreeDragSource
. Alternatively, useTreeDragSourceRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol TreeDragSourceProtocol
-
The tree interface used by GtkTreeView
The
GtkTreeModel
interface defines a generic tree interface for use by theGtkTreeView
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 aGtkTreeView
widget.The model is represented as a hierarchical tree of strongly-typed, columned data. In other words, the model can be seen as a tree where every node has different values depending on which column is being queried. The type of data found in a column is determined by using the GType system (ie.
G_TYPE_INT
,GTK_TYPE_BUTTON
,G_TYPE_POINTER
, etc). The types are homogeneous per column across all nodes. It is important to note that this interface only provides a way of examining a model and observing changes. The implementation of each individual model decides how and if changes are made.In order to make life simpler for programmers who do not need to write their own specialized model, two generic models are provided — the
GtkTreeStore
and theGtkListStore
. To use these, the developer simply pushes data into these models as necessary. These models provide the data structure as well as all appropriate tree interfaces. As a result, implementing drag and drop, sorting, and storing data is trivial. For the vast majority of trees and lists, these two models are sufficient.Models are accessed on a node/column level of granularity. One can query for the value of a model at a certain node and a certain column on that node. There are two structures used to reference a particular node in a model. They are the [struct
Gtk.TreePath
] and the structGtk.TreeIter
. Most of the interface consists of operations on a [structGtk.TreeIter
].A path is essentially a potential node. It is a location on a model that may or may not actually correspond to a node on a specific model. A [struct
Gtk.TreePath
] can be converted into either an array of unsigned integers or a string. The string form is a list of numbers separated by a colon. Each number refers to the offset at that level. Thus, the path0
refers to the root node and the path2:4
refers to the fifth child of the third node.By contrast, a [struct
Gtk.TreeIter
] is a reference to a specific node on a specific model. It is a generic struct with an integer and three generic pointers. These are filled in by the model in a model-specific way. One can convert a path to an iterator by callinggtk_tree_model_get_iter()
. These iterators are the primary way of accessing a model and are similar to the iterators used byGtkTextBuffer
. They are generally statically allocated on the stack and only used for a short time. The model interface defines a set of operations using them for navigating the model.It is expected that models fill in the iterator with private data. For example, the
GtkListStore
model, which is internally a simple linked list, stores a list node in one of the pointers. TheGtkTreeModel
Sort stores an array and an offset in two of the pointers. Additionally, there is an integer field. This field is generally filled with a unique stamp per model. This stamp is for catching errors resulting from using invalid iterators with a model.The lifecycle of an iterator can be a little confusing at first. Iterators are expected to always be valid for as long as the model is unchanged (and doesn’t emit a signal). The model is considered to own all outstanding iterators and nothing needs to be done to free them from the user’s point of view. Additionally, some models guarantee that an iterator is valid for as long as the node it refers to is valid (most notably the
GtkTreeStore
andGtkListStore
). Although generally uninteresting, as one always has to allow for the case where iterators do not persist beyond a signal, some very important performance enhancements were made in the sort model. As a result, theGTK_TREE_MODEL_ITERS_PERSIST
flag was added to indicate this behavior.To help show some common operation of a model, some examples are provided. The first example shows three ways of getting the iter at the location
3:2:5
. While the first method shown is easier, the second is much more common, as you often get paths from callbacks.Acquiring a
GtkTreeIter
// Three ways of getting the iter pointing to the location GtkTreePath *path; GtkTreeIter iter; GtkTreeIter parent_iter; // get the iterator from a string gtk_tree_model_get_iter_from_string (model, &iter, "3:2:5"); // get the iterator from a path path = gtk_tree_path_new_from_string ("3:2:5"); gtk_tree_model_get_iter (model, &iter, path); gtk_tree_path_free (path); // walk the tree to find the iterator gtk_tree_model_iter_nth_child (model, &iter, NULL, 3); parent_iter = iter; gtk_tree_model_iter_nth_child (model, &iter, &parent_iter, 2); parent_iter = iter; gtk_tree_model_iter_nth_child (model, &iter, &parent_iter, 5);
This second example shows a quick way of iterating through a list and getting a string and an integer from each row. The
populate_model()
function used below is not shown, as it is specific to theGtkListStore
. For information on how to write such a function, see theGtkListStore
documentation.Reading data from a
GtkTreeModel
enum { STRING_COLUMN, INT_COLUMN, N_COLUMNS }; ... GtkTreeModel *list_store; GtkTreeIter iter; gboolean valid; int row_count = 0; // make a new list_store list_store = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING, G_TYPE_INT); // Fill the list store with data populate_model (list_store); // Get the first iter in the list, check it is valid and walk // through the list, reading each row. valid = gtk_tree_model_get_iter_first (list_store, &iter); while (valid) { char *str_data; int int_data; // Make sure you terminate calls to `gtk_tree_model_get()` with a “-1” value gtk_tree_model_get (list_store, &iter, STRING_COLUMN, &str_data, INT_COLUMN, &int_data, -1); // Do something with the data g_print ("Row `d:` (`s`,`d`)\n", row_count, str_data, int_data); g_free (str_data); valid = gtk_tree_model_iter_next (list_store, &iter); row_count++; }
The
GtkTreeModel
interface contains two methods for reference counting:gtk_tree_model_ref_node()
andgtk_tree_model_unref_node()
. These two methods are optional to implement. The reference counting is meant as a way for views to let models know when nodes are being displayed.GtkTreeView
will take a reference on a node when it is visible, which means the node is either in the toplevel or expanded. Being displayed does not mean that the node is currently directly visible to the user in the viewport. Based on this reference counting scheme a caching model, for example, can decide whether or not to cache a node based on the reference count. A file-system based model would not want to keep the entire file hierarchy in memory, but just the folders that are currently expanded in every current view.When working with reference counting, the following rules must be taken into account:
Never take a reference on a node without owning a reference on its parent. This means that all parent nodes of a referenced node must be referenced as well.
Outstanding references on a deleted node are not released. This is not possible because the node has already been deleted by the time the row-deleted signal is received.
Models are not obligated to emit a signal on rows of which none of its siblings are referenced. To phrase this differently, signals are only required for levels in which nodes are referenced. For the root level however, signals must be emitted at all times (however the root level is always referenced when any view is attached).
The
See moreTreeModelProtocol
protocol exposes the methods and properties of an underlyingGtkTreeModel
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeTreeModel
. Alternatively, useTreeModelRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol TreeModelProtocol
-
The interface for sortable models used by GtkTreeView
GtkTreeSortable
is an interface to be implemented by tree models which support sorting. TheGtkTreeView
uses the methods provided by this interface to sort the model.The
See moreTreeSortableProtocol
protocol exposes the methods and properties of an underlyingGtkTreeSortable
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeTreeSortable
. Alternatively, useTreeSortableRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol TreeSortableProtocol : TreeModelProtocol
-
GtkViewport
implements scrollability for widgets that lack their own scrolling capabilities.Use
GtkViewport
to scroll child widgets such asGtkGrid
,GtkBox
, and so on.The
GtkViewport
will start scrolling content only if allocated less than the child widget’s minimum size in a given orientation.CSS nodes
GtkViewport
has a single CSS node with nameviewport
.Accessibility
GtkViewport
uses theGTK_ACCESSIBLE_ROLE_GROUP
role.The
See moreViewportProtocol
protocol exposes the methods and properties of an underlyingGtkViewport
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeViewport
. Alternatively, useViewportRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol ViewportProtocol : ScrollableProtocol, WidgetProtocol
-
GtkVolumeButton
is aGtkScaleButton
subclass tailored for volume control.The
See moreVolumeButtonProtocol
protocol exposes the methods and properties of an underlyingGtkVolumeButton
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeVolumeButton
. Alternatively, useVolumeButtonRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol VolumeButtonProtocol : ScaleButtonProtocol
-
The base class for all widgets.
GtkWidget
is the base class all widgets in GTK derive from. It manages the widget lifecycle, layout, states and style.Height-for-width Geometry Management
GTK uses a height-for-width (and width-for-height) geometry management system. Height-for-width means that a widget can change how much vertical space it needs, depending on the amount of horizontal space that it is given (and similar for width-for-height). The most common example is a label that reflows to fill up the available width, wraps to fewer lines, and therefore needs less height.
Height-for-width geometry management is implemented in GTK by way of two virtual methods:
- [vfunc
Gtk.Widget.get_request_mode
] - [vfunc
Gtk.Widget.measure
]
There are some important things to keep in mind when implementing height-for-width and when using it in widget implementations.
If you implement a direct
GtkWidget
subclass that supports height-for-width or width-for-height geometry management for itself or its child widgets, the [vfuncGtk.Widget.get_request_mode
] virtual function must be implemented as well and return the widget’s preferred request mode. The default implementation of this virtual function returnsGTK_SIZE_REQUEST_CONSTANT_SIZE
, which means that the widget will only ever get -1 passed as the for_size value to its [vfuncGtk.Widget.measure
] implementation.The geometry management system will query a widget hierarchy in only one orientation at a time. When widgets are initially queried for their minimum sizes it is generally done in two initial passes in the [enum
Gtk.SizeRequestMode
] chosen by the toplevel.For example, when queried in the normal
GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH
mode:First, the default minimum and natural width for each widget in the interface will be computed using [id
gtk_widget_measure
] with an orientation ofGTK_ORIENTATION_HORIZONTAL
and a for_size of -1. Because the preferred widths for each widget depend on the preferred widths of their children, this information propagates up the hierarchy, and finally a minimum and natural width is determined for the entire toplevel. Next, the toplevel will use the minimum width to query for the minimum height contextual to that width using [idgtk_widget_measure
] with an orientation ofGTK_ORIENTATION_VERTICAL
and a for_size of the just computed width. This will also be a highly recursive operation. The minimum height for the minimum width is normally used to set the minimum size constraint on the toplevel.After the toplevel window has initially requested its size in both dimensions it can go on to allocate itself a reasonable size (or a size previously specified with [method
Gtk.Window.set_default_size
]). During the recursive allocation process it’s important to note that request cycles will be recursively executed while widgets allocate their children. Each widget, once allocated a size, will go on to first share the space in one orientation among its children and then request each child’s height for its target allocated width or its width for allocated height, depending. In this way aGtkWidget
will typically be requested its size a number of times before actually being allocated a size. The size a widget is finally allocated can of course differ from the size it has requested. For this reason,GtkWidget
caches a small number of results to avoid re-querying for the same sizes in one allocation cycle.If a widget does move content around to intelligently use up the allocated size then it must support the request in both
GtkSizeRequestMode
s even if the widget in question only trades sizes in a single orientation.For instance, a [class
Gtk.Label
] that does height-for-width word wrapping will not expect to have [vfuncGtk.Widget.measure
] with an orientation ofGTK_ORIENTATION_VERTICAL
called because that call is specific to a width-for-height request. In this case the label must return the height required for its own minimum possible width. By following this rule any widget that handles height-for-width or width-for-height requests will always be allocated at least enough space to fit its own content.Here are some examples of how a
GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH
widget generally deals with width-for-height requests:static void foo_widget_measure (GtkWidget *widget, GtkOrientation orientation, int for_size, int *minimum_size, int *natural_size, int *minimum_baseline, int *natural_baseline) { if (orientation == GTK_ORIENTATION_HORIZONTAL) { // Calculate minimum and natural width } else // VERTICAL { if (i_am_in_height_for_width_mode) { int min_width, dummy; // First, get the minimum width of our widget GTK_WIDGET_GET_CLASS (widget)->measure (widget, GTK_ORIENTATION_HORIZONTAL, -1, &min_width, &dummy, &dummy, &dummy); // Now use the minimum width to retrieve the minimum and natural height to display // that width. GTK_WIDGET_GET_CLASS (widget)->measure (widget, GTK_ORIENTATION_VERTICAL, min_width, minimum_size, natural_size, &dummy, &dummy); } else { // ... some widgets do both. } } }
Often a widget needs to get its own request during size request or allocation. For example, when computing height it may need to also compute width. Or when deciding how to use an allocation, the widget may need to know its natural size. In these cases, the widget should be careful to call its virtual methods directly, like in the code example above.
It will not work to use the wrapper function [method
Gtk.Widget.measure
] inside your own [vfuncGtk.Widget.size_allocate
] implementation. These return a request adjusted by [classGtk.SizeGroup
], the widget’s align and expand flags, as well as its CSS style.If a widget used the wrappers inside its virtual method implementations, then the adjustments (such as widget margins) would be applied twice. GTK therefore does not allow this and will warn if you try to do it.
Of course if you are getting the size request for another widget, such as a child widget, you must use [id
gtk_widget_measure
]; otherwise, you would not properly consider widget margins, [classGtk.SizeGroup
], and so forth.GTK also supports baseline vertical alignment of widgets. This means that widgets are positioned such that the typographical baseline of widgets in the same row are aligned. This happens if a widget supports baselines, has a vertical alignment of
GTK_ALIGN_BASELINE
, and is inside a widget that supports baselines and has a natural “row” that it aligns to the baseline, or a baseline assigned to it by the grandparent.Baseline alignment support for a widget is also done by the [vfunc
Gtk.Widget.measure
] virtual function. It allows you to report both a minimum and natural size.If a widget ends up baseline aligned it will be allocated all the space in the parent as if it was
GTK_ALIGN_FILL
, but the selected baseline can be found via [idgtk_widget_get_allocated_baseline
]. If the baseline has a value other than -1 you need to align the widget such that the baseline appears at the position.GtkWidget as GtkBuildable
The
GtkWidget
implementation of theGtkBuildable
interface supports various custom elements to specify additional aspects of widgets that are not directly expressed as properties.If the widget uses a [class
Gtk.LayoutManager
],GtkWidget
supports a custom<layout>
element, used to define layout properties:<object class="GtkGrid" id="my_grid"> <child> <object class="GtkLabel" id="label1"> <property name="label">Description</property> <layout> <property name="column">0</property> <property name="row">0</property> <property name="row-span">1</property> <property name="column-span">1</property> </layout> </object> </child> <child> <object class="GtkEntry" id="description_entry"> <layout> <property name="column">1</property> <property name="row">0</property> <property name="row-span">1</property> <property name="column-span">1</property> </layout> </object> </child> </object>
GtkWidget
allows style information such as style classes to be associated with widgets, using the custom<style>
element:<object class="GtkButton" id="button1"> <style> <class name="my-special-button-class"/> <class name="dark-button"/> </style> </object>
GtkWidget
allows defining accessibility information, such as properties, relations, and states, using the custom<accessibility>
element:<object class="GtkButton" id="button1"> <accessibility> <property name="label">Download</property> <relation name="labelled-by">label1</relation> </accessibility> </object>
Building composite widgets from template XML
GtkWidget
exposes some facilities to automate the procedure of creating composite widgets using “templates”.To create composite widgets with
GtkBuilder
XML, one must associate the interface description with the widget class at class initialization time using [methodGtk.WidgetClass.set_template
].The interface description semantics expected in composite template descriptions is slightly different from regular [class
Gtk.Builder
] XML.Unlike regular interface descriptions, [method
Gtk.WidgetClass.set_template
] will expect a<template>
tag as a direct child of the toplevel<interface>
tag. The<template>
tag must specify the “class” attribute which must be the type name of the widget. Optionally, the “parent” attribute may be specified to specify the direct parent type of the widget type, this is ignored byGtkBuilder
but required for UI design tools like Glade to introspect what kind of properties and internal children exist for a given type when the actual type does not exist.The XML which is contained inside the
<template>
tag behaves as if it were added to the<object>
tag defining the widget itself. You may set properties on a widget by inserting<property>
tags into the<template>
tag, and also add<child>
tags to add children and extend a widget in the normal way you would with<object>
tags.Additionally,
<object>
tags can also be added before and after the initial<template>
tag in the normal way, allowing one to define auxiliary objects which might be referenced by other widgets declared as children of the<template>
tag.An example of a template definition:
<interface> <template class="FooWidget" parent="GtkBox"> <property name="orientation">horizontal</property> <property name="spacing">4</property> <child> <object class="GtkButton" id="hello_button"> <property name="label">Hello World</property> <signal name="clicked" handler="hello_button_clicked" object="FooWidget" swapped="yes"/> </object> </child> <child> <object class="GtkButton" id="goodbye_button"> <property name="label">Goodbye World</property> </object> </child> </template> </interface>
Typically, you’ll place the template fragment into a file that is bundled with your project, using
GResource
. In order to load the template, you need to call [methodGtk.WidgetClass.set_template_from_resource
] from the class initialization of yourGtkWidget
type:static void foo_widget_class_init (FooWidgetClass *klass) { // ... gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/com/example/ui/foowidget.ui"); }
You will also need to call [method
Gtk.Widget.init_template
] from the instance initialization function:static void foo_widget_init (FooWidget *self) { // ... gtk_widget_init_template (GTK_WIDGET (self)); }
You can access widgets defined in the template using the [id
gtk_widget_get_template_child
] function, but you will typically declare a pointer in the instance private data structure of your type using the same name as the widget in the template definition, and call methodGtk.WidgetClass.bind_template_child_full
with that name, e.g.typedef struct { GtkWidget *hello_button; GtkWidget *goodbye_button; } FooWidgetPrivate; G_DEFINE_TYPE_WITH_PRIVATE (FooWidget, foo_widget, GTK_TYPE_BOX) static void foo_widget_class_init (FooWidgetClass *klass) { // ... gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/com/example/ui/foowidget.ui"); gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), FooWidget, hello_button); gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), FooWidget, goodbye_button); } static void foo_widget_init (FooWidget *widget) { }
You can also use method
Gtk.WidgetClass.bind_template_callback_full
to connect a signal callback defined in the template with a function visible in the scope of the class, e.g.// the signal handler has the instance and user data swapped // because of the swapped="yes" attribute in the template XML static void hello_button_clicked (FooWidget *self, GtkButton *button) { g_print ("Hello, world!\n"); } static void foo_widget_class_init (FooWidgetClass *klass) { // ... gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/com/example/ui/foowidget.ui"); gtk_widget_class_bind_template_callback (GTK_WIDGET_CLASS (klass), hello_button_clicked); }
The
See moreWidgetProtocol
protocol exposes the methods and properties of an underlyingGtkWidget
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeWidget
. Alternatively, useWidgetRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol WidgetProtocol : InitiallyUnownedProtocol, AccessibleProtocol, BuildableProtocol, ConstraintTargetProtocol
- [vfunc
-
The
See moreWidgetClassProtocol
protocol exposes the methods and properties of an underlyingGtkWidgetClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeWidgetClass
. Alternatively, useWidgetClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol WidgetClassProtocol
-
The
See moreWidgetClassPrivateProtocol
protocol exposes the methods and properties of an underlyingGtkWidgetClassPrivate
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeWidgetClassPrivate
. Alternatively, useWidgetClassPrivateRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol WidgetClassPrivateProtocol
-
The
See moreWidgetPaintableClassProtocol
protocol exposes the methods and properties of an underlyingGtkWidgetPaintableClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeWidgetPaintableClass
. Alternatively, useWidgetPaintableClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol WidgetPaintableClassProtocol
-
The
See moreWindowClassProtocol
protocol exposes the methods and properties of an underlyingGtkWindowClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeWindowClass
. Alternatively, useWindowClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol WindowClassProtocol
-
The
See moreWindowControlsClassProtocol
protocol exposes the methods and properties of an underlyingGtkWindowControlsClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeWindowControlsClass
. Alternatively, useWindowControlsClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol WindowControlsClassProtocol
-
The
See moreWindowGroupClassProtocol
protocol exposes the methods and properties of an underlyingGtkWindowGroupClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeWindowGroupClass
. Alternatively, useWindowGroupClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol WindowGroupClassProtocol
-
The
See moreWindowHandleClassProtocol
protocol exposes the methods and properties of an underlyingGtkWindowHandleClass
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeWindowHandleClass
. Alternatively, useWindowHandleClassRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol WindowHandleClassProtocol
-
GtkWidgetPaintable
is aGdkPaintable
that displays the contents of a widget.GtkWidgetPaintable
will also take care of the widget not being in a state where it can be drawn (like when it isn’t shown) and just draw nothing or where it does not have a size (like when it is hidden) and report no size in that case.Of course,
GtkWidgetPaintable
allows you to monitor widgets for size changes by emitting the [signalGdk.Paintable::invalidate-size
] signal whenever the size of the widget changes as well as for visual changes by emitting the [signalGdk.Paintable::invalidate-contents
] signal whenever the widget changes.You can use a
GtkWidgetPaintable
everywhere aGdkPaintable
is allowed, including using it on aGtkPicture
(or one of its parents) that it was set on itself viagtk_picture_set_paintable()
. The paintable will take care of recursion when this happens. If you do this however, ensure that the [propertyGtk.Picture:can-shrink
] property is set totrue
or you might end up with an infinitely growing widget.The
See moreWidgetPaintableProtocol
protocol exposes the methods and properties of an underlyingGtkWidgetPaintable
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeWidgetPaintable
. Alternatively, useWidgetPaintableRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol WidgetPaintableProtocol : ObjectProtocol, PaintableProtocol
-
A
GtkWindow
is a toplevel window which can contain other widgets.Windows normally have decorations that are under the control of the windowing system and allow the user to manipulate the window (resize it, move it, close it,…).
GtkWindow as GtkBuildable
The
GtkWindow
implementation of the [ifaceGtk.Buildable
] interface supports setting a child as the titlebar by specifying “titlebar” as the “type” attribute of a <child> element.CSS nodes
window.background [.csd / .solid-csd / .ssd] [.maximized / .fullscreen / .tiled] ├── <child> ╰── <titlebar child>.titlebar [.default-decoration]
GtkWindow
has a main CSS node with name window and style class .background.Style classes that are typically used with the main CSS node are .csd (when client-side decorations are in use), .solid-csd (for client-side decorations without invisible borders), .ssd (used by mutter when rendering server-side decorations). GtkWindow also represents window states with the following style classes on the main node: .maximized, .fullscreen, .tiled (when supported, also .tiled-top, .tiled-left, .tiled-right, .tiled-bottom).
GtkWindow
subclasses often add their own discriminating style classes, such as .dialog, .popup or .tooltip.Generally, some CSS properties don’t make sense on the toplevel window node, such as margins or padding. When client-side decorations without invisible borders are in use (i.e. the .solid-csd style class is added to the main window node), the CSS border of the toplevel window is used for resize drags. In the .csd case, the shadow area outside of the window can be used to resize it.
GtkWindow
adds the .titlebar and .default-decoration style classes to the widget that is added as a titlebar child.Accessibility
GtkWindow
uses theGTK_ACCESSIBLE_ROLE_WINDOW
role.The
See moreWindowProtocol
protocol exposes the methods and properties of an underlyingGtkWindow
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeWindow
. Alternatively, useWindowRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol WindowProtocol : RootProtocol, ShortcutManagerProtocol
-
GtkWindowControls
shows window frame controls.Typical window frame controls are minimize, maximize and close buttons, and the window icon.
GtkWindowControls
only displays start or end side of the controls (see [propertyGtk.WindowControls:side
]), so it’s intended to be always used in pair with anotherGtkWindowControls
for the opposite side, for example:<object class="GtkBox"> <child> <object class="GtkWindowControls"> <property name="side">start</property> </object> </child> ... <child> <object class="GtkWindowControls"> <property name="side">end</property> </object> </child> </object>
CSS nodes
windowcontrols ├── [image.icon] ├── [button.minimize] ├── [button.maximize] ╰── [button.close]
A
GtkWindowControls
‘ CSS node is called windowcontrols. It contains subnodes corresponding to each title button. Which of the title buttons exist and where they are placed exactly depends on the desktop environment and [propertyGtk.WindowControls:decoration-layout
] value.When [property
Gtk.WindowControls:empty
] istrue
, it gets the .empty style class.Accessibility
GtkWindowControls
uses theGTK_ACCESSIBLE_ROLE_GROUP
role.The
See moreWindowControlsProtocol
protocol exposes the methods and properties of an underlyingGtkWindowControls
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeWindowControls
. Alternatively, useWindowControlsRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol WindowControlsProtocol : WidgetProtocol
-
GtkWindowGroup
makes group of windows behave like separate applications.It achieves this by limiting the effect of GTK grabs and modality to windows in the same group.
A window can be a member in at most one window group at a time. Windows that have not been explicitly assigned to a group are implicitly treated like windows of the default window group.
GtkWindowGroup
objects are referenced by each window in the group, so once you have added all windows to aGtkWindowGroup
, you can drop the initial reference to the window group withg_object_unref()
. If the windows in the window group are subsequently destroyed, then they will be removed from the window group and drop their references on the window group; when all window have been removed, the window group will be freed.The
See moreWindowGroupProtocol
protocol exposes the methods and properties of an underlyingGtkWindowGroup
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeWindowGroup
. Alternatively, useWindowGroupRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol WindowGroupProtocol : ObjectProtocol
-
GtkWindowHandle
is a titlebar area widget.When added into a window, it can be dragged to move the window, and handles right click, double click and middle click as expected of a titlebar.
CSS nodes
GtkWindowHandle
has a single CSS node with the namewindowhandle
.Accessibility
GtkWindowHandle
uses theGTK_ACCESSIBLE_ROLE_GROUP
role.The
See moreWindowHandleProtocol
protocol exposes the methods and properties of an underlyingGtkWindowHandle
instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, seeWindowHandle
. Alternatively, useWindowHandleRef
as a lighweight,unowned
reference if you already have an instance you just want to use.Declaration
Swift
public protocol WindowHandleProtocol : WidgetProtocol