diff --git a/crates/scene_runner/src/update_world/scene_ui/mod.rs b/crates/scene_runner/src/update_world/scene_ui/mod.rs index 14bc1f4e..8908450e 100644 --- a/crates/scene_runner/src/update_world/scene_ui/mod.rs +++ b/crates/scene_runner/src/update_world/scene_ui/mod.rs @@ -347,11 +347,11 @@ impl Plugin for SceneUiPlugin { create_ui_roots, layout_scene_ui, ( - set_ui_background, + set_ui_text, // text runs before background as both insert to position 0. + set_ui_background, // so text is actually in front of background, but "behind"/before children set_ui_input, set_ui_dropdown, set_ui_pointer_events, - set_ui_text, ), fully_update_target_camera_system, ) diff --git a/crates/scene_runner/src/update_world/scene_ui/ui_background.rs b/crates/scene_runner/src/update_world/scene_ui/ui_background.rs index e49cbeb2..3baf8d6c 100644 --- a/crates/scene_runner/src/update_world/scene_ui/ui_background.rs +++ b/crates/scene_runner/src/update_world/scene_ui/ui_background.rs @@ -175,122 +175,119 @@ pub fn set_ui_background( if let Some(image) = image { let image_color = background.color.unwrap_or(Color::WHITE); let image_color = image_color.with_alpha(image_color.alpha() * link.opacity.0); - match texture_mode { - BackgroundTextureMode::NineSlices(rect) => { - commands.try_with_children(|c| { - c.spawn(( - NodeBundle { - style: Style { - position_type: PositionType::Absolute, - top: Val::Px(0.0), - right: Val::Px(0.0), - left: Val::Px(0.0), - bottom: Val::Px(0.0), - overflow: Overflow::clip(), - ..Default::default() - }, + let background_entity = match texture_mode { + BackgroundTextureMode::NineSlices(rect) => commands + .commands() + .spawn(( + NodeBundle { + style: Style { + position_type: PositionType::Absolute, + top: Val::Px(0.0), + right: Val::Px(0.0), + left: Val::Px(0.0), + bottom: Val::Px(0.0), + overflow: Overflow::clip(), ..Default::default() }, - Ui9Slice { - image: image.image, - center_region: rect.into(), - tint: Some(image_color), + ..Default::default() + }, + Ui9Slice { + image: image.image, + center_region: rect.into(), + tint: Some(image_color), + }, + UiBackgroundMarker, + )) + .id(), + BackgroundTextureMode::Stretch(ref uvs) => commands + .commands() + .spawn(( + NodeBundle { + style: Style { + position_type: PositionType::Absolute, + top: Val::Px(0.0), + right: Val::Px(0.0), + left: Val::Px(0.0), + bottom: Val::Px(0.0), + overflow: Overflow::clip(), + ..Default::default() }, - UiBackgroundMarker, - )); - }); - } - BackgroundTextureMode::Stretch(ref uvs) => { - commands.try_with_children(|c| { - c.spawn(( - NodeBundle { - style: Style { - position_type: PositionType::Absolute, - top: Val::Px(0.0), - right: Val::Px(0.0), - left: Val::Px(0.0), - bottom: Val::Px(0.0), - overflow: Overflow::clip(), - ..Default::default() - }, + ..Default::default() + }, + UiBackgroundMarker, + )) + .try_with_children(|c| { + c.spawn((MaterialNodeBundle { + style: Style { + position_type: PositionType::Absolute, + top: Val::Px(0.0), + right: Val::Px(0.0), + left: Val::Px(0.0), + bottom: Val::Px(0.0), ..Default::default() }, - UiBackgroundMarker, - )) - .try_with_children(|c| { - c.spawn((MaterialNodeBundle { - style: Style { - position_type: PositionType::Absolute, - top: Val::Px(0.0), - right: Val::Px(0.0), - left: Val::Px(0.0), - bottom: Val::Px(0.0), - ..Default::default() - }, - material: stretch_uvs.add(StretchUvMaterial { - image: image.image.clone(), - uvs: *uvs, - color: image_color.to_linear().to_vec4(), - }), + material: stretch_uvs.add(StretchUvMaterial { + image: image.image.clone(), + uvs: *uvs, + color: image_color.to_linear().to_vec4(), + }), + ..Default::default() + },)); + }) + .id(), + BackgroundTextureMode::Center => commands + .commands() + .spawn(( + NodeBundle { + style: Style { + position_type: PositionType::Absolute, + left: Val::Px(0.0), + right: Val::Px(0.0), + top: Val::Px(0.0), + bottom: Val::Px(0.0), + justify_content: JustifyContent::Center, + overflow: Overflow::clip(), + width: Val::Percent(100.0), ..Default::default() - },)); - }); - }); - } - BackgroundTextureMode::Center => { - commands.try_with_children(|c| { - // make a stretchy grid - c.spawn(( - NodeBundle { - style: Style { - position_type: PositionType::Absolute, - left: Val::Px(0.0), - right: Val::Px(0.0), - top: Val::Px(0.0), - bottom: Val::Px(0.0), - justify_content: JustifyContent::Center, - overflow: Overflow::clip(), - width: Val::Percent(100.0), - ..Default::default() - }, + }, + ..Default::default() + }, + UiBackgroundMarker, + )) + .try_with_children(|c| { + c.spacer(); + c.spawn(NodeBundle { + style: Style { + flex_direction: FlexDirection::Column, + justify_content: JustifyContent::Center, + overflow: Overflow::clip(), + height: Val::Percent(100.0), ..Default::default() }, - UiBackgroundMarker, - )) + ..Default::default() + }) .try_with_children(|c| { c.spacer(); - c.spawn(NodeBundle { + c.spawn(ImageBundle { style: Style { - flex_direction: FlexDirection::Column, - justify_content: JustifyContent::Center, overflow: Overflow::clip(), - height: Val::Percent(100.0), ..Default::default() }, + image: UiImage { + color: image_color, + texture: image.image, + flip_x: false, + flip_y: false, + }, ..Default::default() - }) - .try_with_children(|c| { - c.spacer(); - c.spawn(ImageBundle { - style: Style { - overflow: Overflow::clip(), - ..Default::default() - }, - image: UiImage { - color: image_color, - texture: image.image, - flip_x: false, - flip_y: false, - }, - ..Default::default() - }); - c.spacer(); }); c.spacer(); }); - }); - } - } + c.spacer(); + }) + .id(), + }; + commands.insert_children(0, &[background_entity]); } else { warn!("failed to load ui image from content map: {:?}", texture); } diff --git a/crates/scene_runner/src/update_world/scene_ui/ui_text.rs b/crates/scene_runner/src/update_world/scene_ui/ui_text.rs index 232e09ad..56561e14 100644 --- a/crates/scene_runner/src/update_world/scene_ui/ui_text.rs +++ b/crates/scene_runner/src/update_world/scene_ui/ui_text.rs @@ -180,8 +180,9 @@ pub fn set_ui_text( _ => Val::Auto, }; - ent_cmds.try_with_children(|c| { - c.spawn(( + let text_element = ent_cmds + .commands() + .spawn(( NodeBundle { style: Style { flex_direction: FlexDirection::Row, @@ -223,7 +224,9 @@ pub fn set_ui_text( cmds.insert(extras); } }); - }); - }); + }) + .id(); + + ent_cmds.insert_children(0, &[text_element]); } }