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)),
children![
(
TextType::Phase,
Text::new("..."),
TextFont::from_font_size(16.0),
TextColor(Color::WHITE)
),
(
TextType::Timer,
Text::new("--:--"),
TextFont::from_font_size(16.0),
TextColor(Color::WHITE)
),
text_with_component(TextType::Phase, "...", 16.0, Color::WHITE),
text_with_component(TextType::Timer, "...", 16.0, Color::WHITE),
(
Button,
inventory::components::ButtonType::InventoryOpen,
Node::default(),
children![(
Text::new("Inventar"),
TextFont::from_font_size(16.0),
TextColor(Color::WHITE)
)]
children![text("Inventar", 16.0, Color::WHITE)]
),
(
Button,
ButtonType::SettingsOpen,
Node::default(),
children![(
Text::new("Einstellungen"),
TextFont::from_font_size(16.0),
TextColor(Color::WHITE)
)]
children![text("Einstellungen", 16.0, Color::WHITE)]
)
],
));

View File

@@ -33,11 +33,7 @@ pub fn open_settings(commands: &mut Commands) {
..Node::hstack(px(20))
},
children![
(
Text::new("Spiel Einstellungen"),
TextFont::from_font_size(40.0),
TextColor(Color::WHITE),
),
text("Spiel Einstellungen", 40.0, Color::WHITE),
pill_button(
ButtonType::SettingsClose,
ButtonVariant::Destructive,
@@ -89,16 +85,12 @@ pub fn open_settings(commands: &mut Commands) {
..Node::vstack(px(10))
},
children![
(
Text::new("Timer Einstellungen"),
TextFont::from_font_size(18.0),
TextColor(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
),
(
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))
},
children![
(
Text::new("Fokus Phase"),
TextFont::from_font_size(12.0),
TextColor(Color::WHITE)
),
text("Fokus Phase", 12.0, Color::WHITE),
timer_settings(TimerType::Focus)
]
),
@@ -121,11 +109,7 @@ pub fn open_settings(commands: &mut Commands) {
..Node::vstack(px(10))
},
children![
(
Text::new("Kurze Pause"),
TextFont::from_font_size(12.0),
TextColor(Color::WHITE)
),
text("Kurze Pause", 12.0, Color::WHITE),
timer_settings(TimerType::ShortBreak)
]
),
@@ -135,11 +119,7 @@ pub fn open_settings(commands: &mut Commands) {
..Node::vstack(px(10))
},
children![
(
Text::new("Lange Pause"),
TextFont::from_font_size(12.0),
TextColor(Color::WHITE)
),
text("Lange Pause", 12.0, Color::WHITE),
timer_settings(TimerType::LongBreak)
]
)

View File

@@ -9,11 +9,7 @@ pub fn timer_settings(timer_type: TimerType) -> impl Bundle {
},
children![
timer_settings_part(SettingsTimerInput::Minutes(timer_type.clone()), 1),
(
Text::new(":"),
TextFont::from_font_size(24.0),
TextColor(Color::WHITE)
),
text(":", 24.0, Color::WHITE),
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
),
(
input.clone(),
Text::new("--"),
TextFont::from_font_size(24.0),
TextColor(Color::WHITE)
),
text_with_component(input.clone(), "--", 24.0, Color::WHITE),
button(
ButtonType::SettingsTimerChange {
input: input.clone(),

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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