ui_util: Generic UI API.
Move these into their own place.
This commit is contained in:
parent
952764df07
commit
c0f6f39970
|
@ -2,6 +2,8 @@ src += files([
|
|||
'gettext.h',
|
||||
'ui.h',
|
||||
'ui.c',
|
||||
'ui_util.h',
|
||||
'ui_util.c',
|
||||
'ui_cache.c',
|
||||
'ui_cache.h',
|
||||
'ui_misc.c',
|
||||
|
|
117
src/bin/ui/ui.c
117
src/bin/ui/ui.c
|
@ -1198,46 +1198,6 @@ _evisum_search_keypress_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj,
|
|||
}
|
||||
}
|
||||
|
||||
static Evas_Object *
|
||||
_btn_custom_add(Evas_Object *parent, Evas_Object **alias, const char *text,
|
||||
Evas_Smart_Cb clicked_cb, void *data)
|
||||
{
|
||||
Evas_Object *tbl, *rect, *button, *label;
|
||||
|
||||
tbl = elm_table_add(parent);
|
||||
evas_object_size_hint_weight_set(tbl, EXPAND, EXPAND);
|
||||
evas_object_size_hint_align_set(tbl, FILL, FILL);
|
||||
|
||||
rect = evas_object_rectangle_add(tbl);
|
||||
evas_object_size_hint_weight_set(rect, EXPAND, EXPAND);
|
||||
evas_object_size_hint_align_set(rect, FILL, FILL);
|
||||
evas_object_size_hint_min_set(rect,
|
||||
TAB_BTN_WIDTH * elm_config_scale_get(),
|
||||
TAB_BTN_HEIGHT * elm_config_scale_get());
|
||||
|
||||
button = elm_button_add(parent);
|
||||
evas_object_size_hint_weight_set(button, EXPAND, EXPAND);
|
||||
evas_object_size_hint_align_set(button, FILL, FILL);
|
||||
evas_object_show(button);
|
||||
evas_object_smart_callback_add(button, "clicked", clicked_cb, data);
|
||||
|
||||
label = elm_label_add(parent);
|
||||
evas_object_size_hint_weight_set(label, EXPAND, EXPAND);
|
||||
evas_object_size_hint_align_set(label, FILL, FILL);
|
||||
evas_object_show(label);
|
||||
elm_object_text_set(label,
|
||||
eina_slstr_printf("<bigger>%s</bigger>", text));
|
||||
elm_layout_content_set(button, "elm.swallow.content", label);
|
||||
|
||||
elm_table_pack(tbl, rect, 0, 0, 1, 1);
|
||||
elm_table_pack(tbl, button, 0, 0, 1, 1);
|
||||
|
||||
if (alias)
|
||||
*alias = button;
|
||||
|
||||
return tbl;
|
||||
}
|
||||
|
||||
static Evas_Object *
|
||||
_ui_tabs_add(Evas_Object *parent, Ui *ui)
|
||||
{
|
||||
|
@ -1276,7 +1236,7 @@ _ui_tabs_add(Evas_Object *parent, Ui *ui)
|
|||
elm_object_style_set(border, "pad_small");
|
||||
evas_object_show(border);
|
||||
|
||||
btn = _btn_custom_add(parent, &ui->btn_general, _("General"),
|
||||
btn = evisum_ui_button_add(parent, &ui->btn_general, _("General"),
|
||||
_tab_system_activity_clicked_cb, ui);
|
||||
elm_object_disabled_set(ui->btn_general, EINA_TRUE);
|
||||
elm_object_content_set(border, btn);
|
||||
|
@ -1288,7 +1248,7 @@ _ui_tabs_add(Evas_Object *parent, Ui *ui)
|
|||
elm_object_style_set(border, "pad_small");
|
||||
evas_object_show(border);
|
||||
|
||||
btn = _btn_custom_add(parent, &ui->btn_cpu, _("CPU"),
|
||||
btn = evisum_ui_button_add(parent, &ui->btn_cpu, _("CPU"),
|
||||
_tab_cpu_activity_clicked_cb, ui);
|
||||
elm_object_content_set(border, btn);
|
||||
elm_box_pack_end(hbox, border);
|
||||
|
@ -1299,7 +1259,7 @@ _ui_tabs_add(Evas_Object *parent, Ui *ui)
|
|||
elm_object_style_set(border, "pad_small");
|
||||
evas_object_show(border);
|
||||
|
||||
btn = _btn_custom_add(parent, &ui->btn_mem, _("Memory"),
|
||||
btn = evisum_ui_button_add(parent, &ui->btn_mem, _("Memory"),
|
||||
_tab_memory_activity_clicked_cb, ui);
|
||||
elm_object_content_set(border, btn);
|
||||
elm_box_pack_end(hbox, border);
|
||||
|
@ -1310,7 +1270,7 @@ _ui_tabs_add(Evas_Object *parent, Ui *ui)
|
|||
elm_object_style_set(border, "pad_small");
|
||||
evas_object_show(border);
|
||||
|
||||
btn = _btn_custom_add(parent, &ui->btn_storage, _("Storage"),
|
||||
btn = evisum_ui_button_add(parent, &ui->btn_storage, _("Storage"),
|
||||
_tab_disk_activity_clicked_cb, ui);
|
||||
elm_object_content_set(border, btn);
|
||||
elm_box_pack_end(hbox, border);
|
||||
|
@ -1321,7 +1281,7 @@ _ui_tabs_add(Evas_Object *parent, Ui *ui)
|
|||
elm_object_style_set(border, "pad_small");
|
||||
evas_object_show(border);
|
||||
|
||||
btn = _btn_custom_add(parent, &ui->btn_misc, _("Misc"),
|
||||
btn = evisum_ui_button_add(parent, &ui->btn_misc, _("Misc"),
|
||||
_tab_misc_clicked_cb, ui);
|
||||
elm_object_content_set(border, btn);
|
||||
elm_box_pack_end(hbox, border);
|
||||
|
@ -1375,7 +1335,8 @@ _ui_tabs_add(Evas_Object *parent, Ui *ui)
|
|||
elm_object_style_set(border, "pad_small");
|
||||
evas_object_show(border);
|
||||
|
||||
btn = _btn_custom_add(parent, NULL, _("Close"), _btn_quit_clicked_cb, ui);
|
||||
btn = evisum_ui_button_add(parent, NULL, _("Close"), _btn_quit_clicked_cb,
|
||||
ui);
|
||||
elm_object_content_set(border, btn);
|
||||
elm_box_pack_end(box, border);
|
||||
|
||||
|
@ -1426,70 +1387,6 @@ _evisum_resize_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
|
|||
_config_save(ui);
|
||||
}
|
||||
|
||||
const char *
|
||||
evisum_size_format(unsigned long long bytes)
|
||||
{
|
||||
const char *s, *unit = "BKMGTPEZY";
|
||||
unsigned long powi = 1;
|
||||
unsigned long long value;
|
||||
unsigned int precision = 2, powj = 1;
|
||||
|
||||
value = bytes;
|
||||
while (value > 1024)
|
||||
{
|
||||
if ((value / 1024) < powi) break;
|
||||
powi *= 1024;
|
||||
++unit;
|
||||
if (unit[1] == '\0') break;
|
||||
}
|
||||
|
||||
if (*unit == 'B') precision = 0;
|
||||
|
||||
while (precision > 0)
|
||||
{
|
||||
powj *= 10;
|
||||
if ((value / powi) < powj) break;
|
||||
--precision;
|
||||
}
|
||||
|
||||
s = eina_slstr_printf("%1.*f %c", precision, (double) value / powi, *unit);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
static char *
|
||||
_path_append(const char *path, const char *file)
|
||||
{
|
||||
char *concat;
|
||||
int len;
|
||||
char separator = '/';
|
||||
|
||||
len = strlen(path) + strlen(file) + 2;
|
||||
concat = malloc(len * sizeof(char));
|
||||
snprintf(concat, len, "%s%c%s", path, separator, file);
|
||||
|
||||
return concat;
|
||||
}
|
||||
|
||||
const char *
|
||||
evisum_icon_path_get(const char *name)
|
||||
{
|
||||
char *path;
|
||||
const char *icon_path, *directory = PACKAGE_DATA_DIR "/images";
|
||||
icon_path = name;
|
||||
|
||||
path = _path_append(directory, eina_slstr_printf("%s.png", name));
|
||||
if (path)
|
||||
{
|
||||
if (ecore_file_exists(path))
|
||||
icon_path = eina_slstr_printf("%s", path);
|
||||
|
||||
free(path);
|
||||
}
|
||||
|
||||
return icon_path;
|
||||
}
|
||||
|
||||
void
|
||||
evisum_ui_shutdown(Ui *ui)
|
||||
{
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "gettext.h"
|
||||
#include "system/process.h"
|
||||
#include "../evisum_config.h"
|
||||
#include "ui/ui_util.h"
|
||||
#include "ui/ui_cache.h"
|
||||
|
||||
#define _(STR) gettext(STR)
|
||||
|
@ -12,9 +13,6 @@
|
|||
#define EVISUM_WIN_WIDTH 600
|
||||
#define EVISUM_WIN_HEIGHT 520
|
||||
|
||||
#define FILL EVAS_HINT_FILL
|
||||
#define EXPAND EVAS_HINT_EXPAND
|
||||
|
||||
typedef enum
|
||||
{
|
||||
SORT_BY_NONE,
|
||||
|
@ -31,9 +29,6 @@ typedef enum
|
|||
SORT_BY_CPU_USAGE,
|
||||
} Sort_Type;
|
||||
|
||||
#define TAB_BTN_WIDTH 96
|
||||
#define TAB_BTN_HEIGHT 32
|
||||
|
||||
typedef struct Ui
|
||||
{
|
||||
Evas_Object *win;
|
||||
|
@ -119,10 +114,4 @@ evisum_ui_add(Evas_Object *win);
|
|||
void
|
||||
evisum_ui_shutdown(Ui *ui);
|
||||
|
||||
const char *
|
||||
evisum_icon_path_get(const char *name);
|
||||
|
||||
const char *
|
||||
evisum_size_format(unsigned long long bytes);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -944,17 +944,11 @@ _tabs_add(Evas_Object *parent, Ui_Process *ui)
|
|||
evas_object_size_hint_align_set(pad, FILL, FILL);
|
||||
evas_object_show(pad);
|
||||
|
||||
ui->btn_main = btn = elm_button_add(parent);
|
||||
evas_object_size_hint_weight_set(btn, EXPAND, EXPAND);
|
||||
evas_object_size_hint_align_set(btn, FILL, FILL);
|
||||
evas_object_size_hint_min_set(btn, elm_config_scale_get() * TAB_BTN_WIDTH,
|
||||
elm_config_scale_get() * TAB_BTN_HEIGHT);
|
||||
elm_object_text_set(btn, _("Process"));
|
||||
elm_object_disabled_set(btn, EINA_TRUE);
|
||||
evas_object_show(btn);
|
||||
btn = evisum_ui_button_add(parent, &ui->btn_main, _("Process"),
|
||||
_btn_process_clicked_cb, ui);
|
||||
elm_object_disabled_set(ui->btn_main, EINA_TRUE);
|
||||
elm_object_content_set(pad, btn);
|
||||
elm_box_pack_end(hbox, pad);
|
||||
evas_object_smart_callback_add(btn, "clicked", _btn_process_clicked_cb, ui);
|
||||
|
||||
pad = elm_frame_add(parent);
|
||||
elm_object_style_set(pad, "pad_small");
|
||||
|
@ -962,17 +956,10 @@ _tabs_add(Evas_Object *parent, Ui_Process *ui)
|
|||
evas_object_size_hint_align_set(pad, FILL, FILL);
|
||||
evas_object_show(pad);
|
||||
|
||||
ui->btn_thread = btn = elm_button_add(parent);
|
||||
evas_object_size_hint_weight_set(btn, EXPAND, EXPAND);
|
||||
evas_object_size_hint_align_set(btn, FILL, FILL);
|
||||
evas_object_size_hint_min_set(btn, elm_config_scale_get() * TAB_BTN_WIDTH,
|
||||
elm_config_scale_get() * TAB_BTN_HEIGHT);
|
||||
elm_object_text_set(btn, _("Threads"));
|
||||
elm_object_disabled_set(btn, EINA_FALSE);
|
||||
evas_object_show(btn);
|
||||
btn = evisum_ui_button_add(parent, &ui->btn_thread, _("Threads"),
|
||||
_btn_threads_clicked_cb, ui);
|
||||
elm_object_content_set(pad, btn);
|
||||
elm_box_pack_end(hbox, pad);
|
||||
evas_object_smart_callback_add(btn, "clicked", _btn_threads_clicked_cb, ui);
|
||||
|
||||
pad = elm_frame_add(parent);
|
||||
elm_object_style_set(pad, "pad_small");
|
||||
|
@ -980,16 +967,10 @@ _tabs_add(Evas_Object *parent, Ui_Process *ui)
|
|||
evas_object_size_hint_align_set(pad, FILL, FILL);
|
||||
evas_object_show(pad);
|
||||
|
||||
ui->btn_info = btn = elm_button_add(parent);
|
||||
evas_object_size_hint_weight_set(btn, EXPAND, EXPAND);
|
||||
evas_object_size_hint_align_set(btn, FILL, FILL);
|
||||
evas_object_size_hint_min_set(btn, elm_config_scale_get() * TAB_BTN_WIDTH,
|
||||
elm_config_scale_get() * TAB_BTN_HEIGHT);
|
||||
elm_object_text_set(btn, _("Manual"));
|
||||
evas_object_show(btn);
|
||||
btn = evisum_ui_button_add(parent, &ui->btn_info, _("Manual"),
|
||||
_btn_info_clicked_cb, ui);
|
||||
elm_object_content_set(pad, btn);
|
||||
elm_box_pack_end(hbox, pad);
|
||||
evas_object_smart_callback_add(btn, "clicked", _btn_info_clicked_cb, ui);
|
||||
|
||||
pad = elm_frame_add(parent);
|
||||
elm_object_style_set(pad, "pad_medium");
|
||||
|
|
|
@ -0,0 +1,108 @@
|
|||
#include "ui_util.h"
|
||||
#include <Elementary.h>
|
||||
#include "config.h"
|
||||
|
||||
Evas_Object *
|
||||
evisum_ui_button_add(Evas_Object *parent, Evas_Object **alias, const char *text,
|
||||
Evas_Smart_Cb clicked_cb, void *data)
|
||||
{
|
||||
Evas_Object *tbl, *rect, *button, *label;
|
||||
|
||||
tbl = elm_table_add(parent);
|
||||
evas_object_size_hint_weight_set(tbl, EXPAND, EXPAND);
|
||||
evas_object_size_hint_align_set(tbl, FILL, FILL);
|
||||
|
||||
rect = evas_object_rectangle_add(tbl);
|
||||
evas_object_size_hint_weight_set(rect, EXPAND, EXPAND);
|
||||
evas_object_size_hint_align_set(rect, FILL, FILL);
|
||||
evas_object_size_hint_min_set(rect,
|
||||
TAB_BTN_WIDTH * elm_config_scale_get(),
|
||||
TAB_BTN_HEIGHT * elm_config_scale_get());
|
||||
|
||||
button = elm_button_add(parent);
|
||||
evas_object_size_hint_weight_set(button, EXPAND, EXPAND);
|
||||
evas_object_size_hint_align_set(button, FILL, FILL);
|
||||
evas_object_show(button);
|
||||
evas_object_smart_callback_add(button, "clicked", clicked_cb, data);
|
||||
|
||||
label = elm_label_add(parent);
|
||||
evas_object_size_hint_weight_set(label, EXPAND, EXPAND);
|
||||
evas_object_size_hint_align_set(label, FILL, FILL);
|
||||
evas_object_show(label);
|
||||
elm_object_text_set(label,
|
||||
eina_slstr_printf("<bigger>%s</bigger>", text));
|
||||
elm_layout_content_set(button, "elm.swallow.content", label);
|
||||
|
||||
elm_table_pack(tbl, rect, 0, 0, 1, 1);
|
||||
elm_table_pack(tbl, button, 0, 0, 1, 1);
|
||||
|
||||
if (alias)
|
||||
*alias = button;
|
||||
|
||||
return tbl;
|
||||
}
|
||||
|
||||
const char *
|
||||
evisum_size_format(unsigned long long bytes)
|
||||
{
|
||||
const char *s, *unit = "BKMGTPEZY";
|
||||
unsigned long powi = 1;
|
||||
unsigned long long value;
|
||||
unsigned int precision = 2, powj = 1;
|
||||
|
||||
value = bytes;
|
||||
while (value > 1024)
|
||||
{
|
||||
if ((value / 1024) < powi) break;
|
||||
powi *= 1024;
|
||||
++unit;
|
||||
if (unit[1] == '\0') break;
|
||||
}
|
||||
|
||||
if (*unit == 'B') precision = 0;
|
||||
|
||||
while (precision > 0)
|
||||
{
|
||||
powj *= 10;
|
||||
if ((value / powi) < powj) break;
|
||||
--precision;
|
||||
}
|
||||
|
||||
s = eina_slstr_printf("%1.*f %c", precision, (double) value / powi, *unit);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
static char *
|
||||
_path_append(const char *path, const char *file)
|
||||
{
|
||||
char *concat;
|
||||
int len;
|
||||
char separator = '/';
|
||||
|
||||
len = strlen(path) + strlen(file) + 2;
|
||||
concat = malloc(len * sizeof(char));
|
||||
snprintf(concat, len, "%s%c%s", path, separator, file);
|
||||
|
||||
return concat;
|
||||
}
|
||||
|
||||
const char *
|
||||
evisum_icon_path_get(const char *name)
|
||||
{
|
||||
char *path;
|
||||
const char *icon_path, *directory = PACKAGE_DATA_DIR "/images";
|
||||
icon_path = name;
|
||||
|
||||
path = _path_append(directory, eina_slstr_printf("%s.png", name));
|
||||
if (path)
|
||||
{
|
||||
if (ecore_file_exists(path))
|
||||
icon_path = eina_slstr_printf("%s", path);
|
||||
|
||||
free(path);
|
||||
}
|
||||
|
||||
return icon_path;
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
#ifndef __UI_UTIL_H__
|
||||
#define __UI_UTIL_H__
|
||||
|
||||
#include <Evas.h>
|
||||
|
||||
#define FILL EVAS_HINT_FILL
|
||||
#define EXPAND EVAS_HINT_EXPAND
|
||||
|
||||
#define TAB_BTN_WIDTH 96
|
||||
#define TAB_BTN_HEIGHT 32
|
||||
|
||||
Evas_Object *
|
||||
evisum_ui_button_add(Evas_Object *parent, Evas_Object **alias, const char *text,
|
||||
Evas_Smart_Cb clicked_cb, void *data);
|
||||
|
||||
const char *
|
||||
evisum_size_format(unsigned long long bytes);
|
||||
|
||||
const char *
|
||||
evisum_icon_path_get(const char *name);
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue