[][src]Module glerminal::menu_systems

Menu systems is a module that allows easy creation and usage of Menus. Examples of what a menu can be, is ncurses.

Simply lists of InterfaceItems, that the user can browse through, press buttons, input text, do whatever you want with GUI items generally. You can even make your own InterfaceItems if you want.
Selection in Menus works with keyboard and mouse, changeable with FocusSelection.

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

If you wish to use InterfaceItems without the Menu struct, it is required to call handle_events, update and then draw for them, in that order. (See Example InterfaceItem usage without Menu)

Current pre-implemented items to use are

  • TextItem, functions as a text label and a button.
  • TextInput, can accept text input that can be get with get_text.
  • Dialog, can be used to display large volumes of text compactly.
  • Checkbox, can be checked (and unchecked), like a check- or radiobox (if using CheckboxGroup).

Note: This module requires menu_systems feature to be enabled.

Example usage of Menu:

(Same example can be found in Menu)

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);
}

Example InterfaceItem usage without Menu

use glerminal::menu_systems::{InterfaceItem, 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 a button
let mut button = TextItem::new("Press me")
    .with_is_button(true)
    .with_focused(true);

let processor = glerminal::text_processing::DefaultProcessor;

while terminal.refresh() {
    button.handle_events(&terminal.get_current_events());
    if button.was_just_pressed() {
        button.set_text("Pressed!");
    }
    button.update(terminal.delta_time(), &processor);
    if button.get_base().dirty {
        button.draw(&mut text_buffer);
        terminal.flush(&mut text_buffer);
    }
    terminal.draw(&text_buffer);
}

Structs

BorderChars

Represents all the different characters that are used in drawing the border for Window

Checkbox

Represents a Checkbox that can be checked or unchecked, and it's checked-status can be get with is_checked.

CheckboxGroup

Represents a group of checkboxes that can be managed like they were radio buttons.

Dialog

Represents a dialog-window, meaning a window of text that can be scrolled up and down.

Filter

Represents a list of characters that is used to filter which character are registered in a TextInput.

InterfaceItemBase

The base for all interaceItems. Contains metadata that is handled similarily in each InterfaceItem

Menu

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

MenuList

Represents a list of InterfaceItems that is passed to the Menu when updating

MenuSwitcher

A very neat tool designed to be used in making ie. button grids

TextInput

Represents a text-input field, that can be focused, takes in events (keyboard events as text), and it's possible to get the input text with get_text

TextItem

Represents a simple text item that by default can not be selected, but optionally can be selected and pressed like a button.

Window

Represents a window that clears everything in it's way and is able to limit the cursor within it's bounds with set_limits.

Enums

FocusSelection

Represents the way in which focus is selected in the menu

GrowthDirection

Determines the direction where the Menu will expand/grow from it's position

MenuPosition

Represents the position of a menu item in the menu

MenuSelectionMethod

Te way that is used to select the menu when switching menus

Traits

InterfaceItem

Represents a single menu item: an item that is somewhere, can handle events and can be drawn.

InterfaceItemClone

Represents a cloneable InterfaceItem; You should never implement this yourself, but instead derive Clone for all InterfaceItems.