From 3cb2e22e89f6e4c0622cec7ca7e863b91a86136c Mon Sep 17 00:00:00 2001 From: TheRawMeatball Date: Mon, 28 Dec 2020 23:26:50 +0300 Subject: [PATCH] Added use_dpi setting to WindowDescriptor (#1131) Added scale_factor_override --- Cargo.toml | 4 ++ crates/bevy_ui/src/flex/mod.rs | 41 +++++++++--- crates/bevy_window/src/event.rs | 13 ++++ crates/bevy_window/src/lib.rs | 2 + crates/bevy_window/src/window.rs | 60 ++++++++++++++--- crates/bevy_winit/src/lib.rs | 59 +++++++++++++--- crates/bevy_winit/src/winit_windows.rs | 25 +++++-- examples/window/scale_factor_override.rs | 85 ++++++++++++++++++++++++ examples/window/window_settings.rs | 1 - 9 files changed, 254 insertions(+), 36 deletions(-) create mode 100644 examples/window/scale_factor_override.rs diff --git a/Cargo.toml b/Cargo.toml index c30eacdf68..c4a5ca03cd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -346,6 +346,10 @@ path = "examples/window/clear_color.rs" name = "multiple_windows" path = "examples/window/multiple_windows.rs" +[[example]] +name = "scale_factor_override" +path = "examples/window/scale_factor_override.rs" + [[example]] name = "window_settings" path = "examples/window/window_settings.rs" diff --git a/crates/bevy_ui/src/flex/mod.rs b/crates/bevy_ui/src/flex/mod.rs index 475ae9a303..10720ddc8a 100644 --- a/crates/bevy_ui/src/flex/mod.rs +++ b/crates/bevy_ui/src/flex/mod.rs @@ -1,12 +1,13 @@ mod convert; use crate::{Node, Style}; -use bevy_ecs::{Changed, Entity, Query, Res, ResMut, With, Without}; +use bevy_app::{EventReader, Events}; +use bevy_ecs::{Changed, Entity, Local, Query, QueryFilter, Res, ResMut, With, Without}; use bevy_math::Vec2; use bevy_text::CalculatedSize; use bevy_transform::prelude::{Children, Parent, Transform}; use bevy_utils::HashMap; -use bevy_window::{Window, WindowId, Windows}; +use bevy_window::{Window, WindowId, WindowScaleFactorChanged, Windows}; use std::fmt; use stretch::{number::Number, Stretch}; @@ -161,11 +162,15 @@ impl FlexSurface { unsafe impl Send for FlexSurface {} unsafe impl Sync for FlexSurface {} +#[allow(clippy::too_many_arguments)] pub fn flex_node_system( windows: Res, + mut scale_factor_reader: Local>, + scale_factor_events: Res>, mut flex_surface: ResMut, root_node_query: Query, Without)>, node_query: Query<(Entity, &Style, Option<&CalculatedSize>), (With, Changed