// Make the contents of the window
 void OnSelectorPopup(int windowID)
 {
     foreach (var labeler in perceptionCamera.labelers.Where(l => l is IOverlayPanelProvider && l.enabled))
     {
         var panel = labeler as IOverlayPanelProvider;
         if (GUILayout.Button(panel.label))
         {
             m_ActiveProvider = panel;
             m_ShowPopup      = false;
         }
     }
 }
        internal void OnDrawGUI(float x, float y, float width, float height)
        {
            var any = perceptionCamera.labelers.Any(l => l is IOverlayPanelProvider && l.enabled);

            // If there used to be active providers, but they have been turned off, remove
            // the active provider and return null. If one has come online, then set it to the active
            // provider
            if (!any)
            {
                m_ActiveProvider = null;
            }
            else
            {
                var findNewProvider = m_ActiveProvider == null;

                if (!findNewProvider)
                {
                    if (m_ActiveProvider is CameraLabeler l)
                    {
                        findNewProvider = !l.enabled;
                    }
                }

                if (findNewProvider)
                {
                    m_ActiveProvider = perceptionCamera.labelers.First(l => l is IOverlayPanelProvider && l.enabled) as IOverlayPanelProvider;
                }
            }

            if (m_ActiveProvider == null)
            {
                if (m_SegCanvas != null)
                {
                    m_SegCanvas.SetActive(false);
                }
                return;
            }

            if (m_OverlayImage == null)
            {
                SetupVisualizationElements();
            }

            // If all overlays were offline, but now one has come on line
            // we need to set the canvas back to active
            if (!m_SegCanvas.activeSelf)
            {
                m_SegCanvas.SetActive(true);
            }

            GUILayout.Label("Overlay");
            GUILayout.BeginHorizontal();
            GUILayout.Space(10);
            GUILayout.Label("Enabled");
            GUILayout.FlexibleSpace();
            var isEnabled = GUILayout.Toggle(m_Enabled, "");

            GUILayout.EndHorizontal();

            SetEnabled(isEnabled);
            if (!isEnabled)
            {
                return;
            }

            // Create the overlay button
            GUILayout.Space(5);
            GUILayout.BeginHorizontal();
            GUILayout.Space(10);

            // Truncate the label if it overflows the button size
            var label = m_ActiveProvider?.label ?? "Not Selected";
            var trunc = new StringBuilder(label.Substring(0, Math.Min(label.Length, 10)));

            if (trunc.Length != label.Length)
            {
                trunc.Append("...");
            }
            GUILayout.Label("Overlay: ");
            if (GUILayout.Button(trunc.ToString(), m_SelectorToggleStyle))
            {
                // If bottom is clicked we need to show the popup window
                m_ShowPopup = true;
            }
            GUILayout.EndHorizontal();

            if (m_ShowPopup)
            {
                var windowRect = new Rect(x, y, width, height);
                GUILayout.Window(0, windowRect, OnSelectorPopup, "Choose Overlay", m_WindowStyle);
            }

            // Create the transparency sliders
            GUILayout.Space(4);
            GUILayout.Label("Object Alpha:", m_LabelStyle);
            m_SegmentTransparency = GUILayout.HorizontalSlider(m_SegmentTransparency, 0.0f, 1.0f, m_SliderStyle, GUI.skin.horizontalSliderThumb);
            GUILayout.Space(4);
            GUILayout.Label("Background Alpha:", m_LabelStyle);
            m_BackgroundTransparency    = GUILayout.HorizontalSlider(m_BackgroundTransparency, 0.0f, 1.0f, m_SliderStyle, GUI.skin.horizontalSliderThumb);
            GUI.skin.label.padding.left = 0;

            // Grab the overlay image from the active provider
            m_OverlayImage.texture = m_ActiveProvider?.overlayImage;

            var rt = m_SegVisual.transform as RectTransform;

            if (rt != null && m_CachedHeight != Screen.height)
            {
                m_CachedHeight = Screen.height;
                rt.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, m_CachedHeight);
            }

            if (rt != null && m_CachedWidth != Screen.width)
            {
                m_CachedWidth = Screen.width;
                rt.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, Screen.width);
            }

            if (!GUI.changed)
            {
                return;
            }
            m_OverlayImage.material.SetFloat("_SegmentTransparency", m_SegmentTransparency);
            m_OverlayImage.material.SetFloat("_BackTransparency", m_BackgroundTransparency);
        }