Skip to content

Commit

Permalink
Added mroe space for warnings on main page, only if there are more th…
Browse files Browse the repository at this point in the history
…an three warnings for a team
  • Loading branch information
Elsa Debrunner committed Dec 10, 2024
1 parent 1833d25 commit e24a71c
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 7 deletions.
29 changes: 22 additions & 7 deletions refbox/src/app/view_builders/main_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ pub(in super::super) fn build_main_view<'a>(
}
};

center_col = center_col.push(
let num_warns_b = snapshot.b_warnings.len();
let num_warns_w = snapshot.w_warnings.len();

center_col = center_col.push(if num_warns_b | num_warns_w < 4 {
button(
text(config_string(
snapshot,
Expand All @@ -119,10 +122,22 @@ pub(in super::super) fn build_main_view<'a>(
)
.padding(PADDING)
.style(ButtonStyle::LightGray)
.width(Length::Fill)
.height(Length::FillPortion(2))
.on_press(Message::ShowGameDetails),
);
.width(Length::Fill)
.on_press(Message::ShowGameDetails)
} else {
button(
text(config_string_game_num(snapshot, using_uwhscores, games))
.size(SMALL_TEXT)
.line_height(LINE_HEIGHT)
.vertical_alignment(Vertical::Center)
.horizontal_alignment(Horizontal::Left),
)
.padding(PADDING)
.style(ButtonStyle::LightGray)
.width(Length::Fill)
.on_press(Message::ShowGameDetails)
});

if config.track_fouls_and_warnings {
center_col = center_col.push(
Expand All @@ -139,7 +154,7 @@ pub(in super::super) fn build_main_view<'a>(
.b_warnings
.iter()
.rev()
.take(3)
.take(10)
.map(|warning| make_warning_container(
warning,
Some(GameColor::Black)
Expand All @@ -155,7 +170,7 @@ pub(in super::super) fn build_main_view<'a>(
.w_warnings
.iter()
.rev()
.take(3)
.take(10)
.map(|warning| make_warning_container(
warning,
Some(GameColor::White)
Expand All @@ -174,7 +189,7 @@ pub(in super::super) fn build_main_view<'a>(
.height(Length::Fill),
)
.width(Length::Fill)
.height(Length::FillPortion(1))
.height(Length::Fill)
.on_press(Message::NoAction)
.style(ButtonStyle::LightGray)
.on_press(Message::ShowWarnings),
Expand Down
65 changes: 65 additions & 0 deletions refbox/src/app/view_builders/shared_elements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,71 @@ pub(super) fn limit_team_name_len(name: &String, len_limit: usize) -> Cow<'_, St
}
}

pub(super) fn config_string_game_num(
snapshot: &GameSnapshot,
using_uwhscores: bool,
games: &Option<BTreeMap<u32, GameInfo>>,
) -> String {
let mut result = String::new();
if snapshot.current_period == GamePeriod::BetweenGames {
let prev_game;
let next_game;
if using_uwhscores {
if let Some(games) = games {
prev_game = match games.get(&snapshot.game_number) {
Some(game) => game_string_short(game),
None if snapshot.game_number == 0 => "None".to_string(),
None => format!("Error ({})", snapshot.game_number),
};
next_game = match games.get(&snapshot.next_game_number) {
Some(game) => game_string_short(game),
None => format!("Error ({})", snapshot.next_game_number),
};
} else {
prev_game = if snapshot.game_number == 0 {
"None".to_string()
} else {
format!("Error ({})", snapshot.game_number)
};
next_game = format!("Error ({})", snapshot.next_game_number);
}
} else {
prev_game = if snapshot.game_number == 0 {
"None".to_string()
} else {
snapshot.game_number.to_string()
};
next_game = snapshot.next_game_number.to_string();
}

write!(
&mut result,
"Last Game: {}, Next Game: {}\n\n",
prev_game, next_game
)
.unwrap();
snapshot.next_game_number
} else {
let game;
if using_uwhscores {
if let Some(games) = games {
game = match games.get(&snapshot.game_number) {
Some(game) => game_string_short(game),
None => format!("Error ({})", snapshot.game_number),
};
} else {
game = format!("Error ({})", snapshot.game_number);
}
} else {
game = snapshot.game_number.to_string();
}
write!(&mut result, "Game: {}\n\n", game).unwrap();
snapshot.game_number
};

result
}

pub(super) fn config_string(
snapshot: &GameSnapshot,
config: &GameConfig,
Expand Down

0 comments on commit e24a71c

Please sign in to comment.