// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
using System;
using FlaxEngine;
using FlaxEngine.GUI;
namespace FlaxEditor.GUI
{
///
/// The label that contains events for mouse interaction.
///
///
[HideInEditor]
public class ClickableLabel : Label
{
private bool _leftClick;
private bool _isRightDown;
///
/// The double click event.
///
public Action DoubleClick;
///
/// The left mouse button click event.
///
public Action LeftClick;
///
/// The right mouse button click event.
///
public Action RightClick;
///
public override bool OnMouseDoubleClick(Float2 location, MouseButton button)
{
DoubleClick?.Invoke();
return base.OnMouseDoubleClick(location, button);
}
///
public override bool OnMouseDown(Float2 location, MouseButton button)
{
if (button == MouseButton.Left)
_leftClick = true;
else if (button == MouseButton.Right)
_isRightDown = true;
return base.OnMouseDown(location, button);
}
///
public override bool OnMouseUp(Float2 location, MouseButton button)
{
if (button == MouseButton.Left && _leftClick)
{
_leftClick = false;
LeftClick?.Invoke();
}
else if (button == MouseButton.Right && _isRightDown)
{
_isRightDown = false;
RightClick?.Invoke();
}
return base.OnMouseUp(location, button);
}
///
public override void OnMouseLeave()
{
_leftClick = false;
_isRightDown = false;
base.OnMouseLeave();
}
}
}