Skip to content

Commit

Permalink
Use default resolution for viewport_debug example (#9666)
Browse files Browse the repository at this point in the history
# Objective

The `viewport_debug` example opens a window that is physically very
large. Probably larger than the screen for the majority of machines.

## Solution

Remove the custom resolution and adjust the pixel coordinates so that
everything lines up.

At the default resolution, everything is still whole numbers even
without adjusting the viewport coordinates.
  • Loading branch information
rparrett authored Sep 2, 2023
1 parent 8618a14 commit 870d46e
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions examples/ui/viewport_debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ fn main() {
.insert_resource(UiScale(2.0))
.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
resolution: [1600., 1200.].into(),
title: "Viewport Coordinates Debug".to_string(),
// This example relies on these specific viewport dimensions, so let's explicitly
// define them.
resolution: [1280., 720.].into(),
resizable: false,
..Default::default()
}),
Expand Down Expand Up @@ -164,9 +166,9 @@ fn spawn_with_pixel_coords(commands: &mut Commands) {
.spawn((
NodeBundle {
style: Style {
width: Val::Px(800.),
height: Val::Px(600.),
border: UiRect::axes(Val::Px(40.), Val::Px(30.)),
width: Val::Px(640.),
height: Val::Px(360.),
border: UiRect::axes(Val::Px(32.), Val::Px(18.)),
flex_wrap: FlexWrap::Wrap,
..default()
},
Expand All @@ -178,9 +180,9 @@ fn spawn_with_pixel_coords(commands: &mut Commands) {
.with_children(|builder| {
builder.spawn(NodeBundle {
style: Style {
width: Val::Px(240.),
height: Val::Px(180.),
border: UiRect::axes(Val::Px(30.), Val::Px(30.)),
width: Val::Px(192.),
height: Val::Px(108.),
border: UiRect::axes(Val::Px(18.), Val::Px(18.)),
..default()
},
background_color: PALETTE[2].into(),
Expand All @@ -190,8 +192,8 @@ fn spawn_with_pixel_coords(commands: &mut Commands) {

builder.spawn(NodeBundle {
style: Style {
width: Val::Px(480.),
height: Val::Px(180.),
width: Val::Px(384.),
height: Val::Px(108.),
..default()
},
background_color: PALETTE[3].into(),
Expand All @@ -200,9 +202,9 @@ fn spawn_with_pixel_coords(commands: &mut Commands) {

builder.spawn(NodeBundle {
style: Style {
width: Val::Px(360.),
height: Val::Px(180.),
border: UiRect::left(Val::Px(180.)),
width: Val::Px(288.),
height: Val::Px(108.),
border: UiRect::left(Val::Px(144.)),
..default()
},
background_color: PALETTE[4].into(),
Expand All @@ -212,9 +214,9 @@ fn spawn_with_pixel_coords(commands: &mut Commands) {

builder.spawn(NodeBundle {
style: Style {
width: Val::Px(360.),
height: Val::Px(180.),
border: UiRect::right(Val::Px(180.)),
width: Val::Px(288.),
height: Val::Px(108.),
border: UiRect::right(Val::Px(144.)),
..default()
},
background_color: PALETTE[5].into(),
Expand All @@ -224,8 +226,8 @@ fn spawn_with_pixel_coords(commands: &mut Commands) {

builder.spawn(NodeBundle {
style: Style {
width: Val::Px(480.),
height: Val::Px(180.),
width: Val::Px(384.),
height: Val::Px(108.),
..default()
},
background_color: PALETTE[6].into(),
Expand All @@ -234,9 +236,9 @@ fn spawn_with_pixel_coords(commands: &mut Commands) {

builder.spawn(NodeBundle {
style: Style {
width: Val::Px(240.),
height: Val::Px(180.),
border: UiRect::axes(Val::Px(30.), Val::Px(30.)),
width: Val::Px(192.),
height: Val::Px(108.),
border: UiRect::axes(Val::Px(18.), Val::Px(18.)),
..default()
},
background_color: PALETTE[7].into(),
Expand Down

0 comments on commit 870d46e

Please sign in to comment.