extra: refactor site creation

extra_private has grown quite big so extra_util.h is now a seperated
header.
This commit is contained in:
Marcel Hollerbach 2017-04-07 19:08:19 +02:00
parent 890e1b0558
commit 4cdeff4506
5 changed files with 149 additions and 55 deletions

View File

@ -132,17 +132,10 @@ _item_selected(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event
_show_tooltip(elm_object_item_data_get(it));
}
static Extra_Ui_Site_Template temp = {
Extra_Ui_Site_Template background_site = {
extra_backgrounds_list,
"thumb",
_content_basic_get,
_text_basic_get,
_item_selected,
};
Evas_Object*
extra_background_selector_create(void)
{
return extra_ui_site_add(&temp);
}

View File

@ -48,10 +48,10 @@ _extra_win_sync_done_cb(void *data EINA_UNUSED)
evas_object_size_hint_align_set(table, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_show(table);
_ui.background_selector = extra_background_selector_create();
_ui.background_selector = extra_ui_site_add(&background_site);
elm_table_pack(table, _ui.background_selector, 0, 1, 1, 1);
_ui.theme_selector = extra_theme_selector_create();
_ui.theme_selector = extra_ui_site_add(&theme_site);
elm_table_pack(table, _ui.theme_selector, 0, 1, 1, 1);
segcontrol = elm_segment_control_add(table);

View File

@ -2,6 +2,7 @@
# define EXTRA_PRIVATE_H_
#include "../lib/extra.h"
#include "extra_util.h"
typedef struct {
Evas_Object *win;
@ -11,36 +12,7 @@ typedef struct {
} Ui;
extern Ui _ui;
extern Extra_Ui_Site_Template theme_site;
extern Extra_Ui_Site_Template background_site;
Evas_Object* extra_theme_selector_create(void);
Evas_Object* extra_background_selector_create(void);
void extra_ui_theme_ask_for_default(Extra_Theme *theme);
Extra_Progress* extra_ui_progress_popup_show(const char *title, Extra_Done_Cb done, void *data);
typedef char *(Extra_ui_preview_get)(void *obj);
typedef Extra_Request *(Extra_ui_preview_download)(Extra_Progress *progress, void *obj);
typedef struct {
Extra_ui_preview_get *preview_get;
Extra_ui_preview_download *preview_download;
} Extra_Ui_Small_Preview_Accessor;
Evas_Object* extra_ui_small_preview_new(Extra_Ui_Small_Preview_Accessor acc, Evas_Object *par, void *data);
Evas_Object* extra_ui_base_object_detail(void *real_obj, Extra_Base_Object *obj, Extra_Ui_Small_Preview_Accessor acc, Evas_Object *par);
void extra_ui_details_window_show(Evas_Object *content);
void extra_ui_fullscreen_preview(char *path);
void extra_ui_show_popup_toolbar(Evas_Object *content);
void gengrid_reapply_state(Evas_Object *grid);
typedef struct {
Eina_List* (*list)(void);
const char *item_style;
Elm_Gen_Item_Content_Get_Cb content;
Elm_Gen_Item_Text_Get_Cb text;
Evas_Smart_Cb selected;
} Extra_Ui_Site_Template;
Evas_Object* extra_ui_site_add(Extra_Ui_Site_Template *site_temp);
void extra_ui_site_refill(Evas_Object *site);
#endif

View File

@ -189,20 +189,6 @@ _item_selected(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event
extra_ui_show_popup_toolbar(box);
}
static Extra_Ui_Site_Template temp = {
extra_themes_list,
"thumb",
_content_basic_get,
_text_basic_get,
_item_selected,
};
Evas_Object*
extra_theme_selector_create(void)
{
return extra_ui_site_add(&temp);
}
//==== Small preview
static Evas_Object*
@ -254,3 +240,13 @@ extra_theme_small_new(Evas_Object *par, Extra_Theme *theme)
}
return table;
}
//external accessable
Extra_Ui_Site_Template theme_site = {
extra_themes_list,
"thumb",
_content_basic_get,
_text_basic_get,
_item_selected,
};

133
src/bin/extra_util.h Normal file
View File

@ -0,0 +1,133 @@
#ifndef EXTRA_UTIL_H
#define EXTRA_UTIL_H
#include "../lib/extra.h"
/* Typedefs for later use */
typedef struct _Extra_Ui_Small_Preview_Accessor Extra_Ui_Small_Preview_Accessor;
typedef struct _Extra_Ui_Site_Template Extra_Ui_Site_Template;
/*
* General purpose helper functions that displays dialogs / windows / and visual representation
*/
/**
* Ask if the given theme should be displayed as default
*
* @param theme the extra theme to ask for
*/
void extra_ui_theme_ask_for_default(Extra_Theme *theme);
/**
* Create a popup that shows a popup with a progressbar and a label
*
* @param title the title to display in the popup
* @param down_cb once the progress hit 100% this function is called
* @param data the data to pass to down_cb
*
* @return a extra_progress you can pass this value to other api functions, the
progress of this function will then be directly displayed in this object
*/
Extra_Progress* extra_ui_progress_popup_show(const char *title, Extra_Done_Cb done, void *data);
/**
* Fill a Evas_Object with the data passed in by obj
*
* @param real_obj the object that gets passed to the accessor functions
* @param obj the object that specifies the base data
* @param acc the accessor to get preview and download path from a real_obj
* @param parent the parent to use when creating the objects
*
* @return A Elm_Table that contains contents from
*
*/
Evas_Object* extra_ui_base_object_detail(void *real_obj, Extra_Base_Object *obj, Extra_Ui_Small_Preview_Accessor acc, Evas_Object *par);
/**
* Display a inwin in the extra window with the given content
*
* @param content the content to display in the inwin
*
*/
void extra_ui_details_window_show(Evas_Object *content);
/**
* Preview a path as fullscreen window on the desktop
*
* @param path the path to load the image from
*/
void extra_ui_fullscreen_preview(char *path);
/**
* Popups a toolbar at the top center of the window with the specified content
*
* @param content the content to display
*
*/
void extra_ui_show_popup_toolbar(Evas_Object *content);
/*
* Util function to get the state of the current selected item reapplied
*
* @param grid a Elm_Gengrid
*/
void gengrid_reapply_state(Evas_Object *grid);
/*
* Helperfunctions to create a visually representation of a preview or a progressbar
* that displays the progress on downloading the preview
*/
/*
* If the function returns NULL download is called
*/
typedef char *(Extra_ui_preview_get)(void *obj);
typedef Extra_Request *(Extra_ui_preview_download)(Extra_Progress *progress, void *obj);
struct _Extra_Ui_Small_Preview_Accessor{
Extra_ui_preview_get *preview_get;
Extra_ui_preview_download *preview_download;
} ;
/**
* Create a object that previews the visualy component of a object
* If a object is not ready to be displayed the data is downloaded, or the progressbar is displayed
*
* @param acc a struct that defines how to get the preview and download function out of data
* @param obj the parent to use
* @param data the data to pass to the functions of the acc functions
*
* @return a evas image that displayes the previews from the data ptr
*/
Evas_Object* extra_ui_small_preview_new(Extra_Ui_Small_Preview_Accessor acc, Evas_Object *par, void *data);
/**
* Helper functions to define a site
*
* A site is just a gengrid that gets filled with the items returned by the list function pointer
*/
struct _Extra_Ui_Site_Template{
Eina_List* (*list)(void);
const char *item_style;
Elm_Gen_Item_Content_Get_Cb content;
Elm_Gen_Item_Text_Get_Cb text;
Evas_Smart_Cb selected;
};
/**
* Create a Evas Object out of a site template
*
* @param site_temp the content is later copied into the internal struct and
does not need to be present after this call
*/
Evas_Object* extra_ui_site_add(Extra_Ui_Site_Template *site_temp);
/*
* Call again the list function to renew all items in the previously created site.
*
* @param site the evas object, returned by extra_ui_site_add
*
*/
void extra_ui_site_refill(Evas_Object *site);
#endif