Skip to content

Windows as entities #4530

@fowenix

Description

@fowenix

What problem does this solve or what need does it fill?

Windows can't be closed from within bevy, #3575 mentions windows as entities and i really like that idea of that, so here is a proposal on how it could be done

What solution would you like?

WindowId is now Entity

Extend Commands with a window method returns WindowCommands similar to how the entity method returns EntityCommands, WindowCommandQueued will implement Command and on write send itself as an event that window backends like bevy_winit will process.

Window should be separated into different components, WindowCursor, WindowCursorPosition, WindowHandle, WindowPosition, WindowResizeConstraints, WindowResolution, WindowTitle, as well as these markers WindowCurrentlyFocused (WindowFocused is taken by a window event), WindowDecorated, WindowResizable.
A world query struct containing all these components and markers should be publicly exposed..

Windows should be spawned like an entity in Commands with a WindowDescriptor component, window backends should query Added<WindowDescriptor> and create the windows for them, while also applying a Window marker confirming they have been created, query Added<Window> or use a WindowCreated event to get newly created windows.

Despawning windows should be done just as entities (as they are now entities), window backends should close/destroy windows their internal component has been dropped, e.g. WinitWindow (wrapper around winit's Window that destroys itself on drop)

A resource called PrimaryWindow contains the entity id of initial window created by WindowPlugin, this replaces Windows::primary

WindowPlugin should change exit_on_close into a enum called ExitCondition with the values OnPrimaryClosed (when primary window is closed), OnAllClosed (when all windows are closed), DontExit (keep app headless)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-WindowingPlatform-agnostic interface layer to run your app inC-Code-QualityA section of code that is hard to understand or changeC-UsabilityA targeted quality-of-life change that makes Bevy easier to useS-Ready-For-ImplementationThis issue is ready for an implementation PR. Go for it!

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions