Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite of the system event system #73

Closed
FloVanGH opened this issue Jan 14, 2018 · 0 comments
Closed

Rewrite of the system event system #73

FloVanGH opened this issue Jan 14, 2018 · 0 comments

Comments

@FloVanGH
Copy link
Contributor

FloVanGH commented Jan 14, 2018

Here my suggestion for a new system event system:

Event capture

Events should be only captured by widgets, that are interested in the event. e.g. mouse events should be only propagate to widgets, that contains the current mouse position.

Propagation

Propagate events from root to leaf (tunnelling / preview events) and than back from leaf to root (bubbling). Events could be interrupted with event.handled = true.

http://csharphelper.com/blog/2015/03/understand-event-bubbling-and-tunneling-in-wpf-and-c/

Default set of event functions for system events

The widget trait should provide for each system event type (mouse, key, resize, ...) a separate function. The default implementation should do nothing. Each widget that is interested in a particular event could be override the corresponding function. After that there is no need to write complex event match statements in each widget.

Example

pub trait Widget {
    fn preview_mouse_down(event: MouseEvent) {}
    fn mouse_down(event: MouseEvent){}
    fn preview_key_pressed(event: KeyEvent) {}
    fn key_pressed(event: KeyEvent) {}
    ...
}

impl Widget for Button {
    fn mouse_down(event: MouseEvent) {
        // do something
        event.handled = true;
   }
}

Handled flag

Each event should provide a handled flag. If the flag is set to true the propagation of the event should stop. The flag should be set from the widget, that handles the event. This should be solve #44.

Additional

A combination with event aggregation or similar to handle custom "user" event should be possible.

@FloVanGH FloVanGH changed the title Preview events Rewrite of the event system Jan 23, 2018
@FloVanGH FloVanGH changed the title Rewrite of the event system Rewrite of the system event system Jan 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant