Struct Menu

Source
pub struct Menu<'a, T: 'a, S: AsMut<[MenuItem<'a, T>]>> { /* private fields */ }
Expand description

A (context) menu with nestable items

Implementations§

Source§

impl<'a, T: 'a> Menu<'a, T, Vec<MenuItem<'a, T>>>

Source

pub fn new(x: f32, y: f32, on_close: T) -> Self

Construct a new Menu

Source

pub fn position(self, (x, y): (f32, f32)) -> Self

Sets the (x, y) coordinates of the menu relative to it’s parent.

Source

pub fn on_close(self, on_close: T) -> Self

Sets the message to be posted when the menu is closed without selecting an item.

Source

pub fn items(self, items: Vec<MenuItem<'a, T>>) -> Self

Sets all of the items of the menu

Source

pub fn push(self, item: MenuItem<'a, T>) -> Self

Adds an item to the menu

Source

pub fn extend<I: IntoIterator<Item = MenuItem<'a, T>>>(self, iter: I) -> Self

Adds items using an iterator

Trait Implementations§

Source§

impl<'a, T: 'a> Default for Menu<'a, T, Vec<MenuItem<'a, T>>>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'a, T: 'a + Send, S: 'a + Send + AsRef<[MenuItem<'a, T>]> + AsMut<[MenuItem<'a, T>]>> IntoNode<'a, T> for Menu<'a, T, S>

Source§

fn into_node(self) -> Node<'a, T>

Perform the conversion.
Source§

fn class(self, class: &'a str) -> Node<'a, Message>

Convenience function that converts to a node and then adds a style class to the resulting Node.
Source§

fn key<K: Hash>(self, key: K) -> Node<'a, Message>

Convenience function that converts to a node and then sets a custom id to the resulting Node.
Source§

impl<'a, T: 'a + Send, S: Send + AsRef<[MenuItem<'a, T>]> + AsMut<[MenuItem<'a, T>]>> Widget<'a, T> for Menu<'a, T, S>

Source§

type State = MenuState

The type of state this widget keeps track of.
Source§

fn mount(&self) -> Self::State

Create a new state
Source§

fn widget(&self) -> &'static str

The name of this widget, used to identify widgets of this type in stylesheets.
Source§

fn len(&self) -> usize

Should return the amount of children this widget has. Must be consistent with visit_children().
Source§

fn visit_children( &mut self, visitor: &mut dyn FnMut(&mut dyn GenericNode<'a, T>), )

Applies a visitor to all childs of the widget. If an widget fails to visit it’s children, the children won’t be able to resolve their stylesheet, resulting in a panic when calling size, hit, event or draw.
Source§

fn size(&self, _: &MenuState, style: &Stylesheet) -> (Size, Size)

Returns the (width, height) of this widget. The extents are defined as a Size, which will later be resolved to actual dimensions.
Source§

fn hit( &self, state: &MenuState, layout: Rectangle, clip: Rectangle, _style: &Stylesheet, x: f32, y: f32, ) -> bool

Perform a hit detect on the widget. Most widgets are fine with the default implementation, but some widgets (like Window need to report a miss (false) even when the queried position is within their layout. Read more
Source§

fn focused(&self, state: &MenuState) -> bool

Test the widget for focus exclusivity. If the widget or one of it’s descendants is in an exclusive focus state, this function should return true. In all other cases, it should return false. When a widget is in an exclusive focus state it is the only widget that is allowed to receive events in event. Widgets that intended to use this behaviour are modal dialogs, dropdown boxes, context menu’s, etc.
Source§

fn event( &mut self, state: &mut MenuState, viewport: Rectangle, clip: Rectangle, style: &Stylesheet, event: Event, context: &mut Context<T>, )

Handle an event. If an event changes the graphical appearance of an Widget, redraw should be called to let the Ui know that the ui should be redrawn. Read more
Source§

fn draw( &mut self, state: &mut MenuState, viewport: Rectangle, clip: Rectangle, style: &Stylesheet, ) -> Vec<Primitive<'a>>

Draw the widget. Returns a list of Primitives that should be drawn. Read more
Source§

fn key(&self) -> u64

The key of this widget, used for resolving state.
Source§

fn state(&self, _state: &Self::State) -> StateVec

The state of this widget, used for computing the style. If None is returned, Node will automatically compute a state, such as “hover” and “pressed”.
Source§

fn is_empty(&self) -> bool

Returns whether this children has no children. Must be consistent with visit_children().

Auto Trait Implementations§

§

impl<'a, T, S> Freeze for Menu<'a, T, S>
where S: Freeze, T: Freeze,

§

impl<'a, T, S> RefUnwindSafe for Menu<'a, T, S>

§

impl<'a, T, S> Send for Menu<'a, T, S>
where S: Send, T: Send,

§

impl<'a, T, S> Sync for Menu<'a, T, S>
where S: Sync, T: Sync,

§

impl<'a, T, S> Unpin for Menu<'a, T, S>
where S: Unpin, T: Unpin,

§

impl<'a, T, S> UnwindSafe for Menu<'a, T, S>
where S: UnwindSafe, T: UnwindSafe,

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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>