app work
This commit is contained in:
@@ -44,6 +44,7 @@ pub struct WidgetInstance {
|
||||
pub resize: Option<(Id, UiVec2)>,
|
||||
pub mask: MaskIdx,
|
||||
pub layer: usize,
|
||||
pub desired_size: UiVec2,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
@@ -178,6 +179,17 @@ impl<'a> PainterCtx<'a> {
|
||||
|
||||
// draw widgets
|
||||
painter.ctx.widgets.get_dyn_dynamic(id).draw(&mut painter);
|
||||
let desired_size = SizeCtx {
|
||||
text: painter.ctx.text,
|
||||
textures: painter.ctx.textures,
|
||||
widgets: painter.ctx.widgets,
|
||||
checked: &mut Default::default(),
|
||||
screen_size: painter.ctx.screen_size,
|
||||
px_dependent: painter.ctx.px_dependent,
|
||||
id: painter.id,
|
||||
region: UiRegion::full(),
|
||||
}
|
||||
.size_raw(id);
|
||||
|
||||
let sized_children = painter.sized_children;
|
||||
|
||||
@@ -191,6 +203,7 @@ impl<'a> PainterCtx<'a> {
|
||||
children: painter.children,
|
||||
resize,
|
||||
mask: painter.mask,
|
||||
desired_size,
|
||||
layer,
|
||||
};
|
||||
for (cid, size) in sized_children {
|
||||
@@ -394,6 +407,9 @@ impl SizeCtx<'_> {
|
||||
// }
|
||||
self.size_inner(id.id, self.region)
|
||||
}
|
||||
fn size_raw(&mut self, id: Id) -> UiVec2 {
|
||||
self.size_inner(id, self.region)
|
||||
}
|
||||
pub fn size_within<W>(&mut self, id: &WidgetId<W>, region: UiRegion) -> UiVec2 {
|
||||
self.size_inner(id.id, region.within(&self.region))
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::marker::Destruct;
|
||||
use std::{fmt::Display, marker::Destruct};
|
||||
|
||||
use crate::{
|
||||
layout::{Align, Axis, UiNum, Vec2},
|
||||
@@ -114,6 +114,12 @@ impl UiVec2 {
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for UiVec2 {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "rel {} / abs {}", self.rel, self.abs)
|
||||
}
|
||||
}
|
||||
|
||||
impl_op!(UiVec2 Add add; rel abs);
|
||||
impl_op!(UiVec2 Sub sub; rel abs);
|
||||
|
||||
@@ -307,6 +313,12 @@ impl UiRegion {
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for UiRegion {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{} -> {}", self.top_left, self.bot_right)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ScreenRegion {
|
||||
pub top_left: Vec2,
|
||||
|
||||
@@ -170,6 +170,19 @@ impl Ui {
|
||||
font_system: &mut self.data.text.font_system,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn debug(&self, label: &str) {
|
||||
for (id, inst) in &self.data.active {
|
||||
let l = &self.data.widgets.data(id).unwrap().label;
|
||||
if l != label {
|
||||
continue;
|
||||
}
|
||||
println!("\"{label}\" {{");
|
||||
println!(" region: {}", inst.region);
|
||||
println!(" desired_size: {}", inst.desired_size);
|
||||
println!("}}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<W: Widget> Index<&WidgetId<W>> for Ui {
|
||||
|
||||
@@ -96,3 +96,9 @@ impl std::fmt::Debug for Vec2 {
|
||||
write!(f, "({}, {})", self.x, self.y)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Vec2 {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "({}, {})", self.x, self.y)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,10 @@ pub trait Widget: Any {
|
||||
}
|
||||
}
|
||||
|
||||
impl Widget for () {
|
||||
fn draw(&mut self, painter: &mut Painter) {}
|
||||
}
|
||||
|
||||
pub struct WidgetTag;
|
||||
pub struct FnTag;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user