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