Crates.io | bevy_ui_exact_image |
lib.rs | bevy_ui_exact_image |
version | 0.2.1 |
source | src |
created_at | 2023-01-31 18:41:14.944298 |
updated_at | 2023-02-17 19:23:30.477813 |
description | Bevy UI image widget with more control over the size of images and their orientation |
homepage | |
repository | https://github.com/ickshonpe/bevy_ui_exact_image |
max_upload_size | |
id | 772879 |
size | 158,706 |
Add the dependency to your bevy project:
cargo add bevy_ui_exact_image
Then to draw a sized image within a Bevy UI node:
use bevy::prelude::*;
use bevy_ui_exact_image::prelude::*;
fn spawn_example(mut commands: Commands, assets: Res<AssetServer>) {
commands.spawn(Camera2dBundle::default());
commands.spawn((ExactImageBundle {
image: ExactImage {
texture: assets.load("orientation.png"),
// exact images have their own color, independent from the background color.
color: Color::WHITE,
// force the UI to display the texture at 300 x 200 size
size: ExactSize::Exactly(Vec2::new(300., 200.)),
// align the image to the bottom edge of the node, in the center.
alignment: ImageAlignment::BottomCenter,
// use Some(rads) to set rotation
rotation: None,
},
style: Style {
size: Size::new(Val::Px(400.0), Val::Px(400.0)),
..Default::default()
},
/// give the containing node a red color
background_color: BackgroundColor(Color::RED),
..Default::default()
},));
}
fn main() {
App::new()
.add_plugins(DefaultPlugins.set(ImagePlugin::default_nearest()))
.add_plugin(ExactImagePlugin)
.add_startup_system(spawn_example)
.run();
}
Result:
cargo --run --example minimal
cargo --run --example rotation
cargo --run --example size
cargo --run --example alignment
Probably quite a few bugs, I haven't done much testing.
Name stolen from inodentry's related Bevy issue #7439