summaryrefslogtreecommitdiff
path: root/reference/c/ui/src/focus_main.c
blob: 77ea59f88454642ecfd32ec851323d27d0174863 (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
#define EFL_EO_API_SUPPORT 1
#define EFL_BETA_API_SUPPORT 1

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

static void
_gui_about_clicked_cb(void *data EINA_UNUSED, const Efl_Event *event EINA_UNUSED)
{
   printf("Clicked About\n");
}

static void
_gui_quit_clicked_cb(void *data EINA_UNUSED, const Efl_Event *event EINA_UNUSED)
{
   printf("Clicked Quit\n");
   efl_exit(0);
}

static void
_focus_changed(void *data EINA_UNUSED, const Efl_Event *event)
{
   printf("Focus for object '%s' changed to %d\n",
          efl_text_get(event->object),  efl_ui_focus_object_focus_get(event->object));
}

static void
_gui_setup()
{
   Eo *win, *box, *hbox, *about;

   win = efl_add(EFL_UI_WIN_CLASS, efl_main_loop_get(),
                 efl_ui_win_type_set(efl_added, EFL_UI_WIN_TYPE_BASIC),
                 efl_text_set(efl_added, "Hello World"),
                 efl_event_callback_add(efl_added,
                                        EFL_UI_WIN_EVENT_DELETE_REQUEST,
                                        _gui_quit_clicked_cb, NULL),
                 efl_ui_win_autodel_set(efl_added, EINA_TRUE));

   box = efl_add(EFL_UI_BOX_CLASS, win,
                efl_content_set(win, efl_added),
                efl_gfx_hint_size_min_set(efl_added, EINA_SIZE2D(360, 240)));

  efl_add(EFL_UI_TEXT_CLASS, box,
          efl_text_set(efl_added, "Label"),
          efl_text_interactive_editable_set(efl_added, EINA_FALSE),
          efl_event_callback_add(efl_added, EFL_UI_FOCUS_OBJECT_EVENT_FOCUS_CHANGED,
                                 _focus_changed, NULL),
          efl_pack(box, efl_added));

   hbox = efl_add(EFL_UI_BOX_CLASS, box,
                  efl_ui_layout_orientation_set(efl_added, EFL_UI_LAYOUT_ORIENTATION_HORIZONTAL),
                  efl_gfx_hint_weight_set(efl_added, 1.0, 0.1),
                  efl_pack(box, efl_added));

   about = efl_add(EFL_UI_BUTTON_CLASS, hbox,
                   efl_text_set(efl_added, "About"),
                   efl_pack(hbox, efl_added),
                   efl_event_callback_add(efl_added, EFL_UI_FOCUS_OBJECT_EVENT_FOCUS_CHANGED,
                                          _focus_changed, NULL),
                   efl_event_callback_add(efl_added, EFL_UI_EVENT_CLICKED,
                                          _gui_about_clicked_cb, efl_added));

   efl_add(EFL_UI_BUTTON_CLASS, hbox,
           efl_text_set(efl_added, "Quit"),
           efl_pack(hbox, efl_added),
           efl_event_callback_add(efl_added, EFL_UI_FOCUS_OBJECT_EVENT_FOCUS_CHANGED,
                                  _focus_changed, NULL),
           efl_event_callback_add(efl_added, EFL_UI_EVENT_CLICKED,
                                  _gui_quit_clicked_cb, efl_added));

   efl_ui_focus_util_focus(about);
}

EAPI_MAIN void
efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
{
   _gui_setup();
}
EFL_MAIN()