Skip to content

Commit

Permalink
core: add drag int widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
swistakm committed Nov 20, 2016
1 parent 6522c22 commit afbbe96
Show file tree
Hide file tree
Showing 7 changed files with 234 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![completion](https://img.shields.io/badge/completion-40%25%20%28156%20of%20389%29-blue.svg)](https://github.com/swistakm/pyimgui)
[![completion](https://img.shields.io/badge/completion-41%25%20%28160%20of%20389%29-blue.svg)](https://github.com/swistakm/pyimgui)

Builds:

Expand Down
3 changes: 3 additions & 0 deletions doc/source/visual_examples/imgui.core.drag_int2_0.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions doc/source/visual_examples/imgui.core.drag_int3_0.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions doc/source/visual_examples/imgui.core.drag_int4_0.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions doc/source/visual_examples/imgui.core.drag_int_0.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions imgui/cimgui.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -599,25 +599,25 @@ cdef extern from "imgui.h" namespace "ImGui":
const char* display_format,
const char* display_format_max, float power
)
bool DragInt( #
bool DragInt( #
const char* label, int* v,
# note: optional
float v_speed, int v_min, int v_max,
const char* display_format
)
bool DragInt2( #
bool DragInt2( #
const char* label, int v[2],
# note: optional
float v_speed, int v_min, int v_max,
const char* display_format
)
bool DragInt3( #
bool DragInt3( #
const char* label, int v[3],
# note: optional
float v_speed, int v_min, int v_max,
const char* display_format
)
bool DragInt4( #
bool DragInt4( #
const char* label, int v[4],
# note: optional
float v_speed, int v_min, int v_max,
Expand Down
217 changes: 217 additions & 0 deletions imgui/core.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2211,6 +2211,223 @@ def drag_float4(
), (inout_values[0], inout_values[1], inout_values[2], inout_values[3])


def drag_int(
char* label, int value,
float change_speed = 1.0,
int max_value=0,
int min_value=0,
str display_format = "%.f"
):
"""Display int drag widget.
.. todo::
Consider replacing ``display_format`` with something that allows
for safer way to specify display format without loosing the
functionality of wrapped function.
.. visual-example::
:auto_layout:
:width: 400
:height: 130
value = 42
imgui.begin("Example: drag int")
changed, value = imgui.drag_int("drag int", value,)
imgui.text("Changed: %s, Value: %s" % (changed, value))
imgui.end()
Args:
label (str): widget label.
value (int): drag value,
change_speed (float): how fast values change on drag.
max_value (int): max value allowed by widget.
min_value (int): min value allowed by widget.
display_format (str): display format string as C-style ``printf``
format string. **Warning:** Highly unsafe when used without care.
May lead to segmentation faults and other memory violation issues.
Returns:
tuple: a ``(changed, value)`` tuple that contains indicator of
widget state change and the current drag value.
.. wraps::
bool DragInt(
const char* label,
int* v,
float v_speed = 1.0f,
int v_min = 0.0f,
int v_max = 0.0f,
const char* display_format = "%.f",
)
"""
cdef int inout_value = value

return cimgui.DragInt(
label, &inout_value,
change_speed, max_value, min_value, display_format
), inout_value


def drag_int2(
char* label, int value0, int value1,
float change_speed = 1.0,
int max_value=0,
int min_value=0,
str display_format = "%.f"
):
"""Display int drag widget with 2 values.
.. visual-example::
:auto_layout:
:width: 400
:height: 130
values = 88, 42
imgui.begin("Example: drag int")
changed, values = imgui.drag_int2(
"drag ints", *values
)
imgui.text("Changed: %s, Values: %s" % (changed, values))
imgui.end()
Args:
label (str): widget label.
value0, value1 (int): drag values.
change_speed (float): how fast values change on drag.
max_value (int): max value allowed by widget.
min_value (int): min value allowed by widget.
display_format (str): display format string as C-style ``printf``
format string. **Warning:** highly unsafe. See :any:`drag_int()`.
Returns:
tuple: a ``(changed, values)`` tuple that contains indicator of
widget state change and the tuple of current drag values.
.. wraps::
bool DragInt2(
const char* label,
int v[2],
float v_speed = 1.0f,
int v_min = 0.0f,
int v_max = 0.0f,
const char* display_format = "%.f",
)
"""
cdef int[2] inout_values = [value0, value1]
return cimgui.DragInt2(
label, <int*>&inout_values,
change_speed, max_value, min_value, display_format,
), (inout_values[0], inout_values[1])


def drag_int3(
char* label, int value0, int value1, int value2,
float change_speed = 1.0,
int max_value=0,
int min_value=0,
str display_format = "%.f"
):
"""Display int drag widget with 3 values.
.. visual-example::
:auto_layout:
:width: 400
:height: 130
values = 88, 42, 69
imgui.begin("Example: drag int")
changed, values = imgui.drag_int3(
"drag ints", *values
)
imgui.text("Changed: %s, Values: %s" % (changed, values))
imgui.end()
Args:
label (str): widget label.
value0, value1 (int): drag values.
change_speed (float): how fast values change on drag.
max_value (int): max value allowed by widget.
min_value (int): min value allowed by widget.
display_format (str): display format string as C-style ``printf``
format string. **Warning:** highly unsafe. See :any:`drag_int()`.
Returns:
tuple: a ``(changed, values)`` tuple that contains indicator of
widget state change and the tuple of current drag values.
.. wraps::
bool DragInt3(
const char* label,
int v[3],
float v_speed = 1.0f,
int v_min = 0.0f,
int v_max = 0.0f,
const char* display_format = "%.f",
)
"""
cdef int[3] inout_values = [value0, value1, value2]
return cimgui.DragInt3(
label, <int*>&inout_values,
change_speed, max_value, min_value, display_format,
), (inout_values[0], inout_values[1], inout_values[2])


def drag_int4(
char* label, int value0, int value1, int value2, int value3,
float change_speed = 1.0,
int max_value=0,
int min_value=0,
str display_format = "%.f"
):
"""Display int drag widget with 4 values.
.. visual-example::
:auto_layout:
:width: 400
:height: 130
values = 88, 42, 69, 0
imgui.begin("Example: drag int")
changed, values = imgui.drag_int4(
"drag ints", *values
)
imgui.text("Changed: %s, Values: %s" % (changed, values))
imgui.end()
Args:
label (str): widget label.
value0, value1 (int): drag values.
change_speed (float): how fast values change on drag.
max_value (int): max value allowed by widget.
min_value (int): min value allowed by widget.
display_format (str): display format string as C-style ``printf``
format string. **Warning:** highly unsafe. See :any:`drag_int()`.
Returns:
tuple: a ``(changed, values)`` tuple that contains indicator of
widget state change and the tuple of current drag values.
.. wraps::
bool DragInt4(
const char* label,
int v[4],
float v_speed = 1.0f,
int v_min = 0.0f,
int v_max = 0.0f,
const char* display_format = "%.f",
)
"""
cdef int[4] inout_values = [value0, value1, value2, value3]
return cimgui.DragInt4(
label, <int*>&inout_values,
change_speed, max_value, min_value, display_format,
), (inout_values[0], inout_values[1], inout_values[2], inout_values[3])


def is_item_hovered():
"""Check if the last item is hovered by mouse.
Expand Down

0 comments on commit afbbe96

Please sign in to comment.