forked from bevyengine/bevy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ui: feed computed image size into bevy_ui flex
- Loading branch information
Showing
6 changed files
with
124 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use crate::CalculatedSize; | ||
use bevy_asset::{Assets, Handle}; | ||
use bevy_ecs::{Query, Res}; | ||
use bevy_math::Size; | ||
use bevy_render::texture::Texture; | ||
use bevy_sprite::ColorMaterial; | ||
|
||
pub enum Image { | ||
KeepAspect, | ||
} | ||
|
||
impl Default for Image { | ||
fn default() -> Self { | ||
Image::KeepAspect | ||
} | ||
} | ||
|
||
pub fn image_node_system( | ||
materials: Res<Assets<ColorMaterial>>, | ||
textures: Res<Assets<Texture>>, | ||
mut query: Query<(&Image, &mut CalculatedSize, &Handle<ColorMaterial>)>, | ||
) { | ||
for (_image, mut calculated_size, material_handle) in &mut query.iter() { | ||
materials | ||
.get(material_handle) | ||
.and_then(|material| material.texture) | ||
.and_then(|texture_handle| textures.get(&texture_handle)) | ||
.map(|texture| { | ||
calculated_size.size = Size { | ||
width: texture.size.x(), | ||
height: texture.size.y(), | ||
}; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
mod button; | ||
mod text; | ||
mod image; | ||
|
||
pub use button::*; | ||
pub use text::*; | ||
pub use image::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters