Home > Mobile >  How is it possible that i cant use this function?
How is it possible that i cant use this function?

Time:01-18

using this github repo as a reference: https://github.com/emilk/egui/blob/master/examples/retained_image/src/main.rs

Im trying to load an image into my frame using the egui_extras::RetainedImage, but it is giving me an error that the function RetainedImage::from_image_bytes cannot be found in RetainedImage.

I have also checked image.rs class to make sure that the function is even there, which it is.

here is my code:

use eframe::{run_native, epi::App, egui, NativeOptions};
use egui_extras::RetainedImage;
struct InitView {
    image: RetainedImage,
    tint: egui::Color32,
}

impl Default for InitView {
    fn default() -> Self {
        Self {
            image: RetainedImage::from_image_bytes(
                "date_backdrop.png",
                include_bytes!("date_backdrop.png"),
            )
            .unwrap(),
            tint: egui::Color32::from_rgb(255, 0, 255),
        }
    }
}


impl App for InitView {
    fn name(&self) -> &str {
        "CheckIt"
    }

    fn update(&mut self,ctx: &eframe::egui::CtxRef,frame: &mut eframe::epi::Frame<'_>) {
        //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.label("test");
        });
    }
}

fn main(){
    let app: InitView = InitView{..Default::default()};
    let win_options = eframe::NativeOptions{
        initial_window_size: Some(egui::Vec2::new(386.0, 636.0)),
        always_on_top: true,
        resizable: false,
        ..Default::default()
    };
    run_native(Box::new(app), win_options);
}

what im i doing wrong? im still new to rust

CodePudding user response:

You need to add the image feature.

Edit your Cargo.toml and replace egui_extras with egui_extras = { version = "0.20.0", features = ["image"] } or run cargo add egui_extras -F "image" in your project root directory.

  • Related