pub fn event(&mut self, ctx: &mut EventCtx, event: &Event, data: &mut T, env: &Env) {
        if self.old_data.is_none() {
            log::error!(
                "widget {:?} is receiving an event without having first \
                 received WidgetAdded.",
                ctx.widget_id()
            );
        }

        // log if we seem not to be laid out when we should be
        if !matches!(event, Event::WindowConnected | Event::WindowSize(_))
            && self.state.layout_rect.is_none()
        {
            log::warn!(
                "Widget '{}' received an event ({:?}) without having been laid out. \
                This likely indicates a missed call to set_layout_rect.",
                self.inner.type_name(),
                event,
            );
        }

        // 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 {
            cursor: ctx.cursor,
            command_queue: ctx.command_queue,
            window: ctx.window,
            window_id: ctx.window_id,
            base_state: &mut self.state,
            is_handled: false,
            is_root: false,
            focus_widget: ctx.focus_widget,
        };

        let rect = child_ctx.base_state.layout_rect.unwrap_or_default();

        // Note: could also represent this as `Option<Event>`.
        let mut recurse = true;
        let child_event = match event {
            Event::Internal(internal) => match internal {
                InternalEvent::MouseLeave => {
                    let hot_changed = WidgetPod::set_hot_state(
                        &mut self.inner,
                        child_ctx.command_queue,
                        child_ctx.base_state,
                        child_ctx.window_id,
                        rect,
                        None,
                        data,
                        env,
                    );
                    recurse = had_active || hot_changed;
                    Event::Internal(InternalEvent::MouseLeave)
                }
                InternalEvent::TargetedCommand(target, cmd) => {
                    match target {
                        Target::Window(_) => Event::Command(cmd.clone()),
                        Target::Widget(id) if *id == child_ctx.widget_id() => {
                            Event::Command(cmd.clone())
                        }
                        Target::Widget(id) => {
                            // Recurse when the target widget could be our descendant.
                            // The bloom filter we're checking can return false positives.
                            recurse = child_ctx.base_state.children.may_contain(id);
                            Event::Internal(InternalEvent::TargetedCommand(*target, cmd.clone()))
                        }
                        Target::Global => {
                            panic!("Target::Global should be converted before WidgetPod")
                        }
                    }
                }
            },
            Event::WindowConnected => Event::WindowConnected,
            Event::WindowSize(size) => {
                child_ctx.request_layout();
                recurse = ctx.is_root;
                Event::WindowSize(*size)
            }
            Event::MouseDown(mouse_event) => {
                WidgetPod::set_hot_state(
                    &mut self.inner,
                    child_ctx.command_queue,
                    child_ctx.base_state,
                    child_ctx.window_id,
                    rect,
                    Some(mouse_event.pos),
                    data,
                    env,
                );
                recurse = had_active || child_ctx.base_state.is_hot;
                let mut mouse_event = mouse_event.clone();
                mouse_event.pos -= rect.origin().to_vec2();
                Event::MouseDown(mouse_event)
            }
            Event::MouseUp(mouse_event) => {
                WidgetPod::set_hot_state(
                    &mut self.inner,
                    child_ctx.command_queue,
                    child_ctx.base_state,
                    child_ctx.window_id,
                    rect,
                    Some(mouse_event.pos),
                    data,
                    env,
                );
                recurse = had_active || child_ctx.base_state.is_hot;
                let mut mouse_event = mouse_event.clone();
                mouse_event.pos -= rect.origin().to_vec2();
                Event::MouseUp(mouse_event)
            }
            Event::MouseMove(mouse_event) => {
                let hot_changed = WidgetPod::set_hot_state(
                    &mut self.inner,
                    child_ctx.command_queue,
                    child_ctx.base_state,
                    child_ctx.window_id,
                    rect,
                    Some(mouse_event.pos),
                    data,
                    env,
                );
                recurse = had_active || child_ctx.base_state.is_hot || hot_changed;
                let mut mouse_event = mouse_event.clone();
                mouse_event.pos -= rect.origin().to_vec2();
                Event::MouseMove(mouse_event)
            }
            Event::KeyDown(e) => {
                recurse = child_ctx.has_focus();
                Event::KeyDown(*e)
            }
            Event::KeyUp(e) => {
                recurse = child_ctx.has_focus();
                Event::KeyUp(*e)
            }
            Event::Paste(e) => {
                recurse = child_ctx.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()),
        };
        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#tymethod.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 self.old_data.is_none() {
            log::error!(
                "widget {:?} is receiving an event without having first \
                 received WidgetAdded.",
                ctx.widget_id()
            );
        }
        // log if we seem not to be laid out when we should be
        if !matches!(event, Event::WindowConnected | Event::WindowSize(_))
            && self.state.layout_rect.is_none()
        {
            log::warn!(
                "Widget '{}' received an event ({:?}) without having been laid out. \
                This likely indicates a missed call to set_layout_rect.",
                self.inner.type_name(),
                event,
            );
        }
        // 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 {
            cursor: ctx.cursor,
            command_queue: ctx.command_queue,
            window: ctx.window,
            window_id: ctx.window_id,
            base_state: &mut self.state,
            is_handled: false,
            is_root: false,
            focus_widget: ctx.focus_widget,
        };
        let rect = child_ctx.base_state.layout_rect.unwrap_or_default();
        // Note: could also represent this as `Option<Event>`.
        let mut recurse = true;
        let child_event = match event {
            Event::Internal(internal) => match internal {
                InternalEvent::MouseLeave => {
                    let hot_changed = WidgetPod::set_hot_state(
                        &mut self.inner,
                        child_ctx.command_queue,
                        child_ctx.base_state,
                        child_ctx.window_id,
                        rect,
                        None,
                        data,
                        env,
                    );
                    recurse = had_active || hot_changed;
                    Event::Internal(InternalEvent::MouseLeave)
                }
                InternalEvent::TargetedCommand(target, cmd) => {
                    match target {
                        Target::Window(_) => Event::Command(cmd.clone()),
                        Target::Widget(id) if *id == child_ctx.widget_id() => {
                            Event::Command(cmd.clone())
                        }
                        Target::Widget(id) => {
                            // Recurse when the target widget could be our descendant.
                            // The bloom filter we're checking can return false positives.
                            recurse = child_ctx.base_state.children.may_contain(id);
                            Event::Internal(InternalEvent::TargetedCommand(*target, cmd.clone()))
                        }
                        Target::Global => {
                            panic!("Target::Global should be converted before WidgetPod")
                        }
                    }
                }
            },
            Event::WindowConnected => Event::WindowConnected,
            Event::WindowSize(size) => {
                child_ctx.request_layout();
                recurse = ctx.is_root;
                Event::WindowSize(*size)
            }
            Event::MouseDown(mouse_event) => {
                WidgetPod::set_hot_state(
                    &mut self.inner,
                    child_ctx.command_queue,
                    child_ctx.base_state,
                    child_ctx.window_id,
                    rect,
                    Some(mouse_event.pos),
                    data,
                    env,
                );
                recurse = had_active || child_ctx.base_state.is_hot;
                let mut mouse_event = mouse_event.clone();
                mouse_event.pos -= rect.origin().to_vec2();
                Event::MouseDown(mouse_event)
            }
            Event::MouseUp(mouse_event) => {
                WidgetPod::set_hot_state(
                    &mut self.inner,
                    child_ctx.command_queue,
                    child_ctx.base_state,
                    child_ctx.window_id,
                    rect,
                    Some(mouse_event.pos),
                    data,
                    env,
                );
                recurse = had_active || child_ctx.base_state.is_hot;
                let mut mouse_event = mouse_event.clone();
                mouse_event.pos -= rect.origin().to_vec2();
                Event::MouseUp(mouse_event)
            }
            Event::MouseMove(mouse_event) => {
                let hot_changed = WidgetPod::set_hot_state(
                    &mut self.inner,
                    child_ctx.command_queue,
                    child_ctx.base_state,
                    child_ctx.window_id,
                    rect,
                    Some(mouse_event.pos),
                    data,
                    env,
                );
                recurse = had_active || child_ctx.base_state.is_hot || hot_changed;
                let mut mouse_event = mouse_event.clone();
                mouse_event.pos -= rect.origin().to_vec2();
                Event::MouseMove(mouse_event)
            }
            Event::KeyDown(e) => {
                recurse = child_ctx.has_focus();
                Event::KeyDown(*e)
            }
            Event::KeyUp(e) => {
                recurse = child_ctx.has_focus();
                Event::KeyUp(*e)
            }
            Event::Paste(e) => {
                recurse = child_ctx.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()),
        };
        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 self . old_data . is_none ( ) { log :: error ! ( " \
 " ctx widget_id ( ) ) ; } // log if we seem not to be laid out when we should be if ! matches ! ( event Event WindowConnected Event WindowSize ( ) ) && self . state . layout_rect . is_none ( ) { log :: warn ! ( " \
 " self inner type_name ( ) event ) ; } // 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 { cursor : ctx . cursor , command_queue : ctx . command_queue , window : ctx . window , window_id : ctx . window_id , base_state : & mut self . state , is_handled : false , is_root : false , focus_widget : ctx . focus_widget , } ; let rect = child_ctx . base_state . layout_rect . unwrap_or_default ( ) ; // Note: could also represent this as `Option<Event>`. let mut recurse = true ; let child_event = match event { Event :: Internal ( internal ) => match internal { InternalEvent :: MouseLeave => { let hot_changed = WidgetPod :: set_hot_state ( & mut self . inner , child_ctx . command_queue , child_ctx . base_state , child_ctx . window_id , rect , None , data , env , ) ; recurse = had_active || hot_changed ; Event :: Internal ( InternalEvent :: MouseLeave ) } InternalEvent :: TargetedCommand ( target , cmd ) => { match target { Target :: Window ( _ ) => Event :: Command ( cmd . clone ( ) ) , Target :: Widget ( id ) if * id == child_ctx . widget_id ( ) => { Event :: Command ( cmd . clone ( ) ) } Target :: Widget ( id ) => { // Recurse when the target widget could be our descendant. // The bloom filter we're checking can return false positives. recurse = child_ctx . base_state . children . may_contain ( id ) ; Event :: Internal ( InternalEvent :: TargetedCommand ( * target , cmd . clone ( ) ) ) } Target :: Global => { panic ! ( " " ) } } } } , Event :: WindowConnected => Event :: WindowConnected , Event :: WindowSize ( size ) => { child_ctx . request_layout ( ) ; recurse = ctx . is_root ; Event :: WindowSize ( * size ) } Event :: MouseDown ( mouse_event ) => { WidgetPod :: set_hot_state ( & mut self . inner , child_ctx . command_queue , child_ctx . base_state , child_ctx . window_id , rect , Some ( mouse_event . pos ) , data , env , ) ; recurse = had_active || child_ctx . base_state . is_hot ; let mut mouse_event = mouse_event . clone ( ) ; mouse_event . pos -= rect . origin ( ) . to_vec2 ( ) ; Event :: MouseDown ( mouse_event ) } Event :: MouseUp ( mouse_event ) => { WidgetPod :: set_hot_state ( & mut self . inner , child_ctx . command_queue , child_ctx . base_state , child_ctx . window_id , rect , Some ( mouse_event . pos ) , data , env , ) ; recurse = had_active || child_ctx . base_state . is_hot ; let mut mouse_event = mouse_event . clone ( ) ; mouse_event . pos -= rect . origin ( ) . to_vec2 ( ) ; Event :: MouseUp ( mouse_event ) } Event :: MouseMove ( mouse_event ) => { let hot_changed = WidgetPod :: set_hot_state ( & mut self . inner , child_ctx . command_queue , child_ctx . base_state , child_ctx . window_id , rect , Some ( mouse_event . pos ) , data , env , ) ; recurse = had_active || child_ctx . base_state . is_hot || hot_changed ; let mut mouse_event = mouse_event . clone ( ) ; mouse_event . pos -= rect . origin ( ) . to_vec2 ( ) ; Event :: MouseMove ( mouse_event ) } Event :: KeyDown ( e ) => { recurse = child_ctx . has_focus ( ) ; Event :: KeyDown ( * e ) } Event :: KeyUp ( e ) => { recurse = child_ctx . has_focus ( ) ; Event :: KeyUp ( * e ) } Event :: Paste ( e ) => { recurse = child_ctx . 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 ( ) ) , } ; 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