fix: Make popup child a closure
This commit is contained in:
@@ -3,127 +3,83 @@ use super::timer_settings::timer_settings;
|
||||
use crate::prelude::*;
|
||||
|
||||
pub fn open_settings(commands: &mut Commands) {
|
||||
commands
|
||||
.spawn((
|
||||
RootMarker::Settings,
|
||||
Node {
|
||||
position_type: PositionType::Absolute,
|
||||
width: percent(100),
|
||||
height: percent(100),
|
||||
..Node::center()
|
||||
},
|
||||
ZIndex(1),
|
||||
BackgroundColor(Color::srgba(0.0, 0.0, 0.0, 0.8)),
|
||||
GlobalTransform::default(),
|
||||
))
|
||||
.with_children(|parent| {
|
||||
parent
|
||||
.spawn((
|
||||
Node {
|
||||
width: px(700),
|
||||
padding: UiRect::all(px(20.0)),
|
||||
..Node::vstack(px(20))
|
||||
},
|
||||
BackgroundColor(Color::srgb(0.2, 0.2, 0.2)),
|
||||
BorderRadius::all(px(10.0)),
|
||||
))
|
||||
.with_children(|parent| {
|
||||
parent.spawn((
|
||||
spawn_popup(
|
||||
commands,
|
||||
RootMarker::Settings,
|
||||
"Spiel Einstellungen",
|
||||
Node {
|
||||
width: px(700),
|
||||
..default()
|
||||
},
|
||||
|parent| {
|
||||
parent.spawn((
|
||||
Node::vstack(px(10)),
|
||||
children![
|
||||
button(
|
||||
ButtonType::SettingsExit,
|
||||
ButtonVariant::Secondary,
|
||||
Node::from_padding(UiRect::all(px(10))),
|
||||
|color| text("Spiel verlassen", 24.0, color)
|
||||
),
|
||||
button(
|
||||
ButtonType::SettingsSave,
|
||||
ButtonVariant::Secondary,
|
||||
Node::from_padding(UiRect::all(px(10))),
|
||||
|color| text("Spiel speichern", 24.0, color)
|
||||
),(
|
||||
Node {
|
||||
justify_content: JustifyContent::SpaceBetween,
|
||||
..Node::hstack(px(20))
|
||||
justify_content: JustifyContent::Center,
|
||||
..Node::hstack(px(30))
|
||||
},
|
||||
children![
|
||||
text("Spiel Einstellungen", 40.0, Color::WHITE),
|
||||
pill_button(
|
||||
ButtonType::SettingsClose,
|
||||
ButtonVariant::Destructive,
|
||||
(
|
||||
Node {
|
||||
width: px(40),
|
||||
height: px(40),
|
||||
..default()
|
||||
},
|
||||
|color| text("X", 24.0, color)
|
||||
),
|
||||
],
|
||||
));
|
||||
|
||||
parent
|
||||
.spawn(Node::vstack(px(10)))
|
||||
.with_children(|parent| {
|
||||
parent.spawn(button(
|
||||
ButtonType::SettingsExit,
|
||||
ButtonVariant::Secondary,
|
||||
Node {
|
||||
padding: UiRect::all(px(10)),
|
||||
..default()
|
||||
},
|
||||
|color| text("Spiel verlassen", 24.0, color)
|
||||
));
|
||||
|
||||
parent.spawn(button(
|
||||
ButtonType::SettingsSave,
|
||||
ButtonVariant::Secondary,
|
||||
Node {
|
||||
padding: UiRect::all(px(10)),
|
||||
..default()
|
||||
},
|
||||
|color| text("Spiel speichern", 24.0, color)
|
||||
));
|
||||
|
||||
parent.spawn((
|
||||
Node {
|
||||
justify_content: JustifyContent::Center,
|
||||
..Node::hstack(px(30))
|
||||
width: percent(40),
|
||||
..Node::vstack(px(10))
|
||||
},
|
||||
children![
|
||||
(
|
||||
Node {
|
||||
width: percent(40),
|
||||
..Node::vstack(px(10))
|
||||
},
|
||||
children![
|
||||
text("Spiel Einstellungen", 18.0, Color::WHITE),
|
||||
text(
|
||||
"Tipp: Benutze [Umstellen] um in 10er Schritten zu inkrementieren oder dekrementieren!",
|
||||
16.0,
|
||||
Color::WHITE
|
||||
),
|
||||
]
|
||||
text("Spiel Einstellungen", 18.0, Color::WHITE),
|
||||
text(
|
||||
"Tipp: Benutze [Umstellen] um in 10er Schritten zu inkrementieren oder dekrementieren!",
|
||||
16.0,
|
||||
Color::WHITE
|
||||
),
|
||||
(
|
||||
Node {
|
||||
align_items: AlignItems::Center,
|
||||
..Node::vstack(px(10))
|
||||
},
|
||||
children![
|
||||
text("Fokus Phase", 12.0, Color::WHITE),
|
||||
timer_settings(TimerType::Focus)
|
||||
]
|
||||
),
|
||||
(
|
||||
Node {
|
||||
align_items: AlignItems::Center,
|
||||
..Node::vstack(px(10))
|
||||
},
|
||||
children![
|
||||
text("Kurze Pause", 12.0, Color::WHITE),
|
||||
timer_settings(TimerType::ShortBreak)
|
||||
]
|
||||
),
|
||||
(
|
||||
Node {
|
||||
align_items: AlignItems::Center,
|
||||
..Node::vstack(px(10))
|
||||
},
|
||||
children![
|
||||
text("Lange Pause", 12.0, Color::WHITE),
|
||||
timer_settings(TimerType::LongBreak)
|
||||
]
|
||||
)
|
||||
],
|
||||
));
|
||||
});
|
||||
});
|
||||
});
|
||||
]
|
||||
),
|
||||
(
|
||||
Node {
|
||||
align_items: AlignItems::Center,
|
||||
..Node::vstack(px(10))
|
||||
},
|
||||
children![
|
||||
text("Fokus Phase", 12.0, Color::WHITE),
|
||||
timer_settings(TimerType::Focus)
|
||||
]
|
||||
),
|
||||
(
|
||||
Node {
|
||||
align_items: AlignItems::Center,
|
||||
..Node::vstack(px(10))
|
||||
},
|
||||
children![
|
||||
text("Kurze Pause", 12.0, Color::WHITE),
|
||||
timer_settings(TimerType::ShortBreak)
|
||||
]
|
||||
),
|
||||
(
|
||||
Node {
|
||||
align_items: AlignItems::Center,
|
||||
..Node::vstack(px(10))
|
||||
},
|
||||
children![
|
||||
text("Lange Pause", 12.0, Color::WHITE),
|
||||
timer_settings(TimerType::LongBreak)
|
||||
]
|
||||
)
|
||||
],
|
||||
)
|
||||
],
|
||||
));
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -5,5 +5,5 @@ pub mod texts;
|
||||
|
||||
pub use button::{button, pill_button};
|
||||
pub use flexbox::Flexbox;
|
||||
pub use popups::popup;
|
||||
pub use popups::spawn_popup;
|
||||
pub use texts::{text, text_with_component};
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use bevy::ecs::relationship::RelatedSpawnerCommands;
|
||||
|
||||
use super::super::messages::ClosePopupMessage;
|
||||
use crate::prelude::*;
|
||||
|
||||
@@ -7,57 +9,63 @@ pub struct PopupRoot;
|
||||
#[derive(Component)]
|
||||
pub struct PopupCloseButton;
|
||||
|
||||
pub fn popup(
|
||||
pub fn spawn_popup(
|
||||
commands: &mut Commands,
|
||||
root: impl Component,
|
||||
title: impl Into<String>,
|
||||
mut node: Node,
|
||||
child: impl Bundle,
|
||||
child: impl FnOnce(&mut RelatedSpawnerCommands<ChildOf>),
|
||||
) -> impl Bundle {
|
||||
node.flex_direction = FlexDirection::Column;
|
||||
node.row_gap = px(10);
|
||||
node.padding = UiRect::all(px(20));
|
||||
|
||||
(
|
||||
PopupRoot,
|
||||
root,
|
||||
Node {
|
||||
position_type: PositionType::Absolute,
|
||||
width: percent(100),
|
||||
height: percent(100),
|
||||
..Node::center()
|
||||
},
|
||||
ZIndex(100),
|
||||
BackgroundColor(Color::srgba(0., 0., 0., 0.8)),
|
||||
GlobalTransform::default(),
|
||||
children![(
|
||||
node,
|
||||
BackgroundColor(Color::srgb(0.2, 0.2, 0.2)),
|
||||
BorderRadius::all(px(10)),
|
||||
children![
|
||||
(
|
||||
Node {
|
||||
justify_content: JustifyContent::SpaceBetween,
|
||||
align_items: AlignItems::Center,
|
||||
..Node::hstack(px(20))
|
||||
},
|
||||
children![
|
||||
text(title, 40.0, Color::WHITE),
|
||||
button(
|
||||
PopupCloseButton,
|
||||
ButtonVariant::Destructive,
|
||||
Node {
|
||||
width: px(40),
|
||||
height: px(40),
|
||||
..Node::center()
|
||||
},
|
||||
|color| text("X", 24.0, color)
|
||||
)
|
||||
]
|
||||
),
|
||||
child
|
||||
]
|
||||
)],
|
||||
)
|
||||
commands
|
||||
.spawn((
|
||||
PopupRoot,
|
||||
root,
|
||||
Node {
|
||||
position_type: PositionType::Absolute,
|
||||
width: percent(100),
|
||||
height: percent(100),
|
||||
..Node::center()
|
||||
},
|
||||
ZIndex(100),
|
||||
BackgroundColor(Color::srgba(0., 0., 0., 0.8)),
|
||||
GlobalTransform::default(),
|
||||
))
|
||||
.with_children(|parent| {
|
||||
parent
|
||||
.spawn((
|
||||
node,
|
||||
BackgroundColor(Color::srgb(0.2, 0.2, 0.2)),
|
||||
BorderRadius::all(px(10)),
|
||||
))
|
||||
.with_children(|parent| {
|
||||
parent.spawn((
|
||||
Node {
|
||||
justify_content: JustifyContent::SpaceBetween,
|
||||
align_items: AlignItems::Center,
|
||||
..Node::hstack(px(20))
|
||||
},
|
||||
children![
|
||||
text(title, 40.0, Color::WHITE),
|
||||
button(
|
||||
PopupCloseButton,
|
||||
ButtonVariant::Destructive,
|
||||
Node {
|
||||
width: px(40),
|
||||
height: px(40),
|
||||
..Node::center()
|
||||
},
|
||||
|color| text("X", 24.0, color)
|
||||
)
|
||||
],
|
||||
));
|
||||
|
||||
child(parent);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
pub fn handle_popup_close(
|
||||
|
||||
Reference in New Issue
Block a user