Ephoto: Use layout/edje external, toolbars for better icons, and other UI

Use layout and edje externals for better themability when others make elm themes.  Using toolbars improves the size and functionality of the icons.  Remove unnecessary entry/label in single view.
This commit is contained in:
Stephen Houston 2014-01-16 15:34:33 -06:00
parent 4538c84f5b
commit f7b4eda791
3 changed files with 107 additions and 148 deletions

View File

@ -255,7 +255,7 @@ ephoto_title_set(Ephoto *ephoto, const char *title)
{
char buf[1024] = "Ephoto";
if (title) snprintf(buf, sizeof(buf), "%s - Ephoto", title);
if (title) snprintf(buf, sizeof(buf), "Ephoto - %s", title);
elm_win_title_set(ephoto->win, buf);
}

View File

@ -20,7 +20,7 @@ struct _Ephoto_Single_Browser
Ephoto *ephoto;
Evas_Object *main;
Evas_Object *bar;
Evas_Object *sentry;
Evas_Object *edje;
Evas_Object *viewer;
const char *pending_path;
Ephoto_Entry *entry;
@ -491,11 +491,10 @@ _ephoto_single_browser_recalc(Ephoto_Single_Browser *sb)
{
const char *bname = ecore_file_file_get(sb->entry->path);
sb->viewer = _viewer_add(sb->main, sb->entry->path);
elm_box_pack_end(sb->main, sb->viewer);
elm_layout_box_append(sb->main, "elm.box.content", sb->viewer);
evas_object_show(sb->viewer);
evas_object_event_callback_add
(sb->viewer, EVAS_CALLBACK_MOUSE_WHEEL, _mouse_wheel, sb);
elm_entry_entry_set(sb->sentry, bname);
ephoto_title_set(sb->ephoto, bname);
sb->orient = ephoto_file_orient_get(sb->entry->path);
_orient_apply(sb);
@ -697,11 +696,6 @@ _back(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
evas_object_smart_callback_call(sb->main, "back", sb->entry);
}
static void
_changed_file_text(void *data __UNUSED__, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
{
}
static void
_key_down(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info)
{
@ -804,111 +798,75 @@ _ephoto_single_entry_create(void *data, int type __UNUSED__, void *event __UNUSE
return ECORE_CALLBACK_PASS_ON;
}
static Evas_Object *
_button_add(Evas_Object *box, const char *image)
{
Evas_Object *but, *ic;
but = elm_button_add(box);
ic = elm_icon_add(but);
elm_icon_standard_set(ic, image);
evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
elm_object_content_set(but, ic);
evas_object_size_hint_align_set(but, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_box_pack_end(box, but);
evas_object_show(but);
return but;
}
Evas_Object *
ephoto_single_browser_add(Ephoto *ephoto, Evas_Object *parent)
{
Evas_Object *box = elm_box_add(parent);
Evas_Object *but, *sep;
Evas_Object *layout = elm_layout_add(parent);
Elm_Object_Item *icon;
Ephoto_Single_Browser *sb;
EINA_SAFETY_ON_NULL_RETURN_VAL(box, NULL);
EINA_SAFETY_ON_NULL_RETURN_VAL(layout, NULL);
sb = calloc(1, sizeof(Ephoto_Single_Browser));
EINA_SAFETY_ON_NULL_GOTO(sb, error);
sb->ephoto = ephoto;
sb->main = box;
elm_box_horizontal_set(sb->main, EINA_FALSE);
elm_box_homogeneous_set(sb->main, EINA_FALSE);
sb->main = layout;
sb->edje = elm_layout_edje_get(layout);
evas_object_event_callback_add(sb->main, EVAS_CALLBACK_DEL, _main_del, sb);
evas_object_event_callback_add
(sb->main, EVAS_CALLBACK_KEY_DOWN, _key_down, sb);
evas_object_data_set(sb->main, "single_browser", sb);
sb->bar = elm_box_add(sb->main);
elm_box_horizontal_set(sb->bar, EINA_TRUE);
elm_box_homogeneous_set(sb->bar, EINA_FALSE);
evas_object_size_hint_weight_set(sb->bar, 0.0, 0.0);
evas_object_size_hint_align_set(sb->bar, EVAS_HINT_FILL, 0.0);
evas_object_show(sb->bar);
elm_box_pack_end(sb->main, sb->bar);
if (!elm_layout_theme_set(sb->main, "layout", "application", "toolbar-vbox"))
{
ERR("Could not load style 'toolbar-vbox' from theme!");
goto error;
}
sb->bar = edje_object_part_external_object_get(sb->edje, "elm.external.toolbar");
if (!sb->bar)
{
ERR("Could not find toolbar in layout!");
goto error;
}
elm_toolbar_homogeneous_set(sb->bar, EINA_FALSE);
elm_toolbar_shrink_mode_set(sb->bar, ELM_TOOLBAR_SHRINK_MENU);
elm_toolbar_menu_parent_set(sb->bar, parent);
elm_toolbar_select_mode_set(sb->bar, ELM_OBJECT_SELECT_MODE_NONE);
but = _button_add(sb->bar, "go-home");
evas_object_smart_callback_add(but, "clicked", _back, sb);
icon = elm_toolbar_item_append(sb->bar, "go-home", "Back", _back, sb);
elm_toolbar_item_priority_set(icon, 150);
sep = elm_separator_add(sb->bar);
elm_box_pack_end(sb->bar, sep);
evas_object_show(sep);
icon = elm_toolbar_item_append(sb->bar, "media-playback-start", "Slideshow", _slideshow, sb);
elm_toolbar_item_priority_set(icon, 150);
elm_toolbar_item_separator_set(elm_toolbar_item_append(sb->bar, NULL, NULL, NULL, NULL), EINA_TRUE);
but = _button_add(sb->bar, "zoom-in");
evas_object_smart_callback_add(but, "clicked", _zoom_in_cb, sb);
icon = elm_toolbar_item_append(sb->bar, "zoom-in", "In", _zoom_in_cb, sb);
elm_toolbar_item_priority_set(icon, 100);
but = _button_add(sb->bar, "zoom-out");
evas_object_smart_callback_add(but, "clicked", _zoom_out_cb, sb);
icon = elm_toolbar_item_append(sb->bar, "zoom-out", "Out", _zoom_out_cb, sb);
elm_toolbar_item_priority_set(icon, 100);
but = _button_add(sb->bar, "zoom-fit");
evas_object_smart_callback_add(but, "clicked", _zoom_fit_cb, sb);
icon = elm_toolbar_item_append(sb->bar, "zoom-fit", "Fit", _zoom_fit_cb, sb);
elm_toolbar_item_priority_set(icon, 80);
but = _button_add(sb->bar, "zoom-original");
evas_object_smart_callback_add(but, "clicked", _zoom_1_cb, sb);
icon = elm_toolbar_item_append(sb->bar, "zoom-original", "1:1", _zoom_1_cb, sb);
elm_toolbar_item_priority_set(icon, 80);
elm_toolbar_item_separator_set(elm_toolbar_item_append(sb->bar, NULL, NULL, NULL, NULL), EINA_TRUE);
sep = elm_separator_add(sb->bar);
elm_box_pack_end(sb->bar, sep);
evas_object_show(sep);
icon = elm_toolbar_item_append(sb->bar, "go-first", "First", _go_first, sb);
elm_toolbar_item_priority_set(icon, 60);
sb->sentry = elm_entry_add(sb->bar);
evas_object_size_hint_weight_set(sb->sentry, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_align_set(sb->sentry, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_entry_single_line_set(sb->sentry, EINA_TRUE);
elm_entry_scrollable_set(sb->sentry, EINA_TRUE);
elm_scroller_policy_set(sb->sentry, ELM_SCROLLER_POLICY_OFF,
ELM_SCROLLER_POLICY_OFF);
elm_object_disabled_set(sb->sentry, EINA_TRUE);
evas_object_smart_callback_add
(sb->sentry, "activated", _changed_file_text, sb);
elm_box_pack_end(sb->bar, sb->sentry);
evas_object_show(sb->sentry);
icon = elm_toolbar_item_append(sb->bar, "go-previous", "Previous", _go_prev, sb);
elm_toolbar_item_priority_set(icon, 70);
sep = elm_separator_add(sb->bar);
elm_box_pack_end(sb->bar, sep);
evas_object_show(sep);
icon = elm_toolbar_item_append(sb->bar, "go-next", "Next", _go_next, sb);
elm_toolbar_item_priority_set(icon, 70);
but = _button_add(sb->bar, "go-first");
evas_object_smart_callback_add(but, "clicked", _go_first, sb);
but = _button_add(sb->bar, "go-previous");
evas_object_smart_callback_add(but, "clicked", _go_prev, sb);
but = _button_add(sb->bar, "go-next");
evas_object_smart_callback_add(but, "clicked", _go_next, sb);
but = _button_add(sb->bar, "go-last");
evas_object_smart_callback_add(but, "clicked", _go_last, sb);
sep = elm_separator_add(sb->bar);
elm_box_pack_end(sb->bar, sep);
evas_object_show(sep);
but = _button_add(sb->bar, "media-playback-start");
evas_object_smart_callback_add(but, "clicked", _slideshow, sb);
icon = elm_toolbar_item_append(sb->bar, "go-last", "Last", _go_last, sb);
elm_toolbar_item_priority_set(icon, 60);
sb->handlers = eina_list_append
(sb->handlers, ecore_event_handler_add

View File

@ -15,6 +15,7 @@ struct _Ephoto_Thumb_Browser
Ephoto *ephoto;
Evas_Object *main;
Evas_Object *bar;
Evas_Object *edje;
Evas_Object *entry;
Evas_Object *grid;
Eio_File *ls;
@ -229,11 +230,22 @@ _ephoto_thumb_selected(void *data, Evas_Object *o __UNUSED__, void *event_info)
evas_object_smart_callback_call(tb->main, "view", e);
}
static void
_changed_dir(void *data, Evas_Object *o __UNUSED__, void *event_info)
{
Ephoto_Thumb_Browser *tb = data;
const char *path = event_info;
if (path)
ephoto_directory_set(tb->ephoto, path);
else
elm_fileselector_entry_path_set(tb->entry, tb->ephoto->config->directory);
}
static void
_changed_dir_text(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
{
Ephoto_Thumb_Browser *tb = data;
const char *path = elm_entry_entry_get(tb->entry);
const char *path = elm_fileselector_entry_path_get(tb->entry);
if (ecore_file_is_dir(path))
ephoto_directory_set(tb->ephoto, path);
}
@ -376,7 +388,7 @@ _ephoto_thumb_populate_start(void *data, int type __UNUSED__, void *event __UNUS
_todo_items_free(tb);
_grid_items_free(tb);
elm_gengrid_clear(tb->grid);
elm_entry_entry_set(tb->entry, tb->ephoto->config->directory);
elm_fileselector_entry_path_set(tb->entry, tb->ephoto->config->directory);
_up_item_add_if_required(tb);
return ECORE_CALLBACK_PASS_ON;
@ -419,33 +431,15 @@ _ephoto_thumb_entry_create(void *data, int type __UNUSED__, void *event)
return ECORE_CALLBACK_PASS_ON;
}
static Evas_Object *
_button_add(Evas_Object *box, const char *image)
{
Evas_Object *but, *ic;
but = elm_button_add(box);
ic = elm_icon_add(but);
elm_icon_standard_set(ic, image);
evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
elm_object_content_set(but, ic);
evas_object_size_hint_align_set(but, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_box_pack_end(box, but);
evas_object_show(but);
return but;
}
Evas_Object *
ephoto_thumb_browser_add(Ephoto *ephoto, Evas_Object *parent)
{
Evas_Object *box = elm_box_add(parent);
Evas_Object *but, *min, *max;
Evas_Object *layout = elm_layout_add(parent);
Elm_Object_Item *icon;
Evas_Object *min, *max, *ic;
Ephoto_Thumb_Browser *tb;
EINA_SAFETY_ON_NULL_RETURN_VAL(box, NULL);
EINA_SAFETY_ON_NULL_RETURN_VAL(layout, NULL);
tb = calloc(1, sizeof(Ephoto_Thumb_Browser));
EINA_SAFETY_ON_NULL_GOTO(tb, error);
@ -471,52 +465,59 @@ ephoto_thumb_browser_add(Ephoto *ephoto, Evas_Object *parent)
elm_theme_extension_add(NULL, PACKAGE_DATA_DIR "/themes/default/ephoto.edj");
tb->ephoto = ephoto;
tb->main = box;
elm_box_horizontal_set(tb->main, EINA_FALSE);
elm_box_homogeneous_set(tb->main, EINA_FALSE);
tb->edje = elm_layout_edje_get(layout);
tb->main = layout;
evas_object_event_callback_add(tb->main, EVAS_CALLBACK_DEL, _main_del, tb);
evas_object_event_callback_add
evas_object_event_callback_add
(tb->main, EVAS_CALLBACK_KEY_DOWN, _key_down, tb);
evas_object_data_set(tb->main, "thumb_browser", tb);
tb->bar = elm_box_add(tb->main);
elm_box_horizontal_set(tb->bar, EINA_TRUE);
elm_box_homogeneous_set(tb->bar, EINA_FALSE);
evas_object_size_hint_weight_set(tb->bar, 0.0, 0.0);
evas_object_size_hint_align_set(tb->bar, EVAS_HINT_FILL, 0.0);
evas_object_show(tb->bar);
elm_box_pack_end(tb->main, tb->bar);
if (!elm_layout_theme_set(tb->main, "layout", "application", "toolbar-vbox"))
{
ERR("Could not load style 'toolbar-vbox' from theme!");
goto error;
}
tb->bar = edje_object_part_external_object_get(tb->edje, "elm.external.toolbar");
if (!tb->bar)
{
ERR("Could not find toolbar in layout!");
goto error;
}
but = _button_add(tb->bar, "image-x-generic");
evas_object_smart_callback_add(but, "clicked", _view_single, tb);
elm_toolbar_homogeneous_set(tb->bar, EINA_FALSE);
elm_toolbar_shrink_mode_set(tb->bar, ELM_TOOLBAR_SHRINK_MENU);
elm_toolbar_menu_parent_set(tb->bar, parent);
elm_toolbar_select_mode_set(tb->bar, ELM_OBJECT_SELECT_MODE_NONE);
but = _button_add(tb->bar, "media-playback-start");
evas_object_smart_callback_add(but, "clicked", _slideshow, tb);
elm_toolbar_item_append(tb->bar, "image", "View Single", _view_single, tb);
elm_toolbar_item_append(tb->bar, "media-playback-start", "Slideshow", _slideshow, tb);
icon = elm_toolbar_item_append(tb->bar, "zoom-in", "Zoom In", _zoom_in, tb);
max = elm_object_item_widget_get(icon);
icon = elm_toolbar_item_append(tb->bar, "zoom-out", "Zoom Out", _zoom_out, tb);
min = elm_object_item_widget_get(icon);
evas_object_data_set(max, "min", min);
evas_object_data_set(min, "max", max);
tb->entry = elm_entry_add(tb->bar);
ic = elm_icon_add(tb->main);
elm_icon_standard_set(ic, "folder");
evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
tb->entry = elm_fileselector_entry_add(tb->main);
EINA_SAFETY_ON_NULL_GOTO(tb->entry, error);
evas_object_size_hint_weight_set(tb->entry, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_align_set(tb->entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_entry_single_line_set(tb->entry, EINA_TRUE);
elm_entry_scrollable_set(tb->entry, EINA_TRUE);
elm_scroller_policy_set(tb->entry, ELM_SCROLLER_POLICY_OFF,
ELM_SCROLLER_POLICY_OFF);
elm_object_text_set(tb->entry, "Choose");
elm_object_part_content_set(tb->entry, "button icon", ic);
elm_fileselector_entry_folder_only_set(tb->entry, EINA_TRUE);
elm_fileselector_entry_inwin_mode_set(tb->entry, EINA_TRUE);
elm_fileselector_entry_expandable_set(tb->entry, EINA_FALSE);
evas_object_smart_callback_add
(tb->entry, "file,chosen", _changed_dir, tb);
evas_object_smart_callback_add
(tb->entry, "activated", _changed_dir_text, tb);
evas_object_show(tb->entry);
elm_box_pack_end(tb->bar, tb->entry);
but = _button_add(tb->bar, "zoom-in.png");
evas_object_smart_callback_add(but, "clicked", _zoom_in, tb);
max = but;
but = _button_add(tb->bar, "zoom-out.png");
evas_object_smart_callback_add(but, "clicked", _zoom_out, tb);
min = but;
evas_object_data_set(max, "min", min);
evas_object_data_set(min, "max", max);
elm_layout_box_append(tb->main, "elm.box.content", tb->entry);
tb->grid = elm_gengrid_add(tb->main);
EINA_SAFETY_ON_NULL_GOTO(tb->grid, error);
@ -537,7 +538,7 @@ ephoto_thumb_browser_add(Ephoto *ephoto, Evas_Object *parent)
_zoom_set(tb, tb->ephoto->config->thumb_size);
evas_object_show(tb->grid);
elm_box_pack_end(tb->main, tb->grid);
elm_layout_box_append(tb->main, "elm.box.content", tb->grid);
tb->handlers = eina_list_append
(tb->handlers, ecore_event_handler_add