Lines
96.3 %
Functions
100 %
Branches
//! Two overlapping windows laid out by hand, for the hit and mouse tests.
use crate::app::App;
use crate::tabs::reports::chart::TerminalEnv;
use crate::test_support::redraw;
use crate::view::ViewId;
use crate::window::WindowId;
use ratatui::crossterm::event::{KeyModifiers, MouseButton, MouseEvent, MouseEventKind};
use ratatui::layout::Size;
use rpc::chart::ChartBackend;
use std::time::Instant;
use tvui::{Place, Window};
pub(crate) const REAR_AT: Place = Place {
x: 2,
y: 2,
width: 36,
height: 10,
};
pub(crate) const FRONT_AT: Place = Place {
x: 20,
y: 5,
width: 40,
height: 12,
pub(crate) fn place_window(app: &mut App, id: WindowId, place: Place) {
let Some(window) = app.desktop.window(id) else {
return;
app.desktop.restore(Window {
place,
zoomed: false,
..window
});
}
/// An 80 by 24 app with a console behind a loaded accounts list, overlapping, and the frame drawn.
pub(crate) fn overlapped() -> (App, WindowId, WindowId) {
let mut app = crate::test_support::app();
app.terminal.replace(TerminalEnv {
screen: Size::new(80, 24),
cell_pixels: (10, 20),
backend: ChartBackend::Halfblocks,
app.close_all_windows();
app.open_view(ViewId::Console);
app.open_view(ViewId::Accounts);
let row = |i: usize| format!(r#"(:account :id "u{i}" :name "a{i}" :parent "")"#);
let rows: Vec<String> = (0..3).map(row).collect();
app.accounts_mut()
.on_reply(&format!("(:id 1 :value ({}))", rows.join(" ")));
let rear = app.window_id(ViewId::Console);
let front = app.window_id(ViewId::Accounts);
let (Some(rear), Some(front)) = (rear, front) else {
panic!("both windows are open");
place_window(&mut app, rear, REAR_AT);
place_window(&mut app, front, FRONT_AT);
redraw(&mut app);
(app, rear, front)
fn mouse(app: &mut App, kind: MouseEventKind, (x, y): (u16, u16), when: Instant) {
let mouse = MouseEvent {
kind,
column: x,
row: y,
modifiers: KeyModifiers::NONE,
crate::mouse::handle_mouse(app, mouse, when);
redraw(app);
/// A left press at `at` on the last drawn frame, then the redraw the runtime would do.
pub(crate) fn left_click(app: &mut App, at: (u16, u16), when: Instant) {
mouse(app, MouseEventKind::Down(MouseButton::Left), at, when);
pub(crate) fn left_release(app: &mut App, at: (u16, u16), when: Instant) {
mouse(app, MouseEventKind::Up(MouseButton::Left), at, when);
/// A move with the left button held, to `at`.
pub(crate) fn left_drag(app: &mut App, at: (u16, u16), when: Instant) {
mouse(app, MouseEventKind::Drag(MouseButton::Left), at, when);
pub(crate) fn wheel_down(app: &mut App, at: (u16, u16), when: Instant) {
mouse(app, MouseEventKind::ScrollDown, at, when);