-
Notifications
You must be signed in to change notification settings - Fork 297
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
Input Refactoring #670
Comments
Nice, this all sounds really promising :) I'm still unsure about storing generic-ly typed events - this may add to the type param noise significantly throughout conrod, increasing the initial perceived complexity. We wouldn't be able to do things like capturing/uncapturing for custom events, without providing some way for the user to do this from their custom widgets that require these custom events after having downcast them. I think I'd prefer to leave fully generic events as a non-goal of conrod, and instead store a For higher-level events (where we do our own logic to create widget-specific events related to capturing etc, like dragging, double-clicking, etc) I'm unsure whether these would be better as part of the same enum, or whether it would be better to have them as a separate event type that is produced? Perhaps the events that we store could be some conrod-specific input event like this: pub struct Input {
time: Time,
kind: Kind,
}
pub enum Kind {
Raw(piston::input::Input),
HighLevel(HighLevel),
} or perhaps it would be better to store both in their own Anyway, I'm really excited about this! Thanks a lot for taking the time to think this through and have a go, it's been on the back of my mind for a while now. I think it'll be a huge benefit offering these high-level abstractions along with a more event oriented approach, and will likely reduce a lot of the load in widget implementations 😸 BTW, the |
Unfortunately Alternative is create a new trait that is implemented for all |
Looking at @bvssvni Creating a new trait that can be used as a trait object sounds like it would give us what we want (dynamic dispatch), but I don't have a good enough understanding of trait objects and 'object-safety' to know for sure if it's possible. I'd need to read up/experiment. Ultimately, I do feel like an
Seems better than:
I thought about just making something like:
The problem with that approach is you can't filter |
For the record, I'm considerably more in favour of using the So far, we haven't run into any need for (or had any requests for) events that piston itself doesn't already provide, so I think it's safe to use the Also, remember that if a user does require some special widget to handle some fancy event, it is trivial for a user to pass their own unique/custom events directly to the arguments of the widget due to conrod's immediate API. I think I'd much prefer requiring a user to do this, rather than providing full dynamically dispatched events for the rare case that a user would find it slightly more convenient. API-wise, going with the |
@psFried btw, you might already know this, but can do rust syntax highlighting on your code blocks by adding
|
@mitchmindtree I agree. Looking more into Any thoughts on what to call these new high-level events? I kind of hate the name pub enum ConrodEvent {
Raw(piston::input::Input),
Interpreted(WidgetEvent)
} Not sure I'm too hot on those names either... Thanks also for the syntax highlighting tip. That was news to me. |
@mitchmindtree That seems like a reasonable assumption for now. Can use One idea is to use same naming convention as in piston-input, where names ending with |
One thing I'm not quite understanding is the difference between some of the Also, coercing a fn handle_event<T: GenericEvent>(&mut self, event: T) {
event.resize(|w, h| {
self.widget_events.push_event(Input::Resize(w, h))
// ... This is clearly a little hacky, but I think a real long-term solution would involve some redesign of the |
There's a few issues with the way that input is currently handled.
I already took a stab at refactoring input events ( #663 ) and discussion on that PR indicated that we could come up with a more general approach that would allow for all types of events to be handled by widgets. The best idea so far would be to have the
Ui
store aVec<T: GenericEvent>
of all events that have occured since the last update. We would then have a wrapper around that information that would peek at those events and add high-level events to that stream as appropriate. The idea would be for widgets to get all events from a single source and just provide a clean api for them to filter out only the events they care about. This might look something like:The conditional closure thing seems to be the established pattern for handling different types of events, and it makes it very clear which events the widget cares about. Ideally, we would add events for things like mouse clicks, double-clicks, drags, widget taking/losing focus. These wouldn't have to be added all at once, though.
The wrapper around this
Vec<T: GenericEvent>
would have to do two things, though. It would need to 'interpret' a series of event in order to provide the high-level (click, drag, etc.) events, and it would also need to provide those events relative to a specific widget, filtering out the events that don't apply to the widget. It may eventually also be useful to provide feedback on which events were handled in order to support things like event 'bubbling'. I'm thinking that it makes sense to just have single conrod events trait that defines/re-exports all the methods for filtering the events using the callback pattern.This will be a pretty big refactor, but I think well worth it. It shouldn't immediately cause any breaking changes. Eventually, though, we should be able to completely eliminate the
Mouse
class since everything could more easily be handled just using the events. I'll try to start on this as soon as I have time. I'll post a link to my working branch whenever I get it pushed up so people can start commenting on specifics.Edit:
The initial PR to add event based input handling (#684) is getting merged. We still have some widgets that need to get switched over to use the new
WidgetInput
methods instead of the oldUserInput
. Once everything is using the new input handler, thenUserInput
will be removed. This issue will track progress towards that.Things that need switched over:
The text was updated successfully, but these errors were encountered: