Skip to content

Expose Node::get_internal_mode()#90040

Open
zaevi wants to merge 1 commit intogodotengine:masterfrom
zaevi:export_node_internal_mode
Open

Expose Node::get_internal_mode()#90040
zaevi wants to merge 1 commit intogodotengine:masterfrom
zaevi:export_node_internal_mode

Conversation

@zaevi
Copy link
Contributor

@zaevi zaevi commented Mar 30, 2024

Expose Node::get_internal_mode() so that we can easily check if the child entered is a internal node:

extends ScrollContainer

func _init():
	child_entered_tree.connect(_child_entered_tree)

func _child_entered_tree(child : Node):
	if child.get_internal_mode() != INTERNAL_MODE_DISABLED:
		return # Ignore its two ScrollBars.

	print(child)

@zaevi zaevi requested review from a team as code owners March 30, 2024 12:42
@AThousandShips
Copy link
Member

AThousandShips commented Mar 30, 2024

See also (this doesn't fully close that as it's a broader topic):

@timothyqiu
Copy link
Member

If you only want to check if a node is internal, you can do something like:

func is_internal(node: Node) -> bool:
	var count := get_child_count()
	if count == 0:
		return true
	
	var index := node.get_index(true)
	if index < get_child(0).get_index(true):
		return true
	if index > get_child(get_child_count() - 1).get_index(true):
		return true
	return false

Copy link
Member

@timothyqiu timothyqiu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description of INTERNAL_MODE_* should also be updated accordingly. They were written for add_child() so "will" is used.

https://github.com/godotengine/godot/blob/fb2bd1f227e07f7facbf2692cf9ad2e2212bd41c/doc/classes/Node.xml#L1306-L1314

@zaevi zaevi force-pushed the export_node_internal_mode branch from fb2bd1f to f125808 Compare March 30, 2024 13:29
</constant>
<constant name="INTERNAL_MODE_DISABLED" value="0" enum="InternalMode">
The node will not be internal.
The node is not internal.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the description of InternalMode as @timothyqiu suggested.

Copy link
Member

@Mickeon Mickeon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not particularly urgent, but the descriptions of add_sibling(), find_child(), find_children(), get_child(), and more could use an update, as they refer to this value solely as the "internal parameter of add_child()"

<method name="get_internal_mode" qualifiers="const">
<return type="int" enum="Node.InternalMode" />
<description>
Returns the node's internal mode. See [enum InternalMode].
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth mentioning when this value is written to. You know as well as me it's in add_child()/add_sibling().

@zaevi zaevi closed this Nov 23, 2024
@zaevi zaevi deleted the export_node_internal_mode branch November 23, 2024 06:37
@zaevi zaevi restored the export_node_internal_mode branch November 23, 2024 06:38
@zaevi zaevi reopened this Nov 23, 2024
@zaevi
Copy link
Contributor Author

zaevi commented Nov 23, 2024

Sorry I deleted this branch accidently. Restored now

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants