Skip to main content

Dropdown

Struct Dropdown 

Source
pub struct Dropdown {
    pub style: Style,
    pub item_style: Style,
    pub selected_color: Color,
    pub text_color: Color,
    /* private fields */
}
Expand description

Closed-trigger + open-list selector widget (LPAR-13 §5.C).

Stores option strings as owned Strings so callers are not required to keep the source slice alive.

Fields§

§style: Style

Background + border style for the trigger button (Part::MAIN).

§item_style: Style

Style applied to option rows (Part::ITEMS).

§selected_color: Color

Highlight color for the selected row (Part::SELECTED).

§text_color: Color

Text color for option labels.

Implementations§

Source§

impl Dropdown

Source

pub fn new(bounds: Rect) -> Self

Create a Dropdown occupying bounds with no options and the first option selected.

Source

pub fn set_font(&mut self, font: &'static dyn FontMetrics)

Assign the font used to render this widget (FONT-00 §5); resolves to FONT_6X10 when unset.

Source

pub fn set_options(&mut self, options: &[impl AsRef<str>])

Replace the option list.

selected is reset to 0 regardless of the previous value.

Source

pub fn options(&self) -> &[String]

Return a slice of all option strings.

Source

pub fn option_count(&self) -> usize

Return the number of options.

Source

pub fn set_selected(&mut self, index: usize)

Set the selected index (clamped to 0..options.len()).

Source

pub fn selected(&self) -> usize

Return the currently selected index.

Source

pub fn selected_text(&self) -> &str

Return the text of the selected option, or "" when the list is empty.

Source

pub fn open(&mut self)

Open the option list.

Source

pub fn close(&mut self)

Close the option list without changing the selection.

Source

pub fn toggle(&mut self)

Toggle between open and closed states.

Source

pub fn is_open(&self) -> bool

Return true when the option list is visible.

Source

pub fn set_dir(&mut self, dir: DropdownDir)

Set the direction the open list grows relative to the trigger.

Source

pub fn dir(&self) -> DropdownDir

Return the current open direction.

Source

pub fn set_symbol(&mut self, sym: Option<&str>)

Set an optional indicator glyph drawn at the right of the trigger.

Source

pub fn symbol(&self) -> Option<&str>

Return the indicator glyph, if any.

Source

pub fn set_selected_highlight(&mut self, enable: bool)

Set whether the selected option is highlighted inside the open list.

Source

pub fn selected_highlight(&self) -> bool

Return whether selected-item highlighting is enabled.

Source

pub fn navigate_next(&mut self)

Move the highlighted selection one step downward, wrapping at the end.

Wire to ObjectEvent::Key(Key::ArrowDown) via a node handler.

Source

pub fn navigate_prev(&mut self)

Move the highlighted selection one step upward, wrapping at the start.

Wire to ObjectEvent::Key(Key::ArrowUp) via a node handler.

Source

pub fn activate_selected(&mut self)

Confirm the current highlighted selection and close the list.

Wire to ObjectEvent::Key(Key::Enter) via a node handler.

Source

pub fn close_key(&mut self)

Close without changing the selection.

Wire to ObjectEvent::Key(Key::Escape) via a node handler.

Trait Implementations§

Source§

impl Widget for Dropdown

Source§

fn bounds(&self) -> Rect

Return the area this widget occupies relative to its parent.
Source§

fn widget_font_mut(&mut self) -> Option<&mut WidgetFont>

Expose this widget’s font slot for cascade-driven font resolution (FONT-05 §5.B). Read more
Source§

fn set_bounds(&mut self, bounds: Rect)

Called by the LPAR-10 layout pass to notify this widget of its layout-computed bounds. Read more
Source§

fn draw(&self, renderer: &mut dyn Renderer)

Render the widget using the provided Renderer.
Source§

fn handle_event(&mut self, event: &Event) -> bool

Handle an event and return true if it was consumed. Read more
Source§

fn clear_region(&mut self) -> Option<Rect>

Return a region (in draw/landscape coordinates) that should be restored from the pristine background copy, or None. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.