clean up
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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)]
|
||||
|
||||
@@ -3,7 +3,7 @@ use std::{
|
||||
sync::mpsc::{Receiver, Sender, channel},
|
||||
};
|
||||
|
||||
use image::{DynamicImage, GenericImageView};
|
||||
use image::DynamicImage;
|
||||
|
||||
use crate::{render::TexturePrimitive, util::RefCounter};
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use image::{DynamicImage, EncodableLayout, GenericImageView};
|
||||
use image::{DynamicImage, EncodableLayout};
|
||||
use wgpu::{util::DeviceExt, *};
|
||||
|
||||
use crate::layout::{TextureUpdate, Textures};
|
||||
|
||||
Reference in New Issue
Block a user