Git Product home page Git Product logo

egui_winit_platform's Introduction

egui_winit_platform

Latest version Documentation MIT Apache

Platform code to run egui using winit.

Example

We have created a simple example project to show you, how to use this crate.

License

egui_winit_platform is distributed under the terms of both the MIT license and the Apache License (Version 2.0).

See LICENSE-APACHE, LICENSE-MIT.

egui_winit_platform's People

Contributors

clazyzombie avatar cwfitzgerald avatar daniel5gh avatar derivator avatar eupraxia05 avatar gonkalbell avatar gui-yom avatar hasenbanck avatar icandivideby0 avatar jengamon avatar larsjarlvik avatar lpghatguy avatar nehliin avatar nrot avatar parasyte avatar ppakalns avatar rekka avatar rib avatar sapphire-arches avatar setzer22 avatar tgolsson avatar tuguzt avatar villuna avatar wicpar avatar wumpf avatar zachreizner avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

egui_winit_platform's Issues

Text events get created on release of key

if !self.modifier_state.intersects(ModifiersState::CONTROL | ModifiersState::SUPER)

In this line it is not checked whether the key was pressed or released, so egui::Event::Text gets added twice. Once on press, once on release.
I noticed this while using egui::TextEdit.

I think changing this line to

if pressed && !self.modifier_state.intersects(ModifiersState::CONTROL | ModifiersState::SUPER)

fixes the issue

Incompatible with winit 0.28.x

winit 0.28.x introduced some breaking changes that broke egui_winit_platform:

error: Please select a feature to build for unix: `x11`, `wayland`
  --> /home/<redacted>/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.27.5/src/platform_impl/linux/mod.rs:10:1
   |
10 | compile_error!("Please select a feature to build for unix: `x11`, `wayland`");
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0392]: parameter `T` is never used
  --> /home/<redacted>/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.27.5/src/event_loop.rs:35:22
   |
35 | pub struct EventLoop<T: 'static> {
   |                      ^ unused parameter
   |
   = help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData`

error[E0392]: parameter `T` is never used
  --> /home/<redacted>/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.27.5/src/event_loop.rs:46:34
   |
46 | pub struct EventLoopWindowTarget<T: 'static> {
   |                                  ^ unused parameter
   |
   = help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData`

error[E0392]: parameter `T` is never used
   --> /home/<redacted>/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.27.5/src/event_loop.rs:350:27
    |
350 | pub struct EventLoopProxy<T: 'static> {
    |                           ^ unused parameter
    |
    = help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData`

error[E0392]: parameter `T` is never used
   --> /home/<redacted>/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.27.5/src/platform_impl/linux/mod.rs:635:20
    |
635 | pub enum EventLoop<T: 'static> {
    |                    ^ unused parameter
    |
    = help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData`

error[E0392]: parameter `T` is never used
   --> /home/<redacted>/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.27.5/src/platform_impl/linux/mod.rs:642:25
    |
642 | pub enum EventLoopProxy<T: 'static> {
    |                         ^ unused parameter
    |
    = help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData`

error[E0392]: parameter `T` is never used
   --> /home/<redacted>/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.27.5/src/platform_impl/linux/mod.rs:769:32
    |
769 | pub enum EventLoopWindowTarget<T> {
    |                                ^ unused parameter
    |
    = help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData`
    = help: if you intended `T` to be a const parameter, use `const T: usize` instead

For more information about this error, try `rustc --explain E0392`.
error: could not compile `winit` due to 7 previous errors
warning: build failed, waiting for other jobs to finish...

... Not sure where to begin to fix this! Maybe updating the dep on winit would suffice?

winit 1.29.2 support difficulties

I updated winit to 1.29.2, and, because there doesn't seem to be support for it already, decided to quickly update the platform code.

Fortunately, it's all pretty smooth! Although there are a bunch of breaking changes, everything seems to work just fine except one thing: winit::event::WindowEvent::ScaleFactorChanged

The current implementation uses new_inner_size, but this field has been replaced by inner_size_writer in the new version of winit. The new inner_size_writer doesn't allow you to get the suggested inner_size (i.e. new_inner_size) for some reason... So we have to have access to the Window (for Window::inner_size()) Maybe I haven't looked hard enough, but I don't see any way to access the window from anywhere inside Platform (the optional argument in end_frame doesn't work)

My question is: is passing a window reference to handle_event the only way to do this for now?

Note: I will make a pull request when this gets resolved (or should I do it now?)

Support zooming

Unlike the egui_glium platform, this platform doesn't seem to support zoom input. This code from the glium backend seems directly portable to this platform.

New Release

Hello!

In 9fd9278, egui_winit_platform was upgraded to use winit 0.25. However, this has not been published to crates.io yet. Would be it be possible to cut a 0.8.0 release that uses winit 0.25?

Add a convenience function that tells us if egui wants to handle an event

Egui already tells us if it wants keyboard or mouse input, but it would be nice if the integration could sort out for us which winit events that includes. See this prior art for imgui. This is useful to be able to do other stuff with events that egui doesn't care about. If this is something that you would like to see, I could try making a pull request.

Platform API is tricky to use on mobile

Trying to use egui_winit_platform on Android (and I guess the same might be true on iOS) we can only create a winit Window once the application receives a Resumed lifecycle event, even though, ideally, the Platform could be constructed once when initializing the app.

This is awkward because it leads to passing in dummy scale_factor and physical_width/height Descriptor values while we don't yet know anything about the Window we'll be rendering with.

If Platform is initialized with these dummy values then it's also necessary to explicitly update RawInput pixels_per_point and screen_rect to make up for this, which works against the way in which handle_event is designed to handle updating this state automatically in general.

The biggest difficulty though is that the private Platform scale_factor is practically inaccessible and the only (awkward) way this state can be corrected later is by passing a fake ScaleFactorChanged changed event to `handle_events.

All in all I currently do the following to update the Platform state that can't always be determined until the app is Resumed and we get a Window...

                let mut size = window.inner_size();
                let scale_factor = window.scale_factor() as f32;
                let raw_input = platform.raw_input_mut();
                raw_input.pixels_per_point = Some(scale_factor);
                raw_input.screen_rect = Some(egui::Rect::from_min_size(
                    egui::Pos2::default(),
                    egui::vec2(
                        size.width as f32,
                        size.height as f32,
                    ) / scale_factor,
                ));
                platform.handle_event::<Event>(&winit::event::Event::WindowEvent {
                    window_id: window.id(),
                    event: winit::event::WindowEvent::ScaleFactorChanged {
                        scale_factor: scale_factor as f64,
                        new_inner_size: &mut size }
                });

which is uncomfortably dependent on implementation details of egui_winit_platform.

I wonder if it could be best to remove the physical_width/height and scale_factor arguments from Platform::new() considering that this state can't be assumed to be available early on for all platforms.

Maybe there could a set_window API that could be used for associating the Platform with a winit Window which would be an opportunity to initialize both the physical width/height and scale factor which can then be correctly maintained by handle_event.

Perhaps though it's also possible to remove the separate scale_factor state internally and just refer to RawInput::pixels_per_point which seems to be the same scale factor?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.