summaryrefslogtreecommitdiff
path: root/src/lib/elementary/efl_ui_table_layout.c
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 /src/lib/elementary/efl_ui_table_layout.c
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
Diffstat (limited to 'src/lib/elementary/efl_ui_table_layout.c')
-rw-r--r--src/lib/elementary/efl_ui_table_layout.c95
1 files changed, 87 insertions, 8 deletions
diff --git a/src/lib/elementary/efl_ui_table_layout.c b/src/lib/elementary/efl_ui_table_layout.c
index 0a21384..b3009e9 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;