diff options
Diffstat (limited to 'src/ui_widgets.c')
-rw-r--r-- | src/ui_widgets.c | 307 |
1 files changed, 81 insertions, 226 deletions
diff --git a/src/ui_widgets.c b/src/ui_widgets.c index 468b082..f690fb6 100644 --- a/src/ui_widgets.c +++ b/src/ui_widgets.c @@ -8,65 +8,24 @@ */ #include <Elementary.h> -#include <stdarg.h> #include <stdint.h> #include "eulogium.h" #include "gettext.h" +#include "procedures.h" #include "ui_input.h" #include "ui_widgets.h" +#include "ui_wizards.h" -static struct wizard_screen_data material_unload = { - .count = 0, - .screens = { - { - .type = NONE, - .text = "To remove material<br>we need to do stuff", - .data = NULL, - .prev_button = "Skip Wizzard!", - .next_button = "Continue", - }, { - .type = NONE, /* .type = BUTTON? */ - .text = "Choose a nozzle<br>to remove material from", - .data = NULL, - .prev_button = "Left", - .next_button = "Right", - //.prev_func = , - //.next_func = , - }, { .type = END, }, /* sentinel */ - }, -}; - -static struct wizard_screen_data material_load = { - .count = 0, - .screens = { - { - .type = NONE, - .text = "To remove material<br>we need to do stuff", - .data = NULL, - .prev_button = "Skip Wizzard!", - .next_button = "Continue", - }, { - .type = NONE, /* .type = BUTTON? */ - .text = "Choose a nozzle<br>to remove material from", - .data = NULL, - .prev_button = "Left", - .next_button = "Right", - //.prev_func = , - //.next_func = , - }, { .type = END, }, /* sentinel */ - }, -}; - -Elm_Object_Item *ui_stack_push(const struct eulogium_data *eulogium, Evas_Object *content, const enum navi_page_state page_state) /* TODO replace with just the navi pointer */ +Elm_Object_Item *ui_stack_push(Evas_Object *navi, Evas_Object *content, const enum navi_page_state page_state) /* TODO replace with just the navi pointer */ { Elm_Object_Item *navi_item; - if ((!eulogium->navi) || (!content)) { + if ((!navi) || (!content)) { EINA_LOG_CRIT("navi or content where NULL"); return NULL; } - navi_item = elm_naviframe_item_simple_push(eulogium->navi, content); + navi_item = elm_naviframe_item_simple_push(navi, content); if (!navi_item) { EINA_LOG_CRIT("Unable to push item onto navistack"); return NULL; @@ -77,6 +36,15 @@ Elm_Object_Item *ui_stack_push(const struct eulogium_data *eulogium, Evas_Object return navi_item; } +void _event_handler_from_navi_del(const Evas_Object *navi, const char *str) +{ + Ecore_Event_Handler *event; + + event = evas_object_data_get(navi, str); + if (event) + ecore_event_handler_del(event); +} + /* Search through the navistack in reverse order. This loop is almost always * aborted very early on. We basically 'abuse' the loop to skip over invalid * pages, which is actually unlikely and thus the first item of the stack @@ -84,31 +52,35 @@ Elm_Object_Item *ui_stack_push(const struct eulogium_data *eulogium, Evas_Object * place to not pop the very first page of the stack, as that is our * 'main-menu'. TODO Improve doc, this is just an early note. */ -Eina_Bool ui_stack_pop(const struct eulogium_data *eulogium) /* TODO replace with just the navi pointer */ +Eina_Bool ui_stack_pop(const Evas_Object *navi) /* TODO replace with just the navi pointer */ { Eina_List *navi_list, *l; Elm_Object_Item *navi_item; enum navi_page_state page_state; - if (!eulogium->navi) { + if (!navi) { EINA_LOG_CRIT("Naviframe was NULL"); return EINA_FALSE; } + /* clean navi page event handlers */ + _event_handler_from_navi_del(navi, "event_inc"); /* TODO possibly use an array of event handlers if we get more then 3 */ + _event_handler_from_navi_del(navi, "event_dec"); /* TODO possibly use an array of event handlers if we get more then 3 */ + /* FIXME: bug here, when we start eulogium and start a print job, * eulogium restarts midway the print job, the dialog with the * print cleaned pops up, but apparently no bottom has been generated * yet. Make sure to call eulogium_main_menu (new name) first before * process handling. Call moved, but we may still have init issues. */ - navi_item = elm_naviframe_top_item_get(eulogium->navi); + navi_item = elm_naviframe_top_item_get(navi); page_state = (enum navi_page_state)(uintptr_t)elm_object_item_data_get(navi_item); if (page_state == PAGE_BOTTOM) { EINA_LOG_WARN("Not popping bottom frame cowboy"); return EINA_TRUE; } - navi_list = elm_naviframe_items_get(eulogium->navi); + navi_list = elm_naviframe_items_get(navi); l = eina_list_last(navi_list); l = eina_list_prev(l); /* Skip the top entry, it is the currently displayed window and thus @@ -123,7 +95,7 @@ Eina_Bool ui_stack_pop(const struct eulogium_data *eulogium) /* TODO replace wit EINA_LOG_ERR("No item in list?!"); continue; } - page_state = (enum navi_page_state)(uintptr_t)elm_object_item_data_get(navi_item); + page_state = (enum navi_page_state)(uintptr_t)elm_object_item_data_get(navi_item); /* XXX toto, use pointer of _navi_page_state */ if (page_state == PAGE_INVALID) { EINA_LOG_WARN("Page on stack invalid, skipping"); continue; @@ -154,24 +126,11 @@ void ui_stack_page_invalidate(Evas_Object *navi, const enum navi_page_state page eina_list_free(navi_list); } -void _event_handler_from_navi_del(Evas_Object *navi, const char *str) -{ - Ecore_Event_Handler *event; - - event = evas_object_data_get(navi, str); - if (event) - ecore_event_handler_del(event); -} - void ui_stack_pop_cb(void *data, Evas_Object *eo EINA_UNUSED, void *event_info EINA_UNUSED) { - struct eulogium_data *eulogium = data; /* XXX replace this with passing just the navi and event handlers */ - Evas_Object *navi = eulogium->navi; - - _event_handler_from_navi_del(navi, "event_inc"); /* TODO possibly use an array of event handlers if we get more then 3 */ - _event_handler_from_navi_del(navi, "event_dec"); /* TODO possibly use an array of event handlers if we get more then 3 */ + Evas_Object *navi = data; - ui_stack_pop(eulogium); /* XXX replace with just the navi */ + ui_stack_pop(navi); } static void _dial_send_update(void *data, Evas_Object *eo, void *event_info EINA_UNUSED) @@ -188,7 +147,7 @@ static Eina_Bool _dial_change_delay(void *data) Evas_Object *dial = data; evas_object_data_set(dial, "delay", NULL); - evas_object_smart_callback_call(dial, "delay,changed", NULL); + evas_object_smart_callback_call(dial, "changed", NULL); return ECORE_CALLBACK_CANCEL; } @@ -197,7 +156,7 @@ static Eina_Bool _spinner_change(void *data, int type, void *event_info EINA_UNU { struct settings_dial_data *dial_data = data; - /* TODO we now jus tell the backend that there is a change of + or - 1 * step size. + /* TODO we now just tell the backend that there is a change of + or - 1 * step size. * ideally the event_info is filled with the step size/speed of the mouse_wheel events * giving us the step size directly. */ @@ -233,7 +192,7 @@ static Eina_Bool _dial_change(void *data, int type, void *event_info EINA_UNUSED evas_object_smart_callback_call(dial, "changed", NULL); delay = evas_object_data_get(dial, "delay"); ecore_timer_del(delay); - delay = ecore_timer_add(0.25, _dial_change_delay, dial); /* TODO make define for delay */ + delay = ecore_timer_add(0.5, _dial_change_delay, dial); /* TODO make define for delay */ evas_object_data_set(dial, "delay", delay); return ECORE_CALLBACK_PASS_ON; @@ -315,7 +274,45 @@ Evas_Object *ui_widget_spinner(Evas_Object *parent, struct eulogium_data *eulogi elm_object_text_set(_bottom, _("Click when done")); /* TODO, make define for this text */ evas_object_size_hint_weight_set(_bottom, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(_bottom, EVAS_HINT_FILL, EVAS_HINT_FILL); - evas_object_smart_callback_add(_bottom, "clicked", ui_stack_pop_cb, eulogium); + evas_object_smart_callback_add(_bottom, "clicked", ui_stack_pop_cb, eulogium->navi); + evas_object_show(_bottom); + /* remove handler on window destroy? */ + + return eulogium_split_screen(parent, _top, _bottom); +} + +Evas_Object *ui_widget_spinner_add(Evas_Object *parent, struct settings_dial_data *dial_data) +{ + Evas_Object *obj, *_top, *_bottom; + Ecore_Event_Handler *handler; + + _top = elm_box_add(parent); + evas_object_size_hint_weight_set(_top, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(_top, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_show(_top); + + obj = elm_label_add(_top); /* TODO make label sit inverted at the top */ + elm_object_text_set(obj, "test"); + evas_object_size_hint_weight_set(obj, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(obj, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_show(obj); + elm_box_pack_end(_top, obj); + + obj = elm_spinner_add(parent); + evas_object_size_hint_weight_set(obj, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(obj, EVAS_HINT_FILL, EVAS_HINT_FILL); + //handler = ecore_event_handler_add(INPUT_MOUSE_WHEEL_UP, _spinner_change, dial_data); + //evas_object_data_set(parent, "event_inc", handler); + //handler = ecore_event_handler_add(INPUT_MOUSE_WHEEL_DOWN, _spinner_change, dial_data); + //evas_object_data_set(parent, "event_dec", handler); /* XXX do this better (via dial_data?) */ + evas_object_show(obj); + elm_box_pack_end(_top, obj); + + _bottom = elm_button_add(parent); + elm_object_text_set(_bottom, _("Click when done")); /* TODO, make define for this text */ + evas_object_size_hint_weight_set(_bottom, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(_bottom, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_smart_callback_add(_bottom, "clicked", ui_stack_pop_cb, parent); evas_object_show(_bottom); /* remove handler on window destroy? */ @@ -338,7 +335,7 @@ Evas_Object *ui_widget_slider(Evas_Object *parent, struct eulogium_data *eulogiu elm_slider_value_set(_top, dial_data->value); evas_object_size_hint_weight_set(_top, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(_top, EVAS_HINT_FILL, EVAS_HINT_FILL); - evas_object_smart_callback_add(_top, "delay,changed", _dial_send_update, dial_data); + evas_object_smart_callback_add(_top, "changed", _dial_send_update, dial_data); handler = ecore_event_handler_add(INPUT_MOUSE_WHEEL_UP, _dial_change, _top); evas_object_data_set(parent, "event_inc", handler); handler = ecore_event_handler_add(INPUT_MOUSE_WHEEL_DOWN, _dial_change, _top); @@ -369,7 +366,7 @@ Evas_Object *ui_widget_slider(Evas_Object *parent, struct eulogium_data *eulogiu elm_object_text_set(_bottom, _("Click when done")); /* TODO, make define for this text */ evas_object_size_hint_weight_set(_bottom, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(_bottom, EVAS_HINT_FILL, EVAS_HINT_FILL); - evas_object_smart_callback_add(_bottom, "clicked", ui_stack_pop_cb, eulogium); + evas_object_smart_callback_add(_bottom, "clicked", ui_stack_pop_cb, eulogium->navi); evas_object_show(_bottom); return eulogium_split_screen(parent, _top, _bottom); @@ -398,7 +395,7 @@ static void _widget_progress_del(void *data, Evas *e EINA_UNUSED, Evas_Object *e static Eina_Bool _widget_progress_update(void *data, int type EINA_UNUSED, void *event_info EINA_UNUSED) { struct _progress_screen_data *screen = data; - struct print_data *progress = screen->progress_data; + const struct print_data *progress = screen->progress_data; elm_object_text_set(screen->jobname, _(progress->jobname)); elm_object_text_set(screen->status, _(progress->status)); @@ -407,7 +404,7 @@ static Eina_Bool _widget_progress_update(void *data, int type EINA_UNUSED, void return ECORE_CALLBACK_PASS_ON; } -Evas_Object *ui_widget_progress(Evas_Object *parent, struct eulogium_data *eulogium, const struct procedure_data *procedure) +Evas_Object *ui_widget_progress(Evas_Object *parent, const struct procedure_data *procedure) { struct print_data *progress = procedure->meta; /* XXX rename to progress data | check meta_type if it is the correct type. */ Evas_Object *_top, *_bottom, *content; @@ -423,7 +420,7 @@ Evas_Object *ui_widget_progress(Evas_Object *parent, struct eulogium_data *eulog elm_box_homogeneous_set(_top, EINA_FALSE); evas_object_show(_top); - screen->title = elm_label_add(_top); + screen->title = elm_label_add(_top); /* TODO make label sit inverted at the top */ elm_object_text_set(screen->title, _(progress->title)); elm_label_slide_mode_set(screen->title, ELM_LABEL_SLIDE_MODE_NONE); evas_object_size_hint_align_set(screen->title, EVAS_HINT_FILL, EVAS_HINT_FILL); @@ -449,8 +446,13 @@ Evas_Object *ui_widget_progress(Evas_Object *parent, struct eulogium_data *eulog screen->progressbar = elm_progressbar_add(_top); elm_progressbar_horizontal_set(screen->progressbar, EINA_TRUE); - elm_progressbar_pulse_set(screen->progressbar, EINA_FALSE); /* TODO: pulse = time-unknown/pause */ - elm_progressbar_pulse(screen->progressbar, EINA_FALSE); + if (progress->value < 0) { + elm_progressbar_pulse_set(screen->progressbar, EINA_TRUE); + elm_progressbar_pulse(screen->progressbar, EINA_TRUE); + } else { + elm_progressbar_pulse_set(screen->progressbar, EINA_FALSE); + elm_progressbar_pulse(screen->progressbar, EINA_FALSE); + } elm_progressbar_value_set(screen->progressbar, progress->value); /* get this from the procedure meta data */ elm_progressbar_unit_format_set(screen->progressbar, "%1.1f %%"); evas_object_size_hint_align_set(screen->progressbar, EVAS_HINT_FILL, EVAS_HINT_FILL); @@ -458,6 +460,7 @@ Evas_Object *ui_widget_progress(Evas_Object *parent, struct eulogium_data *eulog elm_box_pack_end(_top, screen->progressbar); handler = ecore_event_handler_add(procedure->poll.event, _widget_progress_update, screen); + /* XXX handler add to something?; this is broken atm */ // _bottom = eulogium_dual_button_add(parent, &but_print_tune, &but_print_abort_confirm); // evas_object_show(_bottom); @@ -468,155 +471,7 @@ Evas_Object *ui_widget_progress(Evas_Object *parent, struct eulogium_data *eulog return content; } -struct _wizard_screen_next_cb_data { - struct eulogium_data *eulogium; - struct wizard_screen_data *screen_data; - uint_fast8_t pagenum; - Eina_Bool pageindex; -}; - -static void _wizard_screen_next_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) -{ - Evas_Object *content; - struct eulogium_data *eulogium = ((struct _wizard_screen_next_cb_data *)data)->eulogium; - uint_fast8_t pagenum = ((struct _wizard_screen_next_cb_data *)data)->pagenum; - Eina_Bool pageindex = ((struct _wizard_screen_next_cb_data *)data)->pageindex; - struct wizard_screen_data *screen_data = ((struct _wizard_screen_next_cb_data *)data)->screen_data; - - if (pagenum >= screen_data->count) { - Elm_Object_Item *item; - - item = elm_naviframe_bottom_item_get(eulogium->navi); - if (item) - elm_naviframe_item_pop_to(item); - /* XXX what else? */ - } else { - // content = ui_window_wizard(eulogium->navi, eulogium, screen_data, pagenum, pageindex); - ui_stack_push(eulogium, content, PAGE_NORMAL); - /* XXX what else? */ - } - free(data); -} - -Evas_Object *ui_window_wizard(Evas_Object *parent, struct eulogium_data *eulogium, struct wizard_screen_data *screen_data, uint_fast8_t pagenum, Eina_Bool pageindex) -{ - Evas_Object *object; - Evas_Object *_top, *_bottom; - struct _wizard_screen_next_cb_data *wizard_screen_next_cb_data; - char buf[6]; - - _top = elm_box_add(parent); - evas_object_show(_top); - - if (screen_data->count == 0) { - EINA_LOG_WARN("Tut tut, we can't have a count of 0!\n"); - return NULL; - } - - if (pagenum >= screen_data->count) - pagenum = screen_data->count - 1; - - if (pageindex) { - object = elm_label_add(_top); - snprintf(buf, sizeof(buf), "%d/%d", pagenum + 1, screen_data->count); - elm_object_text_set(object, _(buf)); - evas_object_show(object); - evas_object_size_hint_weight_set(object, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - evas_object_size_hint_align_set(object, 1.0, 0); - elm_box_pack_end(_top, object); - } - - if (screen_data->screens[pagenum].text) { - object = elm_label_add(_top); - elm_object_text_set(object, _(screen_data->screens[pagenum].text)); - evas_object_size_hint_align_set(object, 0.5, 0.5); - evas_object_show(object); - elm_box_pack_end(_top, object); - } - - switch (screen_data->screens[pagenum].type) { - Evas_Object *box; /* TODO rename to 'type' or something */ - - case MATERIAL: - box = elm_box_add(_top); - elm_box_horizontal_set(box, EINA_TRUE); - evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL); - evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - evas_object_show(box); - - object = elm_button_add(box); - evas_object_size_hint_align_set(object, EVAS_HINT_FILL, EVAS_HINT_FILL); - evas_object_size_hint_weight_set(object, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - elm_object_text_set(object, "PLA"); /* Materials need to be handled differently */ - //evas_object_smart_callback_add(object, "clicked", _cb_material_set, "PLA"); - evas_object_show(object); - elm_box_pack_end(box, object); - - object = elm_button_add(box); - evas_object_size_hint_align_set(object, EVAS_HINT_FILL, EVAS_HINT_FILL); - evas_object_size_hint_weight_set(object, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - elm_object_text_set(object, "ABS"); - //evas_object_smart_callback_add(object, "clicked", _cb_material_set, "ABS"); - evas_object_show(object); - elm_box_pack_end(box, object); - - elm_box_pack_end(_top, box); - break; - case PROGRESS: - box = elm_progressbar_add(_top); - elm_progressbar_horizontal_set(box, EINA_TRUE); - elm_progressbar_pulse_set(box, EINA_FALSE); /* TODO: pulse = time-unknown/pause */ - elm_progressbar_pulse(box, EINA_FALSE); - elm_progressbar_value_set(box, 0.5); - elm_progressbar_unit_format_set(box, "%1.0f%%"); - evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL); - evas_object_show(box); - elm_box_pack_end(_top, box); - break; - case FUNC: - /* call function pointer from screen_data.func */ - break; - case END: /* fall through */ - default: - break; - } - - _bottom = elm_box_add(parent); - elm_box_horizontal_set(_bottom, EINA_TRUE); - evas_object_show(_bottom); - - wizard_screen_next_cb_data = malloc(sizeof(struct _wizard_screen_next_cb_data)); - wizard_screen_next_cb_data->eulogium = eulogium; - wizard_screen_next_cb_data->screen_data = screen_data; - wizard_screen_next_cb_data->pagenum = pagenum + 1; - wizard_screen_next_cb_data->pageindex = EINA_TRUE; - - if (screen_data->screens[pagenum].prev_button) { - object = elm_button_add(parent); - evas_object_size_hint_align_set(object, EVAS_HINT_FILL, EVAS_HINT_FILL); - evas_object_size_hint_weight_set(object, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - elm_object_text_set(object, _(screen_data->screens[pagenum].prev_button)); - // evas_object_smart_callback_add(object, "clicked", _cb_content_prev_set, eulogium); - evas_object_show(object); - elm_box_pack_end(_bottom, object); - } - if (screen_data->screens[pagenum].next_button) { - object = elm_button_add(parent); - evas_object_size_hint_align_set(object, EVAS_HINT_FILL, EVAS_HINT_FILL); - evas_object_size_hint_weight_set(object, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - elm_object_text_set(object, _(screen_data->screens[pagenum].next_button)); - evas_object_smart_callback_add(object, "clicked", _wizard_screen_next_cb, wizard_screen_next_cb_data); - evas_object_show(object); - elm_box_pack_end(_bottom, object); - } - - return eulogium_split_screen(parent, _top, _bottom); -} - void ui_init(void) { - while (material_load.screens[material_load.count].type != END) - material_load.count++; - while (material_unload.screens[material_unload.count].type != END) - material_unload.count++; + wizard_init_all(); } |