pub struct Menu { /* fields omitted */ }
Represents a Menu that can contain InterfaceItem
s 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};
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)),
}
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("]");
let mut menu = Menu::new().with_focus(true);
while terminal.refresh() {
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))
.with_item(&mut input, None),
) {
text_buffer.clear();
menu.draw(&mut text_buffer);
terminal.flush(&mut text_buffer);
}
terminal.draw(&text_buffer);
}
Initializes a new empty menu
Sets the position and consumes the Menu, then returns it
Sets weather the TextInput is focused.
Sets the initial growth direction of the Menu
Sets the way the menu is browsed
Sets the position of the menu
Set whether the menu is focused
Sets the growth direction of the Menu
Sets the way the menu is browsed
Get the position of the Menu
Gets the width this Menu should take up when drawn
Get the height this Menu should take up when drawn
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)
Return the current item that is selected.
Returns the button that must be pressed in order to select the previous menu item.
Returns the button that must be pressed in order to select the next menu item.
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.
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static