measure root node of layout
This commit is contained in:
@@ -11,7 +11,7 @@ use crate::{
|
||||
widget::{self, EventParams, WidgetState, div::Div},
|
||||
};
|
||||
|
||||
use glam::Vec2;
|
||||
use glam::{Vec2, vec2};
|
||||
use slotmap::HopSlotMap;
|
||||
use taffy::{TaffyTree, TraversePartialTree};
|
||||
|
||||
@@ -37,6 +37,7 @@ pub struct Layout {
|
||||
pub root_node: taffy::NodeId,
|
||||
|
||||
pub prev_size: Vec2,
|
||||
pub content_size: Vec2,
|
||||
|
||||
pub needs_redraw: bool,
|
||||
|
||||
@@ -227,7 +228,7 @@ impl Layout {
|
||||
None, // no parent
|
||||
Div::create()?,
|
||||
taffy::Style {
|
||||
size: taffy::Size::percent(1.0),
|
||||
size: taffy::Size::auto(),
|
||||
..Default::default()
|
||||
},
|
||||
)?;
|
||||
@@ -235,6 +236,7 @@ impl Layout {
|
||||
Ok(Self {
|
||||
tree,
|
||||
prev_size: Vec2::default(),
|
||||
content_size: Vec2::default(),
|
||||
root_node,
|
||||
root_widget,
|
||||
widget_node_map,
|
||||
@@ -293,6 +295,9 @@ impl Layout {
|
||||
}
|
||||
},
|
||||
)?;
|
||||
let root_size = self.tree.layout(self.root_node).unwrap().size;
|
||||
self.content_size = vec2(root_size.width, root_size.height);
|
||||
log::error!("ContentSize: {:?}", self.content_size);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -172,8 +172,8 @@ impl OverlayRenderer for GuiPanel {
|
||||
fn frame_meta(&mut self) -> Option<FrameMeta> {
|
||||
Some(FrameMeta {
|
||||
extent: [
|
||||
self.max_size.max(self.layout.prev_size.x as _),
|
||||
self.max_size.max(self.layout.prev_size.y as _),
|
||||
self.max_size.max(self.layout.content_size.x as _),
|
||||
self.max_size.max(self.layout.content_size.y as _),
|
||||
1,
|
||||
],
|
||||
..Default::default()
|
||||
|
||||
@@ -51,11 +51,6 @@ where
|
||||
processes: vec![],
|
||||
}));
|
||||
|
||||
let size = vec2(
|
||||
layout.row_size * PIXELS_PER_UNIT,
|
||||
(layout.main_layout.len() as f32) * PIXELS_PER_UNIT,
|
||||
);
|
||||
|
||||
let mut panel = GuiPanel::new_blank(app, 2048)?;
|
||||
|
||||
let (background, _) = panel.layout.add_child(
|
||||
@@ -217,8 +212,13 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
panel.layout.update(vec2(2048., 2048.), 0.0)?;
|
||||
|
||||
let interaction_transform = Affine2::from_translation(vec2(0.5, 0.5))
|
||||
* Affine2::from_scale(vec2(1., -size.x as f32 / size.y as f32));
|
||||
* Affine2::from_scale(vec2(
|
||||
1.,
|
||||
-panel.layout.content_size.x / panel.layout.content_size.y,
|
||||
));
|
||||
|
||||
let width = layout.row_size * 0.05 * app.session.config.keyboard_scale;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user