Class DropDown

All Implemented Interfaces:
PointerInterface

public class DropDown extends Widget
`GtkDropDown` is a widget that allows the user to choose an item
from a list of options.

![An example GtkDropDown](drop-down.png)

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 [class@Gtk.ListItemFactory]. The default factory displays simple strings.

`GtkDropDown` knows how to obtain strings from the items in a
[class@Gtk.StringList]; for other models, you have to provide an expression
to find the strings via [method@Gtk.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 [method@Gtk.DropDown.set_enable_search].

Here is a UI definition example for `GtkDropDown` with a simple model:
```xml
<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>
```

# CSS nodes

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

# Accessibility

`GtkDropDown` uses the %GTK_ACCESSIBLE_ROLE_COMBO_BOX role.

https://docs.gtk.org/gtk4/class.DropDown.html

  • Field Details

  • Constructor Details

    • DropDown

      public DropDown(PointerContainer pointer)
    • DropDown

      public DropDown(@Nullable ListModel model, @Nullable Expression expression)
      Creates a new `GtkDropDown`.

      You may want to call [method@Gtk.DropDown.set_factory]
      to set up a way to map its items to widgets.
      Parameters:
      model - the model to use
      expression - the expression to use
  • Method Details

    • getClassHandler

      public static ClassHandler getClassHandler()
    • newFromStringsDropDown

      public static DropDown newFromStringsDropDown(@Nonnull Strs strings)
      Creates a new `GtkDropDown` that is populated with
      the strings.
      Parameters:
      strings - The strings to put in the dropdown
      Returns:
      a new `GtkDropDown`
    • getEnableSearch

      public boolean getEnableSearch()
      Returns whether search is enabled.
      Returns:
      %TRUE if the popup includes a search entry
    • getExpression

      public Expression getExpression()
      Gets the expression set that is used to obtain strings from items.

      See [method@Gtk.DropDown.set_expression].
      Returns:
      a `GtkExpression`
    • getFactory

      public ListItemFactory getFactory()
      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 [property@Gtk.DropDown:list-factory] is not set.
      Returns:
      The factory in use
    • getListFactory

      public ListItemFactory getListFactory()
      Gets the factory that's currently used to populate list items in the popup.
      Returns:
      The factory in use
    • getModel

      public ListModel getModel()
      Gets the model that provides the displayed items.
      Returns:
      The model in use
    • getSelected

      public int getSelected()
      Gets the position of the selected item.
      Returns:
      the position of the selected item, or %GTK_INVALID_LIST_POSITION if not item is selected
    • getSelectedItem

      public Pointer getSelectedItem()
      Gets the selected item. If no item is selected, %NULL is returned.
      Returns:
      The selected item
    • getShowArrow

      public boolean getShowArrow()
      Returns whether to show an arrow within the widget.
      Returns:
      %TRUE if an arrow will be shown.
    • setEnableSearch

      public void setEnableSearch(boolean enable_search)
      Sets whether a search entry will be shown in the popup that
      allows to search for items in the list.

      Note that [property@Gtk.DropDown:expression] must be set for
      search to work.
      Parameters:
      enable_search - whether to enable search
    • setExpression

      public void setExpression(@Nullable Expression 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.
      Parameters:
      expression - a `GtkExpression`
    • setFactory

      public void setFactory(@Nullable ListItemFactory factory)
      Sets the `GtkListItemFactory` to use for populating list items.
      Parameters:
      factory - the factory to use
    • setListFactory

      public void setListFactory(@Nullable ListItemFactory factory)
      Sets the `GtkListItemFactory` to use for populating list items in the popup.
      Parameters:
      factory - the factory to use
    • setModel

      public void setModel(@Nullable ListModel model)
      Sets the `GListModel` to use.
      Parameters:
      model - the model to use
    • setSelected

      public void setSelected(int position)
      Selects the item at the given position.
      Parameters:
      position - the position of the item to select, or %GTK_INVALID_LIST_POSITION
    • setShowArrow

      public void setShowArrow(boolean show_arrow)
      Sets whether an arrow will be displayed within the widget.
      Parameters:
      show_arrow - whether to show an arrow within the widget
    • onActivate

      public SignalHandler onActivate(DropDown.OnActivate signal)
      Connect to signal "activate".
      See DropDown.OnActivate.onActivate() for signal description.
      Field SIGNAL_ON_ACTIVATE contains original signal name and can be used as resource reference.
      Parameters:
      signal - callback function (lambda).
      Returns:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • asAccessible

      public Accessible asAccessible()
      Implements interface Accessible. Call this to get access to interface functions.
      Overrides:
      asAccessible in class Widget
      Returns:
      Accessible
    • asBuildable

      public Buildable asBuildable()
      Implements interface Buildable. Call this to get access to interface functions.
      Overrides:
      asBuildable in class Widget
      Returns:
      Buildable
    • asConstraintTarget

      public ConstraintTarget asConstraintTarget()
      Implements interface ConstraintTarget. Call this to get access to interface functions.
      Overrides:
      asConstraintTarget in class Widget
      Returns:
      ConstraintTarget
    • getTypeID

      public static long getTypeID()
    • getParentTypeID

      public static long getParentTypeID()
    • getTypeSize

      public static TypeSystem.TypeSize getTypeSize()
    • getParentTypeSize

      public static TypeSystem.TypeSize getParentTypeSize()
    • getInstanceSize

      public static int getInstanceSize()