

As a special guest tonight, we have the \hyperlink{button_example_01}{simple}button example". There are plenty of boxes in it, and to make the cursor buttons that moved a central one around when pressed, we had to use a variety of values for their hints.

To start, let\textquotesingle{}s take a look at the handling of the central button when we were moving it around. To achieve this effect without falling back to a complete manual positioning of the {\ttfamily Evas\+\_\+\+Object} in our canvas, we just put it in a box and played with its alignment within it, as seen in the following snippet of the callback for the pressed buttons. 
\begin{DoxyCodeInclude}
   evas\_object\_size\_hint\_align\_get(app->mid, &ax, &ay);
   \textcolor{keywordflow}{if} (btn == app->cursors.up)
     \{
        ay -= 0.05;
        \textcolor{keywordflow}{if} (ay < 0.0)
          ay = 0.0;
     \}
   \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (btn == app->cursors.down)
     \{
        ay += 0.05;
        \textcolor{keywordflow}{if} (ay > 1.0)
          ay = 1.0;
     \}
   \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (btn == app->cursors.left)
     \{
        ax -= 0.05;
        \textcolor{keywordflow}{if} (ax < 0.0)
          ax = 0.0;
     \}
   \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (btn == app->cursors.right)
     \{
        ax += 0.05;
        \textcolor{keywordflow}{if} (ax > 1.0)
          ax = 1.0;
     \}
   evas\_object\_size\_hint\_align\_set(app->mid, ax, ay);

\end{DoxyCodeInclude}


Not much to it. We get the current alignment of the object and change it by just a little, depending on which button was pressed, then set it again, making sure we stay within the 0.\+0-\/1.\+0 range so the button moves inside the space it has, instead of disappearing under the other objects.

But as useful as an example as that may have been, the usual case with boxes is to set everything at the moment they are created, like we did for everything else in our main function.

The entire layout of our program is made with boxes. We have one set as the resize object for the window, which means it will always be resized with the window. The weight hints set to {\ttfamily E\+V\+A\+S\+\_\+\+H\+I\+N\+T\+\_\+\+E\+X\+P\+A\+N\+D} will tell the window that the box can grow past it\textquotesingle{}s minimum size, which allows resizing of it. 
\begin{DoxyCodeInclude}
   box = elm_box_add(win);
   evas\_object\_size\_hint\_weight\_set(box, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   elm_win_resize_object_add(win, box);
   evas\_object\_show(box);

\end{DoxyCodeInclude}


Two more boxes, set to horizontal, hold the buttons to change the autorepeat configuration used by the buttons. We create each to take over all the available space horizontally, but we don\textquotesingle{}t want them to grow vertically, so we keep that axis of the weight with 0.\+0. Then it gets packed in the main box. 
\begin{DoxyCodeInclude}
   box2 = elm_box_add(win);
   elm_box_horizontal_set(box2, EINA\_TRUE);
   evas\_object\_size\_hint\_weight\_set(box2, EVAS\_HINT\_EXPAND, 0.0);
   elm_box_pack_end(box, box2);
   evas\_object\_show(box2);

\end{DoxyCodeInclude}


The buttons in each of those boxes have nothing special, they are just packed in with their default values and the box will use their minimum size, as set by Elementary itself based on the label, icon, finger size and theme.

But the buttons used to move the central one have a special disposition. The top one first, is placed right into the main box like our other smaller boxes. Set to expand horizontally and not vertically, and in this case we also tell it to fill that space, so it gets resized to take the entire width of the window. 
\begin{DoxyCodeInclude}
   btn = elm_button_add(win);
   elm_button_autorepeat_set(btn, EINA\_TRUE);
   elm_button_autorepeat_initial_timeout_set(btn, 1.0);
   elm_button_autorepeat_gap_timeout_set(btn, 0.5);
   evas\_object\_size\_hint\_weight\_set(btn, EVAS\_HINT\_EXPAND, 0.0);
   evas\_object\_size\_hint\_align\_set(btn, EVAS\_HINT\_FILL, 0.0);
   elm_box_pack_end(box, btn);
   evas\_object\_show(btn);

\end{DoxyCodeInclude}


The bottom one will be the same, but for the other two we need to use a second box set to take as much space as we have, so we can place our side buttons in place and have the big empty space where the central button will move. 
\begin{DoxyCodeInclude}
   box2 = elm_box_add(win);
   elm_box_horizontal_set(box2, EINA\_TRUE);
   evas\_object\_size\_hint\_weight\_set(box2, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   evas\_object\_size\_hint\_align\_set(box2, EVAS\_HINT\_FILL, EVAS\_HINT\_FILL);
   elm_box_pack_end(box, box2);
   evas\_object\_show(box2);

\end{DoxyCodeInclude}


Then the buttons will have their hints inverted to the other top and bottom ones, to expand and fill vertically and keep their minimum size horizontally. 
\begin{DoxyCodeInclude}
   btn = elm_button_add(win);
   elm_button_autorepeat_set(btn, EINA\_TRUE);
   elm_button_autorepeat_initial_timeout_set(btn, 1.0);
   elm_button_autorepeat_gap_timeout_set(btn, 0.5);
   evas\_object\_size\_hint\_weight\_set(btn, 0.0, EVAS\_HINT\_EXPAND);
   evas\_object\_size\_hint\_align\_set(btn, 0.0, EVAS\_HINT\_FILL);
   elm_box_pack_end(box2, btn);
   evas\_object\_show(btn);

\end{DoxyCodeInclude}


The central button takes every thing else. It will ask to be expanded in both directions, but without filling its cell. Changing its alignment by pressing the buttons will make it move around. 
\begin{DoxyCodeInclude}
   btn = elm_button_add(win);
   evas\_object\_size\_hint\_weight\_set(btn, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   elm_box_pack_end(box2, btn);
   evas\_object\_show(btn);

\end{DoxyCodeInclude}


To end, the rightmost button is packed in the smaller box after the central one, and back to the main box we have the bottom button at the end. 