// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
using FlaxEngine;
using FlaxEngine.GUI;
namespace FlaxEditor.CustomEditors.GUI
{
///
/// Custom property name label that fires mouse events for label and supports dragging.
///
///
[HideInEditor]
public class DraggablePropertyNameLabel : ClickablePropertyNameLabel
{
private bool _isLeftMouseButtonDown;
///
/// Mouse drag action delegate.
///
/// The label.
/// The drag data or null if not use drag.
public delegate DragData DragDelegate(DraggablePropertyNameLabel label);
///
/// The mouse starts the drag. Callbacks gets the drag data.
///
public DragDelegate Drag;
///
public DraggablePropertyNameLabel(string name)
: base(name)
{
}
///
public override bool OnMouseUp(Float2 location, MouseButton button)
{
if (button == MouseButton.Left)
{
_isLeftMouseButtonDown = false;
}
base.OnMouseUp(location, button);
return true;
}
///
public override bool OnMouseDown(Float2 location, MouseButton button)
{
if (button == MouseButton.Left)
{
_isLeftMouseButtonDown = true;
}
base.OnMouseDown(location, button);
return true;
}
///
public override void OnMouseLeave()
{
base.OnMouseLeave();
if (_isLeftMouseButtonDown)
{
_isLeftMouseButtonDown = false;
var data = Drag?.Invoke(this);
if (data != null)
{
DoDragDrop(data);
}
}
}
///
public override void OnDestroy()
{
// Unlink event
Drag = null;
base.OnDestroy();
}
}
}