initial text impl
This commit is contained in:
@@ -1,7 +1,14 @@
|
||||
use std::ops::Index;
|
||||
|
||||
use image::DynamicImage;
|
||||
|
||||
use crate::{UiMsg, UiMsgSender, render::TexturePrimitive, util::RefCounter};
|
||||
use crate::{
|
||||
layout::{UiMsg, UiMsgSender},
|
||||
render::TexturePrimitive,
|
||||
util::RefCounter,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct TextureHandle {
|
||||
pub inner: TexturePrimitive,
|
||||
counter: RefCounter,
|
||||
@@ -10,11 +17,11 @@ pub struct TextureHandle {
|
||||
|
||||
/// a texture manager for a ui
|
||||
/// note that this is heavily oriented towards wgpu's renderer so the primitives don't need mapped
|
||||
#[derive(Default)]
|
||||
pub struct Textures {
|
||||
free: Vec<u32>,
|
||||
images: Vec<Option<DynamicImage>>,
|
||||
updates: Vec<Update>,
|
||||
send: UiMsgSender,
|
||||
}
|
||||
|
||||
pub enum TextureUpdate<'a> {
|
||||
@@ -30,8 +37,16 @@ enum Update {
|
||||
}
|
||||
|
||||
impl Textures {
|
||||
pub fn add(&mut self, image: DynamicImage, send: UiMsgSender) -> TextureHandle {
|
||||
let view_idx = self.push(image);
|
||||
pub fn new(send: UiMsgSender) -> Self {
|
||||
Self {
|
||||
free: Vec::new(),
|
||||
images: Vec::new(),
|
||||
updates: Vec::new(),
|
||||
send,
|
||||
}
|
||||
}
|
||||
pub fn add(&mut self, image: impl Into<DynamicImage>) -> TextureHandle {
|
||||
let view_idx = self.push(image.into());
|
||||
// 0 == default in renderer; TODO: actually create samplers here
|
||||
let sampler_idx = 0;
|
||||
TextureHandle {
|
||||
@@ -40,7 +55,7 @@ impl Textures {
|
||||
sampler_idx,
|
||||
},
|
||||
counter: RefCounter::new(),
|
||||
send,
|
||||
send: self.send.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,3 +94,11 @@ impl Drop for TextureHandle {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Index<&TextureHandle> for Textures {
|
||||
type Output = DynamicImage;
|
||||
|
||||
fn index(&self, index: &TextureHandle) -> &Self::Output {
|
||||
self.images[index.inner.view_idx as usize].as_ref().unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user