[][src]Struct glerminal::menu_systems::Menu

pub struct Menu { /* fields omitted */ }

Represents a Menu that can contain InterfaceItems in a list, which through with inputs the user can focus an item and interact with it.

By default selection through Menus is done with a keyboard. It is possible to make selection with a mouse possible by changing FocusSelection with with_focus_selection or set_focus_selection

To add a TextProcessor to the menu, such as the Parser, use with_text_processor

Example menu usage:

use glerminal::menu_systems::{Filter, Menu, MenuList, MenuPosition, TextInput, TextItem};
use glerminal::{TerminalBuilder, TextBuffer};

// Initialize terminal and text buffer
let terminal = TerminalBuilder::new().build();
let mut text_buffer;
match TextBuffer::create(&terminal, (80, 24)) {
    Ok(buffer) => text_buffer = buffer,
    Err(error) => panic!(format!("Failed to initialize text buffer: {}", error)),
}

// Create three example InterfaceItems to use
let mut label = TextItem::new("Text label");
let mut button = TextItem::new("Press me!").with_is_button(true);
let mut input = TextInput::new(None, 10)
    .with_filter(Filter::empty_filter().with_basic_latin_characters())
    .with_prefix("Name: [")
    .with_suffix("]");

// Create the actual menu
let mut menu = Menu::new().with_focus(true);

while terminal.refresh() {

    // Update the menu. Update returns weather it should be redrawn.
    if menu.update(
        &terminal.get_current_events(),
        terminal.delta_time(),
        &text_buffer,
        &mut MenuList::new()
            .with_item(&mut label, None)
            .with_item(&mut button, MenuPosition::RelativeToLast(0, 1))
            // Use MenuPosition to make a gap between label and button
            .with_item(&mut input, None),
    ) {
        text_buffer.clear();              // Clear the screen
        menu.draw(&mut text_buffer);      // Draw the menu
        terminal.flush(&mut text_buffer); // Apply changes; flush
    }

    terminal.draw(&text_buffer);
}

Methods

impl Menu
[src]

pub fn new() -> Menu
[src]

Initializes a new empty menu

pub fn with_pos(self, position: (u32, u32)) -> Menu
[src]

Sets the position and consumes the Menu, then returns it

pub fn with_focus(self, focused: bool) -> Menu
[src]

Sets weather the TextInput is focused.

pub fn with_growth_direction(self, growth_direction: GrowthDirection) -> Menu
[src]

Sets the initial growth direction of the Menu

pub fn with_focus_selection(self, focus_selection: FocusSelection) -> Menu
[src]

Sets the way the menu is browsed

pub fn with_text_processor<T: 'static + TextProcessor>(
    self,
    processor: T
) -> Menu
[src]

Set the text processor for this menu, or in other words, the TextProcessor that is given to each InterfaceItem in their update.

pub fn set_pos(&mut self, pos: (u32, u32))
[src]

Sets the position of the menu

pub fn set_focused(&mut self, focused: bool)
[src]

Set whether the menu is focused

pub fn set_growth_direction(&mut self, growth_direction: GrowthDirection)
[src]

Sets the growth direction of the Menu

pub fn set_focus_selection(&mut self, focus_selection: FocusSelection)
[src]

Sets the way the menu is browsed

pub fn set_text_processor<T: 'static + TextProcessor>(&mut self, processor: T)
[src]

Set the text processor for this menu, or in other words, the TextProcessor that is given to each InterfaceItem in their update.

pub fn get_pos(&self) -> (u32, u32)
[src]

Get the position of the Menu

pub fn get_total_width(&self) -> u32
[src]

Gets the width this Menu should take up when drawn

pub fn get_total_height(&self) -> u32
[src]

Get the height this Menu should take up when drawn

pub fn is_focused(&self) -> bool
[src]

Is the menu currently focused and is it receiving input. If the menu is not focused, selection will point to a non-existing item (-1)

pub fn get_select_idx(&self) -> u32
[src]

Return the current item that is selected.

pub fn set_select_idx(&mut self, idx: u32)
[src]

Tries to set the select idx for the Menu. If idx is greater than get_item_count() - 1, it will cap to that.

Note: Uses a cloned version of the list that is cloned in update. (See get_cloned_list())
Also the idx can move in update, if the item selected can not be selected.

pub fn get_previous_button(&self) -> VirtualKeyCode
[src]

Returns the button that must be pressed in order to select the previous menu item.

pub fn get_next_button(&self) -> VirtualKeyCode
[src]

Returns the button that must be pressed in order to select the next menu item.

pub fn get_cloned_list(&self) -> &[Box<dyn InterfaceItem>]
[src]

Get the currently cloned items in the menu.

In every update, if the items given are dirty (or the amount of items has changed), the list of items is deemed dirty and is then cloned. This cloned list can then be used for drawing or other heuristics, but not altering the actual items.

pub fn update(
    &mut self,
    events: &Events,
    delta: f32,
    text_buffer: &TextBuffer,
    list: &mut MenuList
) -> bool
[src]

Update the menu, first handling any events if necessary, checking dirtyness, saving changes (as a cloned list) for later drawing and functionality. (See get_cloned_list())

Returning whether the menu should be redrawn or not.

pub fn draw(&mut self, text_buffer: &mut TextBuffer)
[src]

Draw the menu and any saved children (see update(input, children))

Trait Implementations

impl Default for Menu
[src]

Auto Trait Implementations

impl !Send for Menu

impl !Sync for Menu

Blanket Implementations

impl<T> From for T
[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

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

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Erased for T

impl<T> Downcast for T where
    T: Any