-
Notifications
You must be signed in to change notification settings - Fork 49
/
image.rs
58 lines (52 loc) · 1.73 KB
/
image.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
48
49
50
51
52
53
54
55
56
57
58
use bevy::{
prelude::{App as BevyApp, AssetServer, Commands, Handle, Res, ResMut},
window::WindowDescriptor,
DefaultPlugins,
};
use kayak_core::styles::PositionType;
use kayak_ui::bevy::{BevyContext, BevyKayakUIPlugin, ImageManager, UICameraBundle};
use kayak_ui::core::{
render,
styles::{Corner, Style, StyleProp, Units},
Index,
};
use kayak_ui::widgets::{App, Image};
fn startup(
mut commands: Commands,
asset_server: Res<AssetServer>,
mut image_manager: ResMut<ImageManager>,
) {
commands.spawn_bundle(UICameraBundle::new());
let handle: Handle<bevy::render::texture::Image> = asset_server.load("generic-rpg-vendor.png");
let ui_image_handle = image_manager.get(&handle);
let context = BevyContext::new(|context| {
let image_styles = Style {
position_type: StyleProp::Value(PositionType::SelfDirected),
left: StyleProp::Value(Units::Pixels(10.0)),
top: StyleProp::Value(Units::Pixels(10.0)),
border_radius: StyleProp::Value(Corner::all(500.0)),
width: StyleProp::Value(Units::Pixels(200.0)),
height: StyleProp::Value(Units::Pixels(182.0)),
..Style::default()
};
render! {
<App>
<Image styles={Some(image_styles)} handle={ui_image_handle} />
</App>
}
});
commands.insert_resource(context);
}
fn main() {
BevyApp::new()
.insert_resource(WindowDescriptor {
width: 1270.0,
height: 720.0,
title: String::from("UI Example"),
..Default::default()
})
.add_plugins(DefaultPlugins)
.add_plugin(BevyKayakUIPlugin)
.add_startup_system(startup)
.run();
}