Skip to content

Basic example doesn't work in eframe template, widgets aren't recognized #7

@dRAT3

Description

@dRAT3

Hi, I cloned the eframe starter and tried to add the widgets to it by copying the basic example into my update function

        let Self { label, value } = self;

        // Examples of how to create different panels and windows.
        // Pick whichever suits you.
        // Tip: a good default choice is to just keep the `CentralPanel`.
        // For inspiration and more examples, go to https://emilk.github.io/egui

        #[cfg(not(target_arch = "wasm32"))] // no File->Quit on web pages!
        egui::TopBottomPanel::top("top_panel").show(ctx, |ui| {
            // The top panel is often a good place for a menu bar:
            egui::menu::bar(ui, |ui| {
                ui.menu_button("File", |ui| {
                    if ui.button("Quit").clicked() {
                        _frame.close();
                    }
                });
            });
        });

        egui::CentralPanel::default().show(ctx, |ui| {
            // The central panel the region left after adding TopPanel's and SidePanel's

            ui.heading("eframe template");
            ui.hyperlink("https://github.com/emilk/eframe_template");
            ui.add(egui::github_link_file!(
                "https://github.com/emilk/eframe_template/blob/master/",
                "Source code."
            ));
            egui::warn_if_debug_build(ui);
        });
        egui::Window::new("My window")
            .default_pos(pos2(20.0, 100.0))
            .show(ctx, |ui| {
                ui.add(Port::new(0));
            });
        egui::Window::new("My window 2")
            .default_pos(pos2(200.0, 20.0))
            .show(ctx, |ui| {
                ui.add(Port::new(1));
                ui.add_space(10.0);
                ui.add(Port::new(2));
            });
        egui::Window::new("My window 3")
            .default_pos(pos2(200.0, 200.0))
            .show(ctx, |ui| {
                ui.add(Port::new(3));

                ui.add(Cable::new(0, Plug::to(0), Plug::to(1)));
                ui.add(Cable::new(1, Plug::to(0), Plug::to(3)));
                ui.add(Cable::new(2, Plug::to(2), Plug::unplugged()));
            });
    }
}

But then I get the error:

error[E0277]: expected a `FnOnce<(&mut egui::Ui,)>` closure, found `egui_cable::port::Port`
    --> src/app.rs:85:24
     |
85   |                 ui.add(Port::new(0));
     |                    --- ^^^^^^^^^^^^ expected an `FnOnce<(&mut egui::Ui,)>` closure, found `egui_cable::port::Port`
     |                    |
     |                    required by a bound introduced by this call
     |
     = help: the trait `for<'a> FnOnce<(&'a mut egui::Ui,)>` is not implemented for `egui_cable::port::Port`
     = help: the following other types implement trait `egui::Widget`:
               &eframe::epaint::PaintStats
               &mut eframe::epaint::TessellationOptions
               egui::Button
               egui::Checkbox<'a>
               egui::DragValue<'a>
               egui::Hyperlink
               egui::Image
               egui::ImageButton
             and 9 others
     = note: required for `egui_cable::port::Port` to implement `egui::Widget`
note: required by a bound in `egui::Ui::add`
    --> /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/egui-0.21.0/src/ui.rs:1055:40
     |
1055 |     pub fn add(&mut self, widget: impl Widget) -> Response {
     |                                        ^^^^^^ required by this bound in `egui::Ui::add`

I get the same error for all the egui_cable widgets.

Do you have any idea what I might've done wrong or if it is a bug?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions