using System; using Jovian.PopupSystem.UI; using UnityEngine; namespace Jovian.PopupSystem { /// /// Handles popup behavior for a . Holds the content callback and /// forwards pointer events to the . This is the behavior layer; /// the MonoBehaviour trigger is the reference holder that forwards events here. /// public sealed class PopupTriggerView { readonly IPopupSystem popupSystem; Action contentCallback; /// /// Creates a new trigger view bound to the given popup system. /// public PopupTriggerView(IPopupSystem popupSystem) { this.popupSystem = popupSystem; } /// /// Sets the content builder callback that will be invoked when the popup is shown. /// public void SetContent(Action callback) { contentCallback = callback; } /// /// Called by when the pointer enters. Reads the trigger's /// category, anchor side, and position mode to show the popup. /// public void OnPointerEnter(PopupTrigger trigger) { if(popupSystem == null || contentCallback == null) { return; } if(trigger.PositionMode == PopupPositionMode.AnchorToElement) { popupSystem.Show(trigger.Category, contentCallback, (RectTransform)trigger.transform, trigger.AnchorSide); } else { popupSystem.Show(trigger.Category, contentCallback); } } /// /// Called by when the pointer exits. Hides the popup /// for the trigger's category. /// public void OnPointerExit(PopupTrigger trigger) { popupSystem?.Hide(trigger.Category); } } }