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

Platform specific traits and requests extensions #3474

Open
kchibisov opened this issue Jan 7, 2024 · 5 comments
Open

Platform specific traits and requests extensions #3474

kchibisov opened this issue Jan 7, 2024 · 5 comments

Comments

@kchibisov
Copy link
Member

We generally could allow users to use the downcast API and IDETs to use extra winit functionality without adding cfg guards, they'll just have to cast before calling something, but if the cast will be always be None it'll be optimized out, so effectively the same as using cfg just your code is always compiling and it's easier to write cross platform code without testing
all the features.

@kchibisov
Copy link
Member Author

Hm, after discussion in winit repo and #winit on matrix we come to conclusion that the only way it can work when the main type has all IDETs, so IDETs can't live in their own crate or at least it doesn't make any sense for them to be there.

However, for extensibility purposes the approach to use vtable like structures and populate them by downcasting event loop to the actual event loop type of the backend is what could be done for out-of-tree backend events.

The actual mechanism for such a thing could look like:

impl FancyBackendVTable {
  fn set_foo_callback<T, F: Fn(&mut T) + 'static>(f:F) {
    self.foo = |app| f(app.downcast_mut::<T>().unwrap());
  }
}

@kchibisov
Copy link
Member Author

Unfortunately, the dyn approach is really tricky to get and rust can't really figure out the type when dyn itself is passed around. However given that EventLoop is generic over State, we can just require everything to be generic over it.

An example of such extensibility is show cased in rust-windowing/winit-next@05b8fd0 .

cc @madsmtm @daxpedda

The point why such thing is even needed, is to erase the MyCoolTrait and not have it in winit-core.

@madsmtm
Copy link
Member

madsmtm commented Feb 2, 2024

I got it, makes sense. But yeah, does require the A: Application bound to be on EventLoop, which is probably fine.

@kchibisov
Copy link
Member Author

kchibisov commented Feb 2, 2024

That's already the case for the run, since we accept the T: Application.

The thing is that user state is only 1 or 1 doing a composition of other states, however the Window could be anything and also with multiple variants could be present at the same time, thus we can't use generics there.

@kchibisov
Copy link
Member Author

kchibisov commented Feb 2, 2024

I figured how to do without generic, but with runtime check instead.

rust-windowing/winit-next#4

So yeah, we can pick whatever we like more. Probably without generic is a bit more flexible.

@madsmtm madsmtm changed the title Define winit-extra crate with platform specific traits and requests extensions Platform specific traits and requests extensions Feb 9, 2024
@daxpedda daxpedda transferred this issue from rust-windowing/winit-next Feb 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants