egui tests
This commit is contained in:
parent
4e42cfdc05
commit
7b475a969c
1193
Cargo.lock
generated
1193
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -5,6 +5,9 @@ edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
clap = { version = "4.5.34", features = ["derive"] }
|
||||
eframe = "0.31.1"
|
||||
egui = "0.31.1"
|
||||
egui_extras = { version = "0.31.1", features = ["all_loaders"] }
|
||||
env_logger = "0.11.7"
|
||||
iced = { version = "0.13.1", features = ["debug", "canvas", "tokio", "image"]}
|
||||
image = "0.25.6"
|
||||
|
80
src/main.rs
80
src/main.rs
@ -314,6 +314,46 @@ use imflow::store::ImageStore;
|
||||
// event_loop.run_app(&mut app).unwrap();
|
||||
// }
|
||||
//
|
||||
use eframe::egui;
|
||||
use egui::{ColorImage, Image, TextureHandle, TextureOptions};
|
||||
|
||||
struct MyApp {
|
||||
// image: Image,
|
||||
store: ImageStore,
|
||||
texture: TextureHandle,
|
||||
}
|
||||
|
||||
impl MyApp {
|
||||
fn new(store: ImageStore, texture: TextureHandle) -> Self {
|
||||
Self {
|
||||
store,
|
||||
texture,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl eframe::App for MyApp {
|
||||
fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
|
||||
// let img = Image::from_bytes("bytes://", buffer_u8);
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
ui.heading("This is an image:");
|
||||
// image::show(ui);
|
||||
// ui.add(img);
|
||||
// ui.textu
|
||||
ui.image(&self.texture);
|
||||
// if ui.add(egui::ImageButton::new(&self.texture)).clicked() {
|
||||
// // Handle click
|
||||
// }
|
||||
// img.
|
||||
|
||||
// ui.heading("This is an image you can click:");
|
||||
// ui.add(egui::ImageButton::new(
|
||||
// self.image.texture_id(ctx),
|
||||
// self.image.size_vec2(),
|
||||
// ));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(version, about, long_about = None)]
|
||||
@ -322,6 +362,46 @@ struct Args {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let native_options = eframe::NativeOptions {
|
||||
viewport: egui::ViewportBuilder::default().with_inner_size((400.0, 400.0)),
|
||||
..eframe::NativeOptions::default()
|
||||
};
|
||||
|
||||
eframe::run_native(
|
||||
"aaa",
|
||||
native_options,
|
||||
Box::new(|cc| {
|
||||
// Initialize image loaders
|
||||
egui_extras::install_image_loaders(&cc.egui_ctx);
|
||||
let mut store = ImageStore::new("./test_images".into());
|
||||
|
||||
let mut imbuf = store.get_current_image().unwrap();
|
||||
|
||||
let width = imbuf.width;
|
||||
let height = imbuf.height;
|
||||
|
||||
let mut buffer = imbuf.argb_buffer.clone();
|
||||
// Reinterpret to avoid copying
|
||||
let buffer_u8 = unsafe {
|
||||
Vec::from_raw_parts(
|
||||
buffer.as_mut_ptr() as *mut u8,
|
||||
buffer.len() * 4,
|
||||
buffer.capacity() * 4,
|
||||
)
|
||||
};
|
||||
std::mem::forget(buffer);
|
||||
|
||||
let color_image = ColorImage::from_rgba_unmultiplied([width, height], &buffer_u8);
|
||||
let texture = cc
|
||||
.egui_ctx
|
||||
.load_texture("img", color_image, TextureOptions::LINEAR);
|
||||
|
||||
Ok(Box::new(MyApp::new(store, texture)))
|
||||
}),
|
||||
)
|
||||
.unwrap();
|
||||
// eframe::run_native(Box::new(MyApp::default()), options);
|
||||
|
||||
let args = Args::parse();
|
||||
const WIDTH: usize = 2000;
|
||||
const HEIGHT: usize = 1000;
|
||||
|
@ -26,7 +26,7 @@ pub struct ImageStore {
|
||||
impl ImageStore {
|
||||
pub fn new(path: PathBuf) -> Self {
|
||||
let current_image_id: usize = 0;
|
||||
let loaded_images: HashMap<PathBuf, ImflowImageBuffer> = HashMap::new();
|
||||
let mut loaded_images: HashMap<PathBuf, ImflowImageBuffer> = HashMap::new();
|
||||
let mut loaded_thumbnails: HashMap<PathBuf, ImflowImageBuffer> = HashMap::new();
|
||||
let available_images = load_available_images(path);
|
||||
let new_path = available_images[0].clone();
|
||||
@ -53,6 +53,9 @@ impl ImageStore {
|
||||
loaded_thumbnails.len()
|
||||
);
|
||||
|
||||
let path = available_images[0].clone();
|
||||
let image = load_image(path.clone());
|
||||
loaded_images.insert(path, image);
|
||||
let mut state = Self {
|
||||
current_image_id,
|
||||
loaded_images,
|
||||
|
Loading…
x
Reference in New Issue
Block a user