scene2d.ui refactoring

In my quest to make the world a slightly better place, there is new wiki article: scene2d
This will get you acquainted with the scene2d basics. It doesn’t touch on the scene2d.ui package at all, since that is quite complex and needs its own wiki page.

Overall most people seemed generally open to improving scene2d. Hopefully this means you won’t be too upset when you update libgdx’s SVN and have errors in your project! The changes so far should not be too bad at all. Only the scene2d.ui package has been touched. It now has a proper API — all fields are private and are exposed as necessary. This unsurprisingly turned out very clean and means less breakage in the future, since implementations are not exposed. Some other minor changes were made to keep things organized and consistent. ComboBox was misnamed and so becomes SelectBox so we don’t have problems when we add an actual combo box later. scene2d.ui is fully javadoc’ed (except for the TextField, Widget, WidgetGroup, and Window (and Table) classes which will be done soon). These are javadocs so don’t expect to find glamorous tutorials, but it should prove helpful. We do realize that the scene2d.ui stuff is complex enough that a detailed wiki page is needed. That should be coming soon… or at least eventually.

A while ago I added a class called Scaling to the utils package. This handles up or down scaling a source rectange to a target rectangle. Turns out I accidentally had the functionality for and Scaling.fill swapped, so if you are using this class and are wondering why all your stuff is scaled incorrectly, it’s because I fixed it.


9 thoughts on “scene2d.ui refactoring

  1. Couldn’t at least some of them be protected? It’s impossible to extend a class properly when everything is private without strange solutions like making additional unnecessary fields.

  2. Protected is public API and means your code will break when we change how the class works. Making everything public API for a project that many people use isn’t a great design. Also, if everything is exposed as a field, it cannot be overridden (eg, isChecked, isPressed).

    I would rather discuss how you want to extend a class to make use of it’s private implementation and design for it to be extended in the way you need. Alternatively, and I know this isn’t ideal for small changes, you can copy and paste the 200 lines or so that make up a widget and customize it.

  3. Thanks for the update 😀

    Just trying to work out one thing though, when I use the Image constructor that takes a name. The parameter isn’t stored.

    /** @param region May be null. */
    public Image (TextureRegion region, Scaling scaling, int align, String name) {
    this.scaling = scaling;
    this.align = align;

  4. @nate – in my situation I wanted to change the textures for AtlasRegion (allowing for them to be rescaled depending on the screen size), but everything was private, so I had to write my own class loading atlas data from file. Right now, well, I don’t need it that much. But some things should be protected not private – the things that one might want to change.

  5. Another thing that seems not necessary – TextField requires NinePatches. There should be an option to create it with only a texture/textureregion or with transparent background.

  6. @aaa, TextureAtlas is already pretty public. I’ve made the cursor, background, and selection optional for TextField.

  7. Finally, a decent article on scene2d! I’ve been having to learn it on my own, and even still struggle to deal with Actions, but it’s good to see that it’s getting refactored because holy hell it’s a mess.

    However, you forgot to mention that for any input to work on Actors, you have to attach the stage as an InputHandler to the Input of the app.

  8. i need a widget like TextBox to achieve multi-line input. i tried to write one based on textfield, but it was vulnerable when typing ENTER or something. is there any good solutions?

Leave a Reply

Your email address will not be published.