Fix back button mouse left click

This commit is contained in:
Thomas
2022-08-24 20:41:55 +02:00
committed by GitHub
parent bddfd6f622
commit b8b565d0c3

View File

@@ -3,7 +3,7 @@ use std::time::{Duration, SystemTime};
use cursive::align::HAlign; use cursive::align::HAlign;
use cursive::direction::Direction; use cursive::direction::Direction;
use cursive::event::{AnyCb, Event, EventResult, MouseButton}; use cursive::event::{AnyCb, Event, EventResult, MouseButton, MouseEvent};
use cursive::theme::{ColorStyle, ColorType, Theme}; use cursive::theme::{ColorStyle, ColorType, Theme};
use cursive::traits::View; use cursive::traits::View;
use cursive::vec::Vec2; use cursive::vec::Vec2;
@@ -298,11 +298,15 @@ impl View for Layout {
} = event } = event
{ {
if position.y == 0 { if position.y == 0 {
// if user clicks within first third of first line, treat it as if mouseevent == MouseEvent::Press(MouseButton::Left)
// a click on the back button
if mouseevent.button() == Some(MouseButton::Left)
&& !self.is_current_stack_empty() && !self.is_current_stack_empty()
&& position.x <= self.last_size.x.saturating_div(3) && position.x
< self
.get_current_screen()
.map(|screen| screen.title())
.unwrap_or_default()
.len()
+ 3
{ {
self.pop_view(); self.pop_view();
} }