This commit is contained in:
2025-08-24 22:44:21 -04:00
parent 880d7eca50
commit 9e751d4161
5 changed files with 11 additions and 13 deletions

View File

@@ -6,7 +6,7 @@ use crate::{
WidgetInstance, Widgets,
},
render::{Primitive, PrimitiveHandle, Primitives},
util::{HashMap, Id},
util::Id,
};
struct State {
@@ -26,7 +26,6 @@ pub struct Painter<'a, Ctx: 'static> {
pub(super) primitives: &'a mut Primitives,
textures: &'a mut Textures,
text: &'a mut TextData,
labels: &'a HashMap<Id, String>,
screen_size: Vec2,
/// state of what's currently being drawn
state: State,
@@ -43,7 +42,6 @@ impl<'a, Ctx> Painter<'a, Ctx> {
text: &'a mut TextData,
textures: &'a mut Textures,
screen_size: Vec2,
labels: &'a HashMap<Id, String>,
) -> Self {
Self {
widgets: nodes,
@@ -54,7 +52,6 @@ impl<'a, Ctx> Painter<'a, Ctx> {
text,
textures,
screen_size,
labels,
state: State {
region: UiRegion::full(),
children: Vec::new(),
@@ -165,6 +162,10 @@ impl<'a, Ctx> Painter<'a, Ctx> {
self.ctx
}
pub fn region_size(&self) -> Vec2 {
self.state.region.in_size(self.screen_size)
}
pub(crate) fn redraw(&mut self, id: &Id) {
if !self.active.widgets.contains_key(id) {
return;

View File

@@ -88,11 +88,6 @@ impl UiPos {
pub fn to_size(&self, size: Vec2) -> Vec2 {
self.anchor * size + self.offset
}
/// snaps this to a specific screen size to get actual pixel coordinates
pub fn snap(&self, size: Vec2) -> Vec2 {
self.to_size(size).round()
}
}
#[derive(Clone, Copy, Debug)]
@@ -195,6 +190,10 @@ impl UiRegion {
pub fn center(&self) -> UiPos {
UiPos::center().within(self)
}
pub fn in_size(&self, size: Vec2) -> Vec2 {
self.bot_right.to_size(size) - self.top_left.to_size(size)
}
}
#[derive(Debug)]

View File

@@ -3,7 +3,7 @@ use std::{
sync::mpsc::{Receiver, Sender, channel},
};
use image::{DynamicImage, GenericImageView};
use image::DynamicImage;
use crate::{render::TexturePrimitive, util::RefCounter};

View File

@@ -113,7 +113,6 @@ impl<Ctx> Ui<Ctx> {
&mut self.text,
&mut self.textures,
self.size,
&self.labels,
);
if let Some(base) = &self.base {
painter.draw(base);
@@ -146,7 +145,6 @@ impl<Ctx> Ui<Ctx> {
&mut self.text,
&mut self.textures,
self.size,
&self.labels,
);
for id in self.updates.drain(..) {
painter.redraw(&id.id);

View File

@@ -1,4 +1,4 @@
use image::{DynamicImage, EncodableLayout, GenericImageView};
use image::{DynamicImage, EncodableLayout};
use wgpu::{util::DeviceExt, *};
use crate::layout::{TextureUpdate, Textures};