u/var: Add u_var_draggable_u16

This commit is contained in:
Mateo de Mayo 2022-05-14 16:55:51 -03:00 committed by Jakob Bornecrantz
parent e5b0840de3
commit 7d266c76b5
2 changed files with 24 additions and 1 deletions
src/xrt
auxiliary/util
state_trackers/gui

View file

@ -101,6 +101,18 @@ struct u_var_draggable_f32
float max;
};
struct u_var_draggable_u16
{
//! @note Using a float instead of storing the value like @ref
//! u_var_draggable_f32. It seemed better to decouple the UI from the value
//! itself.
//! @todo Unify "draggable" widgets interface.
uint16_t *val;
uint16_t step;
uint16_t min;
uint16_t max;
};
/*!
* What kind of variable is this tracking.
*/
@ -138,6 +150,7 @@ enum u_var_kind
U_VAR_KIND_GUI_HEADER,
U_VAR_KIND_BUTTON,
U_VAR_KIND_COMBO,
U_VAR_KIND_DRAGGABLE_U16,
};
#define U_VAR_NAME_STRING_SIZE 256
@ -243,7 +256,8 @@ u_var_force_on(void);
ADD_FUNC(gui_header, bool, GUI_HEADER) \
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_f32, struct u_var_draggable_f32, DRAGGABLE_F32) \
ADD_FUNC(draggable_u16, struct u_var_draggable_u16, DRAGGABLE_U16)
#define ADD_FUNC(SUFFIX, TYPE, ENUM) void u_var_add_##SUFFIX(void *, TYPE *, const char *);

View file

@ -229,6 +229,7 @@ on_button_var(const char *name, void *ptr)
igPopStyleVar(1);
}
}
static void
on_combo_var(const char *name, void *ptr)
{
@ -243,6 +244,13 @@ on_draggable_f32_var(const char *name, void *ptr)
igDragFloat(name, &d->val, d->step, d->min, d->max, "%+f", ImGuiSliderFlags_None);
}
static void
on_draggable_u16_var(const char *name, void *ptr)
{
struct u_var_draggable_u16 *d = (struct u_var_draggable_u16 *)ptr;
igDragScalar(name, ImGuiDataType_U16, d->val, d->step, &d->min, &d->max, NULL, ImGuiSliderFlags_None);
}
static void
on_root_enter(const char *name, void *priv)
{
@ -375,6 +383,7 @@ on_elem(struct u_var_info *info, void *priv)
case U_VAR_KIND_DRAGGABLE_F32: on_draggable_f32_var(name, ptr); break;
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;
default: igLabelText(name, "Unknown tag '%i'", kind); break;
}
}