Skip to content

ADropdownList#

A button with dropdown list.

Header:#include <AUI/View/ADropdownList.h>
CMake:aui_link(my_target PUBLIC aui::views)

Detailed Description#

Shows the selected item as a button; a click opens a popup with all the items. The items come from a list model of strings (AListModel<AString> is the simplest one).

1
2
3
4
5
6
7
8
_new<ADropdownList>(AListModel<AString>::make({
  "Dropdown list 1",
  "Dropdown list 2",
  "Dropdown list 3",
  "Dropdown list 4",
  "Dropdown list 5",
  "Dropdown list 6",
})),

selectionId() is a property with the index of the selected item (starting from 0, the first item is selected by default). Bind it or listen to selectionChanged:

auto list = _new<ADropdownList>(AListModel<AString>::make({ "one-way flight", "return flight" }));
AObject::connect(list->selectionId().changed, AObject::GENERIC_OBSERVER, [](int index) {
    ALogger::info("App") << "Selected " << index;
});

The model can be replaced later with setModel. Like any other view, the list can be disabled with setDisabled().

Examples#

examples/7guis/flight_booker/src/main.cpp

7GUIs Flight Booker — Flight Booker.

    // Set contents
    window->setContents(Centered {
      Vertical {
        _new<ADropdownList>(AListModel<AString>::make({ "one-way flight", "return flight" })) AUI_LET {
                AObject::connect(AUI_REACT(state->isReturnFlight ? 1 : 0), it->selectionId());
                AObject::connect(it->selectionId().changed, AObject::GENERIC_OBSERVER, [=](int newSelection) {
                    state->isReturnFlight = newSelection == 1;
                });
            },
examples/ui/views/src/ExampleWindow.cpp

Views Example — All-in-one views building example.

                GroupBox {
                  Label { "Dropdown lists" },
                  Vertical {
                    /// [dropdown]
                    _new<ADropdownList>(AListModel<AString>::make({
                      "Dropdown list 1",
                      "Dropdown list 2",
                      "Dropdown list 3",
                      "Dropdown list 4",
                      "Dropdown list 5",

Public Methods#

selectionId#


auto ADropdownList::selectionId()

Selected id property.

Examples: