diff --git a/Cargo.toml b/Cargo.toml index 698b07e..5244000 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,5 +8,6 @@ members = [ "hui-painter", "hui-shared", "hui-wgpu", - "hui-winit" + "hui-winit", + "hui-loaders", ] diff --git a/hui-loaders/Cargo.toml b/hui-loaders/Cargo.toml new file mode 100644 index 0000000..60c5c6c --- /dev/null +++ b/hui-loaders/Cargo.toml @@ -0,0 +1,26 @@ +[package] +name = "hui-loaders" +description = "Image loader providers for hUI-painter" +repository = "https://github.com/griffi-gh/hui" +readme = "../README.md" +authors = ["griffi-gh <prasol258@gmail.com>"] +rust-version = "1.85" +version = "0.1.0-alpha.7" +edition = "2024" +license = "GPL-3.0-or-later" +publish = true +include = [ + "src/**/*.rs", + "Cargo.toml", +] + +[dependencies] +hui-painter = { version = "=0.1.0-alpha.7", path = "../hui-painter", default-features = false } +image = { version = "0.25", default-features = false, optional = true } + +[features] +default = ["loader-file", "loader-image", "image-default-formats"] +# hui-painter = ["dep:hui-painter"] +loader-file = [] +loader-image = ["dep:image"] +image-default-formats = ["loader-image", "image/default-formats"] diff --git a/hui-loaders/src/lib.rs b/hui-loaders/src/lib.rs new file mode 100644 index 0000000..f8eee65 --- /dev/null +++ b/hui-loaders/src/lib.rs @@ -0,0 +1,43 @@ +use hui_painter::texture::{SourceTextureFormat, TextureAtlas, TextureHandle}; + +pub mod loaders { + #[cfg(feature = "loader-file")] + mod file; + #[cfg(feature = "loader-file")] + pub use file::FileLoader; + + #[cfg(feature = "loader-image")] + mod image; + #[cfg(feature = "loader-image")] + pub use image::ImageLoader; +} + +pub trait RawDataLoader { + /// Syncronously load the raw data from the source + fn load(&self) -> Vec<u8>; +} + +pub struct TextureData { + /// Texture data in the RGBA8 format + pub data: Vec<u8>, + + /// Texture width in pixel + pub width: usize, +} + +pub trait TextureLoader { + /// Syncronously load the texture data + fn load(&self) -> TextureData; +} + +pub trait AtlasLoadersExt { + fn add_with_loader(&mut self, loader: impl TextureLoader) -> TextureHandle; +} + +impl AtlasLoadersExt for TextureAtlas { + fn add_with_loader(&mut self, loader: impl TextureLoader) -> TextureHandle { + let data = loader.load(); + self.add_with_data(SourceTextureFormat::RGBA8, &data.data, data.width) + } +} + diff --git a/hui-loaders/src/loaders/file.rs b/hui-loaders/src/loaders/file.rs new file mode 100644 index 0000000..6665973 --- /dev/null +++ b/hui-loaders/src/loaders/file.rs @@ -0,0 +1,3 @@ +pub struct FileLoader { + +} \ No newline at end of file diff --git a/hui-loaders/src/loaders/image.rs b/hui-loaders/src/loaders/image.rs new file mode 100644 index 0000000..e9abdb2 --- /dev/null +++ b/hui-loaders/src/loaders/image.rs @@ -0,0 +1,16 @@ +use crate::{RawDataLoader, TextureData, TextureLoader}; + +pub struct ImageLoader<T: RawDataLoader>(pub T); + +impl<T: RawDataLoader> From<T> for ImageLoader<T> { + fn from(loader: T) -> Self { + Self(loader) + } +} + +impl<T: RawDataLoader> TextureLoader for ImageLoader<T> { + fn load(&self) -> TextureData { + let data = self.0.load(); + todo!() + } +} \ No newline at end of file