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
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};
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)),
}
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
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
.
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
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
.
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.
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.
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.
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.
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.
Returns the "default value" for a type. 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
)
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
impl<T> Downcast for T where T: Any, | |
Convert Box<Trait>
(where Trait: Downcast
) to Box<Any>
. Box<Any>
can then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
. Read more
Convert &Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot generate &Any
's vtable from &Trait
's. Read more
Convert &mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot generate &mut Any
's vtable from &mut Trait
's. Read more