summaryrefslogtreecommitdiff
path: root/src/bin/egui_gui/settings_view.c
blob: 36c7d8b90764a4f610266dff30c846a1ea8d95d4 (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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173

#include <Elementary.h>
#include "egui_log.h"
#include "settings_view.h"
#include "gui_widget.h"
#include "egui_logic_private.h"

#include "elm_widget.h"
#include "elm_widget_container.h"
#include "elm_interface_scrollable.h"

static SettingsView_Type _toolbar_selected_type = SETTINGSVIEW_NOT_SELECTED;

static Egui_Layout_Settings_Win_Widgets *g_settings_win = NULL;

static Elm_Genlist_Item_Class *_start_pt_itc = NULL;
static Eina_List *_start_pts = NULL;

void settings_win_set(Egui_Layout_Settings_Win_Widgets *settings_win)
{
   if (g_settings_win) free(g_settings_win);
   g_settings_win = settings_win;
}

/* Enable "Apply" button." */
Eina_Bool
_settings_apply_button_enable(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)
{
   eo_do(g_settings_win->settings_button_apply, elm_obj_widget_disabled_set(EINA_FALSE));
   return EO_CALLBACK_CONTINUE;
}

/* Toolbar item clicked callback. */
static void
_settingsview_toolbar_clicked(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
   SettingsView_Type type = (int) (intptr_t) data;
   if (_toolbar_selected_type == type)
     return;
   _toolbar_selected_type = type;

   const Gui_Context *ctx = _active_context_get();
   eo_do(g_settings_win->project_name_entry, elm_obj_widget_part_text_set(NULL, gui_context_project_name_get(ctx)));
   eo_do(g_settings_win->images_prefix_entry, elm_obj_widget_part_text_set(NULL, gui_context_images_prefix_get(ctx)));

   elm_genlist_clear(g_settings_win->start_points_genlist);
   const Eina_List *itr;
   Dep_Id *wdg_id;
   EINA_LIST_FOREACH(gui_context_main_widgets_get(ctx), itr, wdg_id)
     {
        if (wdg_get(wdg_id))
          {
             Eina_Bool state = !!eina_list_data_find(gui_context_start_points_get(ctx), wdg_id);
             elm_genlist_item_append(g_settings_win->start_points_genlist, _start_pt_itc, (void *) (uintptr_t) wdg_id, NULL,
                   ELM_GENLIST_ITEM_NONE, NULL, NULL);
             if (state) _start_pts = eina_list_append(_start_pts, wdg_id);
          }
     }
}

/* "Apply" button "clicked" callback." */
Eina_Bool
_settings_apply_button_clicked(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)
{
   Gui_Context *ctx = _active_context_get();
   const char *new_val = NULL, *old_val;
   eo_do(g_settings_win->project_name_entry, new_val = elm_obj_widget_part_text_get(NULL));
   old_val = gui_context_project_name_get(ctx);
   if (!old_val) old_val = "";

   if (strlen(new_val) && (strcmp(new_val, old_val)))
     {
        gui_context_project_name_set(ctx, new_val);
     }
   else if (!strlen(new_val))
     {
        eo_do(g_settings_win->project_name_entry, elm_obj_widget_part_text_set(NULL, old_val));
     }

   eo_do(g_settings_win->images_prefix_entry, new_val = elm_obj_widget_part_text_get(NULL));
   old_val = gui_context_images_prefix_get(ctx);

   //if (new_val && old_val && strlen(new_val) && (strcmp(new_val, old_val)))
   /* FIXME add checks */
   if (new_val)
     {
        gui_context_images_prefix_set(ctx, new_val);
     }
   else if (!new_val || !strlen(new_val))
     {
        eo_do(g_settings_win->images_prefix_entry, elm_obj_widget_part_text_set(NULL, old_val));
     }

   Dep_Id *start_pt_id = NULL;
   gui_context_start_points_clear(ctx);
   EINA_LIST_FREE(_start_pts, start_pt_id)
      gui_context_start_point_append(ctx, start_pt_id);
   _start_pts = NULL;

   eo_do(g_settings_win->settings_button_apply, elm_obj_widget_disabled_set(EINA_TRUE));
   return EO_CALLBACK_CONTINUE;
}

/* Delete window callback. */
Eina_Bool
_settings_win_request_delete(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)
{
   _toolbar_selected_type = SETTINGSVIEW_NOT_SELECTED;
   eina_list_free(_start_pts);
   _start_pts = NULL;
   return EO_CALLBACK_CONTINUE;
}

/* This callback is called in the end of creation of settings view window. */
void
settings_win_post_configure()
{
   eo_do(g_settings_win->settings_toolbar, elm_obj_toolbar_item_append("preferences-system", "Project",
                                                    _settingsview_toolbar_clicked, (void *) (intptr_t) SETTINGSVIEW_MAIN));
}

static Eina_Bool
_start_pt_chk_chg(void *data, Eo *obj, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)
{
   Dep_Id *wdg_id = data;
   Eina_Bool state = eo_do(obj, elm_obj_check_state_get());
   if (state)
      _start_pts = eina_list_append(_start_pts, wdg_id);
   else
      _start_pts = eina_list_remove(_start_pts, wdg_id);
   eo_do(g_settings_win->settings_button_apply, elm_obj_widget_disabled_set(EINA_FALSE));
   return EINA_TRUE;
}

static char *
_start_pt_text_get(void *data, Evas_Object *obj EINA_UNUSED, const char *part EINA_UNUSED)
{
   Dep_Id *wdg_id = data;
   const char *wdg_name = dep_name_get(wdg_id);
   return wdg_name ? strdup(wdg_name) : NULL;
}

static Evas_Object *
_start_pt_content_get(void *data, Evas_Object *obj, const char *part)
{
   Dep_Id *wdg_id = data;
   const Gui_Context *ctx = gui_context_get_by_dep_id(wdg_id);
   Eina_Bool state = !!eina_list_data_find(gui_context_start_points_get(ctx), wdg_id);
   if (strcmp(part, "elm.swallow.icon")) return NULL;
   Eo *ck = eo_add(ELM_CHECK_CLASS, obj,
         eo_event_callback_add(ELM_CHECK_EVENT_CHANGED, _start_pt_chk_chg, wdg_id),
         elm_obj_check_state_set(state));
   return ck;
}

void
settingsview_init()
{
   if (!_start_pt_itc)
     {
        _start_pt_itc = elm_genlist_item_class_new();
        _start_pt_itc->item_style = "default";
        _start_pt_itc->func.content_get = _start_pt_content_get;
        _start_pt_itc->func.text_get = _start_pt_text_get;
     }
}

void
settingsview_shutdown()
{
   elm_genlist_item_class_free(_start_pt_itc);
   _start_pt_itc = NULL;
}