u/var: Add u_var_histogram_f32

This commit is contained in:
Mateo de Mayo 2022-05-14 17:03:00 -03:00 committed by Jakob Bornecrantz
parent 84422acd74
commit 7ea7cce930
2 changed files with 20 additions and 1 deletions

View file

@ -113,6 +113,14 @@ struct u_var_draggable_u16
uint16_t max;
};
struct u_var_histogram_f32
{
float *values; //!< Bin heights
int count; //!< Number of bins
float width; //!< Widget width or 0 for auto
float height; //!< Widget height or 0 for auto
};
/*!
* What kind of variable is this tracking.
*/
@ -150,6 +158,7 @@ enum u_var_kind
U_VAR_KIND_GUI_HEADER,
U_VAR_KIND_BUTTON,
U_VAR_KIND_COMBO,
U_VAR_KIND_HISTOGRAM_F32,
U_VAR_KIND_DRAGGABLE_U16,
};
@ -257,7 +266,8 @@ u_var_force_on(void);
ADD_FUNC(button, struct u_var_button, BUTTON) \
ADD_FUNC(combo, struct u_var_combo, COMBO) \
ADD_FUNC(draggable_f32, struct u_var_draggable_f32, DRAGGABLE_F32) \
ADD_FUNC(draggable_u16, struct u_var_draggable_u16, DRAGGABLE_U16)
ADD_FUNC(draggable_u16, struct u_var_draggable_u16, DRAGGABLE_U16) \
ADD_FUNC(histogram_f32, struct u_var_histogram_f32, HISTOGRAM_F32)
#define ADD_FUNC(SUFFIX, TYPE, ENUM) void u_var_add_##SUFFIX(void *, TYPE *, const char *);

View file

@ -237,6 +237,14 @@ on_combo_var(const char *name, void *ptr)
igComboStr(name, combo->value, combo->options, combo->count);
}
static void
on_histogram_f32_var(const char *name, void *ptr)
{
struct u_var_histogram_f32 *h = (struct u_var_histogram_f32 *)ptr;
ImVec2 zero = {h->width, h->height};
igPlotHistogramFloatPtr(name, h->values, h->count, 0, NULL, FLT_MAX, FLT_MAX, zero, sizeof(float));
}
static void
on_draggable_f32_var(const char *name, void *ptr)
{
@ -384,6 +392,7 @@ on_elem(struct u_var_info *info, void *priv)
case U_VAR_KIND_BUTTON: on_button_var(name, ptr); break;
case U_VAR_KIND_COMBO: on_combo_var(name, ptr); break;
case U_VAR_KIND_DRAGGABLE_U16: on_draggable_u16_var(name, ptr); break;
case U_VAR_KIND_HISTOGRAM_F32: on_histogram_f32_var(name, ptr); break;
default: igLabelText(name, "Unknown tag '%i'", kind); break;
}
}