doonv / bevy_dev_console

Source-inspired developer console plugin for the Bevy game engine.
Apache License 2.0
121 stars 11 forks source link

Allow open detection #27

Closed Robert-M-Lucas closed 5 months ago

Robert-M-Lucas commented 5 months ago

Objective

Currently, there appears to be no way to tell if the console is open. This is an almost required feature for a console as without it you cannot block inputs while using the console or control how the mouse behaves when the console is open.

Solution

Imagined usage

(with the console only conditionally included in the project)

fn keyboard_update(
    ...,
    #[cfg(debug_assertions)]
    console: Res<ConsoleUiState>
) {
    #[cfg(debug_assertions)]
    if console.open() {
        return;
    }

    ...
}

I can also see this being useful for locking and unlocking the mouse based on whether the console is visible.

Other

There also appears to be a text_focus field however this appears to not be updated while the console is presented. In the future, it'd be nice to have an text_focused() method so that an open console only blocks input when the text field is selected.