Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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-72%25%20%28327%20of%20450%29-blue.svg)](https://github.com/swistakm/pyimgui)
[![completion](https://img.shields.io/badge/completion-74%25%20%28335%20of%20452%29-blue.svg)](https://github.com/swistakm/pyimgui)
[![Coverage Status](https://coveralls.io/repos/github/swistakm/pyimgui/badge.svg?branch=master)](https://coveralls.io/github/swistakm/pyimgui?branch=master)
[![Documentation Status](https://readthedocs.org/projects/pyimgui/badge/?version=latest)](https://pyimgui.readthedocs.io/en/latest/?badge=latest)

Expand Down
16 changes: 10 additions & 6 deletions imgui/cimgui.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,10 @@ cdef extern from "imgui.h":
# todo: find a way to access enum var here
ImVec4* Colors

ctypedef struct ImGuiPayload:
void* Data # ✓
int DataSize # ✓

ctypedef struct ImGuiContext:
pass

Expand Down Expand Up @@ -1088,12 +1092,12 @@ cdef extern from "imgui.h" namespace "ImGui":
void LogText(const char*, ...) except + # ✗

# Drag and Drop
bool BeginDragDropSource(ImGuiDragDropFlags flags) except + #
bool SetDragDropPayload(const char* type, const void* data, size_t size, ImGuiCond cond) except + #
void EndDragDropSource() except + #
bool BeginDragDropTarget() except + #
const ImGuiPayload* AcceptDragDropPayload(const char* type, ImGuiDragDropFlags flags) except + #
void EndDragDropTarget() except + #
bool BeginDragDropSource(ImGuiDragDropFlags flags) except + #
bool SetDragDropPayload(const char* type, const void* data, size_t size, ImGuiCond cond) except + #
void EndDragDropSource() except + #
bool BeginDragDropTarget() except + #
const ImGuiPayload* AcceptDragDropPayload(const char* type, ImGuiDragDropFlags flags) except + #
void EndDragDropTarget() except + #

# Clipping
void PushClipRect(const ImVec2& clip_rect_min, const ImVec2& clip_rect_max, bool intersect_with_current_clip_rect) except + # ✗
Expand Down
129 changes: 129 additions & 0 deletions imgui/core.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -6568,6 +6568,135 @@ def get_columns_count():
return cimgui.GetColumnsCount()


def begin_drag_drop_source(cimgui.ImGuiDragDropFlags flags=0):
"""Set the current item as a drag and drop source. If this return True, you
can call :func:`set_drag_drop_payload` and :func:`end_drag_drop_source`.

**Note:** this is a beta API.

Args:
flags (ImGuiDragDropFlags): DragDrop flags.

Returns:
bool: True while a drag starting at this source is occurring

.. visual-example::
:auto_layout:
:width: 300

imgui.begin("Example: drag and drop")

imgui.button('source')
if imgui.begin_drag_drop_source():
imgui.set_drag_drop_payload('itemtype', b'payload')
imgui.button('dragged source')
imgui.end_drag_drop_source()

imgui.button('dest')
if imgui.begin_drag_drop_target():
payload = imgui.accept_drag_drop_payload('itemtype')
if payload is not None:
print('Received:', payload)
imgui.end_drag_drop_target()

imgui.end()

.. wraps::
bool BeginDragDropSource(ImGuiDragDropFlags flags = 0)
"""
return cimgui.BeginDragDropSource(flags)


def set_drag_drop_payload(str type, bytes data, cimgui.ImGuiCond condition=0):
"""Set the payload for a drag and drop source. Only call after
:func:`begin_drag_drop_source` returns True.

**Note:** this is a beta API.

For a complete example see :func:`begin_drag_drop_source`.

Args:
type (str): user defined type with maximum 32 bytes.
data (bytes): the data for the payload; will be copied and stored internally.
condition (:ref:`condition flag <condition-options>`): defines on which
condition value should be set. Defaults to :any:`imgui.ALWAYS`.

.. wraps::
bool SetDragDropPayload(const char* type, const void* data, size_t size, ImGuiCond cond = 0)
"""
return cimgui.SetDragDropPayload(_bytes(type), <const char*>data, len(data), condition)


def end_drag_drop_source():
"""End the drag and drop source. Only call after :func:`begin_drag_drop_source`
returns True.

**Note:** this is a beta API.

For a complete example see :func:`begin_drag_drop_source`.

.. wraps::
void EndDragDropSource()
"""
cimgui.EndDragDropSource()


def begin_drag_drop_target():
"""Set the current item as a drag and drop target. If this return True, you
can call :func:`accept_drag_drop_payload` and :func:`end_drag_drop_target`.

**Note:** this is a beta API.

Returns:
bool: True when a drag hovers over the target

For a complete example see :func:`begin_drag_drop_source`.

.. wraps::
bool BeginDragDropTarget()
"""
return cimgui.BeginDragDropTarget()


def accept_drag_drop_payload(str type, cimgui.ImGuiDragDropFlags flags=0):
"""Get the drag and drop payload. Only call after :func:`begin_drag_drop_target`
returns True.

**Note:** this is a beta API.

For a complete example see :func:`begin_drag_drop_source`.

Args:
type (str): user defined type with maximum 32 bytes.
flags (ImGuiDragDropFlags): DragDrop flags.

Returns:
bytes: the payload data that was set by :func:`set_drag_drop_payload`.

.. wraps::
const ImGuiPayload* AcceptDragDropPayload(const char* type, ImGuiDragDropFlags flags = 0)
"""
cdef const cimgui.ImGuiPayload* payload = cimgui.AcceptDragDropPayload(_bytes(type), flags)
if payload == NULL:
return None
cdef const char* data = <const char *>payload.Data
return <bytes>data[:payload.DataSize]


def end_drag_drop_target():
"""End the drag and drop source. Only call after :func:`begin_drag_drop_target`
returns True.

**Note:** this is a beta API.

For a complete example see :func:`begin_drag_drop_source`.

.. wraps::
void EndDragDropTarget()
"""
cimgui.EndDragDropTarget()


def begin_group():
"""Start item group and lock its horizontal starting position.

Expand Down