Skip to content

Commit

Permalink
ImGui: wrap PlotHistogram, PlotLines for python
Browse files Browse the repository at this point in the history
  • Loading branch information
paroj committed Jan 30, 2024
1 parent 67a4575 commit 3765c65
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Components/Overlay/include/ImGui.i
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,29 @@
%typemap(argout) float[4], float[3], float[2] {
$result = SWIG_Python_AppendOutput($result, SWIG_NewPointerObj($1, $descriptor(ImVec4*), 0));
}

// for PlotHistogram, PlotLines
%typemap(in) (const float* values, int values_count)
{
Py_buffer view;
int res = PyObject_GetBuffer($input, &view, PyBUF_CONTIG_RO | PyBUF_FORMAT);
if (res < 0) {
SWIG_fail;
}
PyBuffer_Release(&view);

if(view.ndim != 1 || strcmp(view.format, "f") != 0) {
PyErr_SetString(PyExc_TypeError, "Expected a 1D array of floats");
SWIG_fail;
}

$1 = ($ltype)view.buf;
$2 = view.len / sizeof(float);
}

%typecheck(SWIG_TYPECHECK_STRING) (const float* values, int values_count) {
$1 = true; // actual check in the typemap
}
#endif

%typecheck(SWIG_TYPECHECK_STRING) float[4], float[3], float[2] {
Expand Down

0 comments on commit 3765c65

Please sign in to comment.