forked from enlightenment/efl
efl_ui_grid: make it work with item_container
this also reformats the example, removes comments that are misleading, removes UI elements that have no purpose. Reviewed-by: Cedric BAIL <cedric.bail@free.fr> Differential Revision: https://phab.enlightenment.org/D9384
This commit is contained in:
parent
7525ab16f1
commit
a6543fb68f
|
@ -13,92 +13,66 @@
|
|||
|
||||
#define IMAX 500;
|
||||
|
||||
typedef struct _Grid_Event_Data {
|
||||
Eo *grid;
|
||||
Eo *item;
|
||||
} Grid_Event_Data;
|
||||
|
||||
Eo *
|
||||
EoGenerate(const Efl_Class *klass, Eo *parent, Efl_Ui_Layout_Orientation dir)
|
||||
{
|
||||
Eo* obj = efl_add(klass, parent);
|
||||
if (dir != EFL_UI_LAYOUT_ORIENTATION_DEFAULT) efl_ui_layout_orientation_set(obj, dir);
|
||||
efl_gfx_hint_weight_set(obj, EFL_GFX_HINT_EXPAND, EFL_GFX_HINT_EXPAND);
|
||||
efl_gfx_hint_fill_set(obj, EINA_TRUE, EINA_TRUE);
|
||||
return obj;
|
||||
}
|
||||
|
||||
EAPI_MAIN int
|
||||
elm_main(int argc, char **argv)
|
||||
elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
|
||||
{
|
||||
int itemmax = IMAX;
|
||||
int i = 0;
|
||||
if (argv[1]) itemmax = atoi(argv[1]);
|
||||
Eo *win, *box, *bbx, *upbtn, *allbtn, *clrbtn;
|
||||
Eo *grid, *gitem;
|
||||
Grid_Event_Data *gd = calloc(sizeof(Grid_Event_Data *), 1);
|
||||
int i = 0, itemmax = IMAX;
|
||||
Efl_Ui_Win *win;
|
||||
Efl_Ui_Box *box;
|
||||
Efl_Ui_Grid *grid;
|
||||
Efl_Ui_Item *gitem;
|
||||
|
||||
win = efl_add(EFL_UI_WIN_CLASS, efl_main_loop_get(),
|
||||
efl_ui_win_type_set(efl_added, EFL_UI_WIN_TYPE_BASIC),
|
||||
efl_text_set(efl_added, "Efl.Ui.Grid"),
|
||||
efl_ui_win_autodel_set(efl_added, EINA_TRUE));
|
||||
win = efl_add(EFL_UI_WIN_CLASS, efl_main_loop_get(),
|
||||
efl_ui_win_type_set(efl_added, EFL_UI_WIN_TYPE_BASIC),
|
||||
efl_text_set(efl_added, "Efl.Ui.Grid"),
|
||||
efl_ui_win_autodel_set(efl_added, EINA_TRUE));
|
||||
|
||||
box = EoGenerate(EFL_UI_BOX_CLASS, win, EFL_UI_LAYOUT_ORIENTATION_VERTICAL);
|
||||
box = efl_add(EFL_UI_BOX_CLASS, win);
|
||||
efl_gfx_hint_weight_set(box, EFL_GFX_HINT_EXPAND, EFL_GFX_HINT_EXPAND);
|
||||
elm_win_resize_object_add(win, box);
|
||||
|
||||
Eo *btn = efl_add(EFL_UI_BUTTON_CLASS, box);
|
||||
efl_gfx_hint_weight_set(btn, 0.3, 0.3);
|
||||
efl_gfx_hint_fill_set(btn, EINA_TRUE, EINA_TRUE);
|
||||
efl_text_set(btn, "BUTTON");
|
||||
efl_pack_end(box, btn);
|
||||
|
||||
Eina_Bool horiz = 0;
|
||||
// TEST#1 : Create Grid
|
||||
gd->grid = grid = EoGenerate(EFL_UI_GRID_CLASS, box, (horiz ? EFL_UI_LAYOUT_ORIENTATION_HORIZONTAL : EFL_UI_LAYOUT_ORIENTATION_VERTICAL));
|
||||
efl_ui_grid_item_size_set(grid, EINA_SIZE2D(100, 120)); // 4X4
|
||||
efl_gfx_arrangement_content_padding_set(grid, 5.0, 5.0, EINA_TRUE);
|
||||
efl_gfx_arrangement_content_align_set(grid, 0.5, 0.5);
|
||||
grid = efl_add(EFL_UI_GRID_CLASS, box);
|
||||
efl_gfx_hint_weight_set(grid, EFL_GFX_HINT_EXPAND, EFL_GFX_HINT_EXPAND);
|
||||
efl_pack_end(box, grid);
|
||||
|
||||
// TEST#2 : Set Item Default Size
|
||||
|
||||
Efl_Ui_Grid_Item *target = NULL;
|
||||
|
||||
for (i = 0; i < itemmax; i++)
|
||||
{
|
||||
int r = 0, g = 0, b = 0;
|
||||
// TEST#3 : Create Grid Item
|
||||
gitem = efl_add(EFL_UI_GRID_DEFAULT_ITEM_CLASS, grid);
|
||||
if (i == 300) target = gitem;
|
||||
if (i == 0) gd->item = gitem;
|
||||
Eo *rect = evas_object_rectangle_add(evas_object_evas_get(win));
|
||||
switch (i % 5)
|
||||
{
|
||||
case 0:
|
||||
r = 255;
|
||||
break;
|
||||
case 1:
|
||||
g = 255;
|
||||
break;
|
||||
case 2:
|
||||
b = 255;
|
||||
break;
|
||||
case 3:
|
||||
r = g = b = 255;
|
||||
break;
|
||||
case 4:
|
||||
r = g = b = 0;
|
||||
break;
|
||||
}
|
||||
efl_gfx_color_set(rect, r, g, b, 255);
|
||||
efl_content_set(gitem, rect);
|
||||
// TEST#4 : Pack end
|
||||
efl_pack_end(grid, gitem);
|
||||
}
|
||||
{
|
||||
int r = 0, g = 0, b = 0;
|
||||
gitem = efl_add(EFL_UI_GRID_DEFAULT_ITEM_CLASS, grid);
|
||||
efl_gfx_hint_size_min_set(gitem, EINA_SIZE2D(100, 120));
|
||||
|
||||
Eo *rect = evas_object_rectangle_add(evas_object_evas_get(win));
|
||||
switch (i % 5)
|
||||
{
|
||||
case 0:
|
||||
r = 255;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
g = 255;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
b = 255;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
r = g = b = 255;
|
||||
break;
|
||||
|
||||
case 4:
|
||||
r = g = b = 0;
|
||||
break;
|
||||
}
|
||||
efl_gfx_color_set(rect, r, g, b, 255);
|
||||
efl_content_set(gitem, rect);
|
||||
efl_pack_end(grid, gitem);
|
||||
}
|
||||
|
||||
efl_gfx_entity_size_set(win, EINA_SIZE2D(417, 600));
|
||||
|
||||
elm_run();
|
||||
return 0;
|
||||
}
|
||||
|
||||
ELM_MAIN()
|
||||
|
|
|
@ -119,6 +119,7 @@ examples = [
|
|||
'efl_ui_theme_example_02',
|
||||
'efl_ui_slideshow_example',
|
||||
'efl_ui_radio_example_01',
|
||||
'efl_ui_grid_example_1'
|
||||
]
|
||||
|
||||
foreach example : examples
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,100 +1,10 @@
|
|||
import efl_ui_grid_item;
|
||||
|
||||
class @beta Efl.Ui.Grid extends Efl.Ui.Layout_Base implements
|
||||
Efl.Ui.Scrollable_Interactive,
|
||||
Efl.Ui.Scrollbar,
|
||||
Efl.Pack_Linear, Efl.Pack_Layout,
|
||||
Efl.Ui.Layout_Orientable,
|
||||
Efl.Ui.Selectable,
|
||||
Efl.Ui.Multi_Selectable,
|
||||
Efl.Gfx.Arrangement
|
||||
class @beta Efl.Ui.Grid extends Efl.Ui.Item_Container
|
||||
{
|
||||
[[Simple grid widget with Pack interface.]]
|
||||
methods {
|
||||
@property item_size {
|
||||
[[Property data of item size.]]
|
||||
set {}
|
||||
get {}
|
||||
values {
|
||||
size: Eina.Size2D; [[last selected item of grid.]]
|
||||
}
|
||||
}
|
||||
item_scroll {
|
||||
[[scroll move the item to show in the viewport.]]
|
||||
params {
|
||||
@in item: Efl.Ui.Grid_Item; [[Target item.]]
|
||||
@in animation: bool; [[Boolean value for animation of scroll move.]]
|
||||
}
|
||||
}
|
||||
item_scroll_align {
|
||||
[[scroll move the item to show at the align position of the viewport.]]
|
||||
params {
|
||||
@in item: Efl.Ui.Grid_Item; [[Target item.]]
|
||||
@in align: double; [[align value in Viewport.]]
|
||||
@in animation: bool; [[Boolean value for animation of scroll move.]]
|
||||
}
|
||||
}
|
||||
@property last_selected_item {
|
||||
[[Property data of last selected item.]]
|
||||
get {}
|
||||
values {
|
||||
item: Efl.Ui.Grid_Item; [[last selected item of grid.]]
|
||||
}
|
||||
}
|
||||
selected_items_get {
|
||||
[[Get the selected items iterator. The iterator sequence will be decided by selection.]]
|
||||
return: iterator<Efl.Ui.Grid_Item> @owned @no_unused; [[Iterator covered by selected items list.
|
||||
user have to free the iterator after used.]]
|
||||
}
|
||||
}
|
||||
|
||||
implements {
|
||||
//Efl.Object
|
||||
Efl.Object.constructor;
|
||||
Efl.Object.finalize;
|
||||
Efl.Object.destructor;
|
||||
Efl.Object.invalidate;
|
||||
|
||||
//Efl.Canvas
|
||||
Efl.Canvas.Group.group_calculate;
|
||||
//Efl.Container
|
||||
Efl.Container.content_iterate;
|
||||
Efl.Container.content_count;
|
||||
|
||||
Efl.Ui.Layout_Orientable.orientation { get; set; }
|
||||
|
||||
//Efl.Ui.Widget
|
||||
Efl.Ui.Widget.theme_apply;
|
||||
|
||||
//Efl.Ui.Focus
|
||||
//Efl.Ui.Focus.Object.on_focus_update;
|
||||
|
||||
//Efl.Pack
|
||||
Efl.Pack.pack_clear;
|
||||
Efl.Pack.unpack_all;
|
||||
Efl.Pack.unpack;
|
||||
Efl.Pack.pack;
|
||||
Efl.Pack_Linear.pack_end;
|
||||
|
||||
Efl.Pack_Linear.pack_begin;
|
||||
Efl.Pack_Linear.pack_before;
|
||||
Efl.Pack_Linear.pack_after;
|
||||
Efl.Pack_Linear.pack_at;
|
||||
Efl.Pack_Linear.pack_unpack_at;
|
||||
Efl.Pack_Linear.pack_index_get;
|
||||
Efl.Pack_Linear.pack_content_get;
|
||||
Efl.Pack_Layout.layout_update;
|
||||
Efl.Pack_Layout.layout_request;
|
||||
Efl.Gfx.Arrangement.content_padding { get; set; }
|
||||
Efl.Gfx.Arrangement.content_align { get; set; }
|
||||
|
||||
//Efl.Ui.Scrollable
|
||||
Efl.Ui.Scrollable_Interactive.match_content { set; }
|
||||
|
||||
//Efl.Ui.Multi_Selectable
|
||||
Efl.Ui.Multi_Selectable.select_mode {get; set;}
|
||||
}
|
||||
composite {
|
||||
Efl.Ui.Scrollable_Interactive;
|
||||
Efl.Ui.Scrollbar;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,83 +0,0 @@
|
|||
#ifndef EFL_UI_GRID_PRIVATE_H
|
||||
#define EFL_UI_GRID_PRIVATE_H
|
||||
|
||||
#include "Elementary.h"
|
||||
|
||||
typedef struct _Efl_Ui_Grid_Data
|
||||
{
|
||||
// Eo Objects
|
||||
Eo *obj;
|
||||
Eo *pan; /* Internal pan for scroll */
|
||||
Eo *content;
|
||||
Eo *smanager; /* Scroll Manager for support scroll with pan */
|
||||
Eina_Rect geo;
|
||||
Eina_Position2D pre_pos;
|
||||
Efl_Ui_Layout_Orientation dir;
|
||||
|
||||
struct {
|
||||
Efl_Ui_Grid_Item *item; /* Scroll target item */
|
||||
double align; /* Item scroll aligned position.
|
||||
-1 is for default case of scroll in */
|
||||
Eina_Bool anim : 1; /* boolean data for animation on scroll */
|
||||
} scroll; /* Item scroll values for deferred operation */
|
||||
|
||||
struct {
|
||||
Eina_Size2D size;
|
||||
Eina_Size2D pad;
|
||||
struct {
|
||||
double w;
|
||||
double h;
|
||||
} align;
|
||||
int count;
|
||||
int row;
|
||||
int col;
|
||||
} item;
|
||||
|
||||
int linemax;
|
||||
|
||||
Eina_List *items; /* All item list for internal maintaining */
|
||||
Eina_List *selected; /* Selected items list */
|
||||
Efl_Ui_Grid_Item *last_selected; /* latest selected item */
|
||||
|
||||
Efl_Ui_Select_Mode select_mode; /* Select mode for items
|
||||
with single or multiple seleciton */
|
||||
|
||||
// Boolean Data
|
||||
Eina_Bool freeze_want : 1; /* Flag for Scroll freezing */
|
||||
Eina_Bool match_content_w: 1; /* Flag for size matching on content width.
|
||||
it will disable horizontal scroll */
|
||||
Eina_Bool match_content_h: 1; /* Flag for size matching on content height.
|
||||
it will disable vertical scroll */
|
||||
Eina_Bool pan_resized : 1; /* Flag for pan resized.
|
||||
This value is used for checking scroll is
|
||||
calculated after initialized */
|
||||
Eina_Bool need_update: 1;
|
||||
Eina_Bool pad_scalable: 1;
|
||||
} Efl_Ui_Grid_Data;
|
||||
|
||||
typedef struct _Item_Iterator
|
||||
{
|
||||
Eina_Iterator iterator;
|
||||
Eina_List *list;
|
||||
Eina_Iterator *real_iterator;
|
||||
Eo *object;
|
||||
} Item_Iterator;
|
||||
|
||||
|
||||
#define EFL_UI_GRID_DATA_GET(o, pd) \
|
||||
Efl_Ui_Grid_Data * pd = efl_data_scope_safe_get(o, EFL_UI_GRID_CLASS)
|
||||
|
||||
#define EFL_UI_GRID_DATA_GET_OR_RETURN(o, ptr, ...) \
|
||||
EFL_UI_GRID_DATA_GET(o, ptr); \
|
||||
if (EINA_UNLIKELY(!ptr)) \
|
||||
{ \
|
||||
ERR("No widget data for object %p (%s)", \
|
||||
o, evas_object_type_get(o)); \
|
||||
return __VA_ARGS__; \
|
||||
}
|
||||
|
||||
#define EFL_UI_GRID_CHECK(obj) \
|
||||
if (EINA_UNLIKELY(!efl_isa((obj), EFL_UI_GRID_CLASS))) \
|
||||
return
|
||||
|
||||
#endif
|
|
@ -357,7 +357,6 @@ elementary_headers_unstable = [
|
|||
'efl_ui_list_item_private.h',
|
||||
'efl_ui_list_private.h',
|
||||
'efl_ui_grid_item_private.h',
|
||||
'efl_ui_grid_private.h',
|
||||
'efl_ui_list_view_private.h',
|
||||
'efl_ui_list_view_seg_array.h',
|
||||
'elm_widget_web.h',
|
||||
|
|
|
@ -17,7 +17,6 @@ grid_setup()
|
|||
|
||||
grid = efl_add(EFL_UI_GRID_CLASS, win);
|
||||
|
||||
efl_ui_grid_item_size_set(grid, EINA_SIZE2D(100, 100));
|
||||
efl_gfx_entity_size_set(grid, EINA_SIZE2D(500, 50));
|
||||
efl_gfx_entity_size_set(win, EINA_SIZE2D(500, 50));
|
||||
efl_gfx_entity_visible_set(win, EINA_TRUE);
|
||||
|
@ -31,6 +30,7 @@ grid_item_pack(Eo *grid, int count, Eina_List **l)
|
|||
for (i = 0; i < count; i++)
|
||||
{
|
||||
item = efl_add(EFL_UI_GRID_DEFAULT_ITEM_CLASS, grid);
|
||||
efl_gfx_hint_size_min_set(item, EINA_SIZE2D(100, 100));
|
||||
if (!item) return EINA_FALSE;
|
||||
if (l) *l = eina_list_append(*l, item);
|
||||
efl_pack(grid, item);
|
||||
|
@ -282,14 +282,14 @@ EFL_START_TEST(efl_ui_grid_scroll)
|
|||
ck_assert(grid_item_pack(grid, 100, NULL) != EINA_FALSE);
|
||||
item = efl_pack_content_get(grid, 50);
|
||||
|
||||
timer = efl_add(EFL_LOOP_TIMER_CLASS, efl_main_loop_get(),
|
||||
timer = efl_add(EFL_LOOP_TIMER_CLASS, efl_main_loop_get(),
|
||||
efl_event_callback_add(efl_added, EFL_LOOP_TIMER_EVENT_TIMER_TICK, grid_timer_cb, NULL),
|
||||
efl_loop_timer_loop_reset(efl_added),
|
||||
efl_loop_timer_interval_set(efl_added, 3.0));
|
||||
|
||||
efl_event_callback_array_add(grid, grid_scroll_callbacks(), timer);
|
||||
/*FIXME: efl_ui_scroll_interface only emit scroll event when animation exist */
|
||||
efl_ui_grid_item_scroll(grid, item, EINA_TRUE);
|
||||
efl_ui_item_container_item_scroll(grid, item, EINA_TRUE);
|
||||
ecore_main_loop_begin();
|
||||
}
|
||||
EFL_END_TEST
|
||||
|
|
Loading…
Reference in New Issue