Skip to content

Conversation

@laundmo
Copy link
Contributor

@laundmo laundmo commented Jan 1, 2026

Objective

Some of these converters are useful to users. I found myself needing to convert to a bevy KeyCode so i looked at all places its mentioned and found convert_physical_key_code. Then i looked up why its not in a pub module and found #5980 and #5986

In #5986 @mockersf expressed wanting these to be turned into From implementations, which Cart later argued against and instead wanted as Into implementations in bevy_winit. But the orphan rule disallows this, as the releavant types are implemented in bevy_input, bevy_window, bevy_math, etc.

Because of this, and the fact its been 3 years, i'm proposing just leaving them as converter functions. The usecases are rare enough that users can deal with some non-idiomatic code and unintuitive function names.

Solution

use converters; -> pub use converters;

I've also written basic docstrings.

Testing

  • cargo check
  • cargo doc

Showcase

bevy_winit::converters is now public, allowing access to the following functions:

Newly exposed functions

  • convert_element_state
    Converts a winit::event::ElementState to a Bevy ButtonState
  • convert_enabled_buttons
    Converts a Bevy EnabledButtons to a winit::window::WindowButtons
  • convert_keyboard_input
    Converts a winit::event::KeyEvent and a window Entity to a Bevy KeyboardInput
  • convert_logical_key
    Converts a winit::keyboard::Key to a Bevy bevy_input::keyboard::Key
  • convert_mouse_button
    Converts a winit::event::MouseButton to a Bevy MouseButton
  • convert_native_key
    Converts a winit::keyboard::NativeKey to a Bevy NativeKey
  • convert_physical_key_code
    Converts a winit::keyboard::PhysicalKey to a Bevy KeyCode
  • convert_physical_native_key_code
    Converts a winit::keyboard::NativeKeyCode to a Bevy NativeKeyCode
  • convert_resize_direction
    Converts a Bevy CompassOctant to a winit::window::ResizeDirection
  • convert_system_cursor_icon
    Converts a Bevy SystemCursorIcon to a winit::window::CursorIcon.
  • convert_touch_input
    Converts a winit::event::Touch, winit::dpi::LogicalPosition<f64> and window Entity to a Bevy TouchInput
  • convert_window_level
    Converts a Bevy WindowLevel to a winit::window::WindowLevel
  • convert_window_theme
    Converts a Bevy WindowTheme to a winit::window::Theme
  • convert_winit_theme
    Converts a winit::window::Theme to a Bevy WindowTheme

@alice-i-cecile alice-i-cecile added A-Windowing Platform-agnostic interface layer to run your app in C-Usability A targeted quality-of-life change that makes Bevy easier to use S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it labels Jan 1, 2026
@alice-i-cecile alice-i-cecile added the C-Docs An addition or correction to our documentation label Jan 1, 2026
@alice-i-cecile alice-i-cecile added this to the 0.18 milestone Jan 1, 2026
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Jan 1, 2026
Merged via the queue into bevyengine:main with commit 6dcc191 Jan 1, 2026
47 checks passed
cart pushed a commit that referenced this pull request Jan 8, 2026
# Objective

- Fixes: #5980

Some of these converters are useful to users. I found myself needing to
convert to a bevy KeyCode so i looked at all places its mentioned and
found `convert_physical_key_code`. Then i looked up why its not in a pub
module and found #5980 and #5986

In #5986 @mockersf expressed wanting these to be turned into From
implementations, which Cart later argued against and instead wanted as
Into implementations in bevy_winit. But the orphan rule disallows this,
as the releavant types are implemented in bevy_input, bevy_window,
bevy_math, etc.

Because of this, and the fact its been 3 years, i'm proposing just
leaving them as converter functions. The usecases are rare enough that
users can deal with some non-idiomatic code and unintuitive function
names.

## Solution

`use converters;` -> `pub use converters;`

I've also written basic docstrings.

## Testing

- cargo check
- cargo doc

---

## Showcase

`bevy_winit::converters` is now public, allowing access to the following
functions:

<details><summary>Newly exposed functions</summary>
<p>


- `convert_element_state`
    Converts a `winit::event::ElementState` to a Bevy `ButtonState`
- `convert_enabled_buttons`
    Converts a Bevy `EnabledButtons` to a `winit::window::WindowButtons`
- `convert_keyboard_input`
Converts a `winit::event::KeyEvent` and a window Entity to a Bevy
`KeyboardInput`
- `convert_logical_key`
Converts a `winit::keyboard::Key` to a Bevy `bevy_input`::keyboard::Key
- `convert_mouse_button`
    Converts a `winit::event::MouseButton` to a Bevy `MouseButton`
- `convert_native_key`
    Converts a `winit::keyboard::NativeKey` to a Bevy `NativeKey`
- `convert_physical_key_code`
    Converts a `winit::keyboard::PhysicalKey` to a Bevy `KeyCode`
- `convert_physical_native_key_code`
Converts a `winit::keyboard::NativeKeyCode` to a Bevy `NativeKeyCode`
- `convert_resize_direction`
Converts a Bevy `CompassOctant` to a `winit::window::ResizeDirection`
- `convert_system_cursor_icon`
    Converts a Bevy `SystemCursorIcon` to a `winit::window::CursorIcon.`
- `convert_touch_input`
Converts a `winit::event::Touch`, `winit::dpi::LogicalPosition<f64>` and
window `Entity` to a Bevy `TouchInput`
- `convert_window_level`
    Converts a Bevy `WindowLevel` to a `winit::window::WindowLevel`
- `convert_window_theme`
    Converts a Bevy `WindowTheme` to a `winit::window::Theme`
- `convert_winit_theme`
    Converts a `winit::window::Theme` to a Bevy `WindowTheme`

</p>
</details>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Windowing Platform-agnostic interface layer to run your app in C-Docs An addition or correction to our documentation C-Usability A targeted quality-of-life change that makes Bevy easier to use S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make bevy_winit::converters module public

3 participants