
The purpose of this is to expose `frame.storage()` and `frame.storage_mut()` so users can save/load app state from the `App::update` function, without having to add another parameter to that function. Changes: * Added `Frame::storage()` and `Frame::storage_mut()` * `App::update` now takes a `&mut Frame` rather than just `&Frame` * `Frame` is no longer `Clone` or `Sync` (doesn't have to be since https://github.com/emilk/egui/pull/1366)
53 lines
1.5 KiB
Rust
53 lines
1.5 KiB
Rust
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
|
|
|
|
use eframe::egui;
|
|
use egui_extras::RetainedImage;
|
|
|
|
fn main() {
|
|
let options = eframe::NativeOptions {
|
|
initial_window_size: Some(egui::vec2(500.0, 900.0)),
|
|
..Default::default()
|
|
};
|
|
eframe::run_native(
|
|
"Show an image with eframe/egui",
|
|
options,
|
|
Box::new(|_cc| Box::new(MyApp::default())),
|
|
);
|
|
}
|
|
|
|
struct MyApp {
|
|
image: RetainedImage,
|
|
}
|
|
|
|
impl Default for MyApp {
|
|
fn default() -> Self {
|
|
Self {
|
|
image: RetainedImage::from_image_bytes(
|
|
"rust-logo-256x256.png",
|
|
include_bytes!("rust-logo-256x256.png"),
|
|
)
|
|
.unwrap(),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl eframe::App for MyApp {
|
|
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
|
egui::CentralPanel::default().show(ctx, |ui| {
|
|
ui.heading("This is an image:");
|
|
self.image.show(ui);
|
|
|
|
ui.heading("This is a rotated image:");
|
|
ui.add(
|
|
egui::Image::new(self.image.texture_id(ctx), self.image.size_vec2())
|
|
.rotate(45.0_f32.to_radians(), egui::Vec2::splat(0.5)),
|
|
);
|
|
|
|
ui.heading("This is an image you can click:");
|
|
ui.add(egui::ImageButton::new(
|
|
self.image.texture_id(ctx),
|
|
self.image.size_vec2(),
|
|
));
|
|
});
|
|
}
|
|
}
|