diff --git a/src/xrt/auxiliary/util/u_var.cpp b/src/xrt/auxiliary/util/u_var.cpp index de4ebbacf..62b7f6bc6 100644 --- a/src/xrt/auxiliary/util/u_var.cpp +++ b/src/xrt/auxiliary/util/u_var.cpp @@ -29,9 +29,7 @@ class Var { public: - std::string name; - u_var_kind kind; - void *ptr; + struct u_var_info info = {}; }; class Obj @@ -91,9 +89,9 @@ add_var(void *root, void *ptr, u_var_kind kind, const char *c_name) } Var var; - var.name = std::string(c_name); - var.kind = kind; - var.ptr = ptr; + snprintf(var.info.name, 256, "%s", c_name); + var.info.kind = kind; + var.info.ptr = ptr; s->second.vars.push_back(var); } @@ -169,8 +167,7 @@ u_var_visit(u_var_root_cb enter_cb, enter_cb(obj->name.c_str(), priv); for (auto &var : obj->vars) { - elem_cb(var.name.c_str(), (u_var_kind)var.kind, var.ptr, - priv); + elem_cb(&var.info, priv); } exit_cb(obj->name.c_str(), priv); diff --git a/src/xrt/auxiliary/util/u_var.h b/src/xrt/auxiliary/util/u_var.h index f7cdd1f77..e80690fe5 100644 --- a/src/xrt/auxiliary/util/u_var.h +++ b/src/xrt/auxiliary/util/u_var.h @@ -89,6 +89,23 @@ enum u_var_kind U_VAR_KIND_GUI_HEADER, }; +/*! + * Struct that keeps all of the information about the variable, some of the UI + * state is kept on it. + */ +struct u_var_info +{ + char name[256]; + void *ptr; + + enum u_var_kind kind; + + struct + { + bool graphed; + } gui; +}; + /*! * Callback for entering and leaving root nodes. */ @@ -97,7 +114,7 @@ typedef void (*u_var_root_cb)(const char *, void *); /*! * Callback on each variable a root node has. */ -typedef void (*u_var_elm_cb)(const char *, enum u_var_kind, void *, void *); +typedef void (*u_var_elm_cb)(struct u_var_info *info, void *); /*! * Add a named root object, the u_var subsystem is completely none-invasive diff --git a/src/xrt/state_trackers/gui/gui_scene_debug.c b/src/xrt/state_trackers/gui/gui_scene_debug.c index 4376d6179..792bf238b 100644 --- a/src/xrt/state_trackers/gui/gui_scene_debug.c +++ b/src/xrt/state_trackers/gui/gui_scene_debug.c @@ -41,6 +41,7 @@ struct debug_scene struct xrt_frame_context *xfctx; }; + /* * * Internal functions. @@ -150,8 +151,12 @@ get_float_arr_val(void *_data, int _idx) } static void -on_elem(const char *name, enum u_var_kind kind, void *ptr, void *priv) +on_elem(struct u_var_info *info, void *priv) { + const char *name = info->name; + void *ptr = info->ptr; + enum u_var_kind kind = info->kind; + struct draw_state *state = (struct draw_state *)priv; if (state->hidden && kind != U_VAR_KIND_GUI_HEADER) { return; @@ -174,12 +179,15 @@ on_elem(const char *name, enum u_var_kind kind, void *ptr, void *priv) igSameLine(0.0f, 4.0f); igText("%s", name); break; - case U_VAR_KIND_RGB_U8:; + case U_VAR_KIND_RGB_U8: { struct xrt_colour_rgb_f32 tmp; conv_rgb_u8_to_f32((struct xrt_colour_rgb_u8 *)ptr, &tmp); - on_elem(name, U_VAR_KIND_RGB_F32, &tmp, priv); + igColorEdit3(name, (float *)&tmp, flags); + igSameLine(0.0f, 4.0f); + igText("%s", name); conv_rgb_f32_to_u8(&tmp, (struct xrt_colour_rgb_u8 *)ptr); break; + } case U_VAR_KIND_U8: igDragScalar(name, ImGuiDataType_U8, ptr, drag_speed, NULL, NULL, NULL, power); @@ -338,8 +346,11 @@ on_root_enter_sink(const char *name, void *priv) {} static void -on_elem_sink(const char *name, enum u_var_kind kind, void *ptr, void *priv) +on_elem_sink(struct u_var_info *info, void *priv) { + const char *name = info->name; + void *ptr = info->ptr; + enum u_var_kind kind = info->kind; struct gui_program *p = (struct gui_program *)priv; if (kind != U_VAR_KIND_SINK) {