Crates.io | turbo_atlas_icons |
lib.rs | turbo_atlas_icons |
version | 0.15.0 |
source | src |
created_at | 2024-05-23 19:47:26.805363 |
updated_at | 2024-12-06 19:08:04.219896 |
description | A system for declarative ui icon rendering with Bevy |
homepage | |
repository | https://github.com/ethereumdegen/turbo_atlas_icons |
max_upload_size | |
id | 1250030 |
size | 19,554 |
A crate for bevy to help you more easily render ui icons from an atlas.
Simply add a UiIconComponent to your Ui Node (AtlasImageBundle), set its source to a pre-registered source, and it will work!
app.insert_plugins( TurboAtlasIconsPlugin )
pub struct GuiPixelIconSource(String) ; // This is your own source type that you invent !! Can invent many.
impl UiIconSource for GuiPixelIconSource {
//describe how to get the Icon Handle Name
fn get_icon_name(&self, _world: &World) -> Option<String> {
Some(self.0.clone())
}
//describe how to get the HashMap< IconHandleName -> ImageHandle for this source
fn get_icons_handles_map<'a>(&'a self, world: &'a World) -> &'a TextureHandlesMap{
let images = world.resource::<TextureAssets>();
&images.gui_pixel_icons
}
//describe how to get the texture atlas layout and overall image handle for this source
fn get_texture_atlas<'a>(&'a self, world: &'a World) -> &'a Option<TextureAtlasCombined> {
let texture_atlas_assets = world.resource::<TextureAtlasAssets>();
&texture_atlas_assets.gui_pixel_icons_atlas
}
}
commands.entity(icon_node).insert(
UiIconComponent{
icon_source : Some(Box::new( GuiPixelIconSource("heart_full.tga".into() ) )
}
);
(This is all assuming the TextureAtlasCombined provided to the IconSource lookup has already been loaded into memory --- see sample/texture_atlas_assets for examples of how this could be done -- For example using bevy_asset_loader )