sized widgets!

This commit is contained in:
2025-08-28 01:35:43 -04:00
parent d4d0b3b580
commit 834182ffe8
14 changed files with 313 additions and 106 deletions

View File

@@ -3,13 +3,14 @@ use std::{
sync::mpsc::{Receiver, Sender, channel},
};
use image::DynamicImage;
use image::{DynamicImage, GenericImageView};
use crate::{render::TexturePrimitive, util::RefCounter};
use crate::{layout::Vec2, render::TexturePrimitive, util::RefCounter};
#[derive(Clone)]
pub struct TextureHandle {
pub inner: TexturePrimitive,
inner: TexturePrimitive,
size: Vec2,
counter: RefCounter,
send: Sender<u32>,
}
@@ -25,10 +26,11 @@ pub struct Textures {
}
pub enum TextureUpdate<'a> {
PushFree,
Push(&'a DynamicImage),
Set(u32, &'a DynamicImage),
Free(u32),
PushFree,
SetFree,
}
enum Update {
@@ -49,7 +51,9 @@ impl Textures {
}
}
pub fn add(&mut self, image: impl Into<DynamicImage>) -> TextureHandle {
let view_idx = self.push(image.into());
let image = image.into();
let size = image.dimensions().into();
let view_idx = self.push(image);
// 0 == default in renderer; TODO: actually create samplers here
let sampler_idx = 0;
TextureHandle {
@@ -57,6 +61,7 @@ impl Textures {
view_idx,
sampler_idx,
},
size,
counter: RefCounter::new(),
send: self.send.clone(),
}
@@ -89,12 +94,24 @@ impl Textures {
.as_ref()
.map(TextureUpdate::Push)
.unwrap_or(TextureUpdate::PushFree),
Update::Set(i) => TextureUpdate::Set(i, self.images[i as usize].as_ref().unwrap()),
Update::Set(i) => self.images[i as usize]
.as_ref()
.map(|img| TextureUpdate::Set(i, img))
.unwrap_or(TextureUpdate::SetFree),
Update::Free(i) => TextureUpdate::Free(i),
})
}
}
impl TextureHandle {
pub fn primitive(&self) -> TexturePrimitive {
self.inner
}
pub fn size(&self) -> Vec2 {
self.size
}
}
impl Drop for TextureHandle {
fn drop(&mut self) {
if self.counter.drop() {