[−][src]Module glerminal::menu_systems
Menu systems is a module that allows easy creation and usage of Menu
s.
Examples of what a menu can be, is ncurses.
Simply lists of InterfaceItem
s, that the user can browse through, press buttons,
input text, do whatever you want with GUI items generally. You can even make your own InterfaceItem
s if you want.
Selection in Menu
s works with keyboard and mouse, changeable with FocusSelection
.
Current pre-implemented items to use in Menus 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-systems:
(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::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); }
Structs
Checkbox | Represents a Checkbox that can be checked or unchecked, and it's checked-status can be get with |
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 HashMap from VirtualKeyCode to character. Used to filter out which characters get registered by the textinput. |
InterfaceItemBase | The base for all |
Menu | Represents a Menu that can contain |
MenuList | Represents a list of InterfaceItems that is passed to the Menu when updating |
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 |
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 |
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. |