1414
1515//! Events.
1616
17- use crate :: kurbo:: { Rect , Size } ;
1817use std:: ops:: { Add , Sub } ;
1918
2019use druid_shell:: { Clipboard , KeyEvent , TimerToken } ;
2120
21+ use crate :: kurbo:: { Rect , Size } ;
2222use crate :: mouse:: MouseEvent ;
2323use crate :: { Command , Notification , Point , WidgetId } ;
2424
@@ -304,7 +304,12 @@ pub enum LifeCycle {
304304 ///
305305 /// [`EventCtx::is_focused`]: struct.EventCtx.html#method.is_focused
306306 FocusChanged ( bool ) ,
307+ /// Called when the [`ViewContext`] of this widget changed.
307308 ///
309+ /// See [`view_context_changed`] on how and when to request this event.
310+ ///
311+ /// [`view_context_changed`](EventCtx::view_context_changed)
312+ /// [`ViewContext`](ViewContext)
308313 ViewContextChanged ( ViewContext ) ,
309314 /// Internal druid lifecycle event.
310315 ///
@@ -334,7 +339,8 @@ pub enum InternalLifeCycle {
334339 } ,
335340 /// Used to route the `DisabledChanged` event to the required widgets.
336341 RouteDisabledChanged ,
337- /// The parents widget origin in window coordinate space has changed.
342+
343+ /// Used to route the `ViewContextChanged` event to the required widgets.
338344 RouteViewContextChanged ( ViewContext ) ,
339345 /// For testing: request the `WidgetState` of a specific widget.
340346 ///
@@ -351,7 +357,7 @@ pub enum InternalLifeCycle {
351357 /// For testing: request the `DebugState` of a specific widget.
352358 ///
353359 /// This is useful if you need to get a best-effort description of the
354- /// state of this widget and its children. You can dispatch this event,
360+ /// state of this widget and its children. You can dispatch this event,set_hot
355361 /// specifying the widget in question, and that widget will
356362 /// set its state in the provided `Cell`, if it exists.
357363 DebugRequestDebugState {
@@ -364,18 +370,25 @@ pub enum InternalLifeCycle {
364370 DebugInspectState ( StateCheckFn ) ,
365371}
366372
367- /// Information about the widgets surroundings.
373+ /// Information about the widget's surroundings.
374+ ///
375+ /// The global origin is also saved in the widget state.
376+ ///
377+ /// When the ViewContext of widget changes it receives a `ViewContextChanged` event.
368378#[ derive( Debug , Copy , Clone ) ]
369379pub struct ViewContext {
370- /// The origin of this widget's parent relative to the window.
371- pub parent_window_origin : Point ,
380+ /// The origin of this widget relative to the window.
381+ ///
382+ /// This is written from the perspective of the Widget and not the Pod.
383+ /// For the Pod this is its parent's window origin.
384+ pub window_origin : Point ,
372385
373- /// The last position the cursor was on , relative to the widget.
386+ /// The last position the cursor was at , relative to the widget.
374387 pub last_mouse_position : Option < Point > ,
375388
376389 /// The visible area, this widget is contained in, relative to the widget.
377390 ///
378- /// The area may be larger than the widgets paint_rect.
391+ /// The area may be larger than the widgets ` paint_rect` .
379392 pub clip : Rect ,
380393}
381394
@@ -444,7 +457,7 @@ impl LifeCycle {
444457
445458 /// Returns an event for a widget which maybe is overlapped by another widget.
446459 ///
447- /// When ignore is set to `true` the widget will set its hot state to `false` even if the cursor
460+ /// When ` ignore` is set to `true` the widget will set its hot state to `false` even if the cursor
448461 /// is inside its bounds.
449462 pub fn ignore_hot ( & self , ignore : bool ) -> Self {
450463 if ignore {
@@ -490,11 +503,11 @@ impl InternalLifeCycle {
490503}
491504
492505impl ViewContext {
493- /// Transforms the `ViewContext` into the coordinate_space of its child.
506+ /// Transforms the `ViewContext` into the coordinate space of its child.
494507 pub ( crate ) fn for_child_widget ( & self , child_origin : Point ) -> Self {
495508 let child_origin = child_origin. to_vec2 ( ) ;
496509 ViewContext {
497- parent_window_origin : self . parent_window_origin . add ( child_origin) ,
510+ window_origin : self . window_origin . add ( child_origin) ,
498511 last_mouse_position : self . last_mouse_position . map ( |pos| pos. sub ( child_origin) ) ,
499512 clip : self . clip . sub ( child_origin) ,
500513 }
0 commit comments