From 749303f2bab1b2b374f7b837cc75acf65067699e Mon Sep 17 00:00:00 2001 From: HampusM Date: Thu, 24 Sep 2026 20:29:27 +0200 Subject: refactor(engine): update to version 0.18.0 dear-imgui-rs & dear-imguizmo --- engine/src/ui/view/world.rs | 49 +++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 24 deletions(-) (limited to 'engine/src/ui/view/world.rs') diff --git a/engine/src/ui/view/world.rs b/engine/src/ui/view/world.rs index 95f29d0..411acd7 100644 --- a/engine/src/ui/view/world.rs +++ b/engine/src/ui/view/world.rs @@ -3,6 +3,8 @@ use std::borrow::Cow; use std::io::Cursor; use std::ops::{Deref, DerefMut}; +use ecs::error::Context; + use crate::color::{Rgb, Rgba}; use crate::ecs::actions::Actions; use crate::ecs::component::local::Local; @@ -30,6 +32,7 @@ use crate::ui::dear_imgui::{ bindings as dear_imgui_bindings, Context as DearImguiContext, }; +use crate::util::OptionExt; const BUTTON_RED_NORMAL: [f32; 4] = [124.0, 52.0, 39.0, 255.0]; const BUTTON_RED_HOVERED: [f32; 4] = [181.0, 76.0, 57.0, 255.0]; @@ -59,8 +62,8 @@ pub fn show( icon_textures, } = &mut *state; - let icon_textures = - icon_textures.get_or_insert_with(|| IconTextures::new(dear_imgui_context)); + let icon_textures = icon_textures + .get_or_try_insert_with_fn(|| IconTextures::new(dear_imgui_context))?; let Some(frame) = dear_imgui_context.frame() else { return Ok(()); @@ -113,21 +116,16 @@ pub fn show( fn create_texture( dear_imgui_context: &mut DearImguiContext, image: Image, -) -> dear_imgui_bindings::ManagedTextureId +) -> Result { - let image = image.into_rgba8(); - - let mut texture_data = dear_imgui_bindings::OwnedTextureData::new(); - - texture_data.create( - dear_imgui_bindings::TextureFormat::RGBA32, - image.dimensions().width, - image.dimensions().height, - ); - - texture_data.set_data(image.as_bytes()); - - dear_imgui_context.register_texture(texture_data) + Ok(dear_imgui_context.register_texture( + dear_imgui_bindings::OwnedTextureData::from_pixels( + dear_imgui_bindings::TextureFormat::RGBA32, + image.dimensions().width, + image.dimensions().height, + image.into_rgba8().as_bytes(), + )?, + )) } fn create_spawn_button_widgets( @@ -2238,7 +2236,7 @@ struct IconTextures impl IconTextures { - fn new(dear_imgui_context: &mut DearImguiContext) -> Self + fn new(dear_imgui_context: &mut DearImguiContext) -> Result { let despawn = create_texture( dear_imgui_context, @@ -2246,8 +2244,9 @@ impl IconTextures Cursor::new(include_bytes!("../../../res/ui/delete.png")), ImageFormat::Png, ) - .unwrap(), - ); + .context("Failed to decode 'delete' icon image")?, + ) + .context("Failed to create 'delete' icon texture")?; let warning = create_texture( dear_imgui_context, @@ -2255,8 +2254,9 @@ impl IconTextures Cursor::new(include_bytes!("../../../res/ui/warning.png")), ImageFormat::Png, ) - .unwrap(), - ); + .context("Failed to decode 'warning' icon image")?, + ) + .context("Failed to create 'warning' icon texture")?; let edit = create_texture( dear_imgui_context, @@ -2264,10 +2264,11 @@ impl IconTextures Cursor::new(include_bytes!("../../../res/ui/edit.png")), ImageFormat::Png, ) - .unwrap(), - ); + .context("Failed to decode 'edit' icon image")?, + ) + .context("Failed to create 'edit' icon texture")?; - Self { despawn, warning, edit } + Ok(Self { despawn, warning, edit }) } } -- cgit v1.2.3-18-g5258