Lines
100 %
Functions
Branches
//! A window hanging off an edge draws at its full size and shows the part inside the desktop.
use super::open::app_on;
use crate::app::App;
use crate::hits::{Surface, Target};
use crate::test_support::draw_frame;
use crate::view::ViewId;
use ratatui::buffer::Buffer;
use ratatui::layout::Rect;
use tvui::{Place, Window};
const WIDTH: u16 = 80;
const HEIGHT: u16 = 24;
const SIZE: (u16, u16) = (40, 10);
const TOP: i32 = 3;
fn console_app() -> App {
let mut app = app_on(WIDTH, HEIGHT);
app.open_view(ViewId::Console);
app
}
fn place_front(app: &mut App, x: i32) -> Place {
let id = app.front_window().expect("a front window");
let window = app.desktop.window(id).expect("it is open");
let place = Place {
x,
y: TOP,
width: SIZE.0,
height: SIZE.1,
};
app.desktop.restore(Window {
place,
zoomed: false,
..window
});
place
fn column(buf: &Buffer, x: u16) -> Vec<(String, ratatui::style::Style)> {
let top = u16::try_from(TOP).unwrap_or_default();
(top..top + SIZE.1)
.map(|y| (buf[(x, y)].symbol().to_string(), buf[(x, y)].style()))
.collect()
#[test]
fn a_window_off_the_right_edge_shows_its_left_part_laid_out_as_in_full() {
let mut app = console_app();
place_front(&mut app, 10);
let whole = draw_frame(&app, WIDTH, HEIGHT).0;
place_front(&mut app, 60);
let cut = draw_frame(&app, WIDTH, HEIGHT).0;
for shown in 0..20 {
assert_eq!(
column(&cut, 60 + shown),
column(&whole, 10 + shown),
"{shown}"
);
fn a_window_off_the_left_edge_shows_its_right_part_laid_out_as_in_full() {
place_front(&mut app, -15);
for shown in 0..25 {
assert_eq!(column(&cut, shown), column(&whole, 25 + shown), "{shown}");
fn only_the_cells_on_screen_are_hittable() {
let hits = draw_frame(&app, WIDTH, HEIGHT).1;
let body = Target::Body(Surface::Pane);
let (rect, _) = hits
.entries()
.iter()
.find(|(_, target)| *target == body)
.copied()
.expect("the console body is hittable");
assert_eq!(rect, Rect::new(61, 4, 19, 7));
assert_eq!(rect.right(), WIDTH);
place_front(&mut app, -30);
assert_eq!(rect, Rect::new(0, 4, 9, 7));