-
Notifications
You must be signed in to change notification settings - Fork 50
/
background.rs
63 lines (57 loc) · 1.9 KB
/
background.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
59
60
61
62
63
use bevy::prelude::{Bundle, Commands, Component, Entity, In, Query, Res};
use crate::{
children::KChildren,
context::WidgetName,
on_event::OnEvent,
prelude::KayakWidgetContext,
styles::{ComputedStyles, KStyle, RenderCommand},
widget::Widget,
};
#[derive(Component, PartialEq, Eq, Clone, Default)]
pub struct Background;
impl Widget for Background {}
/// Background Widget
///
/// The name of this widget is slightly misleading.
/// In actuality this widget renders a quad or multiple quads if a border is used.
/// You can customize the colors, border, border-radius, by passing in custom styles.
/// Children are rendered inside of the quad.
#[derive(Bundle)]
pub struct BackgroundBundle {
pub background: Background,
pub styles: KStyle,
pub computed_styles: ComputedStyles,
pub children: KChildren,
pub on_event: OnEvent,
pub widget_name: WidgetName,
}
impl Default for BackgroundBundle {
fn default() -> Self {
Self {
background: Default::default(),
styles: Default::default(),
computed_styles: Default::default(),
children: Default::default(),
on_event: Default::default(),
widget_name: Background.get_name(),
}
}
}
pub fn background_render(
In(entity): In<Entity>,
widget_context: Res<KayakWidgetContext>,
mut commands: Commands,
mut query: Query<(&KStyle, &mut ComputedStyles, &KChildren)>,
) -> bool {
if let Ok((style, mut computed_styles, children)) = query.get_mut(entity) {
*computed_styles = KStyle::default()
.with_style(KStyle {
render_command: RenderCommand::Quad.into(),
..Default::default()
})
.with_style(style)
.into();
children.process(&widget_context, &mut commands, Some(entity));
}
true
}