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::{Bundle, Color, Commands, Component, Entity, In, Query, Res};
use kayak_ui::prelude::{
rsx, widgets::BackgroundBundle, ComputedStyles, Edge, KChildren, KStyle, KayakWidgetContext,
StyleProp, Units, Widget, WidgetName,
};
use crate::tab_context::TabContext;
#[derive(Component, Default, PartialEq, Eq, Clone)]
pub struct Tab {
pub index: usize,
}
impl Widget for Tab {}
#[derive(Bundle)]
pub struct TabBundle {
pub tab: Tab,
pub children: KChildren,
pub styles: ComputedStyles,
pub widget_name: WidgetName,
}
impl Default for TabBundle {
fn default() -> Self {
Self {
tab: Default::default(),
children: Default::default(),
styles: ComputedStyles::default(),
widget_name: Tab::default().get_name(),
}
}
}
pub fn tab_render(
In(entity): In<Entity>,
widget_context: Res<KayakWidgetContext>,
mut commands: Commands,
mut query: Query<(&KChildren, &Tab, &mut ComputedStyles)>,
tab_context_query: Query<&TabContext>,
) -> bool {
if let Ok((children, tab, mut styles)) = query.get_mut(entity) {
let context_entity = widget_context
.get_context_entity::<TabContext>(entity)
.unwrap();
if let Ok(tab_context) = tab_context_query.get(context_entity) {
if tab_context.current_index == tab.index {
styles.0.height = StyleProp::default();
styles.0.width = StyleProp::default();
let parent_id = Some(entity);
let styles = KStyle {
background_color: StyleProp::Value(Color::rgba(0.0781, 0.0898, 0.101, 1.0)),
padding: StyleProp::Value(Edge::all(Units::Pixels(15.0))),
height: Units::Stretch(1.0).into(),
width: Units::Stretch(1.0).into(),
..Default::default()
};
rsx! {
<BackgroundBundle styles={styles} children={children.clone()} />
};
} else {
styles.0.height = StyleProp::Value(Units::Pixels(0.0));
styles.0.width = StyleProp::Value(Units::Pixels(0.0));
}
}
}
true
}