feat: Add text UI component (#56)

This commit is contained in:
demenik
2025-11-28 15:48:59 +01:00
parent 2d0f51ff3d
commit 96c76da7f6
10 changed files with 56 additions and 109 deletions

View File

@@ -39,37 +39,19 @@ fn setup(mut commands: Commands) {
}, },
BackgroundColor(Color::srgba(0.0, 0.0, 0.0, 0.8)), BackgroundColor(Color::srgba(0.0, 0.0, 0.0, 0.8)),
children![ children![
( text_with_component(TextType::Phase, "...", 16.0, Color::WHITE),
TextType::Phase, text_with_component(TextType::Timer, "...", 16.0, Color::WHITE),
Text::new("..."),
TextFont::from_font_size(16.0),
TextColor(Color::WHITE)
),
(
TextType::Timer,
Text::new("--:--"),
TextFont::from_font_size(16.0),
TextColor(Color::WHITE)
),
( (
Button, Button,
inventory::components::ButtonType::InventoryOpen, inventory::components::ButtonType::InventoryOpen,
Node::default(), Node::default(),
children![( children![text("Inventar", 16.0, Color::WHITE)]
Text::new("Inventar"),
TextFont::from_font_size(16.0),
TextColor(Color::WHITE)
)]
), ),
( (
Button, Button,
ButtonType::SettingsOpen, ButtonType::SettingsOpen,
Node::default(), Node::default(),
children![( children![text("Einstellungen", 16.0, Color::WHITE)]
Text::new("Einstellungen"),
TextFont::from_font_size(16.0),
TextColor(Color::WHITE)
)]
) )
], ],
)); ));

View File

@@ -33,11 +33,7 @@ pub fn open_settings(commands: &mut Commands) {
..Node::hstack(px(20)) ..Node::hstack(px(20))
}, },
children![ children![
( text("Spiel Einstellungen", 40.0, Color::WHITE),
Text::new("Spiel Einstellungen"),
TextFont::from_font_size(40.0),
TextColor(Color::WHITE),
),
pill_button( pill_button(
ButtonType::SettingsClose, ButtonType::SettingsClose,
ButtonVariant::Destructive, ButtonVariant::Destructive,
@@ -89,16 +85,12 @@ pub fn open_settings(commands: &mut Commands) {
..Node::vstack(px(10)) ..Node::vstack(px(10))
}, },
children![ children![
( text("Spiel Einstellungen", 18.0, Color::WHITE),
Text::new("Timer Einstellungen"), text(
TextFont::from_font_size(18.0), "Tipp: Benutze [Umstellen] um in 10er Schritten zu inkrementieren oder dekrementieren!",
TextColor(Color::WHITE), 16.0,
Color::WHITE
), ),
(
Text::new("Tipp: Benutze [Umstellen] um in 10er Schritten zu inkrementieren oder dekrementieren!"),
TextFont::from_font_size(16.0),
TextColor(Color::WHITE)
)
] ]
), ),
( (
@@ -107,11 +99,7 @@ pub fn open_settings(commands: &mut Commands) {
..Node::vstack(px(10)) ..Node::vstack(px(10))
}, },
children![ children![
( text("Fokus Phase", 12.0, Color::WHITE),
Text::new("Fokus Phase"),
TextFont::from_font_size(12.0),
TextColor(Color::WHITE)
),
timer_settings(TimerType::Focus) timer_settings(TimerType::Focus)
] ]
), ),
@@ -121,11 +109,7 @@ pub fn open_settings(commands: &mut Commands) {
..Node::vstack(px(10)) ..Node::vstack(px(10))
}, },
children![ children![
( text("Kurze Pause", 12.0, Color::WHITE),
Text::new("Kurze Pause"),
TextFont::from_font_size(12.0),
TextColor(Color::WHITE)
),
timer_settings(TimerType::ShortBreak) timer_settings(TimerType::ShortBreak)
] ]
), ),
@@ -135,11 +119,7 @@ pub fn open_settings(commands: &mut Commands) {
..Node::vstack(px(10)) ..Node::vstack(px(10))
}, },
children![ children![
( text("Lange Pause", 12.0, Color::WHITE),
Text::new("Lange Pause"),
TextFont::from_font_size(12.0),
TextColor(Color::WHITE)
),
timer_settings(TimerType::LongBreak) timer_settings(TimerType::LongBreak)
] ]
) )

View File

@@ -9,11 +9,7 @@ pub fn timer_settings(timer_type: TimerType) -> impl Bundle {
}, },
children![ children![
timer_settings_part(SettingsTimerInput::Minutes(timer_type.clone()), 1), timer_settings_part(SettingsTimerInput::Minutes(timer_type.clone()), 1),
( text(":", 24.0, Color::WHITE),
Text::new(":"),
TextFont::from_font_size(24.0),
TextColor(Color::WHITE)
),
timer_settings_part(SettingsTimerInput::Seconds(timer_type.clone()), 1), timer_settings_part(SettingsTimerInput::Seconds(timer_type.clone()), 1),
], ],
) )
@@ -36,12 +32,7 @@ fn timer_settings_part(input: SettingsTimerInput, amount: u32) -> impl Bundle {
"+", "+",
12.0 12.0
), ),
( text_with_component(input.clone(), "--", 24.0, Color::WHITE),
input.clone(),
Text::new("--"),
TextFont::from_font_size(24.0),
TextColor(Color::WHITE)
),
button( button(
ButtonType::SettingsTimerChange { ButtonType::SettingsTimerChange {
input: input.clone(), input: input.clone(),

View File

@@ -33,11 +33,7 @@ pub fn open_inventory(commands: &mut Commands, items: Query<&ItemStack>) {
..Node::hstack(px(20)) ..Node::hstack(px(20))
}, },
children![ children![
( text("Inventar", 40.0, Color::WHITE),
Text::new("Inventar"),
TextFont::from_font_size(40.0),
TextColor(Color::WHITE),
),
pill_button( pill_button(
ButtonType::InventoryClose, ButtonType::InventoryClose,
ButtonVariant::Destructive, ButtonVariant::Destructive,

View File

@@ -31,16 +31,12 @@ pub fn list_itemstack(itemstack: &ItemStack) -> impl Bundle {
..Node::vstack(px(4)) ..Node::vstack(px(4))
}, },
children![ children![
( text(
Text::new(format!("{} ({})", name, itemstack.amount)), format!("{} ({})", name, itemstack.amount),
TextFont::from_font_size(14.0), 14.0,
TextColor(Color::WHITE) Color::WHITE
), ),
( text(itemstack.item_type.description(), 10.0, Color::WHITE)
Text::new(itemstack.item_type.description()),
TextFont::from_font_size(10.0),
TextColor(Color::WHITE)
)
] ]
) )
], ],

View File

@@ -37,11 +37,7 @@ pub fn spawn_load_popup(commands: &mut Commands) {
..default() ..default()
}, },
children![ children![
( text("Spielstand Auswahl", 40.0, Color::WHITE),
Text::new("Spielstand Auswahl"),
TextFont::from_font_size(40.0),
TextColor(Color::WHITE),
),
pill_button( pill_button(
ButtonType::PopupClose, ButtonType::PopupClose,
ButtonVariant::Destructive, ButtonVariant::Destructive,
@@ -93,23 +89,20 @@ pub fn spawn_load_popup(commands: &mut Commands) {
..default() ..default()
}, },
children![ children![
( text(
Text::new(format!( format!("Spielstand {}", savegame.index + 1),
"Spielstand {}", 24.0,
savegame.index + 1 Color::WHITE
)),
TextFont::from_font_size(24.0),
TextColor(Color::srgb(0.9, 0.9, 0.9))
), ),
( text(
Text::new(format!( format!(
"Beeren: {}, Fokusphasen abgeschlossen: {}", "Beeren: {}, Fokusphasen abgeschlossen: {}",
savegame.total_berries, savegame.total_berries,
savegame.completed_focus savegame.completed_focus
)), ),
TextFont::from_font_size(18.0), 18.0,
TextColor(Color::srgb(0.9, 0.9, 0.9)) Color::WHITE,
) ),
] ]
), ),
pill_button( pill_button(

View File

@@ -25,11 +25,7 @@ fn setup(mut commands: Commands) {
..Node::center() ..Node::center()
}, },
children![ children![
( text("Pomomon Garden", 64.0, Color::WHITE),
Text::new("Pomonon Garten"),
TextFont::from_font_size(64.0),
TextColor(Color::srgb(0.9, 0.9, 0.9))
),
button( button(
ButtonType::LoadGame, ButtonType::LoadGame,
ButtonVariant::Primary, ButtonVariant::Primary,

View File

@@ -17,11 +17,7 @@ pub fn button(
node, node,
BackgroundColor(variant.normal_background()), BackgroundColor(variant.normal_background()),
BorderRadius::all(px(10)), BorderRadius::all(px(10)),
children![( children![text(title, font_size, variant.text_color())],
Text::new(title),
TextFont::from_font_size(font_size),
TextColor(variant.text_color())
)],
) )
} }
@@ -42,11 +38,7 @@ pub fn pill_button(
node, node,
BackgroundColor(variant.normal_background()), BackgroundColor(variant.normal_background()),
BorderRadius::MAX, BorderRadius::MAX,
children![( children![text(title, font_size, variant.text_color())],
Text::new(title),
TextFont::from_font_size(font_size),
TextColor(variant.text_color())
)],
) )
} }

View File

@@ -1,5 +1,7 @@
pub mod button; pub mod button;
pub mod flexbox; pub mod flexbox;
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 texts::{text, text_with_component};

View File

@@ -0,0 +1,19 @@
pub use crate::prelude::*;
pub fn text(content: impl Into<String>, size: f32, color: Color) -> (Text, TextFont, TextColor) {
(
Text::new(content),
TextFont::from_font_size(size),
TextColor(color),
)
}
pub fn text_with_component(
component: impl Component,
content: impl Into<String>,
size: f32,
color: Color,
) -> impl Bundle {
let (a, b, c) = text(content, size, color);
(component, a, b, c)
}