Commit 757d324f authored by Ludovic Fauvet's avatar Ludovic Fauvet

sidebar: improve visible selection using a colored icon

parent 37a52d46
...@@ -176,9 +176,6 @@ intf_push_view(interface *intf, interface_view *view, const char *title) ...@@ -176,9 +176,6 @@ intf_push_view(interface *intf, interface_view *view, const char *title)
void void
intf_show_view(interface *intf, view_e view_type) intf_show_view(interface *intf, view_e view_type)
{ {
if(view_type == VIEW_AUTO)
view_type = preferences_get_index(PREF_CURRENT_VIEW, VIEW_VIDEO);
if(view_type == intf->current_view) if(view_type == intf->current_view)
return; return;
...@@ -429,7 +426,7 @@ create_main_box(interface *intf, Evas_Object *parent) ...@@ -429,7 +426,7 @@ create_main_box(interface *intf, Evas_Object *parent)
} }
static void static void
create_main_layout(interface *intf, Evas_Object *conform) create_main_layout(interface *intf, Evas_Object *conform, view_e view_type)
{ {
/* Add a layout to the conformant */ /* Add a layout to the conformant */
Evas_Object *layout = elm_layout_add(conform); Evas_Object *layout = elm_layout_add(conform);
...@@ -437,7 +434,7 @@ create_main_layout(interface *intf, Evas_Object *conform) ...@@ -437,7 +434,7 @@ create_main_layout(interface *intf, Evas_Object *conform)
evas_object_show(layout); evas_object_show(layout);
/* Create the panel and put it in the layout */ /* Create the panel and put it in the layout */
intf->sidebar = create_sidebar(intf, layout); intf->sidebar = create_sidebar(intf, layout, view_type);
elm_object_part_content_set(layout, "elm.swallow.left", intf->sidebar); elm_object_part_content_set(layout, "elm.swallow.left", intf->sidebar);
/* Create the content box and put it in the layout */ /* Create the content box and put it in the layout */
...@@ -527,11 +524,13 @@ intf_create(application *app) ...@@ -527,11 +524,13 @@ intf_create(application *app)
elm_object_part_content_set(conform, "elm.swallow.indicator_bg", bg); elm_object_part_content_set(conform, "elm.swallow.indicator_bg", bg);
evas_object_show(bg); evas_object_show(bg);
view_e view_type = preferences_get_index(PREF_CURRENT_VIEW, VIEW_VIDEO);
/* Create the main view in the conformant */ /* Create the main view in the conformant */
create_main_layout(intf, conform); create_main_layout(intf, conform, view_type);
/* Create the default view in the content naviframe */ /* Create the default view in the content naviframe */
intf_show_view(intf, VIEW_AUTO); intf_show_view(intf, view_type);
/* */ /* */
evas_object_show(intf->win); evas_object_show(intf->win);
......
...@@ -34,24 +34,31 @@ ...@@ -34,24 +34,31 @@
#include "audio_player.h" #include "audio_player.h"
#include "ui/utils.h" #include "ui/utils.h"
typedef struct sidebar {
bool initialized;
} sidebar_s;
typedef struct menu_cb_data typedef struct menu_cb_data
{ {
interface *intf; interface *intf;
int index; int index;
const Elm_Genlist_Item_Class *itc; const Elm_Genlist_Item_Class *itc;
Elm_Object_Item *it;
sidebar_s *sb;
} menu_cb_data_s; } menu_cb_data_s;
typedef struct { typedef struct {
const char* label; const char* label;
const char* icon_name; const char* icon;
const char* icon_selected;
} menu_entry; } menu_entry;
static const menu_entry menu_entries[] = { static const menu_entry menu_entries[] = {
{ "Video", "ic_menu_video.png" }, { "Video", "ic_menu_video.png", "ic_menu_video_selected.png" },
{ "Audio", "ic_menu_audio.png" }, { "Audio", "ic_menu_audio.png", "ic_menu_audio_selected.png" },
{ "Directory", "ic_menu_folder.png" }, { "Directory", "ic_menu_folder.png", "ic_menu_folder_selected.png" },
{ "Settings", "ic_menu_preferences.png" }, { "Settings", "ic_menu_preferences.png", "ic_menu_preferences_selected.png" },
{ "About", "ic_menu_cone.png" } { "About", "ic_menu_cone.png", "ic_menu_cone_selected.png" }
}; };
static char * static char *
...@@ -73,6 +80,7 @@ sidebar_content_get_cb(void *data, Evas_Object *obj, const char *part) ...@@ -73,6 +80,7 @@ sidebar_content_get_cb(void *data, Evas_Object *obj, const char *part)
{ {
menu_cb_data_s *cd = data; menu_cb_data_s *cd = data;
Evas_Object *content = NULL; Evas_Object *content = NULL;
const char *icon_str;
/* Check the item class style and add the object needed in the item class*/ /* Check the item class style and add the object needed in the item class*/
/* Here, puts the icon in the item class to add it to genlist items */ /* Here, puts the icon in the item class to add it to genlist items */
...@@ -80,7 +88,13 @@ sidebar_content_get_cb(void *data, Evas_Object *obj, const char *part) ...@@ -80,7 +88,13 @@ sidebar_content_get_cb(void *data, Evas_Object *obj, const char *part)
if (part && !strcmp(part, "elm.icon.1")) { if (part && !strcmp(part, "elm.icon.1")) {
content = elm_layout_add(obj); content = elm_layout_add(obj);
elm_layout_theme_set(content, "layout", "list/B/type.3", "default"); elm_layout_theme_set(content, "layout", "list/B/type.3", "default");
Evas_Object *icon = create_icon(content, menu_entries[cd->index].icon_name);
if (elm_genlist_item_selected_get(cd->it))
icon_str = menu_entries[cd->index].icon_selected;
else
icon_str = menu_entries[cd->index].icon;
Evas_Object *icon = create_icon(content, icon_str);
elm_layout_content_set(content, "elm.swallow.content", icon); elm_layout_content_set(content, "elm.swallow.content", icon);
} }
} }
...@@ -94,6 +108,12 @@ sidebar_selected_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info) ...@@ -94,6 +108,12 @@ sidebar_selected_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info)
menu_cb_data_s *cd = data; menu_cb_data_s *cd = data;
/* Generate the view depending on which sidebar genlist item is selected */ /* Generate the view depending on which sidebar genlist item is selected */
if (!cd->sb->initialized)
{
// Don't forward selection until we're ready
return;
}
intf_update_mini_player(cd->intf); intf_update_mini_player(cd->intf);
switch(cd->index){ switch(cd->index){
...@@ -126,8 +146,14 @@ sidebar_item_delete_cb(void *data, Evas_Object *obj, void *event_info) ...@@ -126,8 +146,14 @@ sidebar_item_delete_cb(void *data, Evas_Object *obj, void *event_info)
free(cd); free(cd);
} }
void sidebar_delete_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
{
sidebar_s *sb = data;
free(sb);
}
static Evas_Object * static Evas_Object *
sidebar_create_panel_genlist(interface *intf, Evas_Object *sidebar) sidebar_create_panel_genlist(interface *intf, Evas_Object *sidebar, sidebar_s *sb)
{ {
/* Set then create the Genlist object */ /* Set then create the Genlist object */
Elm_Genlist_Item_Class *itc = elm_genlist_item_class_new(); Elm_Genlist_Item_Class *itc = elm_genlist_item_class_new();
...@@ -166,6 +192,8 @@ sidebar_create_panel_genlist(interface *intf, Evas_Object *sidebar) ...@@ -166,6 +192,8 @@ sidebar_create_panel_genlist(interface *intf, Evas_Object *sidebar)
cd->index = index; cd->index = index;
cd->intf = intf; cd->intf = intf;
cd->itc = itc; cd->itc = itc;
cd->it = it;
cd->sb = sb;
} }
elm_genlist_item_class_free(itc); elm_genlist_item_class_free(itc);
...@@ -182,10 +210,10 @@ sidebar_list_clicked_cb(void *data, Evas_Object *obj, void *event_info) ...@@ -182,10 +210,10 @@ sidebar_list_clicked_cb(void *data, Evas_Object *obj, void *event_info)
} }
Evas_Object* Evas_Object*
create_sidebar(interface *intf, Evas_Object *layout) create_sidebar(interface *intf, Evas_Object *layout, view_e view_type)
{ {
Evas_Object *sidebar_list; Evas_Object *sidebar_list, *sidebar;
Evas_Object *sidebar; sidebar_s *sb = calloc(1, sizeof(*sb));
/* Create then set the sidebar */ /* Create then set the sidebar */
sidebar = elm_panel_add(layout); sidebar = elm_panel_add(layout);
...@@ -194,17 +222,21 @@ create_sidebar(interface *intf, Evas_Object *layout) ...@@ -194,17 +222,21 @@ create_sidebar(interface *intf, Evas_Object *layout)
elm_panel_orient_set(sidebar, ELM_PANEL_ORIENT_LEFT); elm_panel_orient_set(sidebar, ELM_PANEL_ORIENT_LEFT);
/* Add the sidebar genlist in the sidebar */ /* Add the sidebar genlist in the sidebar */
sidebar_list = sidebar_create_panel_genlist(intf, sidebar); sidebar_list = sidebar_create_panel_genlist(intf, sidebar, sb);
evas_object_show(sidebar_list); evas_object_show(sidebar_list);
evas_object_size_hint_weight_set(sidebar_list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_weight_set(sidebar_list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(sidebar_list, EVAS_HINT_FILL, EVAS_HINT_FILL); evas_object_size_hint_align_set(sidebar_list, EVAS_HINT_FILL, EVAS_HINT_FILL);
/* */ /* */
evas_object_smart_callback_add(sidebar_list, "selected", sidebar_list_clicked_cb, sidebar); elm_object_content_set(sidebar, sidebar_list);
/* Select the nth item by default */
elm_genlist_item_selected_set(elm_genlist_nth_item_get(sidebar_list, view_type), EINA_TRUE);
sb->initialized = true;
/* */ /* */
elm_object_content_set(sidebar, sidebar_list); evas_object_smart_callback_add(sidebar_list, "selected", sidebar_list_clicked_cb, sidebar);
elm_genlist_item_selected_set(elm_genlist_first_item_get(sidebar), EINA_TRUE); evas_object_event_callback_add(sidebar_list, EVAS_CALLBACK_FREE, sidebar_delete_cb, sb);
return sidebar; return sidebar;
} }
...@@ -30,6 +30,6 @@ ...@@ -30,6 +30,6 @@
#include "interface.h" #include "interface.h"
Evas_Object* Evas_Object*
create_sidebar(interface *intf, Evas_Object *layout); create_sidebar(interface *intf, Evas_Object *layout, view_e view_type);
#endif /* PANEL_GENLIST_H_ */ #endif /* PANEL_GENLIST_H_ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment