Skip to content

Commit

Permalink
[cimgui 1.53.1] Add raw bindings to drag/drop API
Browse files Browse the repository at this point in the history
Unfortunately, it seems necessary to pull a new dependency, libc, to be able
to use size_t.

Is there any alternative?
  • Loading branch information
malikolivier committed May 1, 2018
1 parent e64a1cf commit b57d639
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
1 change: 1 addition & 0 deletions imgui-sys/Cargo.toml
Expand Up @@ -13,6 +13,7 @@ build = "build.rs"
travis-ci = { repository = "Gekkio/imgui-rs" }

[dependencies]
libc = "0.2"
bitflags = "1.0"
glium = { version = "0.21", default-features = false, optional = true }
gfx = { version = "0.17", optional = true }
Expand Down
82 changes: 82 additions & 0 deletions imgui-sys/src/lib.rs
Expand Up @@ -3,6 +3,8 @@
#[macro_use]
extern crate bitflags;

extern crate libc;

#[cfg(feature = "gfx")]
#[macro_use]
extern crate gfx;
Expand Down Expand Up @@ -380,6 +382,46 @@ bitflags!(
}
);

bitflags!(
/// Flags for igBeginDragDropSource(), igAcceptDragDropPayload()
#[repr(C)]
pub struct ImGuiDragDropFlags: c_int {
// BeginDragDropSource() flags
/// By default, a successful call to igBeginDragDropSource opens a
/// tooltip so you can display a preview or description of the source
/// contents. This flag disable this behavior.
const SourceNoPreviewTooltip = 1 << 0;
/// By default, when dragging we clear data so that igIsItemHovered()
/// will return true, to avoid subsequent user code submitting tooltips.
/// This flag disable this behavior so you can still call
/// igIsItemHovered() on the source item.
const SourceNoDisableHover = 1 << 1;
/// Disable the behavior that allows to open tree nodes and collapsing
/// header by holding over them while dragging a source item.
const SourceNoHoldToOpenOthers = 1 << 2;
/// Allow items such as igText(), igImage() that have no unique
/// identifier to be used as drag source, by manufacturing a temporary
/// identifier based on their window-relative position. This is
/// extremely unusual within the dear imgui ecosystem and so we made it
/// explicit.
const SourceAllowNullID = 1 << 3;
/// External source (from outside of imgui), won't attempt to read
/// current item/window info. Will always return true. Only one Extern
/// source can be active simultaneously.
const SourceExtern = 1 << 4;
// AcceptDragDropPayload() flags
/// igAcceptDragDropPayload() will returns true even before the mouse
/// button is released. You can then call igIsDelivery() to test if the
/// payload needs to be delivered.
const AcceptBeforeDelivery = 1 << 10;
/// Do not draw the default highlight rectangle when hovering over target.
const AcceptNoDrawDefaultRect = 1 << 11;
/// For peeking ahead and inspecting the payload before delivery.
const AcceptPeekOnly = ImGuiDragDropFlags::AcceptBeforeDelivery.bits
| ImGuiDragDropFlags::AcceptNoDrawDefaultRect.bits;
}
);

bitflags!(
/// Flags for indictating which corner of a rectangle should be rounded
#[repr(C)]
Expand Down Expand Up @@ -672,6 +714,28 @@ pub struct ImGuiTextFilter {
pub count_grep: c_int,
}

/// Data payload for Drag and Drop operations
#[repr(C)]
pub struct ImGuiPayload {
/// Data (copied and owned by dear imgui)
pub data: *const c_void,
/// Data size
pub data_size: c_int,

/// Source item id
source_id: ImGuiID,
/// Source parent id (if available)
source_parent_id: ImGuiID,
/// Data timestamp
data_frame_count: c_int,
/// Data type tag (short user-supplied string)
data_type: [c_char; 8 + 1],
/// Set when AcceptDragDropPayload() was called and mouse has been hovering the target item (nb: handle overlapping drag targets)
preview: bool,
/// Set when AcceptDragDropPayload() was called and mouse button is released over the target item.
delivery: bool,
}

#[repr(C)]
pub struct ImGuiTextBuffer {
pub buf: ImVector<c_char>,
Expand Down Expand Up @@ -1687,6 +1751,24 @@ extern "C" {
pub fn igLogText(fmt: *const c_char, ...);
}

// DragDrop
extern "C" {
/// Call when current ID is active.
///
/// When this returns true you need to:
///
/// 1. call [`igSetDragDropPayload`] exactly once,
/// 2. you may render the payload visual/description,
/// 3. pcall [`igEndDragDropSource`]
pub fn igBeginDragDropSource(flags: ImGuiDragDropFlags, mouse_button: c_int) -> bool;
/// Use 'cond' to choose to submit payload on drag start or every frame
pub fn igSetDragDropPayload(type_: *const c_char, data: *const c_void, size: libc::size_t, cond: ImGuiCond) -> bool;
pub fn igEndDragDropSource();
pub fn igBeginDragDropTarget() -> bool;
pub fn igAcceptDragDropPayload(type_: *const c_char, flags: ImGuiDragDropFlags) -> *const ImGuiPayload;
pub fn igEndDragDropTarget();
}

// Clipping
extern "C" {
pub fn igPushClipRect(
Expand Down

0 comments on commit b57d639

Please sign in to comment.