pub fn event(&mut self, ctx: &mut EventCtx, event: &Event, data: &mut T, env: &Env) {
        // If data is `None` it means we were just added
        // This should only be called here if the user has added children but failed to call
        // `children_changed`?
        if self.old_data.is_none() {
            let mut lc_ctx = ctx.make_lifecycle_ctx();
            self.inner
                .lifecycle(&mut lc_ctx, &LifeCycle::WidgetAdded, data, &env);
            self.state.needs_inval |= lc_ctx.needs_inval;
            self.old_data = Some(data.clone());
            self.env = Some(env.clone());
        }

        // TODO: factor as much logic as possible into monomorphic functions.
        if ctx.is_handled {
            // This function is called by containers to propagate an event from
            // containers to children. Non-recurse events will be invoked directly
            // from other points in the library.
            return;
        }
        let had_active = self.state.has_active;
        let mut child_ctx = EventCtx {
            win_ctx: ctx.win_ctx,
            cursor: ctx.cursor,
            command_queue: ctx.command_queue,
            window: &ctx.window,
            window_id: ctx.window_id,
            widget_id: self.id(),
            base_state: &mut self.state,
            had_active,
            is_handled: false,
            is_root: false,
        };
        let rect = child_ctx.base_state.layout_rect;
        // Note: could also represent this as `Option<Event>`.
        let mut recurse = true;
        let mut hot_changed = None;
        let child_event = match event {
            Event::Size(size) => {
                recurse = ctx.is_root;
                Event::Size(*size)
            }
            Event::MouseDown(mouse_event) => {
                let had_hot = child_ctx.base_state.is_hot;
                let now_hot = rect.winding(mouse_event.pos) != 0;
                if (!had_hot) && now_hot {
                    child_ctx.base_state.is_hot = true;
                    hot_changed = Some(true);
                }
                recurse = had_active || !ctx.had_active && now_hot;
                let mut mouse_event = mouse_event.clone();
                mouse_event.pos -= rect.origin().to_vec2();
                Event::MouseDown(mouse_event)
            }
            Event::MouseUp(mouse_event) => {
                recurse = had_active || !ctx.had_active && rect.winding(mouse_event.pos) != 0;
                let mut mouse_event = mouse_event.clone();
                mouse_event.pos -= rect.origin().to_vec2();
                Event::MouseUp(mouse_event)
            }
            Event::MouseMoved(mouse_event) => {
                let had_hot = child_ctx.base_state.is_hot;
                child_ctx.base_state.is_hot = rect.winding(mouse_event.pos) != 0;
                if had_hot != child_ctx.base_state.is_hot {
                    hot_changed = Some(child_ctx.base_state.is_hot);
                }
                recurse = had_active || had_hot || child_ctx.base_state.is_hot;
                let mut mouse_event = mouse_event.clone();
                mouse_event.pos -= rect.origin().to_vec2();
                Event::MouseMoved(mouse_event)
            }
            Event::KeyDown(e) => {
                recurse = child_ctx.base_state.has_focus;
                Event::KeyDown(*e)
            }
            Event::KeyUp(e) => {
                recurse = child_ctx.base_state.has_focus;
                Event::KeyUp(*e)
            }
            Event::Paste(e) => {
                recurse = child_ctx.base_state.has_focus;
                Event::Paste(e.clone())
            }
            Event::Wheel(wheel_event) => {
                recurse = had_active || child_ctx.base_state.is_hot;
                Event::Wheel(wheel_event.clone())
            }
            Event::Zoom(zoom) => {
                recurse = had_active || child_ctx.base_state.is_hot;
                Event::Zoom(*zoom)
            }
            Event::Timer(id) => {
                recurse = child_ctx.base_state.request_timer;
                Event::Timer(*id)
            }
            Event::Command(cmd) => Event::Command(cmd.clone()),
            Event::TargetedCommand(target, cmd) => match target {
                Target::Window(_) => Event::Command(cmd.clone()),
                Target::Widget(id) if *id == self.id => Event::Command(cmd.clone()),
                Target::Widget(id) => {
                    recurse = child_ctx.base_state.children.contains(id);
                    Event::TargetedCommand(*target, cmd.clone())
                }
            },
        };
        child_ctx.base_state.needs_inval = false;
        if let Some(is_hot) = hot_changed {
            let hot_changed_event = LifeCycle::HotChanged(is_hot);
            let mut lc_ctx = child_ctx.make_lifecycle_ctx();
            self.inner
                .lifecycle(&mut lc_ctx, &hot_changed_event, data, &env);
            ctx.base_state.needs_inval |= lc_ctx.needs_inval;
        }
        if recurse {
            child_ctx.base_state.has_active = false;
            self.inner.event(&mut child_ctx, &child_event, data, &env);
            child_ctx.base_state.has_active |= child_ctx.base_state.is_active;
        };

        ctx.base_state.merge_up(&child_ctx.base_state);
        ctx.is_handled |= child_ctx.is_handled;
    }
/// Propagate an event.
///
/// Generally the [`event`] method of a container widget will call this
/// method on all its children. Here is where a great deal of the event
/// flow logic resides, particularly whether to continue propagating
/// the event.
///
/// [`event`]: trait.Widget.html#method.event
Propagate an event.
Generally the [`event`] method of a container widget will call this
method on all its children. Here is where a great deal of the event
flow logic resides, particularly whether to continue propagating
the event.


Propagate an event . Generally the [ ` event ` ] method of a container widget will call this method on all its children . Here is where a great deal of the event flow logic resides particularly whether to continue propagating the event .
pub fn event(&mut self, ctx: &mut EventCtx, event: &Event, data: &mut T, env: &Env) {
        // If data is `None` it means we were just added
        // This should only be called here if the user has added children but failed to call
        // `children_changed`?
        if self.old_data.is_none() {
            let mut lc_ctx = ctx.make_lifecycle_ctx();
            self.inner
                .lifecycle(&mut lc_ctx, &LifeCycle::WidgetAdded, data, &env);
            self.state.needs_inval |= lc_ctx.needs_inval;
            self.old_data = Some(data.clone());
            self.env = Some(env.clone());
        }
        // TODO: factor as much logic as possible into monomorphic functions.
        if ctx.is_handled {
            // This function is called by containers to propagate an event from
            // containers to children. Non-recurse events will be invoked directly
            // from other points in the library.
            return;
        }
        let had_active = self.state.has_active;
        let mut child_ctx = EventCtx {
            win_ctx: ctx.win_ctx,
            cursor: ctx.cursor,
            command_queue: ctx.command_queue,
            window: &ctx.window,
            window_id: ctx.window_id,
            widget_id: self.id(),
            base_state: &mut self.state,
            had_active,
            is_handled: false,
            is_root: false,
        };
        let rect = child_ctx.base_state.layout_rect;
        // Note: could also represent this as `Option<Event>`.
        let mut recurse = true;
        let mut hot_changed = None;
        let child_event = match event {
            Event::Size(size) => {
                recurse = ctx.is_root;
                Event::Size(*size)
            }
            Event::MouseDown(mouse_event) => {
                let had_hot = child_ctx.base_state.is_hot;
                let now_hot = rect.winding(mouse_event.pos) != 0;
                if (!had_hot) && now_hot {
                    child_ctx.base_state.is_hot = true;
                    hot_changed = Some(true);
                }
                recurse = had_active || !ctx.had_active && now_hot;
                let mut mouse_event = mouse_event.clone();
                mouse_event.pos -= rect.origin().to_vec2();
                Event::MouseDown(mouse_event)
            }
            Event::MouseUp(mouse_event) => {
                recurse = had_active || !ctx.had_active && rect.winding(mouse_event.pos) != 0;
                let mut mouse_event = mouse_event.clone();
                mouse_event.pos -= rect.origin().to_vec2();
                Event::MouseUp(mouse_event)
            }
            Event::MouseMoved(mouse_event) => {
                let had_hot = child_ctx.base_state.is_hot;
                child_ctx.base_state.is_hot = rect.winding(mouse_event.pos) != 0;
                if had_hot != child_ctx.base_state.is_hot {
                    hot_changed = Some(child_ctx.base_state.is_hot);
                }
                recurse = had_active || had_hot || child_ctx.base_state.is_hot;
                let mut mouse_event = mouse_event.clone();
                mouse_event.pos -= rect.origin().to_vec2();
                Event::MouseMoved(mouse_event)
            }
            Event::KeyDown(e) => {
                recurse = child_ctx.base_state.has_focus;
                Event::KeyDown(*e)
            }
            Event::KeyUp(e) => {
                recurse = child_ctx.base_state.has_focus;
                Event::KeyUp(*e)
            }
            Event::Paste(e) => {
                recurse = child_ctx.base_state.has_focus;
                Event::Paste(e.clone())
            }
            Event::Wheel(wheel_event) => {
                recurse = had_active || child_ctx.base_state.is_hot;
                Event::Wheel(wheel_event.clone())
            }
            Event::Zoom(zoom) => {
                recurse = had_active || child_ctx.base_state.is_hot;
                Event::Zoom(*zoom)
            }
            Event::Timer(id) => {
                recurse = child_ctx.base_state.request_timer;
                Event::Timer(*id)
            }
            Event::Command(cmd) => Event::Command(cmd.clone()),
            Event::TargetedCommand(target, cmd) => match target {
                Target::Window(_) => Event::Command(cmd.clone()),
                Target::Widget(id) if *id == self.id => Event::Command(cmd.clone()),
                Target::Widget(id) => {
                    recurse = child_ctx.base_state.children.contains(id);
                    Event::TargetedCommand(*target, cmd.clone())
                }
            },
        };
        child_ctx.base_state.needs_inval = false;
        if let Some(is_hot) = hot_changed {
            let hot_changed_event = LifeCycle::HotChanged(is_hot);
            let mut lc_ctx = child_ctx.make_lifecycle_ctx();
            self.inner
                .lifecycle(&mut lc_ctx, &hot_changed_event, data, &env);
            ctx.base_state.needs_inval |= lc_ctx.needs_inval;
        }
        if recurse {
            child_ctx.base_state.has_active = false;
            self.inner.event(&mut child_ctx, &child_event, data, &env);
            child_ctx.base_state.has_active |= child_ctx.base_state.is_active;
        };
        ctx.base_state.merge_up(&child_ctx.base_state);
        ctx.is_handled |= child_ctx.is_handled;
    }
pub fn event ( & mut self , ctx : & mut EventCtx , event : & Event , data : & mut T , env : & Env ) { // If data is `None` it means we were just added // This should only be called here if the user has added children but failed to call // `children_changed`? if self . old_data . is_none ( ) { let mut lc_ctx = ctx . make_lifecycle_ctx ( ) ; self . inner . lifecycle ( & mut lc_ctx , & LifeCycle :: WidgetAdded , data , & env ) ; self . state . needs_inval |= lc_ctx . needs_inval ; self . old_data = Some ( data . clone ( ) ) ; self . env = Some ( env . clone ( ) ) ; } // TODO: factor as much logic as possible into monomorphic functions. if ctx . is_handled { // This function is called by containers to propagate an event from // containers to children. Non-recurse events will be invoked directly // from other points in the library. return ; } let had_active = self . state . has_active ; let mut child_ctx = EventCtx { win_ctx : ctx . win_ctx , cursor : ctx . cursor , command_queue : ctx . command_queue , window : & ctx . window , window_id : ctx . window_id , widget_id : self . id ( ) , base_state : & mut self . state , had_active , is_handled : false , is_root : false , } ; let rect = child_ctx . base_state . layout_rect ; // Note: could also represent this as `Option<Event>`. let mut recurse = true ; let mut hot_changed = None ; let child_event = match event { Event :: Size ( size ) => { recurse = ctx . is_root ; Event :: Size ( * size ) } Event :: MouseDown ( mouse_event ) => { let had_hot = child_ctx . base_state . is_hot ; let now_hot = rect . winding ( mouse_event . pos ) != 0 ; if ( ! had_hot ) && now_hot { child_ctx . base_state . is_hot = true ; hot_changed = Some ( true ) ; } recurse = had_active || ! ctx . had_active && now_hot ; let mut mouse_event = mouse_event . clone ( ) ; mouse_event . pos -= rect . origin ( ) . to_vec2 ( ) ; Event :: MouseDown ( mouse_event ) } Event :: MouseUp ( mouse_event ) => { recurse = had_active || ! ctx . had_active && rect . winding ( mouse_event . pos ) != 0 ; let mut mouse_event = mouse_event . clone ( ) ; mouse_event . pos -= rect . origin ( ) . to_vec2 ( ) ; Event :: MouseUp ( mouse_event ) } Event :: MouseMoved ( mouse_event ) => { let had_hot = child_ctx . base_state . is_hot ; child_ctx . base_state . is_hot = rect . winding ( mouse_event . pos ) != 0 ; if had_hot != child_ctx . base_state . is_hot { hot_changed = Some ( child_ctx . base_state . is_hot ) ; } recurse = had_active || had_hot || child_ctx . base_state . is_hot ; let mut mouse_event = mouse_event . clone ( ) ; mouse_event . pos -= rect . origin ( ) . to_vec2 ( ) ; Event :: MouseMoved ( mouse_event ) } Event :: KeyDown ( e ) => { recurse = child_ctx . base_state . has_focus ; Event :: KeyDown ( * e ) } Event :: KeyUp ( e ) => { recurse = child_ctx . base_state . has_focus ; Event :: KeyUp ( * e ) } Event :: Paste ( e ) => { recurse = child_ctx . base_state . has_focus ; Event :: Paste ( e . clone ( ) ) } Event :: Wheel ( wheel_event ) => { recurse = had_active || child_ctx . base_state . is_hot ; Event :: Wheel ( wheel_event . clone ( ) ) } Event :: Zoom ( zoom ) => { recurse = had_active || child_ctx . base_state . is_hot ; Event :: Zoom ( * zoom ) } Event :: Timer ( id ) => { recurse = child_ctx . base_state . request_timer ; Event :: Timer ( * id ) } Event :: Command ( cmd ) => Event :: Command ( cmd . clone ( ) ) , Event :: TargetedCommand ( target , cmd ) => match target { Target :: Window ( _ ) => Event :: Command ( cmd . clone ( ) ) , Target :: Widget ( id ) if * id == self . id => Event :: Command ( cmd . clone ( ) ) , Target :: Widget ( id ) => { recurse = child_ctx . base_state . children . contains ( id ) ; Event :: TargetedCommand ( * target , cmd . clone ( ) ) } } , } ; child_ctx . base_state . needs_inval = false ; if let Some ( is_hot ) = hot_changed { let hot_changed_event = LifeCycle :: HotChanged ( is_hot ) ; let mut lc_ctx = child_ctx . make_lifecycle_ctx ( ) ; self . inner . lifecycle ( & mut lc_ctx , & hot_changed_event , data , & env ) ; ctx . base_state . needs_inval |= lc_ctx . needs_inval ; } if recurse { child_ctx . base_state . has_active = false ; self . inner . event ( & mut child_ctx , & child_event , data , & env ) ; child_ctx . base_state . has_active |= child_ctx . base_state . is_active ; } ; ctx . base_state . merge_up ( & child_ctx . base_state ) ; ctx . is_handled |= child_ctx . is_handled ; }
Propagate an event.
Propagate an event .
&mut self
ctx
&mut EventCtx
event
&Event
data
&mut T
env
&Env
&mut self
ctx
&mut EventCtx
event
&Event
data
&mut T
env
&Env