Skip to content

Commit

Permalink
Expose surface_size from yakui and PaintDom in LayoutContext
Browse files Browse the repository at this point in the history
  • Loading branch information
LPGhatguy committed Jan 24, 2025
1 parent 0085153 commit 3131f4d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
7 changes: 5 additions & 2 deletions crates/yakui-core/src/layout/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()");

Expand 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);
}

Expand All @@ -136,6 +137,7 @@ impl LayoutDom {
&mut self,
dom: &Dom,
input: &InputState,
paint: &PaintDom,
id: WidgetId,
constraints: Constraints,
) -> Vec2 {
Expand All @@ -146,6 +148,7 @@ impl LayoutDom {
dom,
input,
layout: self,
paint,
};

let size = dom_node.widget.layout(context, constraints);
Expand Down
8 changes: 7 additions & 1 deletion crates/yakui-core/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}

Expand Down
3 changes: 2 additions & 1 deletion crates/yakui-core/src/widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand All @@ -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)
}
}

Expand Down

0 comments on commit 3131f4d

Please sign in to comment.