Next: <GtkDropTarget>, Previous: <GtkDropControllerMotion>, Up: Classes   [Index]


1.50 <GtkDropDown> ¶

Class: <GtkDropDown> ¶

It derives from <GtkWidget>.

Allows the user to choose an item from a list of options.

The <GtkDropDown> displays the [selected]drop-down:selected choice.

The options are given to <GtkDropDown> in the form of <GListModel> and how the individual options are represented is determined by a <GtkListItemFactory>. The default factory displays simple strings, and adds a checkmark to the selected item in the popup.

To set your own factory, use drop-down:set-factory. It is possible to use a separate factory for the items in the popup, with drop-down:set-list-factory.

<GtkDropDown> knows how to obtain strings from the items in a <GtkStringList>; for other models, you have to provide an expression to find the strings via drop-down: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 drop-down:set-enable-search.

Here is a UI definition example for <GtkDropDown> with a simple model:

<object class="GtkDropDown">
  <property name="model">
    <object class="GtkStringList">
      <items>
        <item translatable="yes">Factory</item>
        <item translatable="yes">Home</item>
        <item translatable="yes">Subway</item>
      </items>
    </object>
  </property>
</object>

If a <GtkDropDown> is created in this manner, or with drop-down:new-from-strings, for instance, the object returned from drop-down:get-selected-item will be a <GtkStringObject>.

To learn more about the list widget framework, see the overview.

CSS nodes ¶

<GtkDropDown> has a single CSS node with name dropdown, with the button and popover nodes as children.

Accessibility ¶

<GtkDropDown> uses the Gtk.AccessibleRole.combo_box role.

Properties ¶

Property: drop-down:enable-search self ¶

Whether to show a search entry in the popup.

Note that search requires drop-down:expression to be set.

Its value is a boolean.

Set it with (set! (drop-down:enable-search self) value).

Property: drop-down:expression self ¶

An expression to evaluate to obtain strings to match against the search term.

See drop-down:enable-search for how to enable search. If drop-down:factory is not set, the expression is also used to bind strings to labels produced by a default factory.

Its value is a <GtkExpression>, or #f.

Set it with (set! (drop-down:expression self) value).

Property: drop-down:factory self ¶

Factory for populating list items.

Its value is a <GtkListItemFactory>, or #f.

Set it with (set! (drop-down:factory self) value).

Property: drop-down:header-factory self ¶

The factory for creating header widgets for the popup.

Its value is a <GtkListItemFactory>, or #f.

Set it with (set! (drop-down:header-factory self) value).

Property: drop-down:list-factory self ¶

The factory for populating list items in the popup.

If this is not set, drop-down:factory is used.

Its value is a <GtkListItemFactory>, or #f.

Set it with (set! (drop-down:list-factory self) value).

Property: drop-down:model self ¶

Model for the displayed items.

Its value is a <GListModel>, or #f.

Set it with (set! (drop-down:model self) value).

Property: drop-down:search-match-mode self ¶

The match mode for the search filter.

Its value is a <GtkStringFilterMatchMode> (or, to set it, one of its symbols).

Set it with (set! (drop-down:search-match-mode self) value).

Property: drop-down:selected self ¶

The position of the selected item.

If no item is selected, the property has the value GTK_INVALID_LIST_POSITION.

Its value is an unsigned 32-bit integer.

Set it with (set! (drop-down:selected self) value).

Property: drop-down:selected-item self ¶

The selected item.

Its value is a <GObject>, or #f.

It is read only.

Property: drop-down:show-arrow self ¶

Whether to show an arrow within the GtkDropDown widget.

Its value is a boolean.

Set it with (set! (drop-down:show-arrow self) value).

Procedures ¶

Method: drop-down:get-enable-search? self ⇒ %return ¶
Method: get-enable-search? self ⇒ %return ¶

Returns whether search is enabled.

self

Passed: a <GtkDropDown>.

a <GtkDropDown>

%return

Returned: a boolean.

#t if the popup includes a search entry

Method: drop-down:get-expression self ⇒ %return ¶
Method: get-expression self ⇒ %return ¶

Gets the expression set that is used to obtain strings from items.

See drop-down:set-expression.

self

Passed: a <GtkDropDown>.

a <GtkDropDown>

%return

Returned: a <GtkExpression>, or #f.

a <GtkExpression>

Method: drop-down:get-factory self ⇒ %return ¶
Method: get-factory self ⇒ %return ¶

Gets the factory that’s currently used to populate list items.

The factory returned by this function is always used for the item in the button. It is also used for items in the popup if drop-down:list-factory is not set.

self

Passed: a <GtkDropDown>.

a <GtkDropDown>

%return

Returned: a <GtkListItemFactory>, or #f.

The factory in use

Method: drop-down:get-header-factory self ⇒ %return ¶
Method: get-header-factory self ⇒ %return ¶

Gets the factory that’s currently used to create header widgets for the popup.

self

Passed: a <GtkDropDown>.

a <GtkDropDown>

%return

Returned: a <GtkListItemFactory>, or #f.

The factory in use

Method: drop-down:get-list-factory self ⇒ %return ¶
Method: get-list-factory self ⇒ %return ¶

Gets the factory that’s currently used to populate list items in the popup.

self

Passed: a <GtkDropDown>.

a <GtkDropDown>

%return

Returned: a <GtkListItemFactory>, or #f.

The factory in use

Method: drop-down:get-model self ⇒ %return ¶
Method: get-model self ⇒ %return ¶

Gets the model that provides the displayed items.

self

Passed: a <GtkDropDown>.

a <GtkDropDown>

%return

Returned: a <GListModel>, or #f.

The model in use

Method: drop-down:get-search-match-mode self ⇒ %return ¶
Method: get-search-match-mode self ⇒ %return ¶

Returns the match mode that the search filter is using.

self

Passed: a <GtkDropDown>.

a <GtkDropDown>

%return

Returned: a <GtkStringFilterMatchMode>.

the match mode of the search filter

Method: drop-down:get-selected self ⇒ %return ¶
Method: get-selected self ⇒ %return ¶

Gets the position of the selected item.

self

Passed: a <GtkDropDown>.

a <GtkDropDown>

%return

Returned: an unsigned 32-bit integer.

the position of the selected item, or GTK_INVALID_LIST_POSITION if no item is selected

Method: drop-down:get-selected-item self ⇒ %return ¶
Method: get-selected-item self ⇒ %return ¶

Gets the selected item. If no item is selected, #f is returned.

self

Passed: a <GtkDropDown>.

a <GtkDropDown>

%return

Returned: a <GObject>, or #f.

The selected item

Method: drop-down:get-show-arrow? self ⇒ %return ¶
Method: get-show-arrow? self ⇒ %return ¶

Returns whether to show an arrow within the widget.

self

Passed: a <GtkDropDown>.

a <GtkDropDown>

%return

Returned: a boolean.

#t if an arrow will be shown.

Procedure: drop-down:new [model] [expression] ⇒ %return ¶

Creates a new <GtkDropDown>.

You may want to call drop-down:set-factory to set up a way to map its items to widgets.

model

Passed, or left out: a <GListModel>, or #f.

the model to use

expression

Passed, or left out: a <GtkExpression>, or #f.

the expression to use

%return

Returned: a <GtkWidget>.

a new <GtkDropDown>

Procedure: drop-down:new-from-strings strings ⇒ %return ¶

Creates a new <GtkDropDown> that is populated with the strings.

strings

Passed: a list or vector, each a string.

The strings to put in the dropdown

%return

Returned: a <GtkWidget>.

a new <GtkDropDown>

Method: drop-down:set-enable-search self enable-search ¶
Method: set-enable-search self enable-search ¶

Sets whether a search entry will be shown in the popup that allows to search for items in the list.

Note that drop-down:expression must be set for search to work.

self

Passed: a <GtkDropDown>.

a <GtkDropDown>

enable-search

Passed: a boolean.

whether to enable search

Method: drop-down:set-expression self [expression] ¶
Method: set-expression self [expression] ¶

Sets the expression that gets evaluated to obtain strings from items.

This is used for search in the popup. The expression must have a value type of G_TYPE_STRING.

self

Passed: a <GtkDropDown>.

a <GtkDropDown>

expression

Passed, or left out: a <GtkExpression>, or #f.

a <GtkExpression>

Method: drop-down:set-factory self [factory] ¶
Method: set-factory self [factory] ¶

Sets the <GtkListItemFactory> to use for populating list items.

self

Passed: a <GtkDropDown>.

a <GtkDropDown>

factory

Passed, or left out: a <GtkListItemFactory>, or #f.

the factory to use

Method: drop-down:set-header-factory self [factory] ¶
Method: set-header-factory self [factory] ¶

Sets the <GtkListItemFactory> to use for creating header widgets for the popup.

self

Passed: a <GtkDropDown>.

a <GtkDropDown>

factory

Passed, or left out: a <GtkListItemFactory>, or #f.

the factory to use

Method: drop-down:set-list-factory self [factory] ¶
Method: set-list-factory self [factory] ¶

Sets the <GtkListItemFactory> to use for populating list items in the popup.

self

Passed: a <GtkDropDown>.

a <GtkDropDown>

factory

Passed, or left out: a <GtkListItemFactory>, or #f.

the factory to use

Method: drop-down:set-model self [model] ¶
Method: set-model self [model] ¶

Sets the <GListModel> to use.

self

Passed: a <GtkDropDown>.

a <GtkDropDown>

model

Passed, or left out: a <GListModel>, or #f.

the model to use

Method: drop-down:set-search-match-mode self search-match-mode ¶
Method: set-search-match-mode self search-match-mode ¶

Sets the match mode for the search filter.

self

Passed: a <GtkDropDown>.

a <GtkDropDown>

search-match-mode

Passed: a <GtkStringFilterMatchMode>, or one of its symbols.

the new match mode

Method: drop-down:set-selected self position ¶
Method: set-selected self position ¶

Selects the item at the given position.

self

Passed: a <GtkDropDown>.

a <GtkDropDown>

position

Passed: an unsigned 32-bit integer.

the position of the item to select, or GTK_INVALID_LIST_POSITION

Method: drop-down:set-show-arrow self show-arrow ¶
Method: set-show-arrow self show-arrow ¶

Sets whether an arrow will be displayed within the widget.

self

Passed: a <GtkDropDown>.

a <GtkDropDown>

show-arrow

Passed: a boolean.

whether to show an arrow within the widget

Signals ¶

Signal: drop-down:activate ¶

Connect a handler with (connect object drop-down:activate handler). It is called as (handler self).

Emitted to when the drop down is activated.

The ::activate signal on <GtkDropDown> is an action signal and emitting it causes the drop down to pop up its dropdown.

self

Passed: a <GtkDropDown>.


Next: <GtkDropTarget>, Previous: <GtkDropControllerMotion>, Up: Classes   [Index]