4

GtkDropDown

 3 years ago
source link: https://developer.gnome.org/gtk4/3.98/GtkDropDown.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

GtkDropDown

GtkDropDown — Choose an item from a list

Types and Values

Object Hierarchy

    GObject
    ╰── GInitiallyUnowned
        ╰── GtkWidget
            ╰── GtkDropDown

Implemented Interfaces

GtkDropDown implements AtkImplementorIface, GtkBuildable and GtkConstraintTarget.

Includes

#include <gtk/gtk.h>

Description

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 of GListModel, and how the individual options are represented is determined by a GtkListItemFactory. The default factory displays simple strings, and expects to obtain these from the model by evaluating an expression that has to be provided via gtk_drop_down_set_expression().

The convenience method gtk_drop_down_set_from_strings() can be used to set up a model that is populated from an array of strings and an expression for obtaining those strings.

GtkDropDown can optionally allow search in the popup, which is useful if the list of options is long. To enable the search entry, use gtk_drop_down_set_enable_search().

GtkDropDown as GtkBuildable

The GtkDropDown implementation of the GtkBuildable interface supports adding items directly using the <items> element and specifying <item> elements for each item. Using <items> is equivalent to calling gtk_drop_down_set_from_strings(). Each <item> element supports the regular translation attributes “translatable”, “context” and “comments”.

Here is a UI definition fragment specifying GtkDropDown items:

<object class="GtkDropDown">
  <items>
    <item translatable="yes">Factory</item>
    <item translatable="yes">Home</item>
    <item translatable="yes">Subway</item>
  </items>
</object>

Functions

gtk_drop_down_new ()

GtkWidget *
gtk_drop_down_new (void);

Creates a new empty GtkDropDown.

You most likely want to call gtk_drop_down_set_factory() to set up a way to map its items to widgets and gtk_drop_down_set_model() to set a model to provide items next.


gtk_drop_down_set_from_strings ()

void
gtk_drop_down_set_from_strings (GtkDropDown *self,
                                const char *const *texts);

Populates self with the strings in text , by creating a suitable model and factory.

Parameters

a GtkDropDown

 

texts

a NULL-terminated string array

 

gtk_drop_down_set_model ()

void
gtk_drop_down_set_model (GtkDropDown *self,
                         GListModel *model);

Sets the GListModel to use.

Parameters

a GtkDropDown

 

model

the model to use or NULL for none.

[allow-none][transfer none]

gtk_drop_down_get_model ()

GListModel *
gtk_drop_down_get_model (GtkDropDown *self);

Gets the model that provides the displayed items.

Parameters

Returns

The model in use.

[nullable][transfer none]


gtk_drop_down_set_selected ()

void
gtk_drop_down_set_selected (GtkDropDown *self,
                            guint position);

Selects the item at the given position.

Parameters

a GtkDropDown

 

position

the position of the item to select, or GTK_INVALID_LIST_POSITION

 

gtk_drop_down_get_selected ()

guint
gtk_drop_down_get_selected (GtkDropDown *self);

Gets the position of the selected item.

Parameters

Returns

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


gtk_drop_down_set_factory ()

void
gtk_drop_down_set_factory (GtkDropDown *self,
                           GtkListItemFactory *factory);

Sets the GtkListItemFactory to use for populating list items.

Parameters

a GtkDropDown

 

factory

the factory to use or NULL for none.

[allow-none][transfer none]

gtk_drop_down_get_factory ()

GtkListItemFactory *
gtk_drop_down_get_factory (GtkDropDown *self);

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 “list-factory” is not set.

Parameters

Returns

The factory in use.

[nullable][transfer none]


gtk_drop_down_set_list_factory ()

void
gtk_drop_down_set_list_factory (GtkDropDown *self,
                                GtkListItemFactory *factory);

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

Parameters

a GtkDropDown

 

factory

the factory to use or NULL for none.

[allow-none][transfer none]

gtk_drop_down_get_list_factory ()

GtkListItemFactory *
gtk_drop_down_get_list_factory (GtkDropDown *self);

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

Parameters

Returns

The factory in use.

[nullable][transfer none]


gtk_drop_down_set_expression ()

void
gtk_drop_down_set_expression (GtkDropDown *self,
                              GtkExpression *expression);

Sets the expression that gets evaluated to obtain strings from items when searching in the popup. The expression must have a value type of GTK_TYPE_STRING.

Parameters

a GtkDropDown

 

expression

a GtkExpression, or NULL.

[nullable]

gtk_drop_down_get_expression ()

GtkExpression *
gtk_drop_down_get_expression (GtkDropDown *self);

Gets the expression set with gtk_drop_down_set_expression().

Parameters

Returns

a GtkExpression or NULL.

[nullable][transfer none]


gtk_drop_down_set_enable_search ()

void
gtk_drop_down_set_enable_search (GtkDropDown *self,
                                 gboolean enable_search);

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

Note that “expression” must be set for search to work.

Parameters

a GtkDropDown

 

enable_search

whether to enable search

 

gtk_drop_down_get_enable_search ()

gboolean
gtk_drop_down_get_enable_search (GtkDropDown *self);

Returns whether search is enabled.

Parameters

Returns

TRUE if the popup includes a search entry

Types and Values

GtkDropDown

typedef struct _GtkDropDown GtkDropDown;

Property Details

The “enable-search” property

  “enable-search”            gboolean

Whether to show a search entry in the popup.

Note that search requires “expression” to be set.

Owner: GtkDropDown

Flags: Read / Write

Default value: FALSE


The “expression” property

  “expression”               GtkExpression *

An expression to evaluate to obtain strings to match against the search term (see “enable-search”). If “factory” is not set, the expression is also used to bind strings to labels produced by a default factory.

[type GtkExpression]

Owner: GtkDropDown

Flags: Read / Write


The “factory” property

  “factory”                  GtkListItemFactory *

Factory for populating list items.

Owner: GtkDropDown

Flags: Read / Write


The “list-factory” property

  “list-factory”             GtkListItemFactory *

The factory for populating list items in the popup.

If this is not set, “factory” is used.

Owner: GtkDropDown

Flags: Read / Write


The “model” property

  “model”                    GListModel *

Model for the displayed items.

Owner: GtkDropDown

Flags: Read / Write


The “selected” property

  “selected”                 guint

The position of the selected item in “model”, or GTK_INVALID_LIST_POSITION if no item is selected.

Owner: GtkDropDown

Flags: Read / Write

Default value: 4294967295


Generated by GTK-Doc V1.99

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK