

This is an example that illustrates how Eina\+\_\+\+Tiler works for a given set of rectangles. The rectangles must be given in the command line in the form\+: $<$width$>$x$<$height$>$+$<$x offset$>$+$<$y offset$>$ The example will show two panels, the first(input) will show the given rectangles(in different colors) and in the seconds(output) it will show the rectangles given by the tiler. The rectangles will be added one by one every two seconds. A lot of the example deals with actually painting the rectangles so we'll skip over quite a bit of code, but you can see all of it in \hyperlink{eina_tiler_01_8c-example}{eina\+\_\+tiler\+\_\+01.c}.

The first thing of note in our example is the creation of the tiler\+: 
\begin{DoxyCodeInclude}
   tiler = \hyperlink{group__Eina__Tiler__Group_gaec465d28aa8f533db01e41cbf27aa3c9}{eina\_tiler\_new}(maxw, maxh);

\end{DoxyCodeInclude}
 \begin{DoxyNote}{Note}
{\ttfamily maxw} and {\ttfamily maxh} are calculated such that the tiler's size will fully encompass all given rectangles.
\end{DoxyNote}
We'll now look at the function that actually adds rectangles to our tiler. It first checks if we added all rectangles already and if so stops right there\+:  
\begin{DoxyCodeInclude}
\textcolor{keyword}{static} \hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}
process\_input(\textcolor{keywordtype}{void} *data EINA\_UNUSED)
\{
   \hyperlink{struct__Eina__Iterator}{Eina\_Iterator} *itr;
   \hyperlink{struct__Eina__Rectangle}{Eina\_Rectangle} r, *r1;
   \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} out = 0;

   \textcolor{keywordflow}{if} (input\_idx == input\_count)
     \{
        add\_text(\textcolor{stringliteral}{"Done. Close the window to exit"},
                 WINDOW\_PAD, winh - WINDOW\_PAD, winw - 2 * WINDOW\_PAD);
        \textcolor{keywordflow}{return} \hyperlink{group__Eina__Types__Group_ga1feb115f8e9913e806e090d9bd5a7301}{EINA\_FALSE};
     \}

\end{DoxyCodeInclude}


Our function then clears all rectangles given to us by tiler from the last execution. It does this because each rectangle we add may change everything about the output of eina\+\_\+tiler\+: 
\begin{DoxyCodeInclude}

   output\_rects\_reset();

\end{DoxyCodeInclude}


Next we get another rectangle, print it and show it in the input panel\+: 
\begin{DoxyCodeInclude}

   r = input\_rects[input\_idx];
   printf(\textcolor{stringliteral}{"Iteration #%u: %dx%d%+d%+d\(\backslash\)n"}, input\_idx, r.\hyperlink{struct__Eina__Rectangle_af6a92d51ec25ee3464c81297ffc3a330}{w}, r.\hyperlink{struct__Eina__Rectangle_a7570ed17f58fc94be997414a86130074}{h}, r.\hyperlink{struct__Eina__Rectangle_a8358c0791dcf476432687510ca4e5d5c}{x}, r.\hyperlink{struct__Eina__Rectangle_ae74dc834fb71a1f4cd9e3fe11dec3940}{y});
   input\_idx++;
   add\_input\_rect(&r);

\end{DoxyCodeInclude}


We now come to the tiler stuff, we add our new rectangle to it and get a new iterator for the tiler\+: 
\begin{DoxyCodeInclude}

   \hyperlink{group__Eina__Tiler__Group_ga5a7eaf8984afbd801794bb17b8a1b4c4}{eina\_tiler\_rect\_add}(tiler, &r);
   itr = \hyperlink{group__Eina__Tiler__Group_ga4cf2a6df653219c8e9cb7fbcf0c40954}{eina\_tiler\_iterator\_new}(tiler);

\end{DoxyCodeInclude}


We now iterate over our tiler printing every rect it gives us and sowing it in the output panel\+: 
\begin{DoxyCodeInclude}
   \hyperlink{group__Eina__Iterator__Group_gad2f796ac4df0e500d25235c29821faa3}{EINA\_ITERATOR\_FOREACH}(itr, r1)
     \{
        printf(\textcolor{stringliteral}{"\(\backslash\)tOutput #%u: %dx%d%+d%+d\(\backslash\)n"}, out, r1->\hyperlink{struct__Eina__Rectangle_af6a92d51ec25ee3464c81297ffc3a330}{w}, r1->\hyperlink{struct__Eina__Rectangle_a7570ed17f58fc94be997414a86130074}{h}, r1->\hyperlink{struct__Eina__Rectangle_a8358c0791dcf476432687510ca4e5d5c}{x}, r1->\hyperlink{struct__Eina__Rectangle_ae74dc834fb71a1f4cd9e3fe11dec3940}{y});
        add\_output\_rect(r1);
        out++;
     \}

\end{DoxyCodeInclude}


We of course must remember to free our iterator and that's it for this function\+: 
\begin{DoxyCodeInclude}
   \hyperlink{group__Eina__Iterator__Group_gaf9261991a4b05dc63e3401278a3281f8}{eina\_iterator\_free}(itr);

   \textcolor{keywordflow}{return} \hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE};
\}

\end{DoxyCodeInclude}


You should try many different inputs to see how the tiler works, here are a few suggestions\+: \begin{DoxyItemize}
\item 100x100+0+0 100x100+200+200 \item 100x100+0+0 100x100+5+5 100x100+10+10 100x100+15+15 100x100+20+20 \item 100x100+0+0 100x100+100+100 100x100+200+0 100x100+0+200 100x100+200+200 \item 10x10+0+0 10x10+10+10 10x10+20+0 10x10+0+20 10x10+20+20 \end{DoxyItemize}
