fix ui in font atlas and breakout examples
This commit is contained in:
parent
db665b96c0
commit
a2c1a90695
@ -39,7 +39,7 @@ fn update_node_entity(
|
|||||||
parent_result: Option<f32>,
|
parent_result: Option<f32>,
|
||||||
previous_result: Option<f32>,
|
previous_result: Option<f32>,
|
||||||
) -> Option<f32> {
|
) -> Option<f32> {
|
||||||
let mut transform = node_query.get_mut::<LocalTransform>(entity).unwrap();
|
let mut transform = node_query.get_mut::<LocalTransform>(entity).ok()?;
|
||||||
let mut z = UI_Z_STEP;
|
let mut z = UI_Z_STEP;
|
||||||
let parent_global_z = parent_result.unwrap();
|
let parent_global_z = parent_result.unwrap();
|
||||||
if let Some(previous_global_z) = previous_result {
|
if let Some(previous_global_z) = previous_result {
|
||||||
|
@ -40,8 +40,9 @@ fn setup(
|
|||||||
) {
|
) {
|
||||||
// Add the game's entities to our world
|
// Add the game's entities to our world
|
||||||
commands
|
commands
|
||||||
// camera
|
// cameras
|
||||||
.spawn(Camera2dComponents::default())
|
.spawn(Camera2dComponents::default())
|
||||||
|
.spawn(UiCameraComponents::default())
|
||||||
// paddle
|
// paddle
|
||||||
.spawn(SpriteComponents {
|
.spawn(SpriteComponents {
|
||||||
material: materials.add(Color::rgb(0.2, 0.2, 0.8).into()),
|
material: materials.add(Color::rgb(0.2, 0.2, 0.8).into()),
|
||||||
@ -75,6 +76,12 @@ fn setup(
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
style: Style {
|
style: Style {
|
||||||
|
position_type: PositionType::Absolute,
|
||||||
|
position: Rect {
|
||||||
|
top: Val::Px(5.0),
|
||||||
|
left: Val::Px(5.0),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
@ -41,9 +41,17 @@ fn atlas_render_system(
|
|||||||
for (_size, font_atlas) in set.iter() {
|
for (_size, font_atlas) in set.iter() {
|
||||||
state.added = true;
|
state.added = true;
|
||||||
let texture_atlas = texture_atlases.get(&font_atlas.texture_atlas).unwrap();
|
let texture_atlas = texture_atlases.get(&font_atlas.texture_atlas).unwrap();
|
||||||
commands.spawn(SpriteComponents {
|
commands.spawn(ImageComponents {
|
||||||
material: materials.add(texture_atlas.texture.into()),
|
material: materials.add(texture_atlas.texture.into()),
|
||||||
translation: Vec3::new(-300.0, 0., 0.0).into(),
|
style: Style {
|
||||||
|
position_type: PositionType::Absolute,
|
||||||
|
position: Rect {
|
||||||
|
top: Val::Px(0.0),
|
||||||
|
left: Val::Px(0.0),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
..Default::default()
|
..Default::default()
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
@ -65,15 +73,10 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>, mut state: ResM
|
|||||||
let font_handle = asset_server.load("assets/fonts/FiraSans-Bold.ttf").unwrap();
|
let font_handle = asset_server.load("assets/fonts/FiraSans-Bold.ttf").unwrap();
|
||||||
state.handle = font_handle;
|
state.handle = font_handle;
|
||||||
commands
|
commands
|
||||||
// 2d camera
|
.spawn(UiCameraComponents::default())
|
||||||
.spawn(Camera2dComponents::default())
|
|
||||||
// texture
|
|
||||||
.spawn(TextComponents {
|
.spawn(TextComponents {
|
||||||
style: Style {
|
style: Style {
|
||||||
size: Size {
|
size: Size::new(Val::Px(250.0), Val::Px(60.0)),
|
||||||
width: Val::Px(250.0),
|
|
||||||
height: Val::Px(60.0),
|
|
||||||
},
|
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
text: Text {
|
text: Text {
|
||||||
|
Loading…
Reference in New Issue
Block a user