From added3ad0321a31b063ed5c4aa2f4f4dcb6926fc Mon Sep 17 00:00:00 2001 From: Arthur Roberts Date: Tue, 25 Feb 2025 22:53:42 +0000 Subject: [PATCH] Unsure this is getting any better --- card_stuffs/src/main.rs | 60 +++++++++++++++++++++++++++++++---------- 1 file changed, 46 insertions(+), 14 deletions(-) diff --git a/card_stuffs/src/main.rs b/card_stuffs/src/main.rs index e2cb5e4..903a479 100644 --- a/card_stuffs/src/main.rs +++ b/card_stuffs/src/main.rs @@ -1,5 +1,5 @@ use std::io; -use card_stuffs; +use card_stuffs::{self, NUM_PILES_KLONDIKE}; use crossterm::event::{self, Event, KeyCode, KeyEvent, KeyEventKind}; use ratatui::{ @@ -46,6 +46,31 @@ fn card_widget(card: &card_stuffs::Card) -> List { .border_type(BorderType::Rounded)) } +fn turned_over_card() -> List<'static> { + let hidden_card = [ + format!("###############"), + format!("###############"), + format!("###############"), + format!("###############"), + format!("###############"), + format!("###############"), + format!("###############"), + format!("###############"), + format!("###############"), + format!("###############"), + format!("###############"), + ]; + let card: Vec = hidden_card.iter().map(|(m)| { + ListItem::new(m.to_string()) + }) + .collect(); + + List::new(card) + .block(Block::new() + .borders(Borders::ALL) + .border_type(BorderType::Rounded)) +} + impl App { /// runs the application's main loop until the user quits @@ -89,28 +114,35 @@ impl App { ); let horizontal = Layout::horizontal([ Constraint::Length(CARD_WIDTH), - Constraint::Length(2), Constraint::Length(CARD_WIDTH), - Constraint::Length(2), Constraint::Length(CARD_WIDTH), - Constraint::Length(2), Constraint::Length(CARD_WIDTH), - Constraint::Length(2), Constraint::Length(CARD_WIDTH), - Constraint::Length(2), Constraint::Length(CARD_WIDTH), - Constraint::Length(2), Constraint::Length(CARD_WIDTH), - Constraint::Length(2), ]); - let piles_and_spacers: [Rect; 14] = horizontal.areas(piles_area); + let pileses: [Rect; 7] = horizontal.areas(piles_area); let a_card = card_widget(&self.cards.piles[0][0]); + for pile in 0..card_stuffs::NUM_PILES_KLONDIKE { - frame.render_widget( - Block::new().borders(Borders::ALL).title(format!("pile {}", pile)), - //&a_card, - piles_and_spacers[pile*2] - ) + let mut constraints = Vec::new(); + for card in 0..(card_stuffs::NUM_PILES_KLONDIKE + 13) { + constraints.push(Constraint::Min(2)); + } + let vertical = Layout::vertical(constraints); + let card_display: [Rect; 20] = vertical.areas(pileses[pile]); + for (i, card) in card_display.iter().enumerate() { + match self.cards.piles[pile].get(i) { + None => break, + Some(c) => { + frame.render_widget( + &a_card, + *card + ) + } + + } + } } }