Skip to content

Commit

Permalink
Avoid cloning plugin-icons, clone a handle instead
Browse files Browse the repository at this point in the history
  • Loading branch information
MCOfficer committed Nov 12, 2023
1 parent 261d7aa commit 1396a4b
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/plugins_frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ pub enum PluginState {
pub struct Plugin {
pub state: PluginState,
pub name: String,
icon_bytes: Option<Vec<u8>>,
icon: Option<image::Handle>,
}

impl Plugin {
Expand Down Expand Up @@ -124,14 +124,14 @@ impl Plugin {

fn view(&self) -> Element<PluginMessage> {
let mut content = Row::new().spacing(10).padding(10);
if let Some(bytes) = &self.icon_bytes {
if let Some(icon) = &self.icon {
const ICON_DIMENSION: f32 = 48.;
content = content.push(
Row::new()
.width(Length::Fixed(ICON_DIMENSION))
.align_items(Alignment::Center)
.push(
Image::new(image::Handle::from_memory(bytes.clone())) // Not ideal, clones a couple KB every rendering pass
Image::new(icon.clone())
.height(Length::Fixed(ICON_DIMENSION))
.width(Length::Fixed(ICON_DIMENSION)),
),
Expand Down Expand Up @@ -202,13 +202,14 @@ pub async fn load_plugins() -> Vec<Plugin> {
Ok(retrieved) => {
for p in retrieved {
let name = String::from(p.name());
let icon_bytes = load_icon_cached(&p)
let icon = load_icon_cached(&p)
.map(image::Handle::from_memory)
.map_err(|e| debug!("failed to fetch icon: {}", e))
.ok();
plugins.push(Plugin {
state: PluginState::Idle { espim_plugin: p },
name,
icon_bytes,
icon,
})
}
}
Expand Down

0 comments on commit 1396a4b

Please sign in to comment.