summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYeongjong Lee <cleanlyj@naver.com>2019-02-27 14:45:32 -0500
committerMike Blumenkrantz <zmike@samsung.com>2019-02-27 14:45:32 -0500
commit138fa4eeaa37eb45ec52be9a194ae4d98aa76c1e (patch)
treecc87658f56b404fd6fb9cc740d760c02ae22346b
parent5572000f1a02ed1107d3757d7ca06727c1217813 (diff)
ui.table: implement homogeneous mode
Summary: Homogeneous mode means children are of the same weight and of the same min size which is determined by maximum min size of cells. Depends on D7841 Reviewers: Jaehyun_Cho, jpeg, zmike Subscribers: cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D7892
-rw-r--r--src/lib/elementary/efl_ui_table.c14
-rw-r--r--src/lib/elementary/efl_ui_table.eo15
-rw-r--r--src/lib/elementary/efl_ui_table_layout.c95
-rw-r--r--src/lib/elementary/efl_ui_table_private.h2
4 files changed, 118 insertions, 8 deletions
diff --git a/src/lib/elementary/efl_ui_table.c b/src/lib/elementary/efl_ui_table.c
index 5f42043b16..ff7de54166 100644
--- a/src/lib/elementary/efl_ui_table.c
+++ b/src/lib/elementary/efl_ui_table.c
@@ -123,6 +123,20 @@ _custom_table_calc(Eo *obj, Custom_Table_Data *pd)
123/* End of custom table class */ 123/* End of custom table class */
124 124
125EOLIAN static void 125EOLIAN static void
126_efl_ui_table_homogeneous_set(Eo *obj EINA_UNUSED, Efl_Ui_Table_Data *pd, Eina_Bool homogeneoush, Eina_Bool homogeneousv)
127{
128 pd->homogeneoush = !!homogeneoush;
129 pd->homogeneousv = !!homogeneousv;
130}
131
132EOLIAN static void
133_efl_ui_table_homogeneous_get(const Eo *obj EINA_UNUSED, Efl_Ui_Table_Data *pd, Eina_Bool *homogeneoush, Eina_Bool *homogeneousv)
134{
135 if (homogeneoush) *homogeneoush = pd->homogeneoush;
136 if (homogeneousv) *homogeneousv = pd->homogeneousv;
137}
138
139EOLIAN static void
126_efl_ui_table_efl_pack_layout_layout_update(Eo *obj, Efl_Ui_Table_Data *pd) 140_efl_ui_table_efl_pack_layout_layout_update(Eo *obj, Efl_Ui_Table_Data *pd)
127{ 141{
128 _efl_ui_table_custom_layout(obj, pd); 142 _efl_ui_table_custom_layout(obj, pd);
diff --git a/src/lib/elementary/efl_ui_table.eo b/src/lib/elementary/efl_ui_table.eo
index f3c067f98b..7ccc7d1bc8 100644
--- a/src/lib/elementary/efl_ui_table.eo
+++ b/src/lib/elementary/efl_ui_table.eo
@@ -2,6 +2,21 @@ class @beta Efl.Ui.Table extends Efl.Ui.Widget implements Efl.Pack_Table, Efl.Pa
2 Efl.Ui.Direction 2 Efl.Ui.Direction
3{ 3{
4 [[Efl UI table class]] 4 [[Efl UI table class]]
5 methods {
6 @property homogeneous {
7 [[Control homogeneous mode.
8
9 This will enable the homogeneous mode where cells are of the same
10 weight and of the same min size which is determined by maximum min
11 size of cells.]]
12 values {
13 homogeneoush : bool; [[$true if the box is homogeneous horizontally,
14 $false otherwise]]
15 homogeneousv : bool; [[$true if the box is homogeneous vertically,
16 $false otherwise]]
17 }
18 }
19 }
5 implements { 20 implements {
6 Efl.Object.constructor; 21 Efl.Object.constructor;
7 Efl.Canvas.Group.group_calculate; 22 Efl.Canvas.Group.group_calculate;
diff --git a/src/lib/elementary/efl_ui_table_layout.c b/src/lib/elementary/efl_ui_table_layout.c
index 0a21384a8f..b3009e9f7c 100644
--- a/src/lib/elementary/efl_ui_table_layout.c
+++ b/src/lib/elementary/efl_ui_table_layout.c
@@ -33,6 +33,7 @@ struct _Table_Calc
33 int rows; 33 int rows;
34 int cols; 34 int cols;
35 int want[2]; 35 int want[2];
36 int hgsize[2];
36 double weight_sum[2]; 37 double weight_sum[2];
37 Cell_Calc *cell_calc[2]; 38 Cell_Calc *cell_calc[2];
38 Efl_Ui_Container_Layout_Calc layout_calc[2]; 39 Efl_Ui_Container_Layout_Calc layout_calc[2];
@@ -98,6 +99,45 @@ _cell_weight_calc(Table_Calc *table_calc, Eina_Bool axis)
98} 99}
99 100
100static void 101static void
102_efl_ui_table_homogeneous_cell_init(Table_Calc *table_calc, Eina_Bool axis)
103{
104 int i, index = 0, mmin = 0, count;
105 Cell_Calc *prev_cell = NULL, *cell_calc;
106
107 cell_calc = table_calc->cell_calc[axis];
108 count = axis ? table_calc->rows : table_calc->cols;
109
110 for (i = 0; i < count; i++)
111 {
112 if (!cell_calc[i].occupied) continue;
113
114 cell_calc[i].index = index++;
115 if (cell_calc[i].space > mmin)
116 mmin = cell_calc[i].space;
117
118 if (prev_cell)
119 prev_cell->next = i;
120
121 prev_cell = &cell_calc[i];
122 }
123 if (prev_cell)
124 prev_cell->next = count;
125
126 table_calc->layout_calc[axis].size -= (table_calc->layout_calc[axis].pad
127 * (index - 1));
128
129 table_calc->want[axis] = mmin * index;
130 table_calc->weight_sum[axis] = index;
131
132 if (table_calc->want[axis] > table_calc->layout_calc[axis].size)
133 table_calc->hgsize[axis] = table_calc->want[axis] / index;
134 else
135 table_calc->hgsize[axis] = table_calc->layout_calc[axis].size / index;
136
137 table_calc->hgsize[axis] += table_calc->layout_calc[axis].pad;
138}
139
140static void
101_efl_ui_table_regular_cell_init(Table_Calc *table_calc, Eina_Bool axis) 141_efl_ui_table_regular_cell_init(Table_Calc *table_calc, Eina_Bool axis)
102{ 142{
103 int i, index = 0, acc, want = 0, count; 143 int i, index = 0, acc, want = 0, count;
@@ -140,6 +180,20 @@ _efl_ui_table_regular_cell_init(Table_Calc *table_calc, Eina_Bool axis)
140} 180}
141 181
142static inline int 182static inline int
183_efl_ui_table_homogeneous_item_pos_get(Table_Calc *table_calc, Item_Calc *item, Eina_Bool axis)
184{
185 return 0.5 + table_calc->layout_calc[axis].pos + (table_calc->hgsize[axis]
186 * table_calc->cell_calc[axis][item->cell_index[axis]].index);
187}
188
189static inline int
190_efl_ui_table_homogeneous_item_size_get(Table_Calc *table_calc, Item_Calc *item, Eina_Bool axis)
191{
192 return (table_calc->hgsize[axis] * item->cell_span[axis])
193 - table_calc->layout_calc[axis].pad;
194}
195
196static inline int
143_efl_ui_table_regular_item_pos_get(Table_Calc *table_calc, Item_Calc *item, Eina_Bool axis) 197_efl_ui_table_regular_item_pos_get(Table_Calc *table_calc, Item_Calc *item, Eina_Bool axis)
144{ 198{
145 return 0.5 + table_calc->layout_calc[axis].pos 199 return 0.5 + table_calc->layout_calc[axis].pos
@@ -170,6 +224,8 @@ _efl_ui_table_custom_layout(Efl_Ui_Table *ui_table, Efl_Ui_Table_Data *pd)
170 Item_Calc *items, *item; 224 Item_Calc *items, *item;
171 Efl_Ui_Container_Item_Hints *hints; 225 Efl_Ui_Container_Item_Hints *hints;
172 int i = 0, rows, cols; 226 int i = 0, rows, cols;
227 int (*_efl_ui_table_item_pos_get[2])(Table_Calc *, Item_Calc *, Eina_Bool);
228 int (*_efl_ui_table_item_size_get[2])(Table_Calc *, Item_Calc *, Eina_Bool);
173 229
174 Table_Calc table_calc; 230 Table_Calc table_calc;
175 231
@@ -215,12 +271,12 @@ _efl_ui_table_custom_layout(Efl_Ui_Table *ui_table, Efl_Ui_Table_Data *pd)
215 271
216 _efl_ui_container_layout_item_init(item->obj, hints); 272 _efl_ui_container_layout_item_init(item->obj, hints);
217 273
218 if (table_calc.layout_calc[0].fill) 274 if (table_calc.layout_calc[0].fill || pd->homogeneoush)
219 hints[0].weight = 1; 275 hints[0].weight = 1;
220 else if (hints[0].weight < 0) 276 else if (hints[0].weight < 0)
221 hints[0].weight = 0; 277 hints[0].weight = 0;
222 278
223 if (table_calc.layout_calc[1].fill) 279 if (table_calc.layout_calc[1].fill || pd->homogeneousv)
224 hints[1].weight = 1; 280 hints[1].weight = 1;
225 else if (hints[1].weight < 0) 281 else if (hints[1].weight < 0)
226 hints[1].weight = 0; 282 hints[1].weight = 0;
@@ -251,8 +307,31 @@ _efl_ui_table_custom_layout(Efl_Ui_Table *ui_table, Efl_Ui_Table_Data *pd)
251 } 307 }
252 } 308 }
253 309
254 _efl_ui_table_regular_cell_init(&table_calc, 0); 310 if (pd->homogeneoush)
255 _efl_ui_table_regular_cell_init(&table_calc, 1); 311 {
312 _efl_ui_table_homogeneous_cell_init(&table_calc, 0);
313 _efl_ui_table_item_pos_get[0] = _efl_ui_table_homogeneous_item_pos_get;
314 _efl_ui_table_item_size_get[0] = _efl_ui_table_homogeneous_item_size_get;
315 }
316 else
317 {
318 _efl_ui_table_regular_cell_init(&table_calc, 0);
319 _efl_ui_table_item_pos_get[0] = _efl_ui_table_regular_item_pos_get;
320 _efl_ui_table_item_size_get[0] = _efl_ui_table_regular_item_size_get;
321 }
322
323 if (pd->homogeneousv)
324 {
325 _efl_ui_table_homogeneous_cell_init(&table_calc, 1);
326 _efl_ui_table_item_pos_get[1] = _efl_ui_table_homogeneous_item_pos_get;
327 _efl_ui_table_item_size_get[1] = _efl_ui_table_homogeneous_item_size_get;
328 }
329 else
330 {
331 _efl_ui_table_regular_cell_init(&table_calc, 1);
332 _efl_ui_table_item_pos_get[1] = _efl_ui_table_regular_item_pos_get;
333 _efl_ui_table_item_size_get[1] = _efl_ui_table_regular_item_size_get;
334 }
256 335
257 for (i = 0; i < pd->count; i++) 336 for (i = 0; i < pd->count; i++)
258 { 337 {
@@ -260,10 +339,10 @@ _efl_ui_table_custom_layout(Efl_Ui_Table *ui_table, Efl_Ui_Table_Data *pd)
260 item = &items[i]; 339 item = &items[i];
261 hints = items[i].hints; 340 hints = items[i].hints;
262 341
263 space.x = _efl_ui_table_regular_item_pos_get(&table_calc, item, 0); 342 space.x = _efl_ui_table_item_pos_get[0](&table_calc, item, 0);
264 space.y = _efl_ui_table_regular_item_pos_get(&table_calc, item, 1); 343 space.y = _efl_ui_table_item_pos_get[1](&table_calc, item, 1);
265 space.w = _efl_ui_table_regular_item_size_get(&table_calc, item, 0); 344 space.w = _efl_ui_table_item_size_get[0](&table_calc, item, 0);
266 space.h = _efl_ui_table_regular_item_size_get(&table_calc, item, 1); 345 space.h = _efl_ui_table_item_size_get[1](&table_calc, item, 1);
267 346
268 item_geom.w = hints[0].fill ? space.w : hints[0].min; 347 item_geom.w = hints[0].fill ? space.w : hints[0].min;
269 item_geom.h = hints[1].fill ? space.h : hints[1].min; 348 item_geom.h = hints[1].fill ? space.h : hints[1].min;
diff --git a/src/lib/elementary/efl_ui_table_private.h b/src/lib/elementary/efl_ui_table_private.h
index 0ab08e5109..4aea410376 100644
--- a/src/lib/elementary/efl_ui_table_private.h
+++ b/src/lib/elementary/efl_ui_table_private.h
@@ -45,6 +45,8 @@ struct _Efl_Ui_Table_Data
45 double h, v; 45 double h, v;
46 } align; 46 } align;
47 Eina_Bool linear_recalc : 1; 47 Eina_Bool linear_recalc : 1;
48 Eina_Bool homogeneoush : 1;
49 Eina_Bool homogeneousv : 1;
48}; 50};
49 51
50struct _Table_Item_Iterator 52struct _Table_Item_Iterator