Skip to main content

dear_imgui_rs/drag_drop/
flags.rs

1use crate::sys;
2
3/// Condition for updating a drag and drop payload.
4///
5/// Dear ImGui only accepts `Always` and `Once` for `SetDragDropPayload`.
6#[derive(Debug, Copy, Clone, PartialEq, Eq)]
7#[repr(i32)]
8#[allow(clippy::unnecessary_cast)]
9pub enum DragDropPayloadCond {
10    /// Update the payload every frame while dragging.
11    Always = sys::ImGuiCond_Always as i32,
12    /// Update the payload once when the drag starts.
13    Once = sys::ImGuiCond_Once as i32,
14}
15
16bitflags::bitflags! {
17    /// Flags for drag and drop sources.
18    #[repr(transparent)]
19    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
20    pub struct DragDropSourceFlags: u32 {
21        /// No flags
22        const NONE = 0;
23
24        /// Disable preview tooltip during drag
25        const NO_PREVIEW_TOOLTIP = sys::ImGuiDragDropFlags_SourceNoPreviewTooltip as u32;
26        /// Don't disable hover during drag
27        const NO_DISABLE_HOVER = sys::ImGuiDragDropFlags_SourceNoDisableHover as u32;
28        /// Don't open tree nodes/headers when hovering during drag
29        const NO_HOLD_TO_OPEN_OTHERS = sys::ImGuiDragDropFlags_SourceNoHoldToOpenOthers as u32;
30        /// Allow items without unique ID to be drag sources
31        const ALLOW_NULL_ID = sys::ImGuiDragDropFlags_SourceAllowNullID as u32;
32        /// External drag source (from outside ImGui)
33        const EXTERN = sys::ImGuiDragDropFlags_SourceExtern as u32;
34        /// Automatically expire payload if source stops being submitted
35        const PAYLOAD_AUTO_EXPIRE = sys::ImGuiDragDropFlags_PayloadAutoExpire as u32;
36        /// Hint that the payload may not be copied outside the current Dear ImGui context
37        const PAYLOAD_NO_CROSS_CONTEXT = sys::ImGuiDragDropFlags_PayloadNoCrossContext as u32;
38        /// Hint that the payload may not be copied outside the current process
39        const PAYLOAD_NO_CROSS_PROCESS = sys::ImGuiDragDropFlags_PayloadNoCrossProcess as u32;
40    }
41}
42
43impl Default for DragDropSourceFlags {
44    fn default() -> Self {
45        Self::NONE
46    }
47}
48
49bitflags::bitflags! {
50    /// Flags for drag and drop targets.
51    #[repr(transparent)]
52    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
53    pub struct DragDropTargetFlags: u32 {
54        /// No flags
55        const NONE = 0;
56        /// Accept payload before mouse button is released
57        const BEFORE_DELIVERY = sys::ImGuiDragDropFlags_AcceptBeforeDelivery as u32;
58        /// Don't draw default highlight rectangle when hovering
59        const NO_DRAW_DEFAULT_RECT = sys::ImGuiDragDropFlags_AcceptNoDrawDefaultRect as u32;
60        /// Don't show preview tooltip from source
61        const NO_PREVIEW_TOOLTIP = sys::ImGuiDragDropFlags_AcceptNoPreviewTooltip as u32;
62        /// Render accepting target as hovered (e.g. allow Button() as drop target)
63        const DRAW_AS_HOVERED = sys::ImGuiDragDropFlags_AcceptDrawAsHovered as u32;
64        /// Convenience flag for peeking (BEFORE_DELIVERY | NO_DRAW_DEFAULT_RECT)
65        const PEEK_ONLY = sys::ImGuiDragDropFlags_AcceptPeekOnly as u32;
66    }
67}
68
69impl Default for DragDropTargetFlags {
70    fn default() -> Self {
71        Self::NONE
72    }
73}
74
75pub(super) fn validate_drag_drop_source_flags(caller: &str, flags: DragDropSourceFlags) {
76    let unsupported = flags.bits() & !DragDropSourceFlags::all().bits();
77    assert!(
78        unsupported == 0,
79        "{caller} received unsupported ImGuiDragDropFlags source bits: 0x{unsupported:X}"
80    );
81}
82
83pub(super) fn validate_drag_drop_target_flags(caller: &str, flags: DragDropTargetFlags) {
84    let unsupported = flags.bits() & !DragDropTargetFlags::all().bits();
85    assert!(
86        unsupported == 0,
87        "{caller} received unsupported ImGuiDragDropFlags target bits: 0x{unsupported:X}"
88    );
89}