Skip to content

Commit

Permalink
Rebased on #5103
Browse files Browse the repository at this point in the history
  • Loading branch information
ManevilleF committed Jun 28, 2022
1 parent 5e77f9e commit 2aafef4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
11 changes: 7 additions & 4 deletions crates/bevy_ui/src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use bevy_render::{
view::{ExtractedView, ViewUniforms, Visibility},
RenderApp, RenderStage, RenderWorld,
};
use bevy_sprite::{Rect, SpriteAssetEvents, SpriteSheet, TextureAtlas};
use bevy_sprite::{Rect, SpriteAssetEvents, TextureAtlas, TextureSheet};
use bevy_text::{DefaultTextPipeline, Text};
use bevy_transform::components::GlobalTransform;
use bevy_utils::FloatOrd;
Expand Down Expand Up @@ -183,7 +183,7 @@ pub fn extract_uinodes(
&UiColor,
&UiImage,
&Visibility,
Option<&SpriteSheet>,
Option<&TextureSheet>,
Option<&CalculatedClip>,
)>,
) {
Expand All @@ -196,9 +196,12 @@ pub fn extract_uinodes(
}

let image = image.0.clone_weak();
let sheet: Option<&SpriteSheet> = sheet;
let (atlas_size, rect_min) = sheet
.and_then(|s| texture_atlases.get(&s.texture_atlas).map(|a| (a, s.index)))
.and_then(|s| {
texture_atlases
.get(&s.texture_atlas)
.map(|a| (a, s.texture_index))
})
.and_then(|(atlas, index)| {
atlas
.textures
Expand Down
12 changes: 6 additions & 6 deletions examples/ui/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,20 @@ fn button_system(

fn sheet_button_system(
mut interaction_query: Query<
(&Interaction, &mut SpriteSheet),
(&Interaction, &mut TextureSheet),
(Changed<Interaction>, With<Button>),
>,
) {
for (interaction, mut sheet) in interaction_query.iter_mut() {
match *interaction {
Interaction::Clicked => {
sheet.index = 2;
sheet.texture_index = 2;
}
Interaction::Hovered => {
sheet.index = 1;
sheet.texture_index = 1;
}
Interaction::None => {
sheet.index = 0;
sheet.texture_index = 0;
}
}
}
Expand Down Expand Up @@ -116,8 +116,8 @@ fn setup(
image: handle.into(),
..default()
})
.insert(SpriteSheet {
.insert(TextureSheet {
texture_atlas,
index: 0,
texture_index: 0,
});
}

0 comments on commit 2aafef4

Please sign in to comment.