I am having trouble understanding what exactly to put as the parameters for the iced::overlay::menu::Menu::new() function.
Let us say I have a list of potential services, or windows, that my application offers for user interaction:
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Service {
Account,
Chat,
Demo,
DistributedComputation,
DistributedFileSharing,
ReadMe,
SystemInformation,
}
impl<'a> std::fmt::Display for Service {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{}",
match self {
Service::Account => "Account",
Service::Chat => "Chat",
Service::Demo => "Demo",
Service::DistributedComputation => "Distributed Computation",
Service::DistributedFileSharing => "Distributed File Sharing",
Service::ReadMe => "ReadMe",
Service::SystemInformation => "System",
}
)
}
}
And in my application I want a menu widget that will display these as the options. When an option is selected I want it to emit a message that will then update the view content. Again the issue I am having is what exactly two of the Menu::new() parameters are asking for in order to make this work?
Menu::new(
state: &'a mut State,
options: &'a [T],
hovered_option: &'a mut Option<usize>,
last_selection: &'a mut Option<T>
);
I currently have:
let menu_state = menu::State::new();
/// Creates a new Menu with the given State, a list of options, and the message to be produced when an option is selected.
let menu = Menu::new(
&mut menu_state,
&Service::ALL[..],
hovered_option,
last_selection
)
I am hoping to replace my current pick_list with a menu. The code below shows how I have that implemented.
let pick_list = pick_list(
&Service::ALL[..],
service,
move |service| Message::FrameMessage(FrameMessage::ServiceSelected(service)),
)
.placeholder("Choose a service...");