elementary/theme, widget, win, toolbar, thumb, toggle, util, box - removed white...
[framework/uifw/elementary.git] / src / lib / els_box.c
1 #include <Elementary.h>
2 #include "elm_priv.h"
3
4 static void
5 _smart_extents_calculate(Evas_Object *box, Evas_Object_Box_Data *priv, int horizontal, int homogeneous)
6 {
7    Evas_Coord minw, minh, mnw, mnh;
8    const Eina_List *l;
9    Evas_Object_Box_Option *opt;
10
11    /* FIXME: need to calc max */
12    minw = 0;
13    minh = 0;
14    if (homogeneous)
15      {
16         EINA_LIST_FOREACH(priv->children, l, opt)
17           {
18              evas_object_size_hint_min_get(opt->obj, &mnw, &mnh);
19              if (minh < mnh) minh = mnh;
20              if (minw < mnw) minw = mnw;
21           }
22         if (horizontal)
23           minw *= eina_list_count(priv->children);
24         else
25           minh *= eina_list_count(priv->children);
26      }
27    else
28      {
29         EINA_LIST_FOREACH(priv->children, l, opt)
30           {
31              evas_object_size_hint_min_get(opt->obj, &mnw, &mnh);
32              if (horizontal)
33                {
34                   if (minh < mnh) minh = mnh;
35                   minw += mnw;
36                }
37              else
38                {
39                   if (minw < mnw) minw = mnw;
40                   minh += mnh;
41                }
42           }
43      }
44    evas_object_size_hint_min_set(box, minw, minh);
45 }
46
47 void
48 _els_box_layout(Evas_Object *o, Evas_Object_Box_Data *priv, int horizontal, int homogeneous, int rtl)
49 {
50    Evas_Coord x, y, w, h, xx, yy;
51    const Eina_List *l;
52    Evas_Object *obj;
53    Evas_Coord minw, minh, wdif, hdif;
54    int count = 0, expand = 0;
55    double ax, ay;
56    Evas_Object_Box_Option *opt;
57
58    _smart_extents_calculate(o, priv, horizontal, homogeneous);
59
60    evas_object_geometry_get(o, &x, &y, &w, &h);
61
62    evas_object_size_hint_min_get(o, &minw, &minh);
63    evas_object_size_hint_align_get(o, &ax, &ay);
64    count = eina_list_count(priv->children);
65    if (w < minw)
66      {
67         x = x + ((w - minw) * (1.0 - ax));
68         w = minw;
69      }
70    if (h < minh)
71      {
72         y = y + ((h - minh) * (1.0 - ay));
73         h = minh;
74      }
75    EINA_LIST_FOREACH(priv->children, l, opt)
76      {
77         double wx, wy;
78
79         evas_object_size_hint_weight_get(opt->obj, &wx, &wy);
80         if (horizontal)
81           {
82              if (wx > 0.0) expand++;
83           }
84         else
85           {
86              if (wy > 0.0) expand++;
87           }
88      }
89    if (!expand)
90      {
91         evas_object_size_hint_align_get(o, &ax, &ay);
92         if (horizontal)
93           {
94              x += (double)(w - minw) * ax;
95              w = minw;
96           }
97         else
98           {
99              y += (double)(h - minh) * ay;
100              h = minh;
101           }
102      }
103    wdif = w - minw;
104    hdif = h - minh;
105    xx = x;
106    yy = y;
107    EINA_LIST_FOREACH(priv->children, l, opt)
108      {
109         Evas_Coord mnw, mnh, mxw, mxh;
110         double wx, wy;
111         int fw, fh, xw, xh;
112
113         obj = opt->obj;
114         evas_object_size_hint_align_get(obj, &ax, &ay);
115         evas_object_size_hint_weight_get(obj, &wx, &wy);
116         evas_object_size_hint_min_get(obj, &mnw, &mnh);
117         evas_object_size_hint_max_get(obj, &mxw, &mxh);
118         fw = fh = 0;
119         xw = xh = 0;
120         if (ax == -1.0) {fw = 1; ax = 0.5;}
121         if (ay == -1.0) {fh = 1; ay = 0.5;}
122         if (wx > 0.0) xw = 1;
123         if (wy > 0.0) xh = 1;
124         if (horizontal)
125           {
126              Evas_Coord ww, hh, ow, oh;
127
128              if (homogeneous)
129                {
130                   ww = (w / (Evas_Coord)count);
131                }
132              else
133                {
134                   ww = mnw;
135                   if ((expand > 0) && (xw))
136                     {
137                        if (expand == 1) ow = wdif;
138                        else ow = (w - minw) / expand;
139                        wdif -= ow;
140                        ww += ow;
141                     }
142                }
143              hh = h;
144              ow = mnw;
145              if (fw) ow = ww;
146              if ((mxw >= 0) && (mxw < ow)) ow = mxw;
147              oh = mnh;
148              if (fh) oh = hh;
149              if ((mxh >= 0) && (mxh < oh)) oh = mxh;
150              evas_object_move(obj,
151                               ((!rtl) ? (xx) : (x + (w - (xx - x) - ww)))
152                               + (Evas_Coord)(((double)(ww - ow)) * ax),
153                               yy + (Evas_Coord)(((double)(hh - oh)) * ay));
154              evas_object_resize(obj, ow, oh);
155              xx += ww;
156           }
157         else
158           {
159              Evas_Coord ww, hh, ow, oh;
160
161              if (homogeneous)
162                {
163                   hh = (h / (Evas_Coord)count);
164                }
165              else
166                {
167                   hh = mnh;
168                   if ((expand > 0) && (xh))
169                     {
170                        if (expand == 1) oh = hdif;
171                        else oh = (h - minh) / expand;
172                        hdif -= oh;
173                        hh += oh;
174                     }
175                }
176              ww = w;
177              ow = mnw;
178              if (fw) ow = ww;
179              if ((mxw >= 0) && (mxw < ow)) ow = mxw;
180              oh = mnh;
181              if (fh) oh = hh;
182              if ((mxh >= 0) && (mxh < oh)) oh = mxh;
183              evas_object_move(obj,
184                               xx + (Evas_Coord)(((double)(ww - ow)) * ax),
185                               yy + (Evas_Coord)(((double)(hh - oh)) * ay));
186              evas_object_resize(obj, ow, oh);
187              yy += hh;
188           }
189      }
190 }
191