@@ -36,13 +36,51 @@ namespace ice::gfx
3636
3737 Trait_GfxImageStorage::Trait_GfxImageStorage (ice::TraitContext& ctx, ice::Allocator& alloc) noexcept
3838 : ice::Trait{ ctx }
39+ , ice::TraitDevUI{ {.category = " Engine/Gfx" , .name = " Images" } }
3940 , _allocator{ alloc, " gfx-image-storage" }
4041 , _loaded_images{ _allocator }
4142 {
4243 _context.bind <&Trait_GfxImageStorage::gfx_update, Render>(ice::gfx::ShardID_RenderFrameUpdate);
4344 _context.bind <&Trait_GfxImageStorage::gfx_shutdown, Render>(ice::gfx::ShardID_GfxShutdown);
4445 }
4546
47+ void Trait_GfxImageStorage::build_content () noexcept
48+ {
49+ static ice::i32 selected = -1 ;
50+ ice::Span<GfxImageEntry const > images = ice::hashmap::values (_loaded_images);
51+
52+ ice::String const preview = selected < 0 ? " <asset-uri>" : ice::stringid_hint (images[selected].asset .name ());
53+
54+ if (ImGui::BeginCombo (" Loaded Image" , ice::string::begin (preview)))
55+ {
56+ if (ImGui::Selectable (" ##empty" ))
57+ {
58+ selected = -1 ;
59+ }
60+
61+ ice::i32 idx = 0 ;
62+ for (GfxImageEntry const & entry : images)
63+ {
64+ if (ImGui::Selectable (ice::stringid_hint (entry.asset .name ()), selected == idx))
65+ {
66+ selected = idx;
67+ }
68+ idx += 1 ;
69+ }
70+ ImGui::EndCombo ();
71+ }
72+
73+ if (selected >= 0 )
74+ {
75+ GfxImageEntry const & selected_entry = images[selected];
76+ ImTextureRef const ref{ ImTextureID (selected_entry.image ) };
77+ float const avail_width = ImGui::GetContentRegionAvail ().x ;
78+ ImVec2 const size{ avail_width, avail_width };
79+
80+ ImGui::Image (ref, size);
81+ }
82+ }
83+
4684 auto Trait_GfxImageStorage::on_asset_released (ice::Asset const & asset) noexcept -> ice::Task<>
4785 {
4886 GfxImageEntry* entry = ice::hashmap::try_get (_loaded_images, ice::hash (asset.name ()));
@@ -206,12 +244,14 @@ namespace ice::gfx
206244 // Allocates a handle for it... (TODO: Rework?)
207245 resolve_success.memory = uploaded_request->allocate (ice::size_of<Image>);
208246 *reinterpret_cast <Image*>(resolve_success.memory .location ) = created_images[idx];
247+
248+ ice::u64 const asset_hash = ice::hash (uploaded_request->asset_name ());
209249 ice::Asset asset = uploaded_request->resolve (resolve_success);
210250
211251 // Save the image handle
212252 ice::hashmap::set (
213253 _loaded_images,
214- ice::hash (uploaded_request-> asset_name ()) ,
254+ asset_hash ,
215255 { .asset = ice::move (asset), .image = created_images[idx] }
216256 );
217257 }
0 commit comments