From fd50b45e6187f6c56156915f408340c1c9bd892f Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Wed, 22 Jan 2020 07:45:25 +0300 Subject: [PATCH] anvil: implement input region check --- anvil/src/shell.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/anvil/src/shell.rs b/anvil/src/shell.rs index 6b75b5b..ba63613 100644 --- a/anvil/src/shell.rs +++ b/anvil/src/shell.rs @@ -188,5 +188,19 @@ fn contains_point(attrs: &SurfaceAttributes, point: (f64, f64)) -> bool { width: w, height: h, }; - rect.contains((point.0 as i32, point.1 as i32)) + + let point = (point.0 as i32, point.1 as i32); + + // The input region is always within the surface itself, so if the surface itself doesn't contain the + // point we can return false. + if !rect.contains(point) { + return false; + } + + // If there's no input region, we're done. + if attrs.input_region.is_none() { + return true; + } + + attrs.input_region.as_ref().unwrap().contains(point) }