1
1
Fork 0
mirror of https://github.com/griffi-gh/hUI.git synced 2025-04-01 21:46:29 -05:00

wip hui-loaders

This commit is contained in:
griffi-gh 2025-03-11 14:06:05 +01:00
parent 0f56de482c
commit 72760eba54
5 changed files with 90 additions and 1 deletions

View file

@ -8,5 +8,6 @@ members = [
"hui-painter",
"hui-shared",
"hui-wgpu",
"hui-winit"
"hui-winit",
"hui-loaders",
]

26
hui-loaders/Cargo.toml Normal file
View file

@ -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"]

43
hui-loaders/src/lib.rs Normal file
View file

@ -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)
}
}

View file

@ -0,0 +1,3 @@
pub struct FileLoader {
}

View file

@ -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!()
}
}