

Using extensions is extremely easy, discarding the part where you have to write the theme for them.

In the following example we\textquotesingle{}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\textquotesingle{}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 {\ttfamily N\+U\+LL} in the functions first parameter). 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\textcolor{preprocessor}{\#include <Elementary.h>}}
\DoxyCodeLine{\textcolor{keyword}{static} \textcolor{keywordtype}{void}}
\DoxyCodeLine{btn\_extension\_click\_cb(\textcolor{keywordtype}{void} *data \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}}, \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}} *btn, \textcolor{keywordtype}{void} *ev \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}})}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \textcolor{keyword}{const} \textcolor{keywordtype}{char} *lbl = elm\_object\_text\_get(btn);}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{if} (!strncmp(lbl, \textcolor{stringliteral}{"Load"}, 4))}
\DoxyCodeLine{     \{}
\DoxyCodeLine{        \mbox{\hyperlink{group__Elm__Theme_ga71d7575c05248a5c6d7ae3b525e964cc}{elm\_theme\_extension\_add}}(NULL, edj\_path);}
\DoxyCodeLine{        elm\_object\_text\_set(btn, \textcolor{stringliteral}{"Unload extension"});}
\DoxyCodeLine{     \}}
\DoxyCodeLine{   \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (!strncmp(lbl, \textcolor{stringliteral}{"Unload"}, 6))}
\DoxyCodeLine{     \{}
\DoxyCodeLine{        \mbox{\hyperlink{group__Elm__Theme_ga474684d4227bc309a1ce314ff16c70a7}{elm\_theme\_extension\_del}}(NULL, edj\_path);}
\DoxyCodeLine{        elm\_object\_text\_set(btn, \textcolor{stringliteral}{"Load extension"});}
\DoxyCodeLine{     \}}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}


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. 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\textcolor{keyword}{static} \textcolor{keywordtype}{void}}
\DoxyCodeLine{btn\_style\_click\_cb(\textcolor{keywordtype}{void} *data \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}}, \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}} *btn, \textcolor{keywordtype}{void} *ev \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}})}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \textcolor{keyword}{const} \textcolor{keywordtype}{char} *styles[] = \{}
\DoxyCodeLine{        \textcolor{stringliteral}{"chucknorris"},}
\DoxyCodeLine{        \textcolor{stringliteral}{"default"},}
\DoxyCodeLine{        \textcolor{stringliteral}{"anchor"}}
\DoxyCodeLine{   \};}
\DoxyCodeLine{   \textcolor{keyword}{static} \textcolor{keywordtype}{int} sel\_style = 0;}
\DoxyCodeLine{}
\DoxyCodeLine{   sel\_style = (sel\_style + 1) \% 3;}
\DoxyCodeLine{   \mbox{\hyperlink{group__Elm__Styles_ga7fc2d1f9ba723470da7a05799c49f7fe}{elm\_object\_style\_set}}(btn, styles[sel\_style]);}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}


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\textquotesingle{}re also loading our extension at the beginning. 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{EAPI\_MAIN \textcolor{keywordtype}{int}}
\DoxyCodeLine{elm\_main(\textcolor{keywordtype}{int} argc \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}}, \textcolor{keywordtype}{char} **argv \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}})}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}} *win, *box, *btn;}
\DoxyCodeLine{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Elm__General_ga7a05f37fd3a019da5e26c5fc91fcd937}{elm\_policy\_set}}(\mbox{\hyperlink{group__Elm__General_ggaa16f3378ecdbf660fa378402e3c5a0a9a02fadb6faada04b19d0fa42c11a8d32a}{ELM\_POLICY\_QUIT}}, \mbox{\hyperlink{group__Elm__General_gga46af37e6ac2c406321060be827117196abbe0962d88ae12afe1a173da881f56cd}{ELM\_POLICY\_QUIT\_LAST\_WINDOW\_CLOSED}});}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{preprocessor}{\#ifdef PACKAGE\_DATA\_DIR}}
\DoxyCodeLine{   \mbox{\hyperlink{group__Elm__App_ga4e875d27efb02b4c425619957c0ae7c7}{elm\_app\_compile\_data\_dir\_set}}(PACKAGE\_DATA\_DIR);}
\DoxyCodeLine{\textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{   \textcolor{keywordflow}{if} (\mbox{\hyperlink{group__Ecore__File__Group_gaf5a3cc8bd9bf69a3ebce0678fe799016}{ecore\_file\_exists}}(\textcolor{stringliteral}{"./theme\_example.edj"}))}
\DoxyCodeLine{     \{}
\DoxyCodeLine{        strcpy(edj\_path, \textcolor{stringliteral}{"./theme\_example.edj"});}
\DoxyCodeLine{     \}}
\DoxyCodeLine{   \textcolor{keywordflow}{else}}
\DoxyCodeLine{     \{}
\DoxyCodeLine{        \mbox{\hyperlink{group__Elm__App_ga0cefb59efb95841232561d67e34d9909}{elm\_app\_info\_set}}(elm\_main, \textcolor{stringliteral}{"elementary"}, \textcolor{stringliteral}{"examples/theme\_example.edj"});}
\DoxyCodeLine{        snprintf(edj\_path, \textcolor{keyword}{sizeof}(edj\_path), \textcolor{stringliteral}{"\%s/examples/theme\_example.edj"},}
\DoxyCodeLine{                 \mbox{\hyperlink{group__Elm__App_ga92a09dbf88cc1ca3eab51c51dea589d0}{elm\_app\_data\_dir\_get}}());}
\DoxyCodeLine{     \}}
\DoxyCodeLine{   \mbox{\hyperlink{group__Elm__Theme_ga71d7575c05248a5c6d7ae3b525e964cc}{elm\_theme\_extension\_add}}(NULL, edj\_path);}
\DoxyCodeLine{}
\DoxyCodeLine{   win = \mbox{\hyperlink{group__Elm__Win_gac75d7752662fab73d6420706ce5be996}{elm\_win\_util\_standard\_add}}(\textcolor{stringliteral}{"theme"}, \textcolor{stringliteral}{"Theme example"});}
\DoxyCodeLine{   \mbox{\hyperlink{group__Elm__Win_ga9a16a2f8c9fd5b6e9203ed9dcb53ea8b}{elm\_win\_autodel\_set}}(win, \mbox{\hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE}});}
\DoxyCodeLine{}
\DoxyCodeLine{   box = \mbox{\hyperlink{group__Elm__Box_ga3d0998b60ada633bacfa8869a921cfd7}{elm\_box\_add}}(win);}
\DoxyCodeLine{   evas\_object\_size\_hint\_weight\_set(box, \mbox{\hyperlink{Evas__Common_8h_aa47c85083d3dae0111c21ec49359306a}{EVAS\_HINT\_EXPAND}}, \mbox{\hyperlink{Evas__Common_8h_aa47c85083d3dae0111c21ec49359306a}{EVAS\_HINT\_EXPAND}});}
\DoxyCodeLine{   \mbox{\hyperlink{group__Elm__Win_ga505d6bd217e5ee01e82b548ec35986eb}{elm\_win\_resize\_object\_add}}(win, box);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}}(box);}
\DoxyCodeLine{}
\DoxyCodeLine{   btn = \mbox{\hyperlink{group__Elm__Button_ga0021b9d86d822367035843ed18bc6ea9}{elm\_button\_add}}(win);}
\DoxyCodeLine{   elm\_object\_text\_set(btn, \textcolor{stringliteral}{"Unload extension"});}
\DoxyCodeLine{   elm\_box\_pack\_end(box, btn);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}}(btn);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Smart__Object__Group_ga18a8b179f94d21b2b09e19db11741061}{evas\_object\_smart\_callback\_add}}(btn, \textcolor{stringliteral}{"clicked"}, btn\_extension\_click\_cb, NULL);}
\DoxyCodeLine{}
\DoxyCodeLine{   btn = \mbox{\hyperlink{group__Elm__Button_ga0021b9d86d822367035843ed18bc6ea9}{elm\_button\_add}}(win);}
\DoxyCodeLine{   elm\_object\_text\_set(btn, \textcolor{stringliteral}{"Switch style"});}
\DoxyCodeLine{   \mbox{\hyperlink{group__Elm__Styles_ga7fc2d1f9ba723470da7a05799c49f7fe}{elm\_object\_style\_set}}(btn, \textcolor{stringliteral}{"chucknorris"});}
\DoxyCodeLine{   elm\_box\_pack\_end(box, btn);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}}(btn);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Smart__Object__Group_ga18a8b179f94d21b2b09e19db11741061}{evas\_object\_smart\_callback\_add}}(btn, \textcolor{stringliteral}{"clicked"}, btn\_style\_click\_cb, NULL);}
\DoxyCodeLine{}
\DoxyCodeLine{   evas\_object\_resize(win, 300, 320);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}}(win);}
\DoxyCodeLine{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Elm__General_gadf2553f83e6b0b9c7fbe054019a664a1}{elm\_run}}();}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{return} 0;}
\DoxyCodeLine{\}}
\DoxyCodeLine{\mbox{\hyperlink{group__Elm__General_ga50fe52d513f7e89c9c770afd76de7ad9}{ELM\_MAIN}}()}

\end{DoxyCodeInclude}


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\textquotesingle{}t find them in the default theme. Another way to do this is to set the theme search order using \mbox{\hyperlink{group__Elm__Theme_ga3b3e6f54149ccdc8dfec774e05e8bf1c}{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. 
\begin{DoxyCode}{0}
\DoxyCodeLine{\textcolor{keywordtype}{char} buf[4096];}
\DoxyCodeLine{snprintf(buf, \textcolor{keyword}{sizeof}(buf), \textcolor{stringliteral}{"\%s:./theme\_example.edj"}, elme\_theme\_get(NULL);}
\DoxyCodeLine{\mbox{\hyperlink{group__Elm__Theme_ga3b3e6f54149ccdc8dfec774e05e8bf1c}{elm\_theme\_set}}(NULL, buf);}
\end{DoxyCode}


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\+:

 
\begin{DoxyImageNoCaption}
  \mbox{\includegraphics[width=\textwidth]{screenshots/theme_example_01}}
\end{DoxyImageNoCaption}


That\textquotesingle{}s all. Boringly simple, and the full code in one piece can be found \mbox{\hyperlink{theme_example_01_8c-example}{here}}.

And the code for our extension is \mbox{\hyperlink{theme_example_8edc-example}{here}}. 