Skip to content

Commit

Permalink
move remove thumbnail to assets
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Spaink committed Aug 19, 2023
1 parent c01b16c commit ae2520f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
21 changes: 5 additions & 16 deletions src/app.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
use crate::assets::Assets;
use egui::RichText;
use egui_extras::RetainedImage;

struct Body {
color: String,
hat: Option<String>,
}

pub struct App {
remove_thumb: RetainedImage,
assets: Assets,
ferris: Body,
}

impl Default for App {
fn default() -> Self {
Self {
remove_thumb: RetainedImage::from_image_bytes(
"remove",
include_bytes!("../assets/remove_thumb.png"),
)
.unwrap(),
assets: Assets::new(),
ferris: Body {
color: "orange".to_string(),
Expand All @@ -41,11 +34,7 @@ impl eframe::App for App {
/// Called each time the UI needs repainting, which may be many times per second.
/// Put your widgets into a `SidePanel`, `TopPanel`, `CentralPanel`, `Window` or `Area`.
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
let Self {
remove_thumb,
assets,
ferris,
} = self;
let Self { assets, ferris } = self;

#[cfg(not(target_arch = "wasm32"))] // no File->Quit on web pages!
egui::TopBottomPanel::top("top_panel").show(ctx, |ui| {
Expand Down Expand Up @@ -93,8 +82,8 @@ impl eframe::App for App {
egui::Grid::new("hats").show(ui, |ui| {
if ui
.add(egui::ImageButton::new(
remove_thumb.texture_id(ctx),
remove_thumb.size_vec2(),
assets.remove_thumb.texture_id(ctx),
assets.remove_thumb.size_vec2(),
))
.clicked()
{
Expand Down Expand Up @@ -131,7 +120,7 @@ impl eframe::App for App {
}
});

egui::Area::new("my_area").movable(false).show(ctx, |ui| {
egui::Area::new("body").movable(false).show(ctx, |ui| {
ui.centered_and_justified(|ui| {
if let Some(image) = assets.colors.get(&ferris.color) {
// TODO how to use show_scaled when window resizes???
Expand All @@ -140,7 +129,7 @@ impl eframe::App for App {
});
});

egui::Area::new("my_area").movable(false).show(ctx, |ui| {
egui::Area::new("body").movable(false).show(ctx, |ui| {
ui.centered_and_justified(|ui| {
if let Some(hat) = &ferris.hat {
if let Some(image) = assets.hats.get(hat) {
Expand Down
13 changes: 11 additions & 2 deletions src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub struct Image {
pub struct Assets {
pub colors: HashMap<String, Image>,
pub hats: HashMap<String, Image>,
pub remove_thumb: RetainedImage,
}

macro_rules! load_image {
Expand All @@ -22,7 +23,7 @@ macro_rules! load_image {
)
.unwrap(),
thumb: RetainedImage::from_image_bytes(
"{x}_thumb",
concat!($file, "_thumb"),
include_bytes!(concat!("../assets/", $path, "/", $file, "_thumb.png")),
)
.unwrap(),
Expand Down Expand Up @@ -52,6 +53,14 @@ impl Assets {
hats.insert(i.0, i.1);
}

Assets { colors, hats }
let remove_thumb =
RetainedImage::from_image_bytes("remove", include_bytes!("../assets/remove_thumb.png"))
.unwrap();

Assets {
colors,
hats,
remove_thumb,
}
}
}

0 comments on commit ae2520f

Please sign in to comment.