Runtime Theme Switching

We added a big new feature for applications: dynamic theme switching.

You have certainly seen one of our demo apps, the Widget Browser. You might say: This app already allows for theme switching, you simply choose the new theme from a selectbox. But what actually happened every time a theme had to be switched, was that the whole app started up again with the new theme pre-applied. All theme-specific variants of the app had been generated at compile-time. For a demo app like the widget browser, that’s not a big issue. But for a real, possibly larger app, this might be disadvantageous.

Thus the new solution of switching themes at run-time helps a lot. You don’t have to manage any reloading and reapplying the state of your app. Simply choose a new theme and the framework takes care of all the rest. Your app gets re-dressed in its current state.

Try the runtime theme switching in the latest devel versions of Widget Browser and Feed Reader. See either the selectbox in the header or the preference dialog, respectively.

If you want to use the feature in your own app, that’s also easy. The typical code for a switch is a simple line of code:

qx.theme.manager.Meta.getInstance().setTheme(qx.theme.Classic);

Of course, this cannot only be used for the built-in themes, but also for your own custom themes. If you haven’t created one yet, give it a try now: for instance, extend the Simple theme to setup a custom theme, change some colors in it, add a way to your app to trigger the theme switch, and finally see your app in all new colors!

This feature has landed in master and will be part of the upcoming qooxdoo 2.1 release.

3 thoughts on “Runtime Theme Switching

  1. I remember when theme switching was removed from qooxdoo (I think in 0.8) citing performance issues … did you find a new approach now, that we are getting this back ?

    cheers
    tobi

  2. Yes it has been removed with 0.8. But unfortunately, I can’t recall the exact reason for doing so. With that, I can’t recall the former approach so really can’t give you an answer to your question. But even if its the same algorithm, the browsers speed improvements are still a good reason that its possible today. :)

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">