using UnityEngine;
using UnityEngine.EventSystems;
namespace Jovian.PopupSystem.UI {
///
/// Reference holder MonoBehaviour for popup triggers. Attach to any UI element with a
/// Graphic component (Image, TMP_Text, etc.) that has Raycast Target enabled.
/// Configure category, anchor side, and position mode in the Inspector.
/// Forwards pointer events to the bound .
///
public class PopupTrigger : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler {
[SerializeField] PopupCategory category;
[SerializeField] AnchorSide anchorSide = AnchorSide.Below;
[SerializeField] PopupPositionMode positionMode = PopupPositionMode.AnchorToElement;
PopupTriggerView handler;
/// The popup category this trigger belongs to.
public PopupCategory Category => category;
/// Which side of this element the popup anchors to.
public AnchorSide AnchorSide => anchorSide;
/// Whether the popup anchors to this element or follows the mouse.
public PopupPositionMode PositionMode => positionMode;
/// The bound behavior handler. Null until is called.
public PopupTriggerView Handler => handler;
///
/// Binds a to this trigger. Called automatically
/// by or .
///
public void Bind(PopupTriggerView view) {
handler = view;
}
/// Forwards pointer enter to the bound handler.
public void OnPointerEnter(PointerEventData eventData) {
handler?.OnPointerEnter(this);
}
/// Forwards pointer exit to the bound handler.
public void OnPointerExit(PointerEventData eventData) {
handler?.OnPointerExit(this);
}
}
}