Skip to content

Instantly share code, notes, and snippets.

@vtorri
Created March 15, 2023 11:24
Show Gist options
  • Save vtorri/0a09b3188235e7e1b094b50099ea1c3e to your computer and use it in GitHub Desktop.
Save vtorri/0a09b3188235e7e1b094b50099ea1c3e to your computer and use it in GitHub Desktop.
winlist code
/* gcc -g -Wall -Wextra -o winlist winlist.c `pkg-config --cflags --libs elementary` */
#include <stdio.h>
#include <Elementary.h>
typedef struct
{
Elm_Genlist_Item_Class *itc1;
} api_data;
typedef struct
{
Elm_Object_Item *item;
char *file;
} item;
static void
_cleanup_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
free(data);
}
static void
gl_sel(void *data, Evas_Object *obj, void *event_info)
{
/* printf("sel item data [%p] on genlist obj [%p], item pointer [%p], index [%d]\n", */
/* data, obj, event_info, elm_genlist_item_index_get(event_info)); */
}
Evas_Object *
gl_content_get(void *data, Evas_Object *obj, const char *part)
{
const item *it = data;
Evas_Object *ic;
/* printf(" * %s : %s\n", __FUNCTION__, it->file); */
/* fflush(stdout); */
ic = elm_icon_add(obj);
if (!strcmp(part, "elm.swallow.icon"))
{
elm_image_file_set(ic, it->file, NULL);
evas_object_size_hint_min_set(ic,
ELM_SCALE_SIZE(64),
ELM_SCALE_SIZE(64));
}
evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
return ic;
}
static Eina_List *
_files(void)
{
char cwd[PATH_MAX];
Eina_Iterator *iter;
Eina_List *files = NULL;
char *filename;
if (getcwd(cwd, sizeof(cwd)) == NULL)
return NULL;
iter = eina_file_ls(cwd);
if (!iter)
return NULL;
EINA_ITERATOR_FOREACH(iter, filename)
{
if (eina_str_has_extension(filename, ".jpg"))
files = eina_list_append(files, strdup(filename));
}
eina_iterator_free(iter);
return files;
}
EAPI_MAIN int
elm_main(int argc, char **argv)
{
Evas_Object *win;
Evas_Object *gl;
Evas_Object *o;
int win_w;
int win_h;
api_data *api = calloc(1, sizeof(api_data));
elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
elm_app_name_set("equate");
win = elm_win_add(NULL, "Winlist", ELM_WIN_BASIC);
elm_win_title_set(win, "Winlist");
elm_win_autodel_set(win, EINA_TRUE);
evas_object_event_callback_add(win, EVAS_CALLBACK_FREE, _cleanup_cb, api);
/* background */
o = elm_bg_add(win);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
elm_object_style_set(o, "grad_vert_focus_title_match");
elm_win_resize_object_add(win, o);
evas_object_show(o);
gl = elm_genlist_add(win);
/* for perf : homogeneous */
elm_genlist_homogeneous_set(gl, EINA_TRUE);
evas_object_size_hint_align_set(gl, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_size_hint_weight_set(gl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
elm_win_resize_object_add(win, gl);
evas_object_show(gl);
api->itc1 = elm_genlist_item_class_new();
api->itc1->item_style = "one_icon";
//api->itc1->func.text_get = gl2_text_get;
api->itc1->func.content_get = gl_content_get;
//api->itc1->func.state_get = gl2_state_get;
api->itc1->func.del = NULL;
Eina_List *files;
files = _files();
printf(" * %d\n", eina_list_count(files));
item *items;
items = malloc(eina_list_count(files) * sizeof(item));
char *file;
Eina_List *ll;
EINA_LIST_FOREACH(files, ll, file)
{
printf(" $ %s %u\n", file, (unsigned int)(ll-files));
fflush(stdout);
items[ll-files].file = file;
items[ll-files].item = elm_genlist_item_append(gl,
api->itc1,
items + (ll-files),
NULL,
ELM_GENLIST_ITEM_NONE,
gl_sel,
NULL);
}
//elm_genlist_item_class_free(api->itc1);
win_w = 480;
win_h = 600;
evas_object_resize(win,
win_w * elm_config_scale_get(),
win_h * elm_config_scale_get());
evas_object_show(win);
elm_run();
return 0;
}
ELM_MAIN()
@vtorri
Copy link
Author

vtorri commented Mar 16, 2023

line 44: create the smart obj (and return it)

look in efm_icon and thumb_*.c that generate thumbnails for fs backend
http://www.rasterman.com/files/efm2.tar.xz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment