summaryrefslogtreecommitdiff
path: root/src/bin/egui_gui/descview.c
blob: caeeb06eeef3ac5a82395b87edea9af236683fe6 (plain) (blame)
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
#include <Elementary.h>
#include <Eolian.h>

#include "ffi_glue.h"
#include "egui_log.h"
#include "props_helper.h"
#include "egui_logic_private.h"
#include "descview.h"

#include "elm_widget_container.h"

static Elm_Genlist_Item_Class *_itc_desc = NULL;
static Eo *desc_list = NULL;

// Used to loop in _description_build function
static char *descs[] = { DB_DEF_NAME, DB_DEF_CLASS, DB_DEF_PUBLIC, NULL };

void
descview_build(const Gui_Widget *wdg)
{
   eo_do(desc_list, elm_obj_genlist_clear());

   int i;
   for (i = 0; descs[i]; i++)
     {
        It_Data *it_data = IT_DATA_BUILD(DESCRIPTION_TYPE, wdg);
        it_data->desc = descs[i];
        elm_genlist_item_append(desc_list, _itc_desc, it_data, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
     }
}

static Eina_Bool
_wdg_public_change_cb(void *data, Eo *obj, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)
{
   Eina_Bool state;
   eo_do(obj, state = elm_obj_check_state_get());
   wdg_public_set(data, state);

   return EO_CALLBACK_CONTINUE;
}

static Eina_Bool
_wdg_name_change_cb(void *data, Eo *obj, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)
{
   Gui_Widget *wdg = data;
   const char *str = NULL;
   eo_do(obj, str = elm_obj_widget_part_text_get(NULL));
   widget_name_change(wdg, str);

   return EO_CALLBACK_CONTINUE;
}

static Evas_Object *
_description_item_content_get(It_Data *it_data)
{
   Evas_Object *box = eo_add(ELM_BOX_CLASS, desc_list);
   eo_do(box, evas_obj_visibility_set(EINA_TRUE),
         elm_obj_box_horizontal_set(EINA_TRUE),
         elm_obj_box_padding_set(5, 0),
         evas_obj_size_hint_weight_set(EVAS_HINT_EXPAND, 0),
         evas_obj_size_hint_align_set(EVAS_HINT_FILL, 0)
        );

   it_data->box = box;

   Eo *label = eo_add(ELM_LABEL_CLASS, box);
   eo_do(label, evas_obj_visibility_set(EINA_TRUE),
                elm_obj_widget_part_text_set(NULL, it_data->desc));
   eo_do(box, elm_obj_box_pack_end(label));

   if (!strcmp(it_data->desc, DB_DEF_PUBLIC))
     {
        Eo *ck = props_check_add(box, wdg_public_get(it_data->wdg));
        eo_do (ck, eo_event_callback_add(ELM_ENTRY_EVENT_CHANGED, _wdg_public_change_cb, it_data->wdg));
        elm_object_tooltip_text_set(ck, "Check to make widget accissible from code");
     }
   else if (!strcmp(it_data->desc, DB_DEF_NAME))
     {
        Eo *entry = props_entry_add(box, wdg_name_get(it_data->wdg), GUI_TYPE_STRING);
        eo_do (entry, eo_event_callback_add(ELM_ENTRY_EVENT_ACTIVATED, _wdg_name_change_cb, it_data->wdg));
        elm_object_tooltip_text_set(entry, "Widget name");
     }
   else if (!strcmp(it_data->desc, DB_DEF_CLASS))
     {
        Eo *entry = props_entry_add(box, wdg_class_name_get(it_data->wdg), GUI_TYPE_STRING);
        elm_object_disabled_set(entry, EINA_TRUE);
        elm_object_tooltip_text_set(entry, "Widget class");
     }
   return box;
}

static void
_desc_item_del(void *data, Evas_Object *obj EINA_UNUSED)
{
   It_Data *it_data = data;
   _it_data_free(it_data);
}

static Evas_Object *
_desc_item_content_get(void *data, Evas_Object *obj EINA_UNUSED, const char *part EINA_UNUSED)
{
   return _description_item_content_get(data);
}

void
descview_init(void)
{
   Egui_Layout_Widgets *g = egui_layout_gui_get();

   desc_list = g->main_win->description_list;

   if (!_itc_desc)
     {
        _itc_desc = elm_genlist_item_class_new();
        _itc_desc->item_style = "full";
        _itc_desc->func.content_get = _desc_item_content_get;
        _itc_desc->func.del = _desc_item_del;
     }
}

void
descview_shutdown(void)
{
   eo_do(desc_list, elm_obj_genlist_clear());
   desc_list = NULL;
}