summaryrefslogtreecommitdiff
path: root/src/common/utils.c
blob: cab934bef8c0bb2e8c766772ece8f74d129b681a (plain)
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
 *
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <Elementary.h>
#include <app_debug.h>

Evas_Object *add_window(const char *name)
{
	Evas_Object *win;

	if (!name) {
		_ERR("Invalid argument.");
		return NULL;
	}

	win = elm_win_add(NULL, name, ELM_WIN_BASIC);
	if (!win) {
		_ERR("elm_win_add failed.");
		return NULL;
	}

	elm_win_title_set(win, name);
	elm_win_focus_highlight_enabled_set(win, EINA_TRUE);

	evas_object_show(win);

	return win;
}

Evas_Object *add_layout(Evas_Object *parent, const char *group)
{
	Evas_Object *layout;

	if (!parent || !group) {
		_ERR("Invalid argument.");
		return NULL;
	}

	layout = elm_layout_add(parent);
	if (!layout) {
		_ERR("elm_layout_add failed.");
		return NULL;
	}

	elm_layout_file_set(layout, EDJEFILE, group);

	evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND,
			EVAS_HINT_EXPAND);

	return layout;
}

Evas_Object *add_gengrid(Evas_Object *parent, int item_size_x, int item_size_y)
{
	Evas_Object *grid;

	if (!parent) {
		_ERR("Invalid argument.");
		return NULL;
	}

	grid = elm_gengrid_add(parent);
	if (!grid) {
		_ERR("elm_gengrid_add failed.");
		return NULL;
	}

	evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND,
			EVAS_HINT_EXPAND);
	evas_object_size_hint_align_set(grid, EVAS_HINT_FILL, EVAS_HINT_FILL);

	elm_gengrid_multi_select_set(grid, EINA_FALSE);
	elm_gengrid_horizontal_set(grid, EINA_TRUE);
	elm_gengrid_align_set(grid, 0.0, 0.0);
	elm_gengrid_select_mode_set(grid, ELM_OBJECT_SELECT_MODE_ALWAYS);
	elm_gengrid_item_size_set(grid, elm_config_scale_get() * item_size_x,
			elm_config_scale_get() * item_size_y);
	elm_scroller_policy_set(grid, ELM_SCROLLER_POLICY_OFF,
			ELM_SCROLLER_POLICY_OFF);

	return grid;
}

Evas_Object *add_box(Evas_Object *parent, const char *part,
		Eina_Bool horizontal, Evas_Coord padding_h,
		Evas_Coord padding_v)
{
	Evas_Object *box;

	if (!parent) {
		_ERR("Invalid argument.");
		return NULL;
	}

	box = elm_box_add(parent);
	if (!box) {
		_ERR("elm_box_add failed.");
		return NULL;
	}

	elm_box_horizontal_set(box, horizontal);
	elm_box_padding_set(box, padding_h, padding_v);

	evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND,
			EVAS_HINT_EXPAND);
	evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);

	if (part)
		elm_object_part_content_set(parent, part, box);

	evas_object_show(box);

	return box;
}

Evas_Object *add_button(Evas_Object *parent, const char *part,
		const char *text, const char *style)
{
	Evas_Object *btn;

	if (!parent) {
		_ERR("Invalid argument.");
		return NULL;
	}

	btn = elm_button_add(parent);
	if (!btn) {
		_ERR("elm_button_add failed.");
		return NULL;
	}

	if (part)
		elm_object_part_content_set(parent, part, btn);
	if (text)
		elm_object_text_set(btn, text);
	if (style)
		elm_object_style_set(btn, style);

	evas_object_show(btn);

	return btn;
}