fileselector: Add support to change the size of thumbnails in grid view.
authorRyuan Choi <ryuan.choi@gmail.com>
Tue, 3 Dec 2013 09:28:52 +0000 (18:28 +0900)
committerRyuan Choi <ryuan.choi@gmail.com>
Tue, 3 Dec 2013 09:28:52 +0000 (18:28 +0900)
Reviewers: seoz, raster

Reviewed By: raster

CC: raster
Differential Revision: https://phab.enlightenment.org/D276

legacy/elementary/src/bin/test_fileselector.c
legacy/elementary/src/lib/elc_fileselector.c
legacy/elementary/src/lib/elc_fileselector_eo.h
legacy/elementary/src/lib/elc_fileselector_legacy.h
legacy/elementary/src/lib/elm_widget_fileselector.h

index eb76236..f22a6e9 100644 (file)
@@ -334,6 +334,85 @@ _mode_option_create(Evas_Object *parent, Evas_Object *fs)
    return frame;
 }
 
+static void
+_small_icon_clicked(void *data,
+                    Evas_Object *obj EINA_UNUSED,
+                    void *event_info EINA_UNUSED)
+{
+   Evas_Object *fs = data;
+   Evas_Coord w, h;
+
+   elm_fileselector_thumbnail_size_get(fs, &w, &h);
+
+   elm_fileselector_thumbnail_size_set(fs, 56, 56);
+   printf("Thumbnail icon was changed from %dx%d to 56x56\n", w, h);
+}
+
+static void
+_middle_icon_clicked(void *data,
+                     Evas_Object *obj EINA_UNUSED,
+                     void *event_info EINA_UNUSED)
+{
+   Evas_Object *fs = data;
+   Evas_Coord w, h;
+
+   elm_fileselector_thumbnail_size_get(fs, &w, &h);
+
+   elm_fileselector_thumbnail_size_set(fs, 78, 78);
+   printf("Thumbnail icon was changed from %dx%d to 78x78\n", w, h);
+}
+
+static void
+_big_icon_clicked(void *data,
+                  Evas_Object *obj EINA_UNUSED,
+                  void *event_info EINA_UNUSED)
+{
+   Evas_Object *fs = data;
+   Evas_Coord w, h;
+
+   elm_fileselector_thumbnail_size_get(fs, &w, &h);
+
+   elm_fileselector_thumbnail_size_set(fs, 131, 131);
+   printf("Thumbnail icon was changed from %dx%d to 131x131\n", w, h);
+}
+
+static Evas_Object *
+_thumbnail_size_option_create(Evas_Object *parent, Evas_Object *fs)
+{
+   Evas_Object *frame = NULL, *hbox = NULL, *bt = NULL;
+
+   frame = elm_frame_add(parent);
+   elm_object_text_set(frame, "Thumbnail Size");
+   evas_object_size_hint_weight_set(frame, EVAS_HINT_EXPAND, 0);
+   evas_object_size_hint_align_set(frame, EVAS_HINT_FILL, 0);
+   evas_object_show(frame);
+
+   hbox = elm_box_add(frame);
+   elm_box_horizontal_set(hbox, EINA_TRUE);
+   elm_object_content_set(frame, hbox);
+   evas_object_show(hbox);
+
+   bt = elm_button_add(hbox);
+   elm_object_text_set(bt, "Small icon");
+   evas_object_smart_callback_add(bt, "clicked", _small_icon_clicked, fs);
+   elm_box_pack_end(hbox, bt);
+   evas_object_show(bt);
+
+   bt = elm_button_add(hbox);
+   elm_object_text_set(bt, "Middle icon");
+   evas_object_smart_callback_add(bt, "clicked", _middle_icon_clicked, fs);
+   elm_box_pack_end(hbox, bt);
+   evas_object_show(bt);
+
+   bt = elm_button_add(hbox);
+   elm_object_text_set(bt, "Big icon");
+   evas_object_smart_callback_add(bt, "clicked", _big_icon_clicked, fs);
+   elm_box_pack_end(hbox, bt);
+   evas_object_show(bt);
+
+   return frame;
+}
+
 void
 test_fileselector(void *data       EINA_UNUSED,
                   Evas_Object *obj EINA_UNUSED,
@@ -395,5 +474,6 @@ test_fileselector(void *data       EINA_UNUSED,
    elm_box_pack_end(vbox, _option_create(vbox, fs));
    elm_box_pack_end(vbox, _getter_option_create(vbox, fs));
    elm_box_pack_end(vbox, _mode_option_create(vbox, fs));
+   elm_box_pack_end(vbox, _thumbnail_size_option_create(vbox, fs));
 }
 
index e6a9b8e..3e4e44a 100644 (file)
@@ -21,6 +21,9 @@ EAPI Eo_Op ELM_OBJ_FILESELECTOR_BASE_ID = EO_NOOP;
 #define MY_CLASS_NAME "Elm_Fileselector"
 #define MY_CLASS_NAME_LEGACY "elm_fileselector"
 
+/* FIXME: need a way to find a gap between the size of item and thumbnail */
+#define GENGRID_PADDING 16
+
 static Elm_Genlist_Item_Class *list_itc[ELM_FILE_LAST];
 static Elm_Gengrid_Item_Class *grid_itc[ELM_FILE_LAST];
 
@@ -150,15 +153,25 @@ _itc_icon_folder_get(void *data __UNUSED__,
                      Evas_Object *obj,
                      const char *source)
 {
-   Evas_Object *ic;
+   Evas_Object *ic, *grid, *f;
 
    if (strcmp(source, "elm.swallow.icon")) return NULL;
 
+   f = evas_object_data_get(obj, "parent");
+   ELM_FILESELECTOR_DATA_GET(f, sd);
+
    ic = elm_icon_add(obj);
    elm_icon_standard_set(ic, "folder");
-
    evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
-   return ic;
+   evas_object_show(ic);
+
+   grid = elm_grid_add(obj);
+   elm_grid_size_set(grid, 1, 1);
+   elm_grid_pack(grid, ic, 0, 0, 1, 1);
+   evas_object_size_hint_min_set(grid, sd->thumbnail_size.w, sd->thumbnail_size.h);
+   evas_object_show(grid);
+
+   return grid;
 }
 
 static Evas_Object *
@@ -167,16 +180,26 @@ _itc_icon_image_get(void *data,
                     const char *source)
 {
    const char *filename = data;
-   Evas_Object *ic;
+   Evas_Object *ic, *grid, *f;
 
    if (strcmp(source, "elm.swallow.icon")) return NULL;
 
+   f = evas_object_data_get(obj, "parent");
+   ELM_FILESELECTOR_DATA_GET(f, sd);
+
    ic = elm_icon_add(obj);
    elm_icon_standard_set(ic, "image");
    elm_icon_thumb_set(ic, filename, NULL);
-
    evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
-   return ic;
+   evas_object_show(ic);
+
+   grid = elm_grid_add(obj);
+   elm_grid_size_set(grid, 1, 1);
+   elm_grid_pack(grid, ic, 0, 0, 1, 1);
+   evas_object_size_hint_min_set(grid, sd->thumbnail_size.w, sd->thumbnail_size.h);
+   evas_object_show(grid);
+
+   return grid;
 }
 
 static Evas_Object *
@@ -184,15 +207,25 @@ _itc_icon_file_get(void *data __UNUSED__,
                    Evas_Object *obj,
                    const char *source)
 {
-   Evas_Object *ic;
+   Evas_Object *ic, *grid, *f;
 
    if (strcmp(source, "elm.swallow.icon")) return NULL;
 
+   f = evas_object_data_get(obj, "parent");
+   ELM_FILESELECTOR_DATA_GET(f, sd);
+
    ic = elm_icon_add(obj);
    elm_icon_standard_set(ic, "file");
-
    evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
-   return ic;
+   evas_object_show(ic);
+
+   grid = elm_grid_add(obj);
+   elm_grid_size_set(grid, 1, 1);
+   elm_grid_pack(grid, ic, 0, 0, 1, 1);
+   evas_object_size_hint_min_set(grid, sd->thumbnail_size.w, sd->thumbnail_size.h);
+   evas_object_show(grid);
+
+   return grid;
 }
 
 static Eina_Bool
@@ -1014,6 +1047,7 @@ _files_list_add(Evas_Object *obj)
    Evas_Object *li;
 
    li = elm_genlist_add(obj);
+   evas_object_data_set(li, "parent", obj);
    elm_widget_mirrored_automatic_set(li, EINA_FALSE);
    evas_object_size_hint_align_set(li, EVAS_HINT_FILL, EVAS_HINT_FILL);
    evas_object_size_hint_weight_set(li, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
@@ -1039,16 +1073,17 @@ static Evas_Object *
 _files_grid_add(Evas_Object *obj)
 {
    Evas_Object *grid;
-   int s;
+
+   ELM_FILESELECTOR_DATA_GET(obj, sd);
 
    grid = elm_gengrid_add(obj);
+   evas_object_data_set(grid, "parent", obj);
    elm_widget_mirrored_automatic_set(grid, EINA_FALSE);
    evas_object_size_hint_align_set(grid, EVAS_HINT_FILL, EVAS_HINT_FILL);
    evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
 
-   // XXX: will fail for dynamic finger size changing
-   s = elm_config_finger_size_get() * 2;
-   elm_gengrid_item_size_set(grid, s, s);
+   elm_gengrid_item_size_set(grid, sd->thumbnail_size.w + GENGRID_PADDING, sd->thumbnail_size.h + GENGRID_PADDING);
+
    elm_gengrid_align_set(grid, 0.0, 0.0);
 
    evas_object_smart_callback_add(grid, "selected", _on_item_selected, obj);
@@ -1227,6 +1262,10 @@ _elm_fileselector_smart_add(Eo *obj, void *_pd, va_list *list EINA_UNUSED)
    elm_widget_sub_object_add(obj, pb);
    priv->spinner = pb;
 
+   // XXX: will fail for dynamic finger size changing
+   priv->thumbnail_size.w = elm_config_finger_size_get() * 2 - GENGRID_PADDING;
+   priv->thumbnail_size.h = priv->thumbnail_size.w;
+
    // files_view
    priv->files_view = _files_list_add(obj);
 
@@ -1905,6 +1944,56 @@ _hidden_visible_get(Eo *obj EINA_UNUSED, void *_pd, va_list *list EINA_UNUSED)
    *ret = sd->hidden_visible;
 }
 
+EAPI void
+elm_fileselector_thumbnail_size_set(Evas_Object *obj,
+                                    Evas_Coord w,
+                                    Evas_Coord h)
+{
+   ELM_FILESELECTOR_CHECK(obj);
+   eo_do(obj, elm_obj_fileselector_thumbnail_size_set(w, h));
+}
+
+static void
+_thumbnail_size_set(Eo *obj __UNUSED__, void *_pd, va_list *list EINA_UNUSED)
+{
+   Evas_Coord w = va_arg(*list, Evas_Coord);
+   Evas_Coord h = va_arg(*list, Evas_Coord);
+   Elm_Fileselector_Smart_Data *sd = _pd;
+
+   if (sd->thumbnail_size.w == w && sd->thumbnail_size.h == h) return;
+
+   if (!w || !h)
+     w = h = elm_config_finger_size_get() * 2 - GENGRID_PADDING;
+
+   sd->thumbnail_size.w = w;
+   sd->thumbnail_size.h = h;
+
+   if (sd->mode == ELM_FILESELECTOR_GRID)
+     elm_gengrid_item_size_set(sd->files_view, w + GENGRID_PADDING, h + GENGRID_PADDING);
+
+   _populate(obj, sd->path, NULL, NULL);
+}
+
+EAPI void
+elm_fileselector_thumbnail_size_get(const Evas_Object *obj,
+                                    Evas_Coord *w,
+                                    Evas_Coord *h)
+{
+   ELM_FILESELECTOR_CHECK(obj);
+   eo_do((Eo *) obj, elm_obj_fileselector_thumbnail_size_get(w, h));
+}
+
+static void
+_thumbnail_size_get(Eo *obj EINA_UNUSED, void *_pd, va_list *list EINA_UNUSED)
+{
+   Evas_Coord *w = va_arg(*list, Evas_Coord *);
+   Evas_Coord *h = va_arg(*list, Evas_Coord *);
+   Elm_Fileselector_Smart_Data *sd = _pd;
+
+   if (w) *w = sd->thumbnail_size.w;
+   if (h) *h = sd->thumbnail_size.h;
+}
+
 static void
 _elm_fileselector_smart_focus_next_manager_is(Eo *obj EINA_UNUSED, void *_pd EINA_UNUSED, va_list *list)
 {
@@ -1987,6 +2076,8 @@ _class_constructor(Eo_Class *klass)
         EO_OP_FUNC(ELM_OBJ_FILESELECTOR_ID(ELM_OBJ_FILESELECTOR_SUB_ID_FILTERS_CLEAR), _filters_clear),
         EO_OP_FUNC(ELM_OBJ_FILESELECTOR_ID(ELM_OBJ_FILESELECTOR_SUB_ID_HIDDEN_VISIBLE_SET), _hidden_visible_set),
         EO_OP_FUNC(ELM_OBJ_FILESELECTOR_ID(ELM_OBJ_FILESELECTOR_SUB_ID_HIDDEN_VISIBLE_GET), _hidden_visible_get),
+        EO_OP_FUNC(ELM_OBJ_FILESELECTOR_ID(ELM_OBJ_FILESELECTOR_SUB_ID_THUMBNAIL_SIZE_SET), _thumbnail_size_set),
+        EO_OP_FUNC(ELM_OBJ_FILESELECTOR_ID(ELM_OBJ_FILESELECTOR_SUB_ID_THUMBNAIL_SIZE_GET), _thumbnail_size_get),
         EO_OP_FUNC_SENTINEL
    };
    eo_class_funcs_set(klass, func_desc);
@@ -2049,6 +2140,8 @@ static const Eo_Op_Description op_desc[] = {
      EO_OP_DESCRIPTION(ELM_OBJ_FILESELECTOR_SUB_ID_FILTERS_CLEAR, "Clear filters"),
      EO_OP_DESCRIPTION(ELM_OBJ_FILESELECTOR_SUB_ID_HIDDEN_VISIBLE_SET, "Enable or disable visibility of hidden files/directories in the file selector widget."),
      EO_OP_DESCRIPTION(ELM_OBJ_FILESELECTOR_SUB_ID_HIDDEN_VISIBLE_GET, "Get if visibility of hidden files/directories in the file selector widget is enabled or disabled."),
+     EO_OP_DESCRIPTION(ELM_OBJ_FILESELECTOR_SUB_ID_THUMBNAIL_SIZE_SET, "Set the size for the thumbnail of the file selector widget's view, if it's in #ELM_FILESELECTOR_GRID mode"),
+     EO_OP_DESCRIPTION(ELM_OBJ_FILESELECTOR_SUB_ID_THUMBNAIL_SIZE_GET, "Get the size for the thumbnails of a given file selector widget."),
      EO_OP_DESCRIPTION_SENTINEL
 };
 static const Eo_Class_Description class_desc = {
index e50fa9c..a87a91c 100644 (file)
@@ -32,6 +32,8 @@ enum
    ELM_OBJ_FILESELECTOR_SUB_ID_FILTERS_CLEAR,
    ELM_OBJ_FILESELECTOR_SUB_ID_HIDDEN_VISIBLE_SET,
    ELM_OBJ_FILESELECTOR_SUB_ID_HIDDEN_VISIBLE_GET,
+   ELM_OBJ_FILESELECTOR_SUB_ID_THUMBNAIL_SIZE_SET,
+   ELM_OBJ_FILESELECTOR_SUB_ID_THUMBNAIL_SIZE_GET,
    ELM_OBJ_FILESELECTOR_SUB_ID_LAST
 };
 
@@ -301,5 +303,31 @@ enum
 #define elm_obj_fileselector_hidden_visible_get(ret) ELM_OBJ_FILESELECTOR_ID(ELM_OBJ_FILESELECTOR_SUB_ID_HIDDEN_VISIBLE_GET), EO_TYPECHECK(Eina_Bool *, ret)
 
 /**
+ * @def elm_obj_fileselector_thumbnail_size_get
+ * @since 1.9
+ *
+ * Get the size for the thumbnail of a given file selector widget
+ *
+ * @param[out] w
+ * @param[out] h
+ *
+ * @see elm_fileselector_thumbnail_size_get
+ */
+#define elm_obj_fileselector_thumbnail_size_get(w, h) ELM_OBJ_FILESELECTOR_ID(ELM_OBJ_FILESELECTOR_SUB_ID_THUMBNAIL_SIZE_GET), EO_TYPECHECK(Evas_Coord *, w), EO_TYPECHECK(Evas_Coord *, h)
+
+/**
+ * @def elm_obj_fileselector_group_thumbnail_size_set
+ * @since 1.9
+ *
+ * Set the size for the thumbnail of the file selector widget's view.
+ *
+ * @param[in] w
+ * @param[in] h
+ *
+ * @see elm_fileselector_thumbnail_size_set
+ */
+#define elm_obj_fileselector_thumbnail_size_set(w, h) ELM_OBJ_FILESELECTOR_ID(ELM_OBJ_FILESELECTOR_SUB_ID_THUMBNAIL_SIZE_SET), EO_TYPECHECK(Evas_Coord, w), EO_TYPECHECK(Evas_Coord, h)
+
+/**
  * @}
  */
index 4b5ab8a..e00244d 100644 (file)
@@ -362,3 +362,36 @@ EAPI void                  elm_fileselector_hidden_visible_set(Evas_Object *obj,
  * @ingroup Fileselector
  */
 EAPI Eina_Bool             elm_fileselector_hidden_visible_get(const Evas_Object *obj);
+
+/**
+ * Set the size for the thumbnail of the file selector widget's view.
+ *
+ * @param obj The file selector object
+ * @param w The thumbnail's width.
+ * @param h The thumbnail's height.
+ *
+ * @note If w or h is 0, default value will be used.
+ *
+ * @see elm_fileselector_thumbnail_size_get()
+ *
+ * @since 1.9
+ * @ingroup Fileselector
+ */
+EAPI void                  elm_fileselector_thumbnail_size_set(Evas_Object *obj, Evas_Coord w, Evas_Coord h);
+
+/**
+ * Get the size for the thumbnail of a given file selector widget
+ *
+ * @param obj The file selector object.
+ * @param w Pointer to a variable where to store the thumbnail's width.
+ * @param h Pointer to a variable where to store the thumbnail's height.
+ *
+ * @note Use @c NULL pointers on the size values you're not
+ * interested in: they'll be ignored by the function.
+ *
+ * @see elm_fileselector_thumbnail_size_set()
+ *
+ * @since 1.9
+ * @ingroup Fileselector
+ */
+EAPI void                  elm_fileselector_thumbnail_size_get(const Evas_Object *obj, Evas_Coord *w, Evas_Coord *h);
index cda2471..1a8118c 100644 (file)
@@ -51,6 +51,8 @@ struct _Elm_Fileselector_Smart_Data
    Eio_Monitor             *monitor;
    Eina_List               *handlers;
 
+   Evas_Coord_Size          thumbnail_size;
+
    Elm_Fileselector_Mode mode;
 
    Eina_Bool             only_folder : 1;