Mobile native

[UI Sample] Box Sample Overview

The Box sample demonstrates how to display a number of rectangles using the EFL smart object - box component. The box component is a convenient smart object that packs the children inside the box in a sequence. Evas has pre-made functions to define the box size and the alignment inside its cell space.

The following figure illustrates the box component sample screen.

Figure: Box screen

Box screen

Implementation

The create_base_gui() function creates a window, retrieves the Evas canvas, and adds the box and rectangle objects to the retrieved canvas. The rectangle object is appended to the box object that works as a container component.

static void
create_base_gui(appdata_s *ad)
{
   // Window 
   ad->win = elm_win_util_standard_add(PACKAGE, PACKAGE);
   elm_win_autodel_set(ad->win, EINA_TRUE);
   
   evas_object_smart_callback_add(ad->win, "delete,request", win_delete_request_cb, NULL);
   eext_object_event_callback_add(ad->win, EEXT_CALLBACK_BACK, win_back_cb, ad);
   
   Evas *e = evas_object_evas_get(ad->win);
   Evas_Object *box, *rect;
   int i;

   box = evas_object_box_add(e); // Add a new box object on the provided canvas
   evas_object_show(box);

   for (i = 1; i <= 5; i++)
   {
      rect = evas_object_rectangle_add(e);
      evas_object_size_hint_min_set(rect, 50, 50);
      evas_object_color_set(rect,
                            rand() % 256,
                            rand() % 256,
                            rand() % 256,
                            255);
      evas_object_show(rect);
      evas_object_box_append(box, rect); // Append a new child object to the given box object
   }

   // Show the window after the base GUI is set up
   evas_object_show(ad->win);
}
Go to top