Skip to content

Commit

Permalink
refactor: ♻️ remove all uses of retainedimage
Browse files Browse the repository at this point in the history
  • Loading branch information
melody-rs committed Nov 30, 2023
1 parent e2e551f commit e1deae2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 42 deletions.
7 changes: 3 additions & 4 deletions crates/ui/src/windows/about.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
/// A basic about window.
/// Shows some info on Luminol, along with an icon.
pub struct Window {
icon: egui_extras::RetainedImage,
icon: egui::Image<'static>,
}

const ICON: &[u8] = include_bytes!("../../../../assets/icon-256.png");
Expand All @@ -36,8 +36,7 @@ impl Default for Window {
// We load the icon here so it isn't loaded every frame. That would be bad if we did.
// It would be better to load the image at compile time and only use one image instance
// (as we load the image once at start for the icon) but this is the best I can do.
icon: egui_extras::RetainedImage::from_image_bytes("icon", ICON)
.expect("Failed to load Icon data."),
icon: egui::Image::from_bytes("assets/icon-256.png", ICON).fit_to_original_size(0.5),
}
}
}
Expand Down Expand Up @@ -65,7 +64,7 @@ impl luminol_core::Window for Window {
.show(ctx, |ui| {
// Center the widgets vertically for cleanliness.
ui.vertical_centered(|ui| {
self.icon.show_scaled(ui, 0.5); // We scale the icon down since it's pretty huge.
ui.add(self.icon.clone());
ui.heading("Luminol");

ui.separator();
Expand Down
40 changes: 2 additions & 38 deletions src/lumi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,49 +26,13 @@ mod state;

#[allow(dead_code)]
pub struct Lumi {
speak: egui_extras::RetainedImage,
idle: egui_extras::RetainedImage,
enabled: bool,
}

impl Lumi {
pub fn new() -> Result<Self, String> {
let idle = egui_extras::RetainedImage::from_svg_bytes(
"lumi_idle",
include_bytes!("assets/lumi-idle.svg"),
)?
.with_options(epaint::textures::TextureOptions::LINEAR);
let speak = egui_extras::RetainedImage::from_svg_bytes(
"lumi_speak",
include_bytes!("assets/lumi-speak.svg"),
)?
.with_options(epaint::textures::TextureOptions::LINEAR);

Ok(Lumi {
idle,
speak,
enabled: false,
})
Ok(Lumi { enabled: false })
}

pub fn ui(&mut self, ctx: &egui::Context) {
if !self.enabled {
return;
}

let painter = ctx.layer_painter(egui::LayerId::new(
egui::Order::Tooltip,
"lumi_layer".into(),
));

let size = self.idle.size_vec2() / 4.0;
let pos = ctx.screen_rect().max - size;

painter.image(
self.idle.texture_id(ctx),
egui::Rect::from_min_size(pos, size),
egui::Rect::from_min_max(egui::pos2(0.0, 0.0), egui::pos2(1.0, 1.0)),
egui::Color32::WHITE,
);
}
pub fn ui(&mut self, _ctx: &egui::Context) {}
}

0 comments on commit e1deae2

Please sign in to comment.