Skip to content

Commit

Permalink
Added int slider binding for imgui
Browse files Browse the repository at this point in the history
  • Loading branch information
kecho committed Aug 3, 2024
1 parent 24ef4b1 commit b37c9b6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
14 changes: 14 additions & 0 deletions Source/pymodules/gpu/ImguiBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,20 @@ PyObject* sliderFloat(PyObject* self, PyObject* vargs, PyObject* kwds)
return PyFloat_FromDouble((double)v);
}

PyObject* sliderInt(PyObject* self, PyObject* vargs, PyObject* kwds)
{
CHECK_IMGUI
char* label;
int v, v_min, v_max;
char* fmt = "%d";
static char* argnames[] = { "label", "v", "v_min", "v_max", "fmt", nullptr };
if (!PyArg_ParseTupleAndKeywords(vargs, kwds, "siii|s", argnames, &label, &v, &v_min, &v_max, &fmt))
return nullptr;

ImGui::SliderInt(label, &v, v_min, v_max, fmt);
return Py_BuildValue("i", v);
}

PyObject* inputFloat(PyObject* self, PyObject* vargs, PyObject* kwds)
{
CHECK_IMGUI
Expand Down
14 changes: 14 additions & 0 deletions Source/pymodules/gpu/bindings/Imgui.inl
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,20 @@ COALPY_FN(slider_float, sliderFloat, R"(
The new float value that the user set. Feed this value back on v on the next call to see a proper state update.
)")

COALPY_FN(slider_int, sliderInt, R"(
Draws a slider for an int value.
Parameters:
label (str): the label name for this slider.
v (int): the actual value to draw the slider.
v_min (int); the minimum possible value.
v_max (int): the maximum possible value.
fmt (str)(optional): A formatting value to draw the int. For example %d draws the int.
Returns:
The new int value that the user set. Feed this value back on v on the next call to see a proper state update.
)")

COALPY_FN(input_float, inputFloat, R"(
Draws a box to input a single float value.
Expand Down
4 changes: 3 additions & 1 deletion Source/scripts/coalpy/examples/demo0.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

s1 = gpu.Shader(file="examples/testShader.hlsl", name="testShader")

iv = 10
f = 0.5;
f2 = 0.5;
t = "hello"
Expand All @@ -32,7 +33,7 @@
input_table = gpu.InResourceTable("testjpg_table", [test_image])

def buildUi(imgui):
global f, f2, t, b, w
global iv, f, f2, t, b, w
global sa, sb, sc

imgui.begin_main_menu_bar()
Expand All @@ -52,6 +53,7 @@ def buildUi(imgui):
imgui.button("some button2")
f = imgui.slider_float("test slider", f, -1.0, 1.0);
f2 = imgui.input_float("test float2", f2);
iv = imgui.slider_int("int val slider", iv, 10, 20);
t = imgui.input_text("input text box", t);
imgui.text("some standard text");
b = imgui.checkbox("checkbox test", b)
Expand Down

0 comments on commit b37c9b6

Please sign in to comment.