Newer
Older
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
59
60
61
62
63
64
65
66
67
68
use bevy::prelude::*;
use kayak_ui::prelude::{widgets::*, KStyle, *};
fn startup(
mut commands: Commands,
mut font_mapping: ResMut<FontMapping>,
asset_server: Res<AssetServer>,
) {
let camera_entity = commands
.spawn((Camera2dBundle::default(), CameraUIKayak))
.id();
font_mapping.set_default(asset_server.load("roboto.kayak_font"));
let image = asset_server.load("panel.png");
let mut widget_context = KayakRootContext::new(camera_entity);
widget_context.add_plugin(KayakWidgetsContextPlugin);
let parent_id = None;
// The border prop splits up the image into 9 quadrants like so:
// 1----2----3
// | |
// 4 9 5
// | |
// 6----7----8
// The sizes of sprites for a 15 pixel border are as follows:
// TopLeft = (15, 15)
// TopRight = (15, 15)
// LeftCenter = (15, image_height)
// RightCenter = (15, image_height)
// TopCenter = (image_width, 15)
// BottomCenter = (image_width, 15)
// BottomRight = (15, 15)
// BottomLeft = (15, 15)
// Middle = (
// 30 being left border + right border
// image_width - 30
// 30 being top border + bottom border
// image_height - 30
// )
rsx! {
<KayakAppBundle>
<NinePatchBundle
nine_patch={NinePatch {
handle: image,
border: Edge::all(15.0),
..Default::default()
}}
styles={KStyle {
width: StyleProp::Value(Units::Pixels(512.0)),
height: StyleProp::Value(Units::Pixels(512.0)),
..KStyle::default()
}}
/>
</KayakAppBundle>
};
commands.spawn((widget_context, EventDispatcher::default()));
}
fn main() {
App::new()
.add_plugins(DefaultPlugins.set(ImagePlugin::default_nearest()))
.add_plugins((KayakContextPlugin, KayakWidgets))
.add_systems(Startup, startup)
.run()
}