Nifty GUI: New ideas (proposal maybe)

A month ago I have a small diccusion with @void256 about my ideas for Nifty GUI, I’m having my few modifications (few but big changes) from working branches of Nifty gui… even reworking with its philosophy. In which i still concern of the usefulness of it.

Note that: Nifty is very “abstract” in its code base, it’s not as native as Lemur or Tonegod but a service that lend its self for JME3 renderer. So at the end, I want it to be very flexible and useful. Let see if anyone find these changes as “useful” and worthy as I do:

  1. I let Nifty open its loading process for hooks. So it can let a “Element visitor” and “Type visitor” or listener get noticed when Nifty load its elements and assets.
  2. I rework the event mechanism, in which an event (generic one not just GUI base event) and flow in Nifty’s EventBus just like what other eventbus do.
  3. I also add functional flavours with Groovy as shorter builder, setter getter, text templating, element visitors, selectors…
    You can see 2) and 3) are my efforts to “bring JQuery and all JavaScript godness via Groovy” to Nifty. So basicly there is something like:

// Setter getter, visitor, selector
GQuery("#playBtn").onClick{
it.text = “Clicked”;
}

// Builder
GQuery.panel{
button(“Hello”)
}
// Text templating
GQuery.panel{
textArea("""
long text
yeah $aVar $withoutAnyQuote
Yeah a newline
“”")
}

  1. In the mean time, I also try to define something call “Cascade Style Sheet” CSS for Nifty. It is a language which close to CSS (in fact i’ve use CSS parser) and can also be as short as “LESS” (Scriptable CSS). This CSS define style system which are very familiar to web developers and work beside of the current style system. In other hand, it also brings the style selector to Nifty. Note that currently the style cascade scenerio is unclear (current nifty just parse the style and have a string of the style name, not a hierachy of its ancentors), and can CSS hardly be added if I don’t do Point 1).

Currently i’m switching part of my code to lemur and tonegod because of Nifty performance issues in Android (still happen sometimes) but for Desktop Nifty is still my solid choice. I think this should be open to hear your guys opinions, the usefulness of the changes and the ideas if any. Thanks!

I re read my post I think I don’t explain why i tweak nifty’s Event service.

There are two main reasons (not really solid):

  1. Current event mechanism depend mainly in “id” (yes it’s a string but in a higher overview, it is an naive approach of instance base pub/sub). I add more functions in the event mechanism to make a clearer and more flexible instance filter (via id, attributes, generic marks, classes… etc).
  2. I influented by JavaScript things a lot! JS pub/sub frameworks are very powerful which i simulated with groovy and gpars. Other kind of events (which affect GUI at this end or other… means GUIs can be a event producer, event listener or event consumer) can flow into this eventbus and work smoothly, transparently and can be scripted with fluent syntax. Take a look at this example:

GQuery(“#playBtn”).onClick{
it.text = “Clicked”;
}

the element #playBtn is the “context”- the “it” of the executed piece of code here, a Groovy’s closure. In current Nifty, even I add fluent syntax but there is no way I tied an event with its producer easily without hacking it!!

So I think may be other have better experience can give me an insight on this.