Skip to content

Discussion: mobile and web Window creation APIs #696

@Osspial

Description

@Osspial

Right now, Winit exposes window creation and modification functionality the same way on all platforms. Is that something that makes sense? On mobile, only one function in WindowBuilder (with_multitouch) actually does anything, and only three functions in Window (get_hidpi_factor, get_inner_size, and get_outer_size) do anything useful. A few more functions are implemented for Emscripten, but it has much more in common with mobile platforms than it does with desktop platforms.

Should we expose an entirely different window structure for these platforms that better reflects the underlying capabilities? I don't have much experience with those platforms, but I've written up an example of what I think that sort of API would look like:

  • Bikeshedding aside, I'm calling it View.
  • For creation, View exposes list_views(&EventsLoop) -> impl Iterator<View>, which gets an iterator over all windows the OS provides.
  • View exposes the following methods:
    • set_multitouch(&self, bool): enables or disables multitouch support.
    • get_hidpi_factor(&self) -> f32: gets the HiDPI factor.
    • get_size(&self) -> LogicalSize: gets the window's size.
  • Winit adds two new public platform modules:
    • mobile
      • Exposes extension trait ViewExt with the following methods:
        • set_valid_orientations(ValidScreenOrientations): used to set the valid screen orientations.
      • Adds ValidScreenOrientations struct, defined as followed:
        pub struct ValidScreenOrientations {
            pub portrait: bool,
            pub landscape: bool
        }
    • emscripten
      • Exposes extension trait ViewExt with the following methods:
        • set_fullscreen(bool): sets if the window is fullscreen or not
        • grab_cursor(bool): grabs or ungrabs the cursor
        • hide_cursor(bool): hides or shows the cursor

That design may be infeasible one way or another, so any API corrections are appreciated.

Relevant to #33
cc @francesca64 @seivan @mtak- @willglynn

EDIT: Renamed WindowBorrowed to View since that's a better name for it, and added a reference to EventsLoop in list_views.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C - needs discussionDirection must be ironed outDS - androidAffects the Android backendDS - uikitAffects the UIKit backend (iOS, tvOS, watchOS, visionOS)DS - webAffects the Web backend (WebAssembly/WASM)S - apiDesign and usability

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions