iced-rs / iced_aw

Additional widgets for the Iced GUI library
MIT License
467 stars 110 forks source link

Trouble implementing menus #253

Closed sundaram123krishnan closed 4 months ago

sundaram123krishnan commented 4 months ago

I'm having trouble getting this to work based on the menu example in iced_aw. Specifically, I attempted to implement it, but I'm encountering an issue where menu_items cannot be passed to menu_tpl_1((menu_items)).

The compiler is giving me the following error: a value of type `Vec<icedaw::menu::Item<', , , >> cannot be built from an iterator over elements of type iced::widget::Button<', {closure@src/views/hardwareview.rs:575:65: 575:72}, , >

Below is the implementation:

let mut pin_options_row = Row::new().align_items(Alignment::Center);
        let menu_tpl_1 = |items| menu::Menu::new(items).max_width(180.0).offset(15.0).spacing(5.0);
        let bcm_pin_number = pin_description.bcm_pin_number.unwrap();
        let choices: &[PinFunction] = pin_description.options;
        let selected = selected_function.unwrap_or(&PinFunction::None);
        let menu_items = choices.iter().map(|choice| {
            Button::new(Text::new(choice.to_string())).on_press(move || {
                HardwareMessage::PinFunctionSelected(bcm_pin_number, choice.clone())
            })
        }).collect();

        let mb = menu_bar!((Button::new(Text::new(selected.to_string())), {
            menu_tpl_1((menu_items))
        }));
        pin_options_row = pin_options_row.push(mb);

I don't know any other way to implement this. Any help is much appreciated! Thx in advance!

genusistimelord commented 4 months ago

@latidoremi Can you take a look at this?

sundaram123krishnan commented 4 months ago

Never mind, Fixed. For reference https://github.com/nednoodlehead/punge/blob/a55242520aca2fadee2e2cbeb158fe1da05b704b/src/gui/persistent.rs#L106