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

Scene2D DSL refactoring to ease creation of actors without parents #268

Closed
3 tasks done
czyzby opened this issue Apr 16, 2020 · 1 comment
Closed
3 tasks done

Scene2D DSL refactoring to ease creation of actors without parents #268

czyzby opened this issue Apr 16, 2020 · 1 comment
Assignees
Labels
scene2d Issues of the ktx-scene2d module and Scene2D integration in general
Milestone

Comments

@czyzby
Copy link
Member

czyzby commented Apr 16, 2020

  • Add scene2d object with access to Scene2D DSL.
  • Remove KWidget.appendActor.
  • Rename addTooltip and addTextTooltip to tooltip and textTooltip respectively.

ktx-scene2d currently defines top-level factory functions for commonly used parental actors, e.g. table or window. Creating these widgets with KTX DSL is straightforward:

val myTable = table {
  // Define children here.
  label("Text")
}

A common use case that is currently unsupported is creating non-parental actors with the DSL:

val myLabel = label("Text") {
  // Compilation error: top-level factory function for label is not available.
}

We could add similar factory functions for all LibGDX widgets, but it leads to 2 issues:

  • Code duplication: we now have to maintain and test 2 factory functions for each widget.
  • Name collisions: since both nested label children and top-level label widgets are now created with methods with the same name, it's easy to include the wrong one (e.g. via code completion), which leads to unexpected behaviour (e.g. label not added to the parent).

Instead, a unified API for defining root actors - regardless of whether they can or cannot have children - will be provided, using the same set of factory methods. To achieve that, scene2d object will be created, implementing the KWidget interface to have complete access to the Scene2D DSL. Additionally, it would provide factory methods for widgets that are normally never used as children, such as window and dialog. For example:

val myTable = scene2d.table {
  // Children definitions remain the same:
  label("Text")
}
val myLabel = scene2d.label("Text") {
  // Now it works!
}

Migration to the new API would be very simple, as all that needs to be done is appending the scene2d. prefix to the root actor definitions. In the long run, the usability of the module will improve, as now it would be simpler to define parent-less actors (such as labels) and name collisions are no longer an issue.

Existing top-level factory functions would be deprecated and eventually removed in the following release.

Additionally, the following changes will be applied:

  • addTextTooltip and addTooltip use non-standard method names and will be renamed to tooltip and textTooltip to match other widgets.
  • Internal utility method KWidget.appendActor is no longer necessary since Kotlin 1.2 introduced default values for lambda parameters in inlined functions. Since this is a part of the internal API, it will be removed without prior deprecation.
@czyzby czyzby added the scene2d Issues of the ktx-scene2d module and Scene2D integration in general label Apr 16, 2020
@czyzby czyzby added this to the 1.9.10 milestone Apr 16, 2020
@czyzby czyzby self-assigned this Apr 16, 2020
This was referenced Apr 16, 2020
@czyzby czyzby closed this as completed Apr 16, 2020
@czyzby
Copy link
Member Author

czyzby commented Apr 16, 2020

@Quillraven I believe you're using this module in your application. Just a heads up: top-level actor definitions changed a bit and now you have to add scene2d. prefix. See the issue and changelog for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scene2d Issues of the ktx-scene2d module and Scene2D integration in general
Projects
None yet
Development

No branches or pull requests

1 participant