This repository has been archived by the owner on Feb 18, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathplugin.rs
47 lines (40 loc) · 1.52 KB
/
plugin.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use bevy::prelude::*;
use bevy_ninepatch::{NinePatchBuilder, NinePatchBundle, NinePatchData, NinePatchPlugin};
fn main() -> Result<(), Box<dyn std::error::Error>> {
App::default()
.add_plugins(DefaultPlugins)
// Add the `NinePatchPlugin` plugin
.add_plugin(NinePatchPlugin::<()>::default())
.add_startup_system(setup)
.run();
Ok(())
}
fn setup(
mut commands: Commands,
asset_server: Res<AssetServer>,
mut nine_patches: ResMut<Assets<NinePatchBuilder<()>>>,
) {
let panel_texture_handle = asset_server.load("glassPanel_corners.png");
// load the 9-Patch as an assets and keep an `Handle<NinePatchBuilder<()>>`
let nine_patch_handle = nine_patches.add(NinePatchBuilder::by_margins(20, 20, 20, 20));
commands.spawn(
// this component bundle will be detected by the plugin, and the 9-Patch UI element will be added as a child
// of this entity
NinePatchBundle {
style: Style {
margin: UiRect::all(Val::Auto),
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
size: Size::new(Val::Px(500.), Val::Px(300.)),
..Default::default()
},
nine_patch_data: NinePatchData {
nine_patch: nine_patch_handle,
texture: panel_texture_handle,
..Default::default()
},
..Default::default()
},
);
commands.spawn(Camera2dBundle::default());
}