[][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

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::new(&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 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 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 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 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 for later drawing and 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))

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]