From 3131f4dfc0217fba74b7a44d2c6884896e352498 Mon Sep 17 00:00:00 2001 From: Lucien Greathouse Date: Fri, 24 Jan 2025 18:54:24 -0500 Subject: [PATCH] Expose surface_size from yakui and PaintDom in LayoutContext --- crates/yakui-core/src/layout/mod.rs | 7 +++++-- crates/yakui-core/src/state.rs | 8 +++++++- crates/yakui-core/src/widget.rs | 3 ++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/crates/yakui-core/src/layout/mod.rs b/crates/yakui-core/src/layout/mod.rs index 30de020..7298c62 100644 --- a/crates/yakui-core/src/layout/mod.rs +++ b/crates/yakui-core/src/layout/mod.rs @@ -10,6 +10,7 @@ use crate::event::EventInterest; use crate::geometry::{Constraints, Rect}; use crate::id::WidgetId; use crate::input::{InputState, MouseInterest}; +use crate::paint::PaintDom; use crate::widget::LayoutContext; /// Contains information on how each widget in the DOM is laid out and what @@ -114,7 +115,7 @@ impl LayoutDom { } /// Calculate the layout of all elements in the given DOM. - pub fn calculate_all(&mut self, dom: &Dom, input: &InputState) { + pub fn calculate_all(&mut self, dom: &Dom, input: &InputState, paint: &PaintDom) { profiling::scope!("LayoutDom::calculate_all"); log::debug!("LayoutDom::calculate_all()"); @@ -123,7 +124,7 @@ impl LayoutDom { let constraints = Constraints::tight(self.viewport().size()); - self.calculate(dom, input, dom.root(), constraints); + self.calculate(dom, input, paint, dom.root(), constraints); self.resolve_positions(dom); } @@ -136,6 +137,7 @@ impl LayoutDom { &mut self, dom: &Dom, input: &InputState, + paint: &PaintDom, id: WidgetId, constraints: Constraints, ) -> Vec2 { @@ -146,6 +148,7 @@ impl LayoutDom { dom, input, layout: self, + paint, }; let size = dom_node.widget.layout(context, constraints); diff --git a/crates/yakui-core/src/state.rs b/crates/yakui-core/src/state.rs index b5ab7dd..c7682d5 100644 --- a/crates/yakui-core/src/state.rs +++ b/crates/yakui-core/src/state.rs @@ -60,6 +60,11 @@ impl Yakui { self.paint.set_surface_size(size); } + /// Return the current size of the primary surface. + pub fn surface_size(&self) -> Vec2 { + self.paint.surface_size() + } + /// Set the size and position of the viewport in physical units. pub fn set_unscaled_viewport(&mut self, view: Rect) { self.layout.set_unscaled_viewport(view); @@ -99,7 +104,8 @@ impl Yakui { self.dom.finish(&self.input); self.layout.sync_removals(&self.dom.removed_nodes()); - self.layout.calculate_all(&self.dom, &self.input); + self.layout + .calculate_all(&self.dom, &self.input, &self.paint); self.input.finish(); } diff --git a/crates/yakui-core/src/widget.rs b/crates/yakui-core/src/widget.rs index 9d94797..f8e1208 100644 --- a/crates/yakui-core/src/widget.rs +++ b/crates/yakui-core/src/widget.rs @@ -26,6 +26,7 @@ pub struct LayoutContext<'dom> { pub dom: &'dom Dom, pub input: &'dom InputState, pub layout: &'dom mut LayoutDom, + pub paint: &'dom PaintDom, } impl<'dom> LayoutContext<'dom> { @@ -35,7 +36,7 @@ impl<'dom> LayoutContext<'dom> { /// phase. pub fn calculate_layout(&mut self, widget: WidgetId, constraints: Constraints) -> Vec2 { self.layout - .calculate(self.dom, self.input, widget, constraints) + .calculate(self.dom, self.input, self.paint, widget, constraints) } }