Here is the repo im using as a reference for adding a image: https://github.com/emilk/egui/blob/master/examples/retained_image/src/main.rs
Im getting this error when trying to draw a image to the screen on this line of code:
date_backdrop.show(ui);
"mismatched types
expected mutable reference &mut egui::ui::Ui
found mutable reference &mut Ui
perhaps two different versions of crate egui
are being used?"
dont understand how to fix this issue. still new to rust
here is my code:
use eframe::egui;
use egui_extras::RetainedImage;
struct InitView;
impl eframe::epi::App for InitView {
fn name(&self) -> &str {
"CheckIt"
}
fn update(&mut self,ctx: &eframe::egui::CtxRef,frame: &mut eframe::epi::Frame<'_>) {
let date_backdrop = RetainedImage::from_image_bytes(
"date_backdrop.png",
include_bytes!("date_backdrop.png"),
)
.unwrap();
//background color
let frame = egui::containers::Frame {
fill: egui::Color32::from_rgb(241, 233, 218),
..Default::default()
};
//main window
egui::CentralPanel::default().frame(frame).show(ctx, |ui| {
ui.heading("This is an image:");
date_backdrop.show(ui);
});
}
}
fn main(){
let app: InitView = InitView;
let win_options = eframe::NativeOptions{
initial_window_size: Some(egui::Vec2::new(386.0, 636.0)),
always_on_top: true,
resizable: false,
..Default::default()
};
eframe::run_native(Box::new(app), win_options);
}
Here is my Cargo.toml:
[package]
name = "checkit"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
eframe = "0.14.0"
image = { version = "0.24", default-features = false, features = ["png"] }
egui_extras = { version = "0.20.0", features = ["image"] }
CodePudding user response:
As the error tells, you have two incompatible version of egui
in the dependency tree: eframe 0.14
pulls in egui 0.14
, while egui_extras 0.20
pulls in egui 0.20
. When major version is 0, different minor versions are treated as incompatible, therefore the types from them are not interchangable.
As far as I can see, both eframe
and egui_extras
depend on the same minor version of egui
as their own version, so you have to synchronize these two dependencies to use the same minor version. The easiest way is probably to bump eframe
to 0.20
.