Skip to content

Commit

Permalink
zindex for text
Browse files Browse the repository at this point in the history
  • Loading branch information
robtfm committed Jan 2, 2025
1 parent 2f6398f commit 2f9c7f7
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 104 deletions.
4 changes: 2 additions & 2 deletions crates/scene_runner/src/update_world/scene_ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
193 changes: 95 additions & 98 deletions crates/scene_runner/src/update_world/scene_ui/ui_background.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
11 changes: 7 additions & 4 deletions crates/scene_runner/src/update_world/scene_ui/ui_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -223,7 +224,9 @@ pub fn set_ui_text(
cmds.insert(extras);
}
});
});
});
})
.id();

ent_cmds.insert_children(0, &[text_element]);
}
}

0 comments on commit 2f9c7f7

Please sign in to comment.