veloren/voxygen/egui/src/widgets.rs
Ben Wallis d665ce329d * Added new Admin Commands window to egui, including Give Items and Kits sections
* Added widgets.rs to egui for reusable widgets
* Added filterable_list egui widget
* Reworked DebugShapeAction to be a more generic EguiAction which now allows for ChatCommands (used by admin tools) as well as DebugShape drawing requests.
* Fixed egui event handling so that typing/clicking within egui windows now correctly doesn't pass these events onto the game itself
* Removed /give_item limit for stackable items
2021-09-18 16:17:42 +01:00

35 lines
1014 B
Rust

use egui::{Label, ScrollArea, Ui, Vec2};
pub(crate) fn filterable_list(
ui: &mut Ui,
list_items: &[String],
search_text: &str,
selected_index: &mut usize,
) {
let scroll_area = ScrollArea::auto_sized();
scroll_area.show(ui, |ui| {
ui.spacing_mut().item_spacing = Vec2::new(0.0, 2.0);
let search_text = search_text.to_lowercase();
for (i, list_item) in list_items.iter().enumerate().filter_map(|(i, list_item)| {
if search_text.is_empty() || list_item.to_lowercase().contains(&search_text) {
Some((i, list_item))
} else {
None
}
}) {
if ui
.selectable_label(i == *selected_index, list_item)
.clicked()
{
*selected_index = i;
};
}
});
}
pub(crate) fn two_col_row(ui: &mut Ui, label: impl Into<Label>, content: impl Into<Label>) {
ui.label(label);
ui.label(content);
ui.end_row();
}