Lines
100 %
Functions
Branches
//! The mouse holds one thing at a time: a drag or a press, and a change of overlays drops it.
use super::overlap::{FRONT_AT, left_click, overlapped};
use crate::app::{App, Face, Owner};
use crate::modal::{ConfirmAction, Modal};
use ratatui::layout::{Position, Rect};
use std::time::Instant;
const PRESSED: Rect = Rect::new(2, 2, 6, 1);
fn inside() -> Position {
Position::new(3, 2)
}
fn confirm() -> Modal {
Modal::Confirm {
prompt: "Discard changes?".to_string(),
action: ConfirmAction::DiscardForm,
focus: None,
fn press_button(app: &mut App) {
app.hold_press(Owner::Layer, Face::Button(0), PRESSED);
#[test]
fn a_press_ends_the_drag_that_was_held() {
let (mut app, _, _) = overlapped();
let title = (
u16::try_from(FRONT_AT.x).unwrap_or_default() + 10,
u16::try_from(FRONT_AT.y).unwrap_or_default(),
);
left_click(&mut app, title, Instant::now());
assert!(app.pointer_dragging());
press_button(&mut app);
assert!(!app.dragging());
assert_eq!(app.release_press(inside()), Some(Face::Button(0)));
fn a_drag_ends_the_press_that_was_held() {
assert!(app.dragging());
assert_eq!(app.release_press(inside()), None);
fn a_close_press_is_a_press_like_a_button() {
let mut app = crate::test_support::app();
app.hold_press(Owner::Layer, Face::Close, PRESSED);
assert_eq!(app.pressed_button(), None);
assert_eq!(app.release_press(inside()), Some(Face::Close));
fn pushing_an_overlay_drops_the_press() {
app.overlays.push(confirm());
assert_eq!(app.pressed_button(), Some(0));
fn popping_an_overlay_drops_the_press() {
app.overlays.pop();