Using extensions is extremely easy, discarding the part where you have to write the theme for them.
In the following example we'll be creating two buttons, one to load or unload our extension theme and one to cycle around three possible styles, one of which we created.
After including our one and only header we'll jump to the callback for the buttons. First one takes care of loading or unloading our extension file, relative to the default theme set (thus the
NULL in the functions first parameter).
The second button, as we said before, will just switch around different styles. In this case we have three of them. The first one is our custom style, named after something very unlikely to find in the default theme. The other two styles are the standard and one more, anchor, which exists in the default and is similar to the default, except the button vanishes when the mouse is not over it.
So what happens if the style switches to our custom one when the extension is loaded? Elementary falls back to the default for the widget.
And the main function, simply enough, will create the window, set the buttons and their callbacks, and just to begin with our button styled we're also loading our extension at the beginning.
In this case we wanted to easily remove extensions, but all adding an extension does is tell Elementary where else it should look for themes when it can't find them in the default theme. Another way to do this is to set the theme search order using elm_theme_set(), but this requires that the developer is careful not to override any user configuration. That can be helped by adding our theme to the end of whatever is already set, like in the following snippet.
If we were using overlays instead of extensions, the same thing applies, but the custom theme must be added to the front of the search path.
In the end, we should be looking at something like this:
That's all. Boringly simple, and the full code in one piece can be found here.
And the code for our extension is here.