From 69ba56021670050e247e9b9e4f931d9e2597f389 Mon Sep 17 00:00:00 2001 From: Olliver Schinagl Date: Thu, 4 Jun 2015 21:43:16 +0200 Subject: [griffin.display] Add initial default menu structure Add first lines that shows the new menu structure Signed-off-by: Olliver Schinagl --- src/eulogium.c | 285 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/eulogium.h | 19 ++++ 2 files changed, 304 insertions(+) diff --git a/src/eulogium.c b/src/eulogium.c index 9badd9f..979af86 100644 --- a/src/eulogium.c +++ b/src/eulogium.c @@ -290,6 +290,186 @@ static struct button_def but_change_hotend_2 = { .data = NULL, }; +static struct menu_def menu_system_settings = { + .title = "SETTINGS", + .entry = { + { + .icon = "user-home", + .label = "Return", + .end = NULL, + .footer = "Return to Main menu", + .footer_alt = NULL, + .func = &_cb_content_prev_set, + .toggle_timer = NULL, + .data = NULL, + }, { + .icon = NULL, + .label = "Language", + .end = NULL, + .footer = "Change language", + .footer_alt = NULL, + .func = NULL, + .toggle_timer = NULL, + .data = NULL, + }, { + .icon = NULL, + .label = "Network", + .end = NULL, + .footer = "Manage connectivity", + .footer_alt = "WiFi & Ethernet", + .func = &_but_network_stats_cb, + .toggle_timer = NULL, + .data = NULL, + }, { + .icon = NULL, + .label = "Hot end 1 offset", + .end = NULL, + .footer = "Adjust offset", + .footer_alt = NULL, + .func = NULL, + .toggle_timer = NULL, + .data = NULL, /* hot end 1 pointer? */ + }, { + .icon = NULL, + .label = "Hot end 2 offset", + .end = NULL, + .footer = "Adjust offset", + .footer_alt = NULL, + .func = NULL, + .toggle_timer = NULL, + .data = NULL, /* hot end 2 pointer? */ + }, { + .icon = NULL, + .label = "Feeder power", + .end = NULL, + .footer = "Adjust power ", + .footer_alt = NULL, + .func = NULL, + .toggle_timer = NULL, + .data = NULL, + }, { + .icon = NULL, + .label = "Filament detection", + .end = NULL, + .footer = NULL, + .footer_alt = NULL, + .func = NULL, + .toggle_timer = NULL, + .data = NULL, + }, { + .icon = NULL, + .label = "Camera", + .end = NULL, + .footer = NULL, + .footer_alt = NULL, + .func = NULL, + .toggle_timer = NULL, + .data = NULL, + }, { + .icon = NULL, + .label = "Internal storage", + .end = NULL, + .footer = NULL, + .footer_alt = NULL, + .func = NULL, + .toggle_timer = NULL, + .data = NULL, + }, { + .icon = NULL, + .label = "LED settings", + .end = NULL, + .footer = NULL, + .footer_alt = NULL, + .func = NULL, + .toggle_timer = NULL, + .data = NULL, + }, { + .icon = NULL, + .label = "Retraction", + .end = NULL, + .footer = NULL, + .footer_alt = NULL, + .func = NULL, + .toggle_timer = NULL, + .data = NULL, + }, { + .icon = NULL, + .label = "Motion", + .end = NULL, + .footer = NULL, + .footer_alt = NULL, + .func = NULL, + .data = NULL, + }, { + .icon = NULL, + .label = "Software version", + .end = NULL, + .footer = NULL, + .footer_alt = NULL, + .func = NULL, + .toggle_timer = NULL, + .data = NULL, + }, { + .icon = NULL, + .label = "Factory reset", + .end = NULL, + .footer = NULL, + .footer_alt = NULL, + .func = NULL, + .toggle_timer = NULL, + .data = NULL, + }, { NULL }, /* sentinel */ + }, + .data = NULL, +}; + +static struct menu_def menu_settings_network = { + .title = "NETWORK", + .entry = { + { + .icon = NULL, + .label = "Network info", + .end = NULL, + .footer = NULL, + .func = &_but_network_stats_cb, + .toggle_timer = NULL, + .data = NULL, + }, { + .icon = NULL, + .label = "Manage WiFi", + .end = NULL, + .footer = NULL, + .func = NULL, + .toggle_timer = NULL, + .data = NULL, + }, { + .icon = NULL, + .label = "WiFi", + .end = NULL, + .footer = NULL, + .func = NULL, + .toggle_timer = NULL, + .data = NULL, + }, { + .icon = NULL, + .label = "Ethernet", + .end = NULL, + .footer = NULL, + .func = NULL, + .toggle_timer = NULL, + .data = NULL, + }, { + .label = "Hotspot", + .footer = NULL, + .end = NULL, + .func = NULL, + .toggle_timer = NULL, + .data = NULL, + }, { NULL }, /* sentinel */ + }, + .data = NULL, +}; + static void eulogium_print_data_clear(struct eulogium_data *eulogium) { if (eulogium->progress_data_refresh) @@ -1226,6 +1406,110 @@ Evas_Object *eulogium_print_menu(struct eulogium_data *eulogium, char *filepath) return box; } +static void _update_footer_unfocus_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) +{ + struct menu_entry_def *entry = data; + + if (entry->toggle_timer) + ecore_timer_del(entry->toggle_timer); +} + +static Eina_Bool _timer_footer_toggle_cb(void *data) +{ + struct menu_entry_def *entry = data; + Evas_Object *footer = entry->data; + static uint_fast8_t toggle = 0; + + if (toggle) + elm_object_text_set(footer, entry->footer); + else + elm_object_text_set(footer, entry->footer_alt); + toggle = !toggle; + + return ECORE_CALLBACK_RENEW; +} + +static void _update_footer_focus_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) +{ + struct menu_entry_def *entry = data; + Evas_Object *footer = entry->data; + + if (!entry->footer) { + elm_object_text_set(footer, entry->label); + return; + } + elm_object_text_set(footer, entry->footer); + + if (entry->footer_alt) { + entry->toggle_timer = ecore_timer_add(1.5, _timer_footer_toggle_cb, entry); /* XXX magic value!! */ + if (!entry->toggle_timer) + EINA_LOG_ERR("Unable to create toggle timer for entry %s", entry->label); + } + +} + +Evas_Object *menu_widget_list(struct eulogium_data *eulogium, Evas_Object *parent, struct menu_def *menu) +{ + int i; + Evas_Object *obj; + Evas_Object *box; + Evas_Object *list; + Evas_Object *icon; + Evas_Object *item; + + box = elm_box_add(parent); + + eulogium->footer = elm_label_add(box); + + obj = elm_label_add(box); + elm_object_text_set(obj, menu->title); + evas_object_size_hint_align_set(obj, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_show(obj); + elm_box_pack_start(box, obj); + + list = eulogium_button_list_add(box); + elm_scroller_bounce_set(list, EINA_FALSE, EINA_FALSE); + elm_scroller_policy_set(list, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO); + evas_object_size_hint_weight_set(list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(list, EVAS_HINT_FILL, EVAS_HINT_FILL); + //elm_list_mode_set(list, ELM_LIST_COMPRESS); + elm_scroller_movement_block_set(list, ELM_SCROLLER_MOVEMENT_BLOCK_HORIZONTAL | ELM_SCROLLER_MOVEMENT_BLOCK_VERTICAL); + evas_object_show(list); + elm_box_pack_end(box, list); + + for (i = 0; menu->entry[i].label != NULL; i++) { + if (menu->entry[i].icon) { + icon = elm_icon_add(list); + elm_icon_standard_set(icon, menu->entry[i].icon); + } else { + icon = NULL; + } + item = eulogium_button_list_append(list, menu->entry[i].label, icon, menu->entry[i].func, eulogium); /*XXX TODO pass data from struct */ + menu->entry[i].data = eulogium->footer; /* XXX ugly-ness keeps adding. the footer widget should not be passed like this :( */ + evas_object_smart_callback_add(item, "focused", _update_footer_focus_cb, &menu->entry[i]); + evas_object_smart_callback_add(item, "unfocused", _update_footer_unfocus_cb, &menu->entry[i]); + } + + eulogium_button_list_go(list); +// evas_object_smart_callback_add(list, "longpressed", _cb_filelist_filedetails, NULL); /* TODO, use inwin */ + evas_object_show(list); + + obj = elm_separator_add(box); + elm_separator_horizontal_set(obj, EINA_TRUE); + evas_object_size_hint_weight_set(obj, EVAS_HINT_EXPAND, 0); + evas_object_show(obj); + elm_box_pack_end(box, obj); + + /* Footer is initialized at the start of the function, so that the for loop can work with it. */ + elm_object_text_set(eulogium->footer, NULL); + evas_object_size_hint_align_set(eulogium->footer, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_show(eulogium->footer); + elm_box_pack_end(box, eulogium->footer); + + evas_object_show(box); + return box; +} + struct _multi_screen_next_cb_data { struct eulogium_data *eulogium; struct multi_screen_data *screen_data; @@ -1525,6 +1809,7 @@ static void eulogium_setup(struct eulogium_data *eulogium) eulogium_print_data_clear(eulogium); eulogium->printer.status = DISCONNECTED; eulogium->printer.file_handlers = NULL; + eulogium->footer = NULL; eulogium_button_cb_data_set(&but_return, eulogium); eulogium_button_cb_data_set(&but_print_abort, eulogium); eulogium_button_cb_data_set(&but_print_progress_tune, eulogium); diff --git a/src/eulogium.h b/src/eulogium.h index 39acd0b..d6d59d3 100644 --- a/src/eulogium.h +++ b/src/eulogium.h @@ -90,6 +90,7 @@ struct eulogium_data { Evas_Object *status; Evas_Object *progress; Ecore_Timer *progress_data_refresh; + Evas_Object *footer; /* XXX this really shows why we need per window persistent data */ struct printer_data printer; struct print_data print; struct dbus_data dbus; @@ -109,6 +110,23 @@ struct button_def { void *data; }; +struct menu_entry_def { + const char *icon; + const char *label; + Evas_Object *end; + const char *footer; /* Primary footer */ + const char *footer_alt; /* Alternating footer */ + Ecore_Timer *toggle_timer; + void (*func)(void *data, Evas_Object *object, void *event_info); + void *data; +}; + +struct menu_def { + const char *title; + void *data; + struct menu_entry_def entry[]; +}; + struct multi_text { uint_fast8_t count; const char *button_text; @@ -145,6 +163,7 @@ Evas_Object *eulogium_dual_button_add(Evas_Object *parent, const struct button_d Evas_Object *eulogium_print_menu(struct eulogium_data *eulogium, char *filepath); Evas_Object *eulogium_print_progress(struct eulogium_data *eulogium); Evas_Object *eulogium_multi_text_menu(struct eulogium_data *eulogium, Evas_Object *parent, struct button_def *button, struct multi_text *data, const uint_fast8_t pagenum, Eina_Bool pageindex); +Evas_Object *menu_widget_list(struct eulogium_data *eulogium, Evas_Object *parent, struct menu_def *menu); Evas_Object *eulogium_multi_screen_menu(struct eulogium_data *eulogium, Evas_Object *parent, struct multi_screen_data *screen_data, const uint_fast8_t pagenum, Eina_Bool pageindex); #endif /* _EULOGIUM_H */ -- cgit v0.12