This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch master
in repository efm2.
View the commit online.
commit ad6f12665ac36686bae279a6db98a4faf4d6d3a9
Author: Carsten Haitzler (Rasterman) <ras...@rasterman.com>
AuthorDate: Sat Nov 4 20:45:21 2023 +0000
add bar graph object and code to handle this in custom details
---
src/backends/table/open | 4 +-
src/efm/efm.c | 1 +
src/efm/efm_graph.c | 229 ++++++++++++++++++++++++++++++++++++++++++++++++
src/efm/efm_graph.h | 11 +++
src/efm/efm_icon.c | 2 +-
src/efm/efm_util.c | 46 +++++++++-
src/efm/meson.build | 1 +
7 files changed, 287 insertions(+), 7 deletions(-)
diff --git a/src/backends/table/open b/src/backends/table/open
index 23af0e7..deb8b8b 100755
--- a/src/backends/table/open
+++ b/src/backends/table/open
@@ -153,10 +153,10 @@ function handle_cmd_dir_set() {
e_cmd "file-add path="${F}" "${M}" "${D}\
" detail1=std:software-update-available detail2=hello%20world detail3=cc:/fg/normal/desklock/fprint/success detail4=Booya detail5=0/20/5/15 detail6=4096/65536"
- D="detail-format=text,text,text,text,text,text"
+ D="detail-format=text,text,text,text,bargraph,bargraph"
e_val_escape F ${DIR}"zzzz1"
e_cmd "file-add path="${F}" "${M}" "${D}\
- " detail1=a detail2=b detail3=c detail4=d detail5=e detail6=f"
+ " detail1=a detail2=b detail3=c detail4=d detail5=0-100,50,70,80,100,15,30,70,65,62,61,55,43,10,14,17,50 detail6=#e343ff88,0-10,3,4,0,4,10,8"
D="detail-format=text,text,text,text,text,text"
e_val_escape F ${DIR}"zzzz2"
diff --git a/src/efm/efm.c b/src/efm/efm.c
index 8fc5c88..79db2ed 100644
--- a/src/efm/efm.c
+++ b/src/efm/efm.c
@@ -7,6 +7,7 @@
// maximum number of files in a dir on a real system to be fast with: 3,000
#include "efm.h"
#include "efm_icon.h"
+#include "efm_graph.h"
#include "cmd.h"
#include "sort.h"
diff --git a/src/efm/efm_graph.c b/src/efm/efm_graph.c
new file mode 100644
index 0000000..96822e6
--- /dev/null
+++ b/src/efm/efm_graph.c
@@ -0,0 +1,229 @@
+#include "efm_graph.h"
+#include "eina_stringshare.h"
+
+typedef struct _Smart_Data Smart_Data;
+
+struct _Smart_Data
+{
+ Evas_Object_Smart_Clipped_Data __clipped_data;
+
+ Eina_Rectangle geom;
+
+ int num, min, max;
+ int *vals;
+ Eina_Stringshare *colorspec;
+
+ Evas_Object *o_smart; // the smart object container itself
+ Evas_Object *o_base;
+ Evas_Object *o_grid;
+ Evas_Object **o_vals;
+
+ Eina_Bool reset_vals : 1;
+};
+
+static Evas_Smart *_smart = NULL;
+static Evas_Smart_Class _sc = EVAS_SMART_CLASS_INIT_NULL;
+static Evas_Smart_Class _sc_parent = EVAS_SMART_CLASS_INIT_NULL;
+
+#define ENTRY \
+ Smart_Data *sd = evas_object_smart_data_get(obj); \
+ if (!sd) return
+
+static void
+_clear(Smart_Data *sd)
+{
+ int i;
+
+ if (sd->o_vals)
+ {
+ for (i = 0; i < sd->num; i++) evas_object_del(sd->o_vals[i]);
+ free(sd->o_vals);
+ sd->o_vals = NULL;
+ }
+ if (sd->vals) free(sd->vals);
+ sd->vals = NULL;
+ sd->num = 0;
+}
+
+// gui code
+static void
+_smart_add(Evas_Object *obj)
+{ // create a new efm icon
+ Smart_Data *sd;
+ Evas *e;
+ Evas_Object *o;
+ const char *theme_edj_file, *grp;
+
+ sd = calloc(1, sizeof(Smart_Data));
+ if (!sd) return;
+ evas_object_smart_data_set(obj, sd);
+
+ _sc_parent.add(obj);
+
+ e = evas_object_evas_get(obj);
+
+ sd->o_smart = obj;
+ sd->o_base = o = edje_object_add(e);
+ grp = "e/fileman/default/graph/base";
+ theme_edj_file = elm_theme_group_path_find(NULL, grp);
+ edje_object_file_set(o, theme_edj_file, grp);
+ evas_object_smart_member_add(o, sd->o_smart); // this is a member
+ evas_object_show(o);
+
+ sd->o_grid = o = evas_object_grid_add(e);
+ edje_object_part_swallow(sd->o_base, "e.swallow.content", o);
+ evas_object_grid_size_set(o, 1, 1);
+ evas_object_show(o);
+}
+
+static void
+_smart_del(Evas_Object *obj)
+{ // delete/free efm view
+ ENTRY;
+ int i;
+
+ if (sd->o_vals)
+ {
+ for (i = 0; i < sd->num; i++) evas_object_del(sd->o_vals[i]);
+ free(sd->o_vals);
+ sd->o_vals = NULL;
+ }
+ if (sd->o_grid)
+ {
+ evas_object_del(sd->o_grid);
+ sd->o_grid = NULL;
+ }
+ if (sd->o_base)
+ {
+ evas_object_del(sd->o_base);
+ sd->o_base = NULL;
+ }
+ eina_stringshare_replace(&sd->colorspec, NULL);
+ sd->o_smart = NULL;
+
+ _sc_parent.del(obj);
+ evas_object_smart_data_set(obj, NULL);
+}
+
+static void
+_smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
+{ // efm icon object moved
+ ENTRY;
+
+ if ((sd->geom.x == x) && (sd->geom.y == y)) return;
+ sd->geom.x = x;
+ sd->geom.y = y;
+ evas_object_smart_changed(obj);
+}
+
+static void
+_smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
+{ // efm icon object resized
+ ENTRY;
+
+ if ((sd->geom.w == w) && (sd->geom.h == h)) return;
+ sd->geom.w = w;
+ sd->geom.h = h;
+ evas_object_smart_changed(obj);
+}
+
+static void
+_smart_calculate(Evas_Object *obj)
+{ // recalc position/size
+ ENTRY;
+ int i;
+ Evas *e;
+ Evas_Object *o;
+ const char *theme_edj_file, *grp;
+ double v, range;
+ Edje_Message_String msg;
+
+ e = evas_object_evas_get(obj);
+ evas_object_geometry_set(sd->o_base,
+ sd->geom.x, sd->geom.y, sd->geom.w, sd->geom.h);
+ grp = "e/fileman/default/graph/bar";
+ theme_edj_file = elm_theme_group_path_find(NULL, grp);
+
+ if ((!sd->o_vals) && (sd->num > 0))
+ {
+ evas_object_grid_size_set(sd->o_grid, sd->num, 1);
+ sd->o_vals = malloc(sd->num * sizeof(Evas_Object *));
+ if (sd->o_vals)
+ {
+ sd->reset_vals = EINA_TRUE;
+ for (i = 0; i < sd->num; i++)
+ {
+ sd->o_vals[i] = o = edje_object_add(e);
+ edje_object_file_set(o, theme_edj_file, grp);
+ evas_object_grid_pack(sd->o_grid, o, i, 0, 1, 1);
+ evas_object_show(o);
+ }
+ }
+ }
+ if ((sd->o_vals) && (sd->reset_vals))
+ {
+ range = sd->max - sd->min;
+ if (range <= 1.0) range = 1.0;
+ for (i = 0; i < sd->num; i++)
+ {
+ v = (double)(sd->vals[i] - sd->min) / range;
+ if (sd->colorspec)
+ {
+ msg.str = (char *)sd->colorspec;
+ edje_object_message_send(sd->o_vals[i],
+ EDJE_MESSAGE_STRING, 1,
+ &msg);
+ edje_object_message_signal_process(sd->o_vals[i]);
+ }
+ edje_object_part_drag_value_set(sd->o_vals[i],
+ "e.dragable.value",
+ 0.0, v);
+ printf("%i - %1.2f\n", i, v);
+ }
+ }
+ sd->reset_vals = EINA_FALSE;
+}
+
+Evas_Object *
+efm_graph_add(Evas_Object *parent)
+{ // add new icon object
+ if (!_smart)
+ {
+ evas_object_smart_clipped_smart_set(&_sc_parent);
+ _sc = _sc_parent;
+ _sc.name = "efm_graph";
+ _sc.version = EVAS_SMART_CLASS_VERSION;
+ _sc.add = _smart_add;
+ _sc.del = _smart_del;
+ _sc.resize = _smart_resize;
+ _sc.move = _smart_move;
+ _sc.calculate = _smart_calculate;
+ };
+ if (!_smart) _smart = evas_smart_class_new(&_sc);
+ return evas_object_smart_add(evas_object_evas_get(parent), _smart);
+}
+
+void
+efm_graph_values_set(Evas_Object *obj, int num, int *vals, int min, int max)
+{ // set set of values
+ ENTRY;
+
+ _clear(sd);
+ sd->vals = malloc(num * sizeof(int));
+ if (!sd->vals) return;
+ sd->num = num;
+ sd->min = min;
+ sd->max = max;
+ sd->reset_vals = EINA_TRUE;
+ memcpy(sd->vals, vals, num * sizeof(int));
+ evas_object_smart_changed(sd->o_smart);
+}
+
+void
+efm_graph_colorspec_set(Evas_Object *obj, const char *cc)
+{
+ ENTRY;
+
+ eina_stringshare_replace(&sd->colorspec, cc);
+ _clear(sd);
+}
diff --git a/src/efm/efm_graph.h b/src/efm/efm_graph.h
new file mode 100644
index 0000000..7d47b9c
--- /dev/null
+++ b/src/efm/efm_graph.h
@@ -0,0 +1,11 @@
+#ifndef EFM_GRAPH_H
+#define EFM_GRAPH_H 1
+
+#include <Elementary.h>
+
+Evas_Object *efm_graph_add(Evas_Object *parent);
+void efm_graph_values_set(Evas_Object *obj, int num, int *vals, int min,
+ int max);
+void efm_graph_colorspec_set(Evas_Object *obj, const char *cc);
+
+#endif
diff --git a/src/efm/efm_icon.c b/src/efm/efm_icon.c
index 5f3e720..a620983 100644
--- a/src/efm/efm_icon.c
+++ b/src/efm/efm_icon.c
@@ -522,7 +522,7 @@ _size_get(Smart_Data *sd, int *w, int *h)
static void
_smart_calculate(Evas_Object *obj)
-{ // recalce position/size
+{ // recalc position/size
Eina_Rectangle geom;
ENTRY;
diff --git a/src/efm/efm_util.c b/src/efm/efm_util.c
index 0f2d435..fd7170b 100644
--- a/src/efm/efm_util.c
+++ b/src/efm/efm_util.c
@@ -1428,14 +1428,14 @@ _icon_detail_add(Icon *icon, Smart_Data *sd, Evas *e,
if (!strcmp(format, "text")) // format: just the string as-is
_icon_detail_rectangle_add(icon, sd, e, col, detail);
else if (!strcmp(format, "size"))
- {
+ { // format: "13/28" = value/max_value
char **plist;
unsigned long long size, size_max;
double sz;
plist = eina_str_split(detail, "/", 2);
if (plist[0] && plist[1])
- { // format: "13/28" = value/max_value
+ {
size = atoll(plist[0]);
size_max = atoll(plist[1]);
@@ -1702,13 +1702,51 @@ _icon_detail_add(Icon *icon, Smart_Data *sd, Evas *e,
elm_grid_pack(icon->o_list_detail_swallow[col], o, 0, 0, 1, 1);
evas_object_smart_callback_add(o, "changed",
- _cb_icon_detail_slider_changed,
- icon);
+ _cb_icon_detail_slider_changed, icon);
evas_object_show(o);
}
free(*plist);
free(plist);
}
+ else if (!strcmp(format, "bargraph"))
+ { // format: "0-100,13,23,80,100,78,17,0,35,57" = min-max,val1,val2,...
+ char **plist, **p, *cc = NULL;
+ int min, max, num, *vals, start;
+
+ plist = eina_str_split(detail, ",", -1);
+ if (plist[0] && plist[1])
+ {
+ start = 0;
+ if ((plist[0][0] == '#') || (plist[0][0] == 'c'))
+ {
+ start++;
+ cc = plist[0];
+ }
+ if (sscanf(plist[start], "%i-%i", &min, &max) == 2)
+ {
+ for (num = -1, p = plist + start; *p; p++) num++;
+
+ if (num > 0)
+ {
+ vals = malloc(num * sizeof(int));
+ for (num = -1, p = plist + start; *p; p++)
+ {
+ if (num >= 0) vals[num] = atoi(*p);
+ num++;
+ }
+ o = _icon_detail_grid_add(icon, sd, col);
+ o = efm_graph_add(o);
+ if (cc) efm_graph_colorspec_set(o, cc);
+ efm_graph_values_set(o, num, vals, min, max);
+ elm_grid_pack(icon->o_list_detail_swallow[col], o, 0, 0, 1, 1);
+ evas_object_show(o);
+ free(vals);
+ }
+ }
+ }
+ free(*plist);
+ free(plist);
+ }
else
fprintf(stderr, "Uknown format for file '%s' column %i format '%s'\n",
icon->info.file, col, format);
diff --git a/src/efm/meson.build b/src/efm/meson.build
index c9a60ef..43c6ed0 100644
--- a/src/efm/meson.build
+++ b/src/efm/meson.build
@@ -9,6 +9,7 @@ executable('efm', [
'efm.c',
'sort.c',
'efm_icon.c',
+ 'efm_graph.c',
'main.c'
],
include_directories: inc,
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.