three-d icon indicating copy to clipboard operation
three-d copied to clipboard

Show image on the panel

Open YueChuCheng opened this issue 3 years ago • 7 comments

Hi, I am searching for ways to show images on the panel, currently, I refer to this example in egui and write the code below

        let image = RetainedImage::from_image_bytes(
            "./data/img/1.jpg",
            include_bytes!("./data/img/1.jpg"),
        )
        .unwrap();

        TopBottomPanel::top("test panel").show(gui_context, |ui| {
            ui.add(egui::Image::new(
                            image.texture_id(gui_context),
                            image.size_vec2(),
                        ))
        });

Error shows as

error[E0277]: the trait bound `Vec2: From<emath::vec2::Vec2>` is not satisfied
   --> src/main.rs:180:29
    |
178 |                         ui.add(egui::Image::new(
    |                                ---------------- required by a bound introduced by this call
179 |                             image.texture_id(gui_context),
180 |                             image.size_vec2(),
    |                             ^^^^^^^^^^^^^^^^^ the trait `From<emath::vec2::Vec2>` is not implemented for `Vec2`
    |

and

error[E0308]: mismatched types
   --> src/main.rs:179:29
    |
178 |                         ui.add(egui::Image::new(
    |                                ---------------- arguments to this function are incorrect
179 |                             image.texture_id(gui_context),
    |                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected enum `TextureId`, found enum `epaint::TextureId`
    |

I think it is because can't share variable type between three_d::egui and egui, but I have no idea how to fix this, wish you can give me some advice. 🙏

YueChuCheng avatar May 12 '22 04:05 YueChuCheng

I think your problem is that you are both using egui and three_d::egui. You can just use egui for all of your gui rendering and three_d for the 3D stuff only?

asny avatar May 12 '22 13:05 asny

I think the problem here is more likely that three-d is using a quite old version of egui. I can take a look and try to upgrade to 1.18.1. This would also lead to a breaking change, but since 0.12 is going to be breaking anyway, it should be okay.

konsti219 avatar May 12 '22 15:05 konsti219

Yes, you're right 🙂 But I still don't understand why you want to mix three_d::egui and egui, just use one of them. But anyway, you are of course welcome to upgrade egui, it would be much appreciated, but keep in mind that three_d::egui will be deprecated when #216 is done. So if you're up for it, you are also much welcome to do #216.

asny avatar May 12 '22 17:05 asny

I think your problem is that you are both using egui and three_d::egui. You can just use egui for all of your gui rendering and three_d for the 3D stuff only?

@asny thanks for your reply, but how can I connect both three_d::window and eframe window? The only example I can find is this one, but it only uses eframe to render, seems not what you mean You can just use egui for all of your gui rendering and three_d for the 3D stuff only?.

YueChuCheng avatar May 15 '22 14:05 YueChuCheng

In that example the paint_with_three_d method draw stuff using three-d so that is exactly what you want to do. Basically you don't need both eframe and a three-d window, it does the same thing, namely setting up a window and handling input. The same as you don't need both versions of egui, just choose the original one. What you need from three-d is the 3D rendering capabilities which is in the renderer module of three-d. So just expand the eframe example 🙂 does it make sense?

asny avatar May 16 '22 04:05 asny

@asny Hi, just test eframe but it seems not as convenient as three_d while doing camera control and some other feature, so I still wish that rendering can be done by three_d::window 😄. But according to your previous comment, it seems unable to add ui component like egui::Image right?

YueChuCheng avatar May 16 '22 17:05 YueChuCheng

Sorry for the late reply. It should definitely be doable to use a three-d window and the original egui. Actually, the plan is to use that combination in all of the examples and deprecate three-d version of egui (#216 ). I will look at it soon so you'll have an example of how to do it, but nothing is really holding you back, just use egui-glow instead of the three-d version of egui. Does it make sense?

asny avatar May 19 '22 10:05 asny

I've updated to the latest version of egui so now you should be able to use the latest features. Also I've made it possible to use the controls without the window so you can also use eframe and the controls from three-d.

asny avatar Aug 10 '22 09:08 asny