static bool AvailableEmplacement(EventAreaItem current, IEnumerable <EventAreaItem> currentZones)
 {
     return(!currentZones.Any(o =>
     {
         if (!(current.end <= o.start || current.start >= o.end))
         {
             return true;
         }
         return false;
     }));
 }
        private List <EventAreaItem> ComputeEventItemArea(ClipBackgroundRegion baseRegion, double maxClipTime, IEnumerable <VisualEffectPlayableSerializedEvent> allEvents, uint clipEventCount)
        {
            m_TextEventAreaRequested.Clear();
            m_TextEventArea.Clear();

            int index = 0;

            m_TextEventAreaRequested.Clear();
            foreach (var itEvent in allEvents)
            {
                var timeAfterClamp = Clamp(itEvent.time, 0.0f, maxClipTime);
                var relativeTime   = InverseLerp(baseRegion.startTime, baseRegion.endTime, timeAfterClamp);

                var currentType = IconType.SingleEvent;
                if (index < clipEventCount)
                {
                    currentType = index % 2 == 0 ? IconType.ClipEnter : IconType.ClipExit;
                }

                var color = new Color(itEvent.editorColor.r, itEvent.editorColor.g, itEvent.editorColor.b);

                GUIContent iconContent = null;
                switch (currentType)
                {
                case IconType.ClipEnter: iconContent = Content.clipEnterIcon; break;

                case IconType.ClipExit: iconContent = Content.clipExitIcon; break;

                case IconType.SingleEvent: iconContent = Content.singleEventIcon; break;
                }

                var iconOffset = 0.0f;
                switch (currentType)
                {
                case IconType.ClipEnter:
                    iconOffset = 0.0f;
                    break;

                case IconType.ClipExit:
                    iconOffset = -iconContent.image.width * Style.kIconScale;
                    break;

                case IconType.SingleEvent:
                    iconOffset = -iconContent.image.width * Style.kIconScale * 0.5f;
                    break;
                }
                var iconArea = new Rect(
                    baseRegion.position.width * (float)relativeTime + iconOffset,
                    (Style.kEventNameHeight - (iconContent.image.height * Style.kIconScale)) * 0.5f,
                    iconContent.image.width * Style.kIconScale,
                    iconContent.image.height * Style.kIconScale);

                var icon = new EventAreaItem(iconArea, currentType, iconContent, color);
                m_TextEventAreaRequested.Add(icon);

                iconArea.y = 0.0f;
                var text = new EventAreaItem(iconArea, currentType, (string)itEvent.name);
                m_TextEventAreaRequested.Add(text);

                index++;
            }

            //Resolve text overlapping
            m_TextEventArea.Clear();

            //Putting all icon
            foreach (var request in m_TextEventAreaRequested)
            {
                var candidate = request;
                if (!candidate.text)
                {
                    m_TextEventArea.Add(candidate);
                }
            }

            //Resolve text overlapping
            foreach (var request in m_TextEventAreaRequested)
            {
                var candidate = request;
                if (candidate.text)
                {
                    //Trimming text content until it fits
                    while (!string.IsNullOrEmpty(candidate.content.text))
                    {
                        if (AvailableEmplacement(candidate, m_TextEventArea))
                        {
                            break;
                        }

                        var newName = candidate.content.text;
                        if (newName.Length > 2)
                        {
                            newName = newName.Substring(0, newName.Length - 2) + "…";
                        }
                        else
                        {
                            newName = string.Empty;
                        }
                        candidate.content = new GUIContent(newName);
                        candidate.RecomputeRange();
                    }

                    if (string.IsNullOrEmpty(candidate.content.text))
                    {
                        continue; //Avoid putting empty range
                    }
                    m_TextEventArea.Add(candidate);
                }
            }
            return(m_TextEventArea);
        }