-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a gizmo-based overlay to show UI node outlines #10420
Conversation
You added a new feature but didn't update the readme. Please run |
@@ -12,6 +12,8 @@ pub mod ui_material; | |||
pub mod update; | |||
pub mod widget; | |||
|
|||
#[cfg(feature = "debug")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should rename this feature to something like debug_layout
, just to reduce ambiguity.
} | ||
fn finish(&self, _app: &mut App) { | ||
info!( | ||
"The bevy_ui debug overlay is active!\n\ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"The bevy_ui debug overlay is active!\n\ | |
"The bevy_ui layout debug overlay is active!\n\ |
----------------------------------------------\n\ | ||
\n\ | ||
This will show the outline of UI nodes.\n\ | ||
Press `F9` to switch between debug mods." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Press `F9` to switch between debug mods." | |
Press `F9` to cycle between debug modes." |
This needs to move to the |
I really don't want to set the precedent of scattering magic keybinds throughout the codebase. IMO that is out of scope of any library, and is the responsibility of a user's keybinding plugin. Hardcoding these - even if they are configurable defaults - means users will need to know where all these mappings happen throughout the code, and where to disable them. I'd much prefer the crate exposes an event. This keeps the library unopinionated about what is triggering the event, because the source can be anything - a ui button, a keypress, etc. If we want to start developing default keybinds, that belongs in a separate |
In this specific case, you have to explicitly enable the behavior. As a reminder: this is strictly for debugging, it would never make it to the player, and it is off by default (in the sense it is not compiled into the app, it's behind a I already took a careful look at user impact when adding this feature to cuicui_layout. I think your point stands for situations where those keybindings exist for regular behaviors or for implicitly brought-in code. But it hold little water in this specific situation: The keybinding is printed in the console, it is a debugging feature, it only exists when the feature is enabled, it must be enabled explicitly and it is a rarely used key.
I really don't want to lock that kind of feature behind having to write additional code. I see your point if the main way of interacting with bevy debugging feature is through the editor, but fundamentally, there is no reason to lock this behind an editor, writing boilerplate or bringing in a dependency. |
Users might already use F9 for keybinds in their game, however. Perhaps we could make it configurable under the plugin setup? DefaultPlugins.set(UiDebugPlugin {
trigger_key: Keycode::SPACE, // Defaults to F9
}); |
I'm not interested in implementing this feature. I'm really busy and have much more interesting (and profitable) things to do. But anyone who wants it, feel free to take the mantle. I wrote the most difficult part, all is left is to do is integrate it with bevy. The PR is up for adoption. |
# Objective - This is an adopted version of #10420 - The objective is to help debugging the Ui layout tree with helpful outlines, that can be easily enabled/disabled ## Solution - Like #10420, the solution is using the bevy_gizmos in outlining the nodes --- ## Changelog ### Added - Added debug_overlay mod to `bevy_dev_tools` - Added bevy_ui_debug feature to `bevy_dev_tools` ## How to use - The user must use `bevy_dev_tools` feature in TOML - The user must use the plugin UiDebugPlugin, that can be found on `bevy::dev_tools::debug_overlay` - Finally, to enable the function, the user must set `UiDebugOptions::enabled` to true Someone can easily toggle the function with something like: ```rust fn toggle_overlay(input: Res<ButtonInput<KeyCode>>, options: ResMut<UiDebugOptions>) { if input.just_pressed(KeyCode::Space) { // The toggle method will enable if disabled and disable if enabled options.toggle(); } } ``` Note that this feature can be disabled from dev_tools, as its in fact behind a default feature there, being the feature bevy_ui_debug. # Limitations Currently, due to limitations with gizmos itself, it's not possible to support this feature to more the one window, so this tool is limited to the primary window only. # Showcase ![image](https://github.com/bevyengine/bevy/assets/126117294/ce9d70e6-0a57-4fa9-9753-ff5a9d82c009) Ui example with debug_overlay enabled ![image](https://github.com/bevyengine/bevy/assets/126117294/e945015c-5bab-4d7f-9273-472aabaf25a9) And disabled --------- Co-authored-by: Nicola Papale <[email protected]> Co-authored-by: Pablo Reinhardt <[email protected]> Co-authored-by: Alice Cecile <[email protected]>
# Objective - This is an adopted version of #10420 - The objective is to help debugging the Ui layout tree with helpful outlines, that can be easily enabled/disabled ## Solution - Like #10420, the solution is using the bevy_gizmos in outlining the nodes --- ## Changelog ### Added - Added debug_overlay mod to `bevy_dev_tools` - Added bevy_ui_debug feature to `bevy_dev_tools` ## How to use - The user must use `bevy_dev_tools` feature in TOML - The user must use the plugin UiDebugPlugin, that can be found on `bevy::dev_tools::debug_overlay` - Finally, to enable the function, the user must set `UiDebugOptions::enabled` to true Someone can easily toggle the function with something like: ```rust fn toggle_overlay(input: Res<ButtonInput<KeyCode>>, options: ResMut<UiDebugOptions>) { if input.just_pressed(KeyCode::Space) { // The toggle method will enable if disabled and disable if enabled options.toggle(); } } ``` Note that this feature can be disabled from dev_tools, as its in fact behind a default feature there, being the feature bevy_ui_debug. # Limitations Currently, due to limitations with gizmos itself, it's not possible to support this feature to more the one window, so this tool is limited to the primary window only. # Showcase ![image](https://github.com/bevyengine/bevy/assets/126117294/ce9d70e6-0a57-4fa9-9753-ff5a9d82c009) Ui example with debug_overlay enabled ![image](https://github.com/bevyengine/bevy/assets/126117294/e945015c-5bab-4d7f-9273-472aabaf25a9) And disabled --------- Co-authored-by: Nicola Papale <[email protected]> Co-authored-by: Pablo Reinhardt <[email protected]> Co-authored-by: Alice Cecile <[email protected]>
Objective
It is useful to be able to visualize the outline of UI nodes. Especially if you have intermediary transparent containers, it's useful to see how they look like.
Currently, bevy doesn't have any way to visualize UI nodes. The current best workaround is to set the
Outline
component, however, this may interfere with user code.cuicui_layout
does have a debug overlay though.Solution
Port the
cuicui_layout
debug overlay to bevy UI.An interesting aspect of the
cuicui_layout
debug overlay is that it "insets" the outline of containers set within other containers. It can be otherwise hard to see which node contains what.Design
order
set to255
, and UI disabled.RenderLayers
of gizmos to16
Limitations
Currently, enabling the UI debug overlay monopolizes gizmos, it will disable gizmos rendering from other sources than the debug overlay. #10342 would allow to fix this.
Changelog
Add a UI outline debug overlay.
It is enabled as follow:
--feature bevy_ui_debug
cargo feature (off by defaultF9
to toggle the UI debug overlay (instructions are printed in the log output)