@@ -153,9 +153,8 @@ impl Application for GameOfLife {
153153mod grid {
154154 use crate :: Preset ;
155155 use iced:: {
156- canvas:: {
157- self , Cache , Canvas , Cursor , Event , Frame , Geometry , Path , Text ,
158- } ,
156+ canvas:: event:: { self , Event } ,
157+ canvas:: { self , Cache , Canvas , Cursor , Frame , Geometry , Path , Text } ,
159158 mouse, Color , Element , HorizontalAlignment , Length , Point , Rectangle ,
160159 Size , Vector , VerticalAlignment ,
161160 } ;
@@ -328,12 +327,18 @@ mod grid {
328327 event : Event ,
329328 bounds : Rectangle ,
330329 cursor : Cursor ,
331- ) -> Option < Message > {
330+ ) -> ( event :: Status , Option < Message > ) {
332331 if let Event :: Mouse ( mouse:: Event :: ButtonReleased ( _) ) = event {
333332 self . interaction = Interaction :: None ;
334333 }
335334
336- let cursor_position = cursor. position_in ( & bounds) ?;
335+ let cursor_position =
336+ if let Some ( position) = cursor. position_in ( & bounds) {
337+ position
338+ } else {
339+ return ( event:: Status :: Ignored , None ) ;
340+ } ;
341+
337342 let cell = Cell :: at ( self . project ( cursor_position, bounds. size ( ) ) ) ;
338343 let is_populated = self . state . contains ( & cell) ;
339344
@@ -345,28 +350,32 @@ mod grid {
345350
346351 match event {
347352 Event :: Mouse ( mouse_event) => match mouse_event {
348- mouse:: Event :: ButtonPressed ( button) => match button {
349- mouse:: Button :: Left => {
350- self . interaction = if is_populated {
351- Interaction :: Erasing
352- } else {
353- Interaction :: Drawing
354- } ;
355-
356- populate. or ( unpopulate)
357- }
358- mouse:: Button :: Right => {
359- self . interaction = Interaction :: Panning {
360- translation : self . translation ,
361- start : cursor_position,
362- } ;
353+ mouse:: Event :: ButtonPressed ( button) => {
354+ let message = match button {
355+ mouse:: Button :: Left => {
356+ self . interaction = if is_populated {
357+ Interaction :: Erasing
358+ } else {
359+ Interaction :: Drawing
360+ } ;
361+
362+ populate. or ( unpopulate)
363+ }
364+ mouse:: Button :: Right => {
365+ self . interaction = Interaction :: Panning {
366+ translation : self . translation ,
367+ start : cursor_position,
368+ } ;
363369
364- None
365- }
366- _ => None ,
367- } ,
370+ None
371+ }
372+ _ => None ,
373+ } ;
374+
375+ ( event:: Status :: Captured , message)
376+ }
368377 mouse:: Event :: CursorMoved { .. } => {
369- match self . interaction {
378+ let message = match self . interaction {
370379 Interaction :: Drawing => populate,
371380 Interaction :: Erasing => unpopulate,
372381 Interaction :: Panning { translation, start } => {
@@ -380,7 +389,14 @@ mod grid {
380389 None
381390 }
382391 _ => None ,
383- }
392+ } ;
393+
394+ let event_status = match self . interaction {
395+ Interaction :: None => event:: Status :: Ignored ,
396+ _ => event:: Status :: Captured ,
397+ } ;
398+
399+ ( event_status, message)
384400 }
385401 mouse:: Event :: WheelScrolled { delta } => match delta {
386402 mouse:: ScrollDelta :: Lines { y, .. }
@@ -413,12 +429,12 @@ mod grid {
413429 self . grid_cache . clear ( ) ;
414430 }
415431
416- None
432+ ( event :: Status :: Captured , None )
417433 }
418434 } ,
419- _ => None ,
435+ _ => ( event :: Status :: Ignored , None ) ,
420436 } ,
421- _ => None ,
437+ _ => ( event :: Status :: Ignored , None ) ,
422438 }
423439 }
424440
0 commit comments