godot-kotlin-jvm icon indicating copy to clipboard operation
godot-kotlin-jvm copied to clipboard

`Control` has no setter for many properties such as `anchor*`, `rectPosition`, etc.

Open Humberd opened this issue 4 years ago • 11 comments

open val anchorRight: Double
    get() {
      TransferContext.writeArguments()
      TransferContext.callMethod(rawPtr, ENGINEMETHOD_ENGINECLASS_CONTROL_GET_ANCHOR_RIGHT, DOUBLE)
      return TransferContext.readReturnValue(DOUBLE, false) as Double
    }

Humberd avatar May 01 '21 09:05 Humberd

Hello ! We cannot do much on this. Control::_set_anchor is private method. This is why no setter is generated.

piiertho avatar May 01 '21 10:05 piiertho

I was comparing it with a C# API and it was there

public float AnchorRight
{
  get => this.GetAnchor(Margin.Right);
  set => this._SetAnchor(Margin.Right, value);
}

Humberd avatar May 01 '21 10:05 Humberd

I'm not sure about exposing private c++ method. Is it possible in gdscript ? If so maybe we should expose private method. But I would first look if this can introduce side effects.

EDIT: you also have setAnchor method.

piiertho avatar May 01 '21 11:05 piiertho

I'm against exposing private methods. If one really wants to set it, he can set it dynamically.

chippmann avatar May 01 '21 11:05 chippmann

I agree, the point of being private is that we can't use them

I'm just curious about that following. If they are private, why are they available in the API in the first place?

CedNaru avatar May 01 '21 16:05 CedNaru

hum I'm confused. Isn't a method starting with an underscore is just to say that the function is virtual, not private, like _ready?

image

If this was really private, that wouldn't be in the ClassDB in the first place.

CedNaru avatar May 01 '21 16:05 CedNaru

It is private in control cpp: https://github.com/godotengine/godot/blob/8e68f2e5f48c66bfa80b9bb7746a488afb70086d/scene/gui/control.h#L216

piiertho avatar May 01 '21 17:05 piiertho

yeah but it's still registered to the classDB: https://github.com/godotengine/godot/blob/8e68f2e5f48c66bfa80b9bb7746a488afb70086d/scene/gui/control.cpp#L2834

the true question: Can you call it from Gdscript ? if that's the case we should follow that as a reference

CedNaru avatar May 02 '21 00:05 CedNaru

We can definitely call it from C#

Humberd avatar May 02 '21 06:05 Humberd

The question to me is: Even if other languages allow it for whatever reason, should we really allow it? I mean we are quite strict up until now. Should we be more permissive? To me not the other languages are the source of truth. Cpp is.

chippmann avatar May 07 '21 10:05 chippmann

The question to me is: Even if other languages allow it for whatever reason, should we really allow it? I mean we are quite strict up until now. Should we be more permissive? To me not the other languages are the source of truth. Cpp is.

I totally agree with you. I think we should open an issue on Godot if that's not fixed in master. It is pretty weird to expose private method through ClassDB.

piiertho avatar May 10 '21 07:05 piiertho

We won't expose methods declared private in the api.json. If one want's to call those (which other languages seemingly provide) one can still do that with the not typesafe call functions.

chippmann avatar Nov 24 '22 10:11 chippmann