Skip to content

Commit

Permalink
Merge remote-tracking branch 'fix-8942/main' into fix-pr-8942
Browse files Browse the repository at this point in the history
  • Loading branch information
tygyh committed Dec 7, 2023
2 parents 03b6106 + c551edd commit b79974c
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions crates/bevy_ui/src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -624,11 +624,11 @@ pub fn extract_text_uinodes(
) {
// TODO: Support window-independent UI scale: https://github.com/bevyengine/bevy/issues/5621

let scale_factor = (windows
let scale_factor = windows
.get_single()
.map(|window| window.scale_factor())
.unwrap_or(1.)
* ui_scale.0) as f32;
* ui_scale.0;

let inverse_scale_factor = scale_factor.recip();

Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_ui/src/render/ui_material_pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ pub fn extract_ui_material_nodes<M: UiMaterial>(
.unwrap_or(Vec2::ZERO)
// The logical window resolution returned by `Window` only takes into account the window scale factor and not `UiScale`,
// so we have to divide by `UiScale` to get the size of the UI viewport.
/ ui_scale.0 as f32;
/ ui_scale.0;
for (stack_index, entity) in ui_stack.uinodes.iter().enumerate() {
if let Ok((entity, uinode, style, transform, handle, view_visibility, clip)) =
uinode_query.get(*entity)
Expand Down
14 changes: 8 additions & 6 deletions crates/bevy_winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ pub fn winit_runner(mut app: App) {
window.set_physical_cursor_position(Some(physical_position));
event_writers.cursor_moved.send(CursorMoved {
window: window_entity,
position: (physical_position / window.resolution.scale_factor())
position: (physical_position / window.resolution.scale_factor() as f64)
.as_vec2(),
});
}
Expand Down Expand Up @@ -596,7 +596,9 @@ pub fn winit_runner(mut app: App) {
}
},
WindowEvent::Touch(touch) => {
let location = touch.location.to_logical(window.resolution.scale_factor());
let location = touch
.location
.to_logical(window.resolution.scale_factor() as f64);
event_writers
.touch_input
.send(converters::convert_touch_input(touch, location));
Expand All @@ -619,7 +621,7 @@ pub fn winit_runner(mut app: App) {
);

let prior_factor = window.resolution.scale_factor();
window.resolution.set_scale_factor(scale_factor);
window.resolution.set_scale_factor(scale_factor as f32);
let new_factor = window.resolution.scale_factor();

if let Some(forced_factor) = window.resolution.scale_factor_override() {
Expand All @@ -628,7 +630,7 @@ pub fn winit_runner(mut app: App) {
// incorporates any resize constraints.
*new_inner_size =
winit::dpi::LogicalSize::new(window.width(), window.height())
.to_physical::<u32>(forced_factor);
.to_physical::<u32>(forced_factor as f64);
} else if approx::relative_ne!(new_factor, prior_factor) {
event_writers.window_scale_factor_changed.send(
WindowScaleFactorChanged {
Expand All @@ -638,8 +640,8 @@ pub fn winit_runner(mut app: App) {
);
}

let new_logical_width = (new_inner_size.width as f64 / new_factor) as f32;
let new_logical_height = (new_inner_size.height as f64 / new_factor) as f32;
let new_logical_width = new_inner_size.width as f32 / new_factor;
let new_logical_height = new_inner_size.height as f32 / new_factor;
if approx::relative_ne!(window.width(), new_logical_width)
|| approx::relative_ne!(window.height(), new_logical_height)
{
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_winit/src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub(crate) fn create_windows<'a>(

window
.resolution
.set_scale_factor(winit_window.scale_factor());
.set_scale_factor(winit_window.scale_factor() as f32);
commands
.entity(entity)
.insert(RawHandleWrapper {
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_winit/src/winit_windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl WinitWindows {

let logical_size = LogicalSize::new(window.width(), window.height());
if let Some(sf) = window.resolution.scale_factor_override() {
winit_window_builder.with_inner_size(logical_size.to_physical::<f64>(sf))
winit_window_builder.with_inner_size(logical_size.to_physical::<f64>(sf.into()))
} else {
winit_window_builder.with_inner_size(logical_size)
}
Expand Down

0 comments on commit b79974c

Please sign in to comment.