Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

The Pick List Widget

A dropdown menu that lets the user select one option from a list of strings. Clicking the widget opens a dropdown; selecting an item closes it and triggers the callback.

Interface

val pick_list: fn(
  ?#selected: &[string, null],
  ?#on_select: fn(string) -> Any,
  ?#placeholder: &string,
  ?#width: &Length,
  ?#padding: &Padding,
  ?#disabled: &bool,
  &Array<string>
) -> Widget

Parameters

  • #selected – Reference to the currently selected value, or null if nothing is selected. When null, the placeholder text is shown instead.
  • #on_select – Callback invoked when the user picks an item. Receives the selected string. Typically: #on_select: |v| choice <- v.
  • #placeholder – Text displayed when #selected is null. Gives the user a hint about what to choose.
  • #width – Width of the dropdown. Accepts Length values.
  • #padding – Interior padding around the displayed text. Accepts Padding values.
  • #disabled – When true, the dropdown cannot be opened. Defaults to false.
  • positional &Array<string> – Reference to the list of available options.

Examples

use gui;
use gui::text;
use gui::pick_list;
use gui::column;
mod icon;

let language: [string, null] = null;

let col = column(
    #spacing: &15.0,
    #padding: &`All(30.0),
    #width: &`Fill,
    &[
        text(#size: &24.0, &"Pick List Demo"),
        text(&"Selected: [language]"),
        pick_list(
            #selected: &language,
            #on_select: |v| language <- v,
            #placeholder: &"Choose a language...",
            &["English", "Spanish", "French", "Japanese"]
        )
    ]
);

[&window(#icon: &icon::icon, #title: &"Pick List", &col)]

Pick List

See Also

  • Combo Box — searchable dropdown with type-to-filter
  • Radio — inline single-select when there are few options