1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
/*
* vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
*/
/* TODO: support different preference modes ala edje */
#include "e.h"
typedef struct _E_Widget_Data E_Widget_Data;
struct _E_Widget_Data
{
Evas_Object *obj;
Evas_Object *child;
int aspect_w, aspect_h;
int aspect_preference;
double align_x, align_y;
};
static void
_e_wid_del_hook(Evas_Object *obj)
{
E_Widget_Data *wd;
wd = e_widget_data_get(obj);
if (!wd) return;
free(wd);
}
static void
_e_wid_reconfigure(E_Widget_Data *wd)
{
int px, py, pw, ph;
int cx, cy, cw, ch;
double ap, ad;
if (!wd->obj || !wd->child) return;
evas_object_geometry_get(wd->obj, &px, &py, &pw, &ph);
ap = (double)pw / ph;
ad = (double)(wd->aspect_w) / wd->aspect_h;
if (ap >= ad)
{
ch = ph;
cw = (ch * wd->aspect_w) / wd->aspect_h;
}
else
{
cw = pw;
ch = (cw * wd->aspect_h) / wd->aspect_w;
}
cx = px + (wd->align_x * (pw - cw));
cy = py + (wd->align_y * (ph - ch));
evas_object_resize(wd->child, cw, ch);
evas_object_move(wd->child, cx, cy);
}
static void
_cb_reconfigure(void *data, Evas *a, Evas_Object *obj, void *event_info)
{
E_Widget_Data *wd = data;
_e_wid_reconfigure(wd);
}
EAPI Evas_Object *
e_widget_aspect_add(Evas *evas, int w, int h)
{
Evas_Object *obj;
E_Widget_Data *wd;
obj = e_widget_add(evas);
wd = calloc(1, sizeof(E_Widget_Data));
wd->obj = obj;
e_widget_data_set(obj, wd);
e_widget_del_hook_set(obj, _e_wid_del_hook);
evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _cb_reconfigure, wd);
evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _cb_reconfigure, wd);
wd->align_x = 0.5;
wd->align_y = 0.5;
wd->aspect_w = w;
wd->aspect_h = h;
_e_wid_reconfigure(wd);
return obj;
}
EAPI void
e_widget_aspect_aspect_set(Evas_Object *obj, int w, int h)
{
E_Widget_Data *wd;
wd = e_widget_data_get(obj);
if (!wd) return;
wd->aspect_w = w;
wd->aspect_h = h;
_e_wid_reconfigure(wd);
}
EAPI void
e_widget_aspect_align_set(Evas_Object *obj, double align_x, double align_y)
{
E_Widget_Data *wd;
wd = e_widget_data_get(obj);
if (!wd) return;
wd->align_x = align_x;
wd->align_y = align_y;
_e_wid_reconfigure(wd);
}
EAPI void
e_widget_aspect_child_set(Evas_Object *obj, Evas_Object *child)
{
E_Widget_Data *wd;
int mw, mh;
wd = e_widget_data_get(obj);
if (!wd) return;
wd->child = child;
e_widget_min_size_get(child, &mw, &mh);
e_widget_min_size_set(obj, mw, mh);
e_widget_sub_object_add(obj, child);
_e_wid_reconfigure(wd);
}
|