summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Williams <andy@andywilliams.me>2016-01-15 22:14:24 +0000
committerAndy Williams <andy@andywilliams.me>2016-01-15 22:14:24 +0000
commit360560acc21f64a563b5db3e2325f7bae474ecdb (patch)
treea61db33ae42e9b8cf74015b534f0a15a106740e2
parent98e6b941ef031228d2412d5c940961ab2e088f44 (diff)
scale UI based on window size
Recalculate when the window is resized too.
-rw-r--r--src/main.c34
1 files changed, 26 insertions, 8 deletions
diff --git a/src/main.c b/src/main.c
index ed3c94b..3c83cc4 100644
--- a/src/main.c
+++ b/src/main.c
@@ -6,7 +6,11 @@
6#include "Equate.h" 6#include "Equate.h"
7#include "calc.h" 7#include "calc.h"
8 8
9static Evas_Object *win; 9#define EQUATE_WIDTH 200
10#define EQUATE_HEIGHT 250
11#define EQUATE_TEXT_SCALE 1.6
12
13static Evas_Object *win, *table;
10static Evas_Object *readout; 14static Evas_Object *readout;
11 15
12static const struct 16static const struct
@@ -178,7 +182,6 @@ _create_button(Evas_Object *table, const char *text, int op, int x, int y,
178 evas_object_size_hint_align_set(button, EVAS_HINT_FILL, EVAS_HINT_FILL); 182 evas_object_size_hint_align_set(button, EVAS_HINT_FILL, EVAS_HINT_FILL);
179 elm_object_text_set(button, text); 183 elm_object_text_set(button, text);
180 184
181 elm_object_scale_set(button, 2.0);
182 evas_object_smart_callback_add(button, "clicked", _button_cb, (void *)(uintptr_t)op); 185 evas_object_smart_callback_add(button, "clicked", _button_cb, (void *)(uintptr_t)op);
183 186
184 elm_table_pack(table, button, x, y, w, 1); 187 elm_table_pack(table, button, x, y, w, 1);
@@ -265,10 +268,21 @@ _key_down_cb(void *data, int type, void *event)
265} 268}
266 269
267static void 270static void
268_create_gui(void) 271_resize_cb(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj,
272 void *event_info EINA_UNUSED)
269{ 273{
270 Evas_Object *table; 274 Evas_Coord w, h;
275 double relative_scale;
276
277 evas_object_geometry_get(win, NULL, NULL, &w, &h);
278 relative_scale = ((double) h / EQUATE_HEIGHT);
279 elm_object_scale_set(table, EQUATE_TEXT_SCALE * relative_scale);
280 evas_object_resize(table, w, h);
281}
271 282
283static void
284_create_gui(void)
285{
272 win = elm_win_add(NULL, "equate", ELM_WIN_BASIC); 286 win = elm_win_add(NULL, "equate", ELM_WIN_BASIC);
273 elm_win_title_set(win, "Equate"); 287 elm_win_title_set(win, "Equate");
274 elm_win_autodel_set(win, EINA_TRUE); 288 elm_win_autodel_set(win, EINA_TRUE);
@@ -278,18 +292,22 @@ _create_gui(void)
278 elm_table_homogeneous_set(table, EINA_TRUE); 292 elm_table_homogeneous_set(table, EINA_TRUE);
279 evas_object_size_hint_weight_set(table, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); 293 evas_object_size_hint_weight_set(table, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
280 evas_object_size_hint_align_set(table, EVAS_HINT_FILL, EVAS_HINT_FILL); 294 evas_object_size_hint_align_set(table, EVAS_HINT_FILL, EVAS_HINT_FILL);
281 elm_win_resize_object_add(win, table); 295
296 evas_object_move(table, 0, 0);
297 evas_object_resize(table, EQUATE_WIDTH, EQUATE_HEIGHT);
282 evas_object_show(table); 298 evas_object_show(table);
283 299
284 ecore_event_handler_add (ECORE_EVENT_KEY_DOWN, _key_down_cb, NULL); 300 ecore_event_handler_add(ECORE_EVENT_KEY_DOWN, _key_down_cb, NULL);
285 301
302 elm_object_scale_set(table, EQUATE_TEXT_SCALE);
286 evas_object_show(win); 303 evas_object_show(win);
287 evas_object_resize(win, 260, 300); 304 evas_object_resize(win, EQUATE_WIDTH * elm_config_scale_get(),
305 EQUATE_HEIGHT * elm_config_scale_get());
306 evas_object_event_callback_add(win, EVAS_CALLBACK_RESIZE, _resize_cb, NULL);
288 307
289 readout = elm_label_add(table); 308 readout = elm_label_add(table);
290 evas_object_size_hint_weight_set(readout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); 309 evas_object_size_hint_weight_set(readout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
291 evas_object_size_hint_align_set(readout, 1.0, EVAS_HINT_FILL); 310 evas_object_size_hint_align_set(readout, 1.0, EVAS_HINT_FILL);
292 elm_object_scale_set(readout, 2.0);
293 elm_table_pack(table, readout, 0, 0, 4, 1); 311 elm_table_pack(table, readout, 0, 0, 4, 1);
294 evas_object_show(readout); 312 evas_object_show(readout);
295 313