//! Build and show dropdown menus. use crate::alignment; use crate::event::{self, Event}; use crate::layout; use crate::mouse; use crate::overlay; use crate::renderer; use crate::text::{self, Text}; use crate::touch; use crate::widget::scrollable::{self, Scrollable}; use crate::widget::Container; use crate::{ Clipboard, Color, Element, Hasher, Layout, Length, Padding, Point, Rectangle, Shell, Size, Vector, Widget, }; pub use iced_style::menu::Style; /// A list of selectable options. #[allow(missing_debug_implementations)] pub struct Menu<'a, T, Renderer: text::Renderer> { state: &'a mut State, options: &'a [T], hovered_option: &'a mut Option, last_selection: &'a mut Option, width: u16, padding: Padding, text_size: Option, font: Renderer::Font, style: Style, } impl<'a, T, Renderer> Menu<'a, T, Renderer> where T: ToString + Clone, Renderer: text::Renderer + 'a, { /// Creates a new [`Menu`] with the given [`State`], a list of options, and /// the message to produced when an option is selected. pub fn new( state: &'a mut State, options: &'a [T], hovered_option: &'a mut Option, last_selection: &'a mut Option, ) -> Self { Menu { state, options, hovered_option, last_selection, width: 0, padding: Padding::ZERO, text_size: None, font: Default::default(), style: Default::default(), } } /// Sets the width of the [`Menu`]. pub fn width(mut self, width: u16) -> Self { self.width = width; self } /// Sets the [`Padding`] of the [`Menu`]. pub fn padding>(mut self, padding: P) -> Self { self.padding = padding.into(); self } /// Sets the text size of the [`Menu`]. pub fn text_size(mut self, text_size: u16) -> Self { self.text_size = Some(text_size); self } /// Sets the font of the [`Menu`]. pub fn font(mut self, font: Renderer::Font) -> Self { self.font = font; self } /// Sets the style of the [`Menu`]. pub fn style(mut self, style: impl Into