fix(ui): Fixed a potential rare bug in the UI where the application would panic if the height of the downloads window is 0.
This commit is contained in:
@@ -178,8 +178,8 @@ fn draw_downloads_context(f: &mut Frame<'_>, app: &App<'_>, area: Rect) {
|
|||||||
if !downloads_vec.is_empty() {
|
if !downloads_vec.is_empty() {
|
||||||
f.render_widget(block, area);
|
f.render_widget(block, area);
|
||||||
|
|
||||||
let max_items = (((area.height as f64 / 2.0).floor() * 2.0) as usize) / 2;
|
let max_items = ((((area.height as f32 / 2.0).floor() * 2.0) as i32) / 2) - 1;
|
||||||
let items = cmp::min(downloads_vec.len(), max_items - 1);
|
let items = cmp::min(downloads_vec.len(), max_items.unsigned_abs() as usize);
|
||||||
let download_item_areas = Layout::vertical(
|
let download_item_areas = Layout::vertical(
|
||||||
iter::repeat(Constraint::Length(2))
|
iter::repeat(Constraint::Length(2))
|
||||||
.take(items)
|
.take(items)
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ use std::{cmp, iter};
|
|||||||
|
|
||||||
use chrono::{Duration, Utc};
|
use chrono::{Duration, Utc};
|
||||||
use library::LibraryUi;
|
use library::LibraryUi;
|
||||||
use log::debug;
|
|
||||||
use ratatui::{
|
use ratatui::{
|
||||||
layout::{Constraint, Layout, Rect},
|
layout::{Constraint, Layout, Rect},
|
||||||
style::Stylize,
|
style::Stylize,
|
||||||
@@ -168,10 +167,9 @@ fn draw_downloads_context(f: &mut Frame<'_>, app: &App<'_>, area: Rect) {
|
|||||||
|
|
||||||
if !downloads_vec.is_empty() {
|
if !downloads_vec.is_empty() {
|
||||||
f.render_widget(block, area);
|
f.render_widget(block, area);
|
||||||
let max_items = (((area.height as f64 / 2.0).floor() * 2.0) as usize) / 2;
|
|
||||||
|
|
||||||
let items = cmp::min(downloads_vec.len(), max_items - 1);
|
let max_items = ((((area.height as f64 / 2.0).floor() * 2.0) as i64) / 2) - 1;
|
||||||
debug!("Items: {items}");
|
let items = cmp::min(downloads_vec.len(), max_items.abs() as usize);
|
||||||
let download_item_areas = Layout::vertical(
|
let download_item_areas = Layout::vertical(
|
||||||
iter::repeat(Constraint::Length(2))
|
iter::repeat(Constraint::Length(2))
|
||||||
.take(items)
|
.take(items)
|
||||||
|
|||||||
Reference in New Issue
Block a user