stack & padding fix sorta, preparing for scroll areas
This commit is contained in:
@@ -27,6 +27,8 @@ enum Ptr {
|
||||
/// is that realistically desired?
|
||||
pub struct Layers {
|
||||
vec: Vec<LayerNode>,
|
||||
/// index of last layer at top level (start at first = 0)
|
||||
last: usize,
|
||||
}
|
||||
|
||||
/// TODO: this can be replaced with Primitives itself atm
|
||||
@@ -45,6 +47,7 @@ impl Layers {
|
||||
pub fn new() -> Layers {
|
||||
Self {
|
||||
vec: vec![LayerNode::head()],
|
||||
last: 0,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +76,7 @@ impl Layers {
|
||||
match self.vec[i_new].next {
|
||||
Ptr::Next(i) => self.vec[i].prev = Ptr::Next(i_new),
|
||||
Ptr::Parent(i) => self.vec[i].child.as_mut().unwrap().tail = i_new,
|
||||
Ptr::None => (),
|
||||
Ptr::None => self.last = i_new,
|
||||
}
|
||||
i_new
|
||||
}
|
||||
@@ -95,11 +98,15 @@ impl Layers {
|
||||
}
|
||||
|
||||
pub fn iter_mut(&mut self) -> LayerIteratorMut<'_> {
|
||||
LayerIteratorMut::new(&mut self.vec)
|
||||
LayerIteratorMut::new(&mut self.vec, self.last)
|
||||
}
|
||||
|
||||
pub fn iter(&self) -> impl Iterator<Item = (usize, &Layer)> {
|
||||
self.indices().map(|i| (i, &self.vec[i].data))
|
||||
}
|
||||
|
||||
pub fn indices(&self) -> LayerIndexIterator<'_> {
|
||||
LayerIndexIterator::new(&self.vec)
|
||||
LayerIndexIterator::new(&self.vec, self.last)
|
||||
}
|
||||
|
||||
pub fn write<P: Primitive>(
|
||||
@@ -179,9 +186,9 @@ impl<'a> DoubleEndedIterator for LayerIteratorMut<'a> {
|
||||
}
|
||||
|
||||
impl<'a> LayerIteratorMut<'a> {
|
||||
fn new(vec: &'a mut Vec<LayerNode>) -> Self {
|
||||
fn new(vec: &'a mut Vec<LayerNode>, last: usize) -> Self {
|
||||
Self {
|
||||
inner: LayerIndexIterator::new(vec),
|
||||
inner: LayerIndexIterator::new(vec, last),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -203,7 +210,10 @@ impl<'a> Iterator for LayerIndexIterator<'a> {
|
||||
} else if let Ptr::Next(i) = node.next {
|
||||
Some(i)
|
||||
} else if let Ptr::Parent(i) = node.next {
|
||||
let node = &self.vec[i];
|
||||
let mut node = &self.vec[i];
|
||||
while let Ptr::Parent(i) = node.next {
|
||||
node = &self.vec[i];
|
||||
}
|
||||
if let Ptr::Next(i) = node.next {
|
||||
Some(i)
|
||||
} else {
|
||||
@@ -243,8 +253,8 @@ impl<'a> DoubleEndedIterator for LayerIndexIterator<'a> {
|
||||
}
|
||||
|
||||
impl<'a> LayerIndexIterator<'a> {
|
||||
fn new(vec: &'a Vec<LayerNode>) -> Self {
|
||||
let mut last = 0;
|
||||
fn new(vec: &'a Vec<LayerNode>, last: usize) -> Self {
|
||||
let mut last = last;
|
||||
while let Some(c) = vec[last].child {
|
||||
last = c.tail;
|
||||
}
|
||||
|
||||
@@ -69,9 +69,19 @@ impl<'a> PainterCtx<'a> {
|
||||
};
|
||||
|
||||
if let Some((rid, size)) = &active.resize {
|
||||
self.redraw(&rid.duplicate());
|
||||
if self.drawing.contains(id) {
|
||||
return;
|
||||
let checked = &mut HashMap::default();
|
||||
let mut ctx = SizeCtx {
|
||||
checked,
|
||||
text: self.text,
|
||||
textures: self.textures,
|
||||
widgets: self.widgets,
|
||||
};
|
||||
let desired = ctx.size_inner(id);
|
||||
if *size != desired {
|
||||
self.redraw(&rid.duplicate());
|
||||
if self.drawing.contains(id) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -298,14 +308,17 @@ pub struct SizeCtx<'a> {
|
||||
}
|
||||
|
||||
impl SizeCtx<'_> {
|
||||
fn size_inner(&mut self, id: &Id) -> UiVec2 {
|
||||
let size = self.widgets.get_dyn_dynamic(id).desired_size(self);
|
||||
self.checked.insert(id.duplicate(), size);
|
||||
size
|
||||
}
|
||||
pub fn size<W>(&mut self, id: &WidgetId<W>) -> UiVec2 {
|
||||
// TODO: determine if this is useful
|
||||
// if let Some(size) = self.checked.get(&id.id) {
|
||||
// return Some(*size);
|
||||
// }
|
||||
let size = self.widgets.get_dyn_dynamic(&id.id).desired_size(self);
|
||||
self.checked.insert(id.id.duplicate(), size);
|
||||
size
|
||||
self.size_inner(&id.id)
|
||||
}
|
||||
pub fn draw_text(
|
||||
&mut self,
|
||||
|
||||
@@ -100,9 +100,7 @@ impl UiVec2 {
|
||||
self.rel * size + self.abs
|
||||
}
|
||||
|
||||
pub const fn max_size() -> Self {
|
||||
Self::rel(Vec2::ONE)
|
||||
}
|
||||
pub const MAX_SIZE: Self = Self::rel(Vec2::ONE);
|
||||
|
||||
pub const fn from_axis(axis: Axis, aligned: UiScalar, ortho: UiScalar) -> Self {
|
||||
Self {
|
||||
@@ -134,6 +132,8 @@ impl_op!(UiScalar Add add; rel abs);
|
||||
impl_op!(UiScalar Sub sub; rel abs);
|
||||
|
||||
impl UiScalar {
|
||||
pub const ZERO: Self = Self { rel: 0.0, abs: 0.0 };
|
||||
|
||||
pub fn new(rel: f32, abs: f32) -> Self {
|
||||
Self { rel, abs }
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ use std::{any::Any, marker::PhantomData};
|
||||
pub trait Widget: Any {
|
||||
fn draw(&mut self, painter: &mut Painter);
|
||||
fn desired_size(&mut self, _: &mut SizeCtx) -> UiVec2 {
|
||||
UiVec2::max_size()
|
||||
UiVec2::MAX_SIZE
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ impl<const LEN: usize, Ws> WidgetArr<LEN, Ws> {
|
||||
}
|
||||
|
||||
pub struct ArrTag;
|
||||
pub trait WidgetArrLike<const LEN: usize, Tags> {
|
||||
pub trait WidgetArrLike<const LEN: usize, Tag> {
|
||||
type Ws;
|
||||
fn ui(self, ui: &mut Ui) -> WidgetArr<LEN, Self::Ws>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user