scale UI based on window size
Recalculate when the window is resized too.
This commit is contained in:
parent
98e6b941ef
commit
360560acc2
34
src/main.c
34
src/main.c
|
@ -6,7 +6,11 @@
|
|||
#include "Equate.h"
|
||||
#include "calc.h"
|
||||
|
||||
static Evas_Object *win;
|
||||
#define EQUATE_WIDTH 200
|
||||
#define EQUATE_HEIGHT 250
|
||||
#define EQUATE_TEXT_SCALE 1.6
|
||||
|
||||
static Evas_Object *win, *table;
|
||||
static Evas_Object *readout;
|
||||
|
||||
static const struct
|
||||
|
@ -178,7 +182,6 @@ _create_button(Evas_Object *table, const char *text, int op, int x, int y,
|
|||
evas_object_size_hint_align_set(button, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
||||
elm_object_text_set(button, text);
|
||||
|
||||
elm_object_scale_set(button, 2.0);
|
||||
evas_object_smart_callback_add(button, "clicked", _button_cb, (void *)(uintptr_t)op);
|
||||
|
||||
elm_table_pack(table, button, x, y, w, 1);
|
||||
|
@ -264,11 +267,22 @@ _key_down_cb(void *data, int type, void *event)
|
|||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
_resize_cb(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj,
|
||||
void *event_info EINA_UNUSED)
|
||||
{
|
||||
Evas_Coord w, h;
|
||||
double relative_scale;
|
||||
|
||||
evas_object_geometry_get(win, NULL, NULL, &w, &h);
|
||||
relative_scale = ((double) h / EQUATE_HEIGHT);
|
||||
elm_object_scale_set(table, EQUATE_TEXT_SCALE * relative_scale);
|
||||
evas_object_resize(table, w, h);
|
||||
}
|
||||
|
||||
static void
|
||||
_create_gui(void)
|
||||
{
|
||||
Evas_Object *table;
|
||||
|
||||
win = elm_win_add(NULL, "equate", ELM_WIN_BASIC);
|
||||
elm_win_title_set(win, "Equate");
|
||||
elm_win_autodel_set(win, EINA_TRUE);
|
||||
|
@ -278,18 +292,22 @@ _create_gui(void)
|
|||
elm_table_homogeneous_set(table, EINA_TRUE);
|
||||
evas_object_size_hint_weight_set(table, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
||||
evas_object_size_hint_align_set(table, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
||||
elm_win_resize_object_add(win, table);
|
||||
|
||||
evas_object_move(table, 0, 0);
|
||||
evas_object_resize(table, EQUATE_WIDTH, EQUATE_HEIGHT);
|
||||
evas_object_show(table);
|
||||
|
||||
ecore_event_handler_add (ECORE_EVENT_KEY_DOWN, _key_down_cb, NULL);
|
||||
ecore_event_handler_add(ECORE_EVENT_KEY_DOWN, _key_down_cb, NULL);
|
||||
|
||||
elm_object_scale_set(table, EQUATE_TEXT_SCALE);
|
||||
evas_object_show(win);
|
||||
evas_object_resize(win, 260, 300);
|
||||
evas_object_resize(win, EQUATE_WIDTH * elm_config_scale_get(),
|
||||
EQUATE_HEIGHT * elm_config_scale_get());
|
||||
evas_object_event_callback_add(win, EVAS_CALLBACK_RESIZE, _resize_cb, NULL);
|
||||
|
||||
readout = elm_label_add(table);
|
||||
evas_object_size_hint_weight_set(readout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
||||
evas_object_size_hint_align_set(readout, 1.0, EVAS_HINT_FILL);
|
||||
elm_object_scale_set(readout, 2.0);
|
||||
elm_table_pack(table, readout, 0, 0, 4, 1);
|
||||
evas_object_show(readout);
|
||||
|
||||
|
|
Loading…
Reference in New Issue