Esempio n. 1
0
        void IHudTab.OnGUI(HudPanel hud)
        {
            m_Connection.RefreshTopicsList();

            GUILayout.BeginHorizontal();
            bool showPrompt = (GUI.GetNameOfFocusedControl() != "topic_filter" && m_TopicFilter == "");

            GUI.SetNextControlName("topic_filter");
            if (showPrompt)
            {
                Color oldCol = GUI.color;
                GUI.color = new Color(oldCol.r, oldCol.g, oldCol.b, 0.5f);
                GUILayout.TextField("(Type here to filter topics)");
                GUI.color = oldCol;
            }
            else
            {
                m_TopicFilter = GUILayout.TextField(m_TopicFilter).ToLower();
            }

            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            if (m_SortMode != SortMode.v2D)
            {
                GUILayout.Space(5);
            }
            string label2D = m_SortMode == SortMode.v2D ? "\u25BC2D" : "2D";

            if (GUILayout.Button(label2D, HudPanel.s_BoldStyle, GUILayout.Width(20)))
            {
                SetSortMode(m_SortMode == SortMode.v2D ? SortMode.Normal : SortMode.v2D);
            }
            if (m_SortMode == SortMode.v2D)
            {
                GUILayout.Space(5);
            }
            if (m_SortMode != SortMode.v3D)
            {
                GUILayout.Space(5);
            }
            string label3D = m_SortMode == SortMode.v3D ? "\u25BC3D" : "3D";

            if (GUILayout.Button(label3D, HudPanel.s_BoldStyle, GUILayout.Width(25)))
            {
                SetSortMode(m_SortMode == SortMode.v3D ? SortMode.Normal : SortMode.v3D);
            }
            if (m_SortMode == SortMode.v3D)
            {
                GUILayout.Space(5);
            }
            string labelTopic = m_SortMode == SortMode.Topic ? "\u25BCTopic" : m_SortMode == SortMode.TopicDescending ? "\u25B2Topic" : "Topic";

            if (GUILayout.Button(labelTopic, HudPanel.s_BoldStyle))
            {
                if (m_SortMode == SortMode.TopicDescending)
                {
                    SetSortMode(SortMode.Normal);
                }
                else if (m_SortMode == SortMode.Topic)
                {
                    SetSortMode(SortMode.TopicDescending);
                }
                else
                {
                    SetSortMode(SortMode.Topic);
                }
            }
            GUILayout.EndHorizontal();

            m_TopicMenuScrollPosition = GUILayout.BeginScrollView(m_TopicMenuScrollPosition);
            var numTopicsShown = 0;

            if (m_TopicsSorted == null)
            {
                SortTopics();
            }

            foreach (VisualizationTopicsTabEntry topicState in m_TopicsSorted)
            {
                if (m_TopicFilter != "" && !topicState.Topic.ToLower().Contains(m_TopicFilter) && !topicState.RosMessageName.ToLower().Contains(m_TopicFilter))
                {
                    continue;
                }

                numTopicsShown++;
                topicState.DrawGUI();
            }

            GUILayout.EndScrollView();

            if (numTopicsShown == 0)
            {
                if (!m_Connection.AllTopics.Any())
                {
                    GUILayout.Label("No topics registered");
                }
                else
                {
                    GUILayout.Label($"No topics named \"{m_TopicFilter}\"!");
                }
            }
        }