Skip to content
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

Z-index for the Button node? Or... all Control Nodes? #7692

Closed
Qws opened this issue Jan 31, 2017 · 16 comments
Closed

Z-index for the Button node? Or... all Control Nodes? #7692

Qws opened this issue Jan 31, 2017 · 16 comments

Comments

@Qws
Copy link

Qws commented Jan 31, 2017

Why is there no z-index for the Button node, Panel node and I believe all Control Nodes?

When I press on the button in my game, a panel should be sliding from out of camera view into the camera view. The panel should be beneath the button on Z-Index. But instead it overlaps the button.

But for some reason it doesn't has Z-index option. And from the other controls I've seen, none actually do... is there a particle reason for it?

I'm using Godot 2.1.2 Stable.

@reduz
Copy link
Member

reduz commented Jan 31, 2017 via email

@27thLiz
Copy link
Contributor

27thLiz commented Feb 1, 2017

Note that you can still set the z-index for controls manually: some_control.set("z", index).

@AlexHolly
Copy link
Contributor

AlexHolly commented Jun 6, 2017

Edit: Adding multiple CanvasLayers Solved my issue

I tried some_control.set("z", index) it looks like it has no effect I tried 2.1.2 stable and 3.0

I am using Sprites that have a z-index > 0 and the UI should be on top of the sprite but it looks like the z-index from control is 0 and there is no way to change it.

image

extends Control

func _ready():
	set("z", 2)
	$WindowDialog.popup()

image

I could probably solve this somehow with all sprites having a z-index<0 but it looks more like a missing feature or bug.

@jahd2602
Copy link
Contributor

jahd2602 commented Apr 2, 2018

GUI, like most 2D in Godot, is displayed on tree-order. No index is provided.

Sprites are displayed on tree-order, but they have z-index that we can change to fine-tune without too many complications. GUI controls should also have that option.

@henriquelalves
Copy link
Contributor

Giving my two cents here, but z-index should be a CanvasItem property, not a Node2D one (that way it would be editor configurable for both Control and Node2D).

@swarnimarun
Copy link
Contributor

Has anything progressed o this topic?
And I like the idea of Z-Index being property of Canvas_Item. But the problem seems to be of the fact that z-index doesn't work in 3D but Controls work in 3D so how should it implemented.

@MrHoothoot
Copy link

This would be a nice feature. It adds more flexibility.

@reduz
Copy link
Member

reduz commented Jun 25, 2018 via email

@eligt
Copy link
Contributor

eligt commented Aug 17, 2018

@reduz Is input handling the only reason for such limitation? I personally use lots of Labels and other controls exclusively for their display function while all input is handled higher up in a root node (as that's the only level at which input state becomes relevant). Unless there's a different way to display text that I'm missing, then I think it's quite cumbersome to limit z-sorting of UI elements just because of Input handling as 90% of use cases will be for display-only.

@raffomania
Copy link

So, given the following Tree:

SpriteControl
  Sprite
GUIControl

When I set a z-index > 0 on Sprite, as well as Z as relative to true, Sprite still draws over children of GUIControl.

Given that Controls are drawn in tree order, shouldn't GUIControl draw over all children of SpriteControl, if they have Z as relative set to true?

@deepmax
Copy link

deepmax commented Oct 2, 2018

So, given the following Tree:

SpriteControl
  Sprite
GUIControl

When I set a z-index > 0 on Sprite, as well as Z as relative to true, Sprite still draws over children of GUIControl.

Given that Controls are drawn in tree order, shouldn't GUIControl draw over all children of SpriteControl, if they have Z as relative set to true?

Is there any workaround for this?

@AlexHolly
Copy link
Contributor

Like this maybe?
image

@razcore-rad
Copy link
Contributor

razcore-rad commented Jan 19, 2019

I see this is a long-standing discussion. I'll throw my 2 cents in cause I also found it unintuitive that you can't z-order Controls given they're supposed to be visual elements, apart from Containers. I understand that the reason is input handling. @reduz couldn't we then handle input in z-order and if same z-order in tree order?

I was doing something that requires this sort of layout, but I want to then place some nodes on top of others visually. It makes sense to me that they receive input on the visual order too (z-order) more so than tree order, if they were to have a z-order property.
image

This is the node setup:
image

When I do say this:

func _ready() -> void:
	get_child(3).set_as_toplevel(true)

It messes it up so that's not an option
image

As a workaround I see if I set TextureRects' show_behind_parent to true and then proceed to set one to false it visually does the job, so I guess that works, but then as I understand it, the input will still be processed in reverse tree order, I really think these properties should be considered for input.
image

edit: and what happens if we want the overlap to go from right to left? At the moment with it can't be achieved, unless done manually.

@KoBeWi
Copy link
Member

KoBeWi commented May 14, 2019

If you put Control under Node2D, it will inherit its Z-index. That should be anough in most cases, UI is supposed to go on separate CanvasLayer anyways.

@sethboyles
Copy link

One issue with the z-index being tied to tree order is that for the various Containers, display position is also tied to tree order. Meaning if you have a Control that moves out of the bounds of its parent Container (say, in an animation), you have to no way of controlling which bordering elements it goes over or under, it will always go over elements to the left and under elements to the right (or above and below).

The Node2D solution doesn't work here, because then you lose the formatting of the Container.

@Calinou
Copy link
Member

Calinou commented May 15, 2020

Closing in favor of godotengine/godot-proposals#839, as feature proposals are now tracked on the Godot proposals repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests