Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DPI scale factor to the render root state #872

Merged
merged 5 commits into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions masonry/src/app/render_root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ pub(crate) struct RenderRootState {
/// Pass tracing configuration, used to skip tracing to limit overhead.
pub(crate) trace: PassTracing,
pub(crate) inspector_state: InspectorState,
pub(crate) scale_factor: f64,
}

pub(crate) struct MutateCallback {
Expand Down Expand Up @@ -290,6 +291,7 @@ impl RenderRoot {
is_picking_widget: false,
hovered_widget: None,
},
scale_factor,
},
widget_arena: WidgetArena {
widgets: TreeArena::new(),
Expand Down Expand Up @@ -339,6 +341,7 @@ impl RenderRoot {
match event {
WindowEvent::Rescale(scale_factor) => {
self.scale_factor = scale_factor;
self.global_state.scale_factor = scale_factor;
self.request_render_all();
Handled::Yes
}
Expand Down
17 changes: 17 additions & 0 deletions masonry/src/core/contexts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,23 @@ impl_context_method!(
}
);

// Methods on all context types except LayoutCtx and ComposeCtx.
// Access selected global state information.
impl_context_method!(
MutateCtx<'_>,
QueryCtx<'_>,
EventCtx<'_>,
UpdateCtx<'_>,
PaintCtx<'_>,
AccessCtx<'_>,
{
/// Get DPI scaling factor.
pub fn get_scale_factor(&self) -> f64 {
self.global_state.scale_factor
}
}
);

// Methods on all context types
// Access status information (hovered/pointer captured/disabled/etc).
impl_context_method!(
Expand Down
Loading