Skip to content

Commit

Permalink
fix division by zero
Browse files Browse the repository at this point in the history
  • Loading branch information
zignis committed Apr 16, 2024
1 parent d3c59e6 commit d1f89da
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/utils/truncate_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ where
let mut text = text.to_owned();
let text_width = compute_text_width(&text);
let text_chars = text.graphemes(true).count().max(1); // Total number of characters.
let char_width = text_width / text_chars; // Average width of each character in pixels.
let char_width = (text_width / text_chars).max(1); // Average width of each character in pixels.
// Maximum number of characters that can fit inside the given `max_width` value.
let mut fitting_chars = ((max_width / char_width as u32) as f32).floor() as usize;

Expand Down
4 changes: 2 additions & 2 deletions src/utils/wrap_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ where
F: Fn(&str) -> usize,
{
let text_width = compute_text_width(text);
let text_chars = text.graphemes(true).count();
let char_width = text_width / text_chars.max(1); // Average width of each character in pixels.
let text_chars = text.graphemes(true).count().max(1);
let char_width = (text_width / text_chars).max(1); // Average width of each character in pixels.
let columns = max_width / char_width as u32;
let lines = wrap(text, columns as usize);

Expand Down

0 comments on commit d1f89da

Please sign in to comment.