Blender V4.3
blender::ui::DropTargetInterface Class Referenceabstract

#include <UI_interface.hh>

Inherited by blender::ui::GridViewItemDropTarget, and blender::ui::TreeViewItemDropTarget.

Public Member Functions

 DropTargetInterface ()=default
 
virtual ~DropTargetInterface ()=default
 
virtual bool can_drop (const wmDrag &drag, const char **r_disabled_hint) const =0
 
virtual std::optional< DropLocationchoose_drop_location (const ARegion &region, const wmEvent &event) const
 
virtual std::string drop_tooltip (const DragInfo &drag) const =0
 
virtual bool on_drop (bContext *C, const DragInfo &drag) const =0
 

Detailed Description

This provides a common interface for UI elements that want to support dragging & dropping entities into/onto them. With it, the element can determine if the dragged entity can be dropped onto itself, provide feedback while dragging and run custom code for the dropping.

By default the drop target behaves so that data can be dragged into or onto it. choose_drop_location() can be overridden to change that.

Note that this is just an interface (not in the strict sense of a Java/C# interface though). A wmDropBox is needed to request instances of it from a UI element and call its functions. For example the drop box using "UI_OT_view_drop" implements dropping for views and view items via this interface. To support other kinds of UI elements, similar drop boxes would be necessary.

Definition at line 151 of file UI_interface.hh.

Constructor & Destructor Documentation

◆ DropTargetInterface()

blender::ui::DropTargetInterface::DropTargetInterface ( )
default

◆ ~DropTargetInterface()

virtual blender::ui::DropTargetInterface::~DropTargetInterface ( )
virtualdefault

Member Function Documentation

◆ can_drop()

virtual bool blender::ui::DropTargetInterface::can_drop ( const wmDrag & drag,
const char ** r_disabled_hint ) const
pure virtual

Check if the data dragged with drag can be dropped on the element this drop target is for.

Parameters
r_disabled_hintReturn a static string to display to the user, explaining why dropping isn't possible on this UI element. Shouldn't be done too aggressively, e.g. don't set this if the drag-type can't be dropped here; only if it can but there's another reason it can't be dropped. Can assume this is a non-null pointer.

Implemented in blender::ed::asset_browser::AssetCatalogDropTarget, blender::ui::bonecollections::BoneCollectionDropTarget, and blender::ui::greasepencil::LayerNodeDropTarget.

Referenced by blender::ui::drop_target_apply_drop(), and blender::ui::drop_target_tooltip().

◆ choose_drop_location()

std::optional< DropLocation > blender::ui::DropTargetInterface::choose_drop_location ( const ARegion & region,
const wmEvent & event ) const
virtual

Once the drop target validated that it can receive the dragged data using can_drop(), this method can determine where/how the data should be dropped exactly: before, after or into the drop target. Additional feedback can be drawn then while dragging, and the on_drop() function should operate accordingly. Implementations of this function may want to use DropBehavior to control which locations may be returned here.

If the returned optional is unset, dropping will be disabled. The default implementation returns DropLocation::Into.

Reimplemented in blender::ui::TreeViewItemDropTarget.

Definition at line 18 of file interface_drop.cc.

References blender::ui::Into.

Referenced by blender::ui::drop_target_apply_drop(), and blender::ui::drop_target_tooltip().

◆ drop_tooltip()

virtual std::string blender::ui::DropTargetInterface::drop_tooltip ( const DragInfo & drag) const
pure virtual

Custom text to display when dragging over the element using this drop target. Should explain what happens when dropping the data onto this UI element. Will only be used if DropTargetInterface::can_drop() returns true, so the implementing override doesn't have to check that again. The returned value must be a translated string.

Implemented in blender::ed::asset_browser::AssetCatalogDropTarget, blender::ui::bonecollections::BoneCollectionDropTarget, and blender::ui::greasepencil::LayerNodeDropTarget.

Referenced by blender::ui::drop_target_tooltip().

◆ on_drop()

virtual bool blender::ui::DropTargetInterface::on_drop ( bContext * C,
const DragInfo & drag ) const
pure virtual

Execute the logic to apply a drop of the data dragged with drag onto/into the UI element this drop target is for.

Implemented in blender::ed::asset_browser::AssetCatalogDropTarget, blender::ui::bonecollections::BoneCollectionDropTarget, and blender::ui::greasepencil::LayerNodeDropTarget.

Referenced by blender::ui::drop_target_apply_drop().


The documentation for this class was generated from the following files: