diff --git a/src/features/hud/mod.rs b/src/features/hud/mod.rs index 1f0f2d8..5e0dbdb 100644 --- a/src/features/hud/mod.rs +++ b/src/features/hud/mod.rs @@ -48,8 +48,7 @@ fn setup(mut commands: Commands) { padding: UiRect::all(px(10)), ..default() }, - "Shop", - 16.0 + |color| text("Shop", 16.0, color) ), button( inventory::components::ButtonType::InventoryOpen, @@ -58,8 +57,7 @@ fn setup(mut commands: Commands) { padding: UiRect::all(px(10)), ..default() }, - "Inventar", - 16.0 + |color| text("Inventar", 16.0, color) ), button( ButtonType::SettingsOpen, @@ -68,8 +66,7 @@ fn setup(mut commands: Commands) { padding: UiRect::all(px(10)), ..default() }, - "Einstellungen", - 16.0 + |color| text("Einstellungen", 16.0, color) ) ], )); diff --git a/src/features/hud/ui/settings.rs b/src/features/hud/ui/settings.rs index f2b16f5..cb82cc4 100644 --- a/src/features/hud/ui/settings.rs +++ b/src/features/hud/ui/settings.rs @@ -43,8 +43,7 @@ pub fn open_settings(commands: &mut Commands) { height: px(40), ..default() }, - "X", - 24.0 + |color| text("X", 24.0, color) ), ], )); @@ -59,8 +58,7 @@ pub fn open_settings(commands: &mut Commands) { padding: UiRect::all(px(10)), ..default() }, - "Spiel verlassen", - 24.0, + |color| text("Spiel verlassen", 24.0, color) )); parent.spawn(button( @@ -70,8 +68,7 @@ pub fn open_settings(commands: &mut Commands) { padding: UiRect::all(px(10)), ..default() }, - "Spiel speichern", - 24.0, + |color| text("Spiel speichern", 24.0, color) )); parent.spawn(( diff --git a/src/features/hud/ui/timer_settings.rs b/src/features/hud/ui/timer_settings.rs index 49fce78..136b391 100644 --- a/src/features/hud/ui/timer_settings.rs +++ b/src/features/hud/ui/timer_settings.rs @@ -29,8 +29,7 @@ fn timer_settings_part(input: SettingsTimerInput, amount: u32) -> impl Bundle { width: percent(100), ..default() }, - "+", - 12.0 + |color| text("+", 12.0, color) ), text_with_component(input.clone(), "--", 24.0, Color::WHITE), button( @@ -43,8 +42,7 @@ fn timer_settings_part(input: SettingsTimerInput, amount: u32) -> impl Bundle { width: percent(100), ..default() }, - "-", - 12.0 + |color| text("-", 12.0, color) ), ], ) diff --git a/src/features/inventory/ui/inventory.rs b/src/features/inventory/ui/inventory.rs index 6daa1f7..50ed085 100644 --- a/src/features/inventory/ui/inventory.rs +++ b/src/features/inventory/ui/inventory.rs @@ -2,7 +2,11 @@ use super::super::components::{ButtonType, RootMarker}; use crate::prelude::GameConfig; use crate::{features::inventory::ui::list_itemstack, prelude::*}; -pub fn open_inventory(commands: &mut Commands, items: Query<&ItemStack>, game_config: &Res) { +pub fn open_inventory( + commands: &mut Commands, + items: Query<&ItemStack>, + game_config: &Res, +) { commands .spawn(( RootMarker::Inventory, @@ -44,8 +48,7 @@ pub fn open_inventory(commands: &mut Commands, items: Query<&ItemStack>, game_co height: px(40), ..default() }, - "X", - 24.0 + |color| text("X", 24.0, color) ), ], )); diff --git a/src/features/savegame/ui/load.rs b/src/features/savegame/ui/load.rs index 2df621b..2a111c4 100644 --- a/src/features/savegame/ui/load.rs +++ b/src/features/savegame/ui/load.rs @@ -47,8 +47,7 @@ pub fn spawn_load_popup(commands: &mut Commands) { height: px(40), ..default() }, - "X", - 24.0 + |color| text("X", 24.0, color) ) ], )); @@ -64,63 +63,61 @@ pub fn spawn_load_popup(commands: &mut Commands) { }) .with_children(|parent| { for savegame in SavegamePath::list() { - parent.spawn(( - Button, - ButtonType::SavegameLoad { - savegame_path: savegame.path.clone(), - }, - ButtonVariant::Secondary, - Node { - width: percent(100), - height: px(80), - flex_direction: FlexDirection::Row, - column_gap: px(10.0), - padding: UiRect::horizontal(px(10.0)), - ..Node::center() - }, - BackgroundColor(ButtonVariant::Secondary.normal_background()), - BorderRadius::all(px(10)), - children![ - ( + parent.spawn( + button( + ButtonType::SavegameLoad { savegame_path: savegame.path.clone() }, + ButtonVariant::Secondary, + Node { + width: percent(100), + padding: UiRect::all(px(10)), + ..Node::center() + }, + |color| ( Node { width: percent(100), - height: percent(100), - flex_direction: FlexDirection::Column, - justify_content: JustifyContent::Center, - ..default() + align_items: AlignItems::Center, + ..Node::hstack(px(10)) }, - children![ - text( - format!("Spielstand {}", savegame.index + 1), - 24.0, - Color::WHITE - ), - text( - format!( - "Beeren: {}, Fokusphasen abgeschlossen: {}", - savegame.total_berries, - savegame.completed_focus + children![( + Node { + width: percent(100), + height: percent(100), + flex_direction: FlexDirection::Column, + justify_content: JustifyContent::Center, + ..default() + }, + children![ + text( + format!("Spielstand {}", savegame.index + 1), + 24.0, + color ), - 18.0, - Color::WHITE, - ), - ] - ), - pill_button( - ButtonType::SavegameDelete { - savegame_path: savegame.path.clone() - }, - ButtonVariant::Destructive, - Node { - width: px(40), - height: px(40), - ..default() - }, - "X", - 24.0 - ), - ], - )); + text( + format!( + "Beeren: {}, Fokusphasen abgeschlossen: {}", + savegame.total_berries, + savegame.completed_focus + ), + 18.0, + Color::WHITE, + ), + ] + ), + pill_button( + ButtonType::SavegameDelete { + savegame_path: savegame.path.clone() + }, + ButtonVariant::Destructive, + Node { + width: px(40), + height: px(40), + ..default() + }, + |color| text("X", 24.0, color) + )] + ) + ), + ); } }); }); diff --git a/src/features/shop/ui/shop.rs b/src/features/shop/ui/shop.rs index 5dbafea..7054405 100644 --- a/src/features/shop/ui/shop.rs +++ b/src/features/shop/ui/shop.rs @@ -42,8 +42,7 @@ pub fn open_shop(commands: &mut Commands) { height: px(40), ..default() }, - "X", - 24.0 + |color| text("X", 24.0, color) ), ], )); diff --git a/src/features/start_screen/mod.rs b/src/features/start_screen/mod.rs index afcfdff..89483c2 100644 --- a/src/features/start_screen/mod.rs +++ b/src/features/start_screen/mod.rs @@ -34,8 +34,7 @@ fn setup(mut commands: Commands) { padding: UiRect::all(px(10)), ..default() }, - "Spiel laden", - 33.0 + |color| text("Spiel laden", 33.0, color) ), button( ButtonType::NewGame, @@ -45,8 +44,7 @@ fn setup(mut commands: Commands) { padding: UiRect::all(px(10)), ..default() }, - "Neues Spiel", - 33.0, + |color| text("Neues Spiel", 33.0, color) ), button( ButtonType::Settings, @@ -56,8 +54,7 @@ fn setup(mut commands: Commands) { padding: UiRect::all(px(10)), ..default() }, - "Einstellungen", - 33.0 + |color| text("Einstellungen", 33.0, color) ), ], )); diff --git a/src/features/ui/ui/button.rs b/src/features/ui/ui/button.rs index 3ce229a..9d51dca 100644 --- a/src/features/ui/ui/button.rs +++ b/src/features/ui/ui/button.rs @@ -1,14 +1,15 @@ - - use crate::prelude::*; -pub fn button( +pub fn button( button_type: impl Component, variant: ButtonVariant, mut node: Node, - title: impl Into, - font_size: f32, -) -> impl Bundle { + child: C, +) -> impl Bundle +where + C: FnOnce(Color) -> R, + R: Bundle, +{ node.justify_content = JustifyContent::Center; node.align_items = AlignItems::Center; @@ -19,17 +20,20 @@ pub fn button( node, BackgroundColor(variant.normal_background()), BorderRadius::all(px(10)), - children![text(title, font_size, variant.text_color())], + children![child(variant.text_color())], ) } -pub fn pill_button( +pub fn pill_button( button_type: impl Component, variant: ButtonVariant, mut node: Node, - title: impl Into, - font_size: f32, -) -> impl Bundle { + child: C, +) -> impl Bundle +where + C: FnOnce(Color) -> R, + R: Bundle, +{ node.justify_content = JustifyContent::Center; node.align_items = AlignItems::Center; @@ -40,7 +44,7 @@ pub fn pill_button( node, BackgroundColor(variant.normal_background()), BorderRadius::MAX, - children![text(title, font_size, variant.text_color())], + children![child(variant.text_color())], ) }