spinners and fmt
This commit is contained in:
@@ -5,12 +5,12 @@
|
||||
//! and background colors. Objects are drawn over their floor cell, and the
|
||||
//! player is drawn on top of everything.
|
||||
|
||||
use kiln_core::cp437::tile_to_char;
|
||||
use crate::utils::rgba8_to_color;
|
||||
use kiln_core::Board;
|
||||
use kiln_core::cp437::tile_to_char;
|
||||
use ratatui::buffer::Buffer;
|
||||
use ratatui::layout::Rect;
|
||||
use ratatui::widgets::Widget;
|
||||
use crate::utils::rgba8_to_color;
|
||||
|
||||
/// A ratatui widget that draws a [`Board`] (with objects and the player) into a
|
||||
/// rectangular area, scrolled so the player stays visible on larger boards.
|
||||
@@ -60,7 +60,8 @@ impl<'a> BoardWidget<'a> {
|
||||
/// reports off-screen cells as `None` — needed for exact cursor placement.)
|
||||
pub fn board_to_screen(area: Rect, board: &Board, bx: usize, by: usize) -> Option<(u16, u16)> {
|
||||
let (off_x, pad_x, cols) = BoardWidget::axis(board.width, area.width as usize, board.player.x);
|
||||
let (off_y, pad_y, rows) = BoardWidget::axis(board.height, area.height as usize, board.player.y);
|
||||
let (off_y, pad_y, rows) =
|
||||
BoardWidget::axis(board.height, area.height as usize, board.player.y);
|
||||
// Cell must fall within the visible window on both axes.
|
||||
if bx < off_x || bx >= off_x + cols || by < off_y || by >= off_y + rows {
|
||||
return None;
|
||||
@@ -75,7 +76,8 @@ pub fn board_to_screen(area: Rect, board: &Board, bx: usize, by: usize) -> Optio
|
||||
/// the drawn board (in the centering pad or past the visible cells).
|
||||
pub fn screen_to_board(area: Rect, board: &Board, sx: u16, sy: u16) -> Option<(usize, usize)> {
|
||||
let (off_x, pad_x, cols) = BoardWidget::axis(board.width, area.width as usize, board.player.x);
|
||||
let (off_y, pad_y, rows) = BoardWidget::axis(board.height, area.height as usize, board.player.y);
|
||||
let (off_y, pad_y, rows) =
|
||||
BoardWidget::axis(board.height, area.height as usize, board.player.y);
|
||||
// Screen-space offset from the first drawn cell; reject anything before it.
|
||||
let col = (sx as i32) - (area.x as i32 + pad_x as i32);
|
||||
let row = (sy as i32) - (area.y as i32 + pad_y as i32);
|
||||
@@ -140,4 +142,3 @@ impl Widget for BoardWidget<'_> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user