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
69
70
71
72
73
74
75
76
77
78
79
80
81
use bevy::prelude::*;
use kayak_ui::prelude::*;
use crate::parent_widget;
use crate::theme::tokens::THEME_NINEPATCH_PANEL_DEFAULT;
use crate::theme::ThemeProvider;
use crate::{px, value};
#[derive(Default, Copy, Clone, Eq, PartialEq)]
pub enum PanelVariant {
#[default]
Regular,
Simple,
}
#[derive(Component, Default, Clone, PartialEq)]
pub struct PanelProps {
pub background: Option<String>,
pub inner_layout: StyleProp<LayoutType>,
}
impl Widget for PanelProps {}
parent_widget!(PanelProps => PanelWidget);
pub fn render_panel_widget(
In(entity): In<Entity>,
widget_context: Res<KayakWidgetContext>,
mut commands: Commands,
mut query: Query<(&PanelProps, &KChildren, &mut ComputedStyles, &KStyle)>,
theme_provider: ThemeProvider,
) -> bool {
if let Ok((props, children, mut computed, style)) = query.get_mut(entity) {
let parent_id = Some(entity);
let patch = theme_provider
.get_patch(
props
.background
.clone()
.unwrap_or_else(|| String::from(THEME_NINEPATCH_PANEL_DEFAULT)),
)
.unwrap();
*computed = KStyle {
render_command: value(RenderCommand::NinePatch {
handle: patch.handle.clone_weak(),
border: patch.border,
scale: 1.0,
}),
min_height: px(patch.border.bottom + patch.border.top + 8.0),
min_width: px(patch.border.left + patch.border.right + 8.0),
..Default::default()
}
.with_style(style)
.with_style(KStyle {
padding: value(Edge::new(
Units::Pixels(patch.border.top),
Units::Pixels(patch.border.right),
Units::Pixels(patch.border.bottom),
Units::Pixels(patch.border.left),
)),
..Default::default()
})
.into();
let inner_style = match &style.padding {
StyleProp::Unset => KStyle {
layout_type: props.inner_layout.clone(),
..Default::default()
},
pad => KStyle {
layout_type: props.inner_layout.clone(),
padding: pad.clone(),
..Default::default()
},
};
children.process(&widget_context, &mut commands, Some(entity));
}
true
}