summaryrefslogtreecommitdiff
path: root/reference/c/ui/src/ui_container.c
blob: 2dd3b0c5d65595297815987eeeaab41944aa1e53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#define EFL_EO_API_SUPPORT 1
#define EFL_BETA_API_SUPPORT 1

#include <Eina.h>
#include <Elementary.h>
#include <Efl_Ui.h>

/*
 * Efl.UI container exmaples.
 *
 * Load and pack a selection of containers.
 * Each has it's own unique layout and methods which are demonstrated below.
 */

/*
 * TODO Layout
 * TODO - still ELM Conformant
 * TODO - still ELM Mapbuf
 * TODO - still ELM Naviframe
 * TODO - still ELM Scroller
 * TODO - still ELM Table
 */

// quit the app, called if the user clicks the Quit button or the window is deleted
static void
_gui_quit_cb(void *data EINA_UNUSED, const Efl_Event *event EINA_UNUSED)
{
   efl_exit(0);
}

// Load a simple grid layout into the window
static Efl_Ui_Grid *
_ui_grid_setup(Efl_Ui_Win *win)
{
   Efl_Ui_Grid *grid;
   int i;

   grid = efl_add(EFL_UI_GRID_CLASS, win);

   efl_pack_grid_columns_set(grid, 2);
   efl_pack_grid_direction_set(grid, EFL_UI_DIR_RIGHT, EFL_UI_DIR_DOWN);

   efl_add(EFL_UI_BUTTON_CLASS, win,
           efl_text_set(efl_added, "Long Button"),
           efl_pack_grid(grid, efl_added, 0, 2, 2, 1));

   for (i = 1; i <= 4; i++)
     {
        efl_add(EFL_UI_BUTTON_CLASS, win,
                efl_text_set(efl_added, eina_slstr_printf("Grid %d", i)),
                efl_pack(grid, efl_added));
     }

   return grid;
}

// Load some boxes - a horizontal one for the window layout and a vertical
// one to contain a flow
static void
_ui_boxes_setup(Efl_Ui_Win *win)
{
   Efl_Ui_Box *hbox, *box, *button;
   int i;

   hbox = efl_add(EFL_UI_BOX_CLASS, win,
                 efl_ui_direction_set(efl_added, EFL_UI_DIR_HORIZONTAL),
                 efl_pack_padding_set(efl_added, 5, 0, EINA_TRUE),
                 efl_content_set(win, efl_added));

   box = efl_add(EFL_UI_BOX_CLASS, win,
                 efl_pack(hbox, efl_added));
   efl_pack(hbox, _ui_grid_setup(win));

   for (i = 1; i <= 4; i++)
     {
        button = efl_add(EFL_UI_BUTTON_CLASS, win,
                         efl_text_set(efl_added, eina_slstr_printf("Boxed %d", i)),
                         efl_pack(box, efl_added));

        if (i == 2)
          efl_gfx_size_hint_max_set(button, EINA_SIZE2D(100, 50));
     }

}

// Load a vertical and horizontal split into the window
// TODO re-enable this when it actually works in EFL
static void
_ui_panes_setup(Efl_Ui_Win *win)
{
   Efl_Ui_Panes *split, *horiz_split;

   split = efl_add(EFL_UI_PANES_CLASS, win,
                   efl_content_set(win, efl_added),
                   efl_ui_panes_split_ratio_set(efl_added,  0.75));

   efl_add(EFL_UI_BOX_CLASS, win,
           efl_content_set(efl_part(split, "first"), efl_added));

   horiz_split = efl_add(EFL_UI_PANES_CLASS, win,
                         efl_content_set(efl_part(split, "second"), efl_added),
                         efl_ui_panes_split_ratio_set(efl_added,  0.85));

   efl_add(EFL_UI_BOX_CLASS, win,
           efl_content_set(efl_part(horiz_split, "first"), efl_added));

   efl_add(EFL_UI_BUTTON_CLASS, win,
           efl_text_set(efl_added, "Quit"),
           efl_content_set(efl_part(horiz_split, "second"), efl_added),
           efl_event_callback_add(efl_added, EFL_UI_EVENT_CLICKED,
                                  _gui_quit_cb, efl_added));
}

EAPI_MAIN void
efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
{
   Eo *win;

   win = efl_add(EFL_UI_WIN_CLASS, NULL,
                 efl_ui_win_type_set(efl_added, EFL_UI_WIN_BASIC),
                 efl_text_set(efl_added, "Hello World"),
                 efl_ui_win_autodel_set(efl_added, EINA_TRUE));

//   _ui_panes_setup(win);
   _ui_boxes_setup(win);
   // when the user clicks "close" on a window there is a request to delete
   efl_event_callback_add(win, EFL_UI_WIN_EVENT_DELETE_REQUEST, _gui_quit_cb, NULL);


   efl_gfx_size_set(win, EINA_SIZE2D(350, 250));
}
EFL_MAIN()