Selection and Highlighting appears okay
Still need to appropriately test with piles of visible cards > 1
This commit is contained in:
@@ -39,7 +39,7 @@ impl Default for App {
|
||||
const CARD_HEIGHT: u16 = 11;
|
||||
const CARD_WIDTH: u16 = 15;
|
||||
|
||||
fn draw_waste(cards_in_waste: &Vec<card_stuffs::Card>, area: Rect, frame: &mut Frame, highlight: bool) {
|
||||
fn draw_waste(cards_in_waste: &Vec<card_stuffs::Card>, area: Rect, frame: &mut Frame, highlight: bool, selected: bool) {
|
||||
let horizontal = Layout::horizontal([
|
||||
Constraint::Length(3),
|
||||
Constraint::Length(3),
|
||||
@@ -50,7 +50,7 @@ fn draw_waste(cards_in_waste: &Vec<card_stuffs::Card>, area: Rect, frame: &mut F
|
||||
// There must be a better way to do all of this
|
||||
if cards_in_waste.len() == 0 {
|
||||
frame.render_widget(
|
||||
empty_pile(highlight),
|
||||
empty_pile(highlight, selected),
|
||||
top_waste
|
||||
);
|
||||
}
|
||||
@@ -143,11 +143,27 @@ impl App {
|
||||
deck_area
|
||||
);
|
||||
|
||||
draw_waste(&self.cards.waste, waste_area, frame, self.highlighted_card == CardPosition::TopWaste);
|
||||
{
|
||||
let highlight = self.highlighted_card == CardPosition::TopWaste;
|
||||
let selected = {
|
||||
match self.selected_card {
|
||||
None => false,
|
||||
Some(pos) => pos == CardPosition::TopWaste
|
||||
}
|
||||
};
|
||||
draw_waste(&self.cards.waste, waste_area, frame, highlight, selected);
|
||||
}
|
||||
|
||||
for (i, fa) in foundation_areas.iter().enumerate() {
|
||||
let highlight = self.highlighted_card == CardPosition::Foundation(i);
|
||||
let selected = {
|
||||
match self.selected_card {
|
||||
None => false,
|
||||
Some(pos) => pos == CardPosition::Foundation(i)
|
||||
}
|
||||
};
|
||||
frame.render_widget(
|
||||
empty_pile(self.highlighted_card == CardPosition::Foundation(i)),
|
||||
empty_pile(highlight, selected),
|
||||
*fa
|
||||
);
|
||||
}
|
||||
@@ -190,7 +206,12 @@ impl App {
|
||||
Some(c) => {
|
||||
let is_top_card = i == self.cards.piles[pile].len() - 1;
|
||||
let highlight = self.highlighted_card == CardPosition::Pile(pile, i);
|
||||
let selected = true; // FIXME
|
||||
let selected = {
|
||||
match self.selected_card {
|
||||
None => false,
|
||||
Some(pos) => pos == CardPosition::Pile(pile, i)
|
||||
}
|
||||
};
|
||||
let a_card = match c.visible {
|
||||
true => card_widget(c, is_top_card, highlight, selected),
|
||||
false => card_widget(c, is_top_card, highlight, selected),
|
||||
@@ -236,6 +257,7 @@ impl App {
|
||||
KeyCode::Char('1') => self.cards.num_cards_turned = 1,
|
||||
KeyCode::Char('3') => self.cards.num_cards_turned = 3,
|
||||
KeyCode::Char('h') => self.show_help = !self.show_help, // toggle
|
||||
KeyCode::Char(' ') => self.select_card(),
|
||||
KeyCode::Left => self.highlighted_card = handle_move_highlighted(&self.highlighted_card, Direction::Left, &self.cards),
|
||||
KeyCode::Right => self.highlighted_card = handle_move_highlighted(&self.highlighted_card, Direction::Right, &self.cards),
|
||||
KeyCode::Up => self.highlighted_card = handle_move_highlighted(&self.highlighted_card, Direction::Up, &self.cards),
|
||||
@@ -247,6 +269,12 @@ impl App {
|
||||
fn exit(&mut self) {
|
||||
self.exit = true;
|
||||
}
|
||||
|
||||
fn select_card(&mut self) {
|
||||
self.selected_card = Some(self.highlighted_card);
|
||||
// FIXME - actually moving the selected card to next position
|
||||
// FIXME - don't allow selection of empty pile/foundation
|
||||
}
|
||||
}
|
||||
|
||||
fn main() -> io::Result<()> {
|
||||
@@ -488,7 +516,7 @@ fn facedown_card(top: bool) -> Paragraph<'static> {
|
||||
.border_type(BorderType::Rounded))
|
||||
}
|
||||
|
||||
fn empty_pile(highlight: bool) -> Paragraph<'static> {
|
||||
fn empty_pile(highlight: bool, selected: bool) -> Paragraph<'static> {
|
||||
// made using https://www.asciiart.eu/
|
||||
let hidden_card = format!(
|
||||
"
|
||||
@@ -504,6 +532,8 @@ fn empty_pile(highlight: bool) -> Paragraph<'static> {
|
||||
let mut border_style = Style::new();
|
||||
if highlight {
|
||||
border_style = border_style.fg(Color::Blue);
|
||||
} else if selected {
|
||||
border_style = border_style.fg(Color::Green);
|
||||
}
|
||||
|
||||
Paragraph::new(hidden_card)
|
||||
|
||||
Reference in New Issue
Block a user