-
-
Notifications
You must be signed in to change notification settings - Fork 21.2k
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
Allow extending CanvasItem in GDExtension #67510
Conversation
8553e40
to
81cff6e
Compare
get_transform
and get_anchorable_rect
methods in GDExtension81cff6e
to
4a48096
Compare
4a48096
to
22541d8
Compare
22541d8
to
ac6e820
Compare
ac6e820
to
1fb32c9
Compare
For the most part, this looks good to me! The one thing I'm unsure about is if there's any compatibility breaking issues with an abstract class becoming virtual? From the perspective of godot-cpp, I think it's fine. But I'm not sure what impact that would have on the Rust or Python bindings? Or, outside of GDExtension, what impact would this have in C#? |
There's some prior discussion here:
From what I can see in those discussions the conclusion was that it doesn't make sense to inherit/instantiate CanvasItem. I'm not sure if this decision has changed since then. About breaking compatibility in C#: Removing the |
@raulsntos Reduz's comment here from 2022 March 5 seems to be in favor of this PR:
|
A little bit after that the conversation continues like this:
Which I interpreted as: CanvasItem would be abstract because it makes no sense to inherit from script or GDExtension. After that, the conversation continues:
So as I understand it, while he seems to be in favor of making some classes virtual, CanvasItem seems to be an exception. |
I don't see why "those make no sense to inherit from script". It absolutely does make sense to inherit CanvasItem in GDExtension. This PR is all that's required, the rest of the code already works. |
Discussed at the GDExtension meeting, and from a GDExtension perspective this seems fine from the technical side. It would be good to know more about both (1) the use-case for inheriting from CanvasItem and (2) why @reduz thought that it would make no sense to inherit from CanvasItem. @BastiaanOlij brought up that we can't extend abstract classes because on the Godot side we have to make an instance of the class we are extending. In theory, because C++ modules can extend abstract classes, we should be able to in GDExtension as well, but this a technical limitation. Previous discussions had the outcome that we needed to create an |
1fb32c9
to
708e4a9
Compare
708e4a9
to
e891f2e
Compare
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.
Some use cases such as implementing an HTML engine (or anything that would involve wanting to create their own UI system without relying on the Godot's internal UI rendering logic) could be a potential use-case for exposing this were discussed in a conversation, so I think this looks good to me.
e891f2e
to
a46c382
Compare
a46c382
to
9db5377
Compare
9db5377
to
7b7099c
Compare
7b7099c
to
04b209f
Compare
04b209f
to
110d852
Compare
Sorry, as I mentioned before, I oppose this. Reasoning is:
|
To make it clear, core code needs to be as bloat free as possible, so any change there has to be extremely well justified with a real-world application that is impeded without this change. It is not the case here. |
Given that my justifications for this PR are not extreme, I'll close this. For my 1D module I will just keep it as a module and note that it's not possible to do this in GDExtension. |
Just to clarify, that is still the case even with this PR. |
This PR allows extending CanvasItem and overriding its
get_transform
method in GDExtension by defining a method called_get_transform
. This will not affect Control or Node2D because both of those classes override their ownget_transform
. The_get_transform
method is therefore only used when implementing a custom CanvasItem.