-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathimage.rs
52 lines (46 loc) · 1.42 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
use bevy::prelude::{Bundle, Component, Entity, Handle, In, Query};
use crate::{
context::WidgetName,
styles::{ComputedStyles, KStyle, RenderCommand},
widget::Widget,
};
/// Renders a bevy image asset within the GUI
/// The rendered image respects the styles.
#[derive(Component, PartialEq, Eq, Clone, Default)]
pub struct KImage(pub Handle<bevy::prelude::Image>);
impl Widget for KImage {}
#[derive(Bundle)]
pub struct KImageBundle {
pub image: KImage,
pub styles: KStyle,
pub computed_styles: ComputedStyles,
pub widget_name: WidgetName,
}
impl Default for KImageBundle {
fn default() -> Self {
Self {
image: Default::default(),
styles: Default::default(),
computed_styles: ComputedStyles::default(),
widget_name: KImage::default().get_name(),
}
}
}
pub fn image_render(
In(entity): In<Entity>,
mut query: Query<(&KStyle, &mut ComputedStyles, &KImage)>,
) -> bool {
if let Ok((style, mut computed_styles, image)) = query.get_mut(entity) {
*computed_styles = KStyle::default()
.with_style(KStyle {
render_command: RenderCommand::Image {
handle: image.0.clone_weak(),
}
.into(),
..Default::default()
})
.with_style(style)
.into();
}
true
}