========== Extensions ========== .. _Syntax Extension: Properties are the main way to set values on objects, but they are limited by the GObject type system in what values they can accept. Some classes, therefore, have specialized syntax for certain features. .. note:: Extensions are a feature of ``Gtk.Buildable``--see `Gtk.Buildable.custom_tag_start() `_ for internal details. Because they aren't part of the type system, they aren't present in typelib files like properties and signals are. Therefore, if a library adds a new extension, syntax for it must be added to Blueprint manually. If there's a commonly used extension that isn't supported by Blueprint, please `file an issue `_. .. rst-class:: grammar-block Extension = :ref:`ExtAccessibility` | :ref:`ExtAdwAlertDialog` | :ref:`ExtAdwMessageDialog` | :ref:`ExtAdwBreakpoint` | :ref:`ExtComboBoxItems` | :ref:`ExtFileFilterMimeTypes` | :ref:`ExtFileFilterPatterns` | :ref:`ExtFileFilterSuffixes` | :ref:`ExtLayout` | :ref:`ExtListItemFactory` | :ref:`ExtSizeGroupWidgets` | :ref:`ExtStringListStrings` | :ref:`ExtStyles` .. _Syntax ExtAccessibility: Accessibility Properties ------------------------ .. rst-class:: grammar-block ExtAccessibility = 'accessibility' '{' ExtAccessibilityProp* '}' ExtAccessibilityProp = `> ':' (:ref:`Value ` | ('[' (:ref: Value ),* ']') ) ';' Valid in any `Gtk.Widget `_. The ``accessibility`` block defines values relevant to accessibility software. The property names and acceptable values are described in the `Gtk.AccessibleRelation `_, `Gtk.AccessibleState `_, and `Gtk.AccessibleProperty `_ enums. .. note:: Relations which allow for a list of values, for example `labelled-by`, must be given as a single relation with a list of values instead of duplicating the relation like done in Gtk.Builder. .. _Syntax ExtAdwBreakpoint: Adw.Breakpoint -------------- .. rst-class:: grammar-block ExtAdwBreakpointCondition = 'condition' '(' `> ')' ExtAdwBreakpoint = 'setters' '{' ExtAdwBreakpointSetter* '}' ExtAdwBreakpointSetter = `> '.' `> ':' :ref:`Value ` ';' Valid in `Adw.Breakpoint `_. Defines the condition for a breakpoint and the properties that will be set at that breakpoint. See the documentation for `Adw.Breakpoint `_. .. note:: The `Adw.Breakpoint:condition `_ property has type `Adw.BreakpointCondition `_, which GtkBuilder doesn't know how to parse from a string. Therefore, the ``condition`` syntax is used instead. .. _Syntax ExtAdwAlertDialog: Adw.AlertDialog Responses ---------------------------- .. rst-class:: grammar-block ExtAdwAlertDialog = 'responses' '[' (ExtAdwAlertDialogResponse),* ']' ExtAdwAlertDialogResponse = `> ':' :ref:`StringValue` ExtAdwAlertDialogFlag* ExtAdwAlertDialogFlag = 'destructive' | 'suggested' | 'disabled' Valid in `Adw.AlertDialog `_. The ``responses`` block defines the buttons that will be added to the dialog. The ``destructive`` or ``suggested`` flag sets the appearance of the button, and the ``disabled`` flag can be used to disable the button. .. code-block:: blueprint using Adw 1; Adw.AlertDialog { responses [ cancel: _("Cancel"), delete: _("Delete") destructive, save: "Save" suggested, wipeHardDrive: "Wipe Hard Drive" destructive disabled, ] } .. _Syntax ExtAdwMessageDialog: Adw.MessageDialog Responses ---------------------------- .. rst-class:: grammar-block ExtAdwMessageDialog = 'responses' '[' (ExtAdwMessageDialogResponse),* ']' ExtAdwMessageDialogResponse = `> ':' :ref:`StringValue` ExtAdwMessageDialogFlag* ExtAdwMessageDialogFlag = 'destructive' | 'suggested' | 'disabled' Valid in `Adw.MessageDialog `_. The ``responses`` block defines the buttons that will be added to the dialog. The ``destructive`` or ``suggested`` flag sets the appearance of the button, and the ``disabled`` flag can be used to disable the button. .. code-block:: blueprint using Adw 1; Adw.MessageDialog { responses [ cancel: _("Cancel"), delete: _("Delete") destructive, save: "Save" suggested, wipeHardDrive: "Wipe Hard Drive" destructive disabled, ] } .. _Syntax ExtComboBoxItems: Gtk.ComboBoxText Items ---------------------- .. rst-class:: grammar-block ExtComboBoxItems = 'items' '[' (ExtComboBoxItem),* ']' ExtComboBoxItem = ( `> ':' )? :ref:`StringValue` Valid in `Gtk.ComboBoxText `_, which is deprecated as of Gtk 4.10. The ``items`` block defines the items that will be added to the combo box. The optional ID can be used to refer to the item rather than its label. .. code-block:: blueprint ComboBoxText { items [ item1: "Item 1", item2: "Item 2", item3: "Item 3", ] } .. _Syntax ExtFileFilter: Gtk.FileFilter Filters ---------------------- .. rst-class:: grammar-block ExtFileFilterMimeTypes = 'mime-types' '[' (ExtFileFilterItem),* ']' ExtFileFilterPatterns = 'patterns' '[' (ExtFileFilterItem),* ']' ExtFileFilterSuffixes = 'suffixes' '[' (ExtFileFilterItem),* ']' ExtFileFilterItem = `> Valid in `Gtk.FileFilter `_. The ``mime-types``, ``patterns``, and ``suffixes`` blocks define the items that will be added to the file filter. The ``mime-types`` block accepts mime types (including wildcards for subtypes, such as ``image/*``). The ``patterns`` block accepts glob patterns, and the ``suffixes`` block accepts file extensions. .. code-block:: blueprint FileFilter { mime-types [ "text/plain", "image/*" ] patterns [ "*.txt" ] suffixes [ "png", "jpg" ] } .. _Syntax ExtLayout: Widget Layouts -------------- .. rst-class:: grammar-block ExtLayout = 'layout' '{' ExtLayoutProp* '}' ExtLayoutProp = `> ':' :ref:`Value` ';' Valid in `Gtk.Widget `_. The ``layout`` block describes how the widget should be positioned within its parent. The available properties depend on the parent widget's layout manager. .. code-block:: blueprint Grid { Button { layout { column: 0; row: 0; } } Button { layout { column: 1; row: 0; } } Button { layout { column: 0; row: 1; row-span: 2; } } } .. _Syntax ExtListItemFactory: Gtk.BuilderListItemFactory Templates ------------------------------------ .. rst-class:: grammar-block ExtListItemFactory = 'template' :ref:`TypeName` :ref:`ObjectContent` Valid in `Gtk.BuilderListItemFactory `_. The ``template`` block defines the template that will be used to create list items. This block is unique within Blueprint because it defines a completely separate sub-blueprint which is used to create each list item. The sub-blueprint may not reference objects in the main blueprint or vice versa. The template type must be `Gtk.ListItem `_, `Gtk.ColumnViewRow `_, or `Gtk.ColumnViewCell `_. The template object can be referenced with the ``template`` keyword. .. code-block:: blueprint ListView { factory: BuilderListItemFactory { template ListItem { child: Label { label: bind template.item as .string; }; } }; model: NoSelection { model: StringList { strings [ "Item 1", "Item 2", "Item 3" ] }; }; } .. _Syntax ExtScaleMarks: Gtk.Scale Marks --------------- .. rst-class:: grammar-block ExtScaleMarks = 'marks' '[' (ExtScaleMark),* ']' ExtScaleMark = 'mark' '(' ( '-' | '+' )? `> ( ',' `> ( ',' :ref:`StringValue` )? )? ')' Valid in `Gtk.Scale `_. The ``marks`` block defines the marks on a scale. A single ``mark`` has up to three arguments: a value, an optional position, and an optional label. The position can be ``left``, ``right``, ``top``, or ``bottom``. The label may be translated. .. _Syntax ExtSizeGroupWidgets: Gtk.SizeGroup Widgets --------------------- .. rst-class:: grammar-block ExtSizeGroupWidgets = 'widgets' '[' (ExtSizeGroupWidget),* ']' ExtSizeGroupWidget = `> Valid in `Gtk.SizeGroup `_. The ``widgets`` block defines the widgets that will be added to the size group. .. code-block:: blueprint Box { Button button1 {} Button button2 {} } SizeGroup { widgets [button1, button2] } .. _Syntax ExtStringListStrings: Gtk.StringList Strings ---------------------- .. rst-class:: grammar-block ExtStringListStrings = 'strings' '[' (ExtStringListItem),* ']' ExtStringListItem = :ref:`StringValue` Valid in `Gtk.StringList `_. The ``strings`` block defines the strings in the string list. .. code-block:: blueprint StringList { strings ["violin", "guitar", _("harp")] } .. _Syntax ExtStyles: CSS Styles ---------- .. rst-class:: grammar-block ExtStyles = 'styles' '[' ExtStylesProp* ']' ExtStylesProp = `> Valid in any `Gtk.Widget `_. The ``styles`` block defines CSS classes that will be added to the widget. .. code-block:: blueprint Button { styles ["suggested-action"] } .. _Syntax ChildExtension: Child Extensions ---------------- .. rst-class:: grammar-block ChildExtension = :ref:`ExtResponse` Child extensions are similar to regular extensions, but they apply to a child of the object rather than the object itself. They are used to add properties to child widgets of a container, such as the buttons in a `Gtk.Dialog `_. The child extension takes the place of a child type inside the square brackets. Currently, the only child extension is :ref:`ExtResponse`. .. _Syntax ExtResponse: Dialog & InfoBar Responses -------------------------- .. rst-class:: grammar-block ExtResponse = 'action' 'response' '=' ( `> | `> ) 'default'? Valid as a child extension for children of `Gtk.Dialog `_ or `Gtk.InfoBar `_, which are both deprecated as of Gtk 4.10. The ``action response`` extension sets the ``action`` child type for the child and sets the child's integer response type. The response type may be either a member of the `Gtk.ResponseType `_ enum or a positive, application-defined integer. No more than one child of a dialog or infobar may have the ``default`` flag. .. code-block:: blueprint Dialog { [action response=ok default] Button {} [action response=cancel] Button {} [action response=1] Button {} }