protected void FillCombobox()
        {
            PComboBox.Items.Add("Edit");
            PComboBox.Items.Add("View");

            PComboBox.SelectedIndex = PComboBox.FindStringExact("View");
        }
Exemplo n.º 2
0
 /// <summary>
 /// Updates the displayed text to match the current item.
 /// </summary>
 private void Update()
 {
     if (comboBox != null && chosen != null)
     {
         PComboBox <Option> .SetSelectedItem(comboBox, chosen, false);
     }
 }
Exemplo n.º 3
0
        protected override IUIComponent GetUIComponent()
        {
            // Find largest option to size the label appropriately
            Option longestOption = null;
            string longestText   = " ";

            foreach (var option in options)
            {
                string optionText = option.Title;
                if (optionText.Length > longestText.Length)
                {
                    longestText   = optionText;
                    longestOption = option;
                }
            }
            var dd = new PComboBox <Option>("Select")
            {
                BackColor = PUITuning.Colors.ButtonPinkStyle, InitialItem = longestOption,
                Content   = options, EntryColor = PUITuning.Colors.ButtonBlueStyle,
                TextStyle = PUITuning.Fonts.TextLightStyle, OnOptionSelected = UpdateValue,
            };

            dd.OnRealize += OnRealize;
            return(dd);
        }
Exemplo n.º 4
0
 /// <summary>Raises the <see cref="E:System.Windows.Forms.ListControl.SelectedValueChanged" /> event. </summary>
 /// <param name="e">An <see cref="T:System.EventArgs" /> that contains the event data. </param>
 protected override void OnSelectedValueChanged(EventArgs e)
 {
     PComboBox.SetModelValue(this, PComboBox.SelectedItemProperty, SelectedItem, EBindingSourceUpdateReason.PropertyChanged);
     base.OnSelectedValueChanged(e);
 }
Exemplo n.º 5
0
        private void RebuildPanel()
        {
            // Update schedule data

            int selectedSchedule = (sensor != null) ? sensor.scheduleIndex : 0;
            int selectedGroup    = (sensor != null) ? sensor.blockTypeIndex : 0;

            schedules = new List <StringListOption>();
            var slist = ScheduleManager.Instance.GetSchedules();

            foreach (Schedule s in slist)
            {
                schedules.Add(new StringListOption(s.name));
            }

            if (selectedSchedule < 0 || selectedSchedule >= schedules.Count)
            {
                selectedSchedule = 0;
                if (sensor != null)
                {
                    sensor.scheduleIndex = selectedSchedule;
                }
            }

            groups = new List <StringListOption>();
            var glist = Db.Get().ScheduleGroups.allGroups;

            foreach (ScheduleGroup g in glist)
            {
                groups.Add(new StringListOption(g.Name));
            }

            if (selectedGroup < 0 || selectedGroup >= groups.Count)
            {
                selectedGroup = 0;
                if (sensor != null)
                {
                    sensor.blockTypeIndex = selectedGroup;
                }
            }

            // Rebuild UI

            if (ContentContainer != null)
            {
                Destroy(ContentContainer);
                ContentContainer = null;
            }

            var margin     = new RectOffset(8, 8, 8, 8);
            var baseLayout = gameObject.GetComponent <BoxLayoutGroup>();

            if (baseLayout != null)
            {
                baseLayout.Params = new BoxLayoutParams()
                {
                    Margin    = margin,
                    Direction = PanelDirection.Vertical,
                    Alignment = TextAnchor.UpperCenter,
                    Spacing   = 8
                };
            }

            var mainPanel = new PPanel();

            var scheduleRow = new PPanel("Schedule Select")
            {
                FlexSize  = Vector2.right,
                Alignment = TextAnchor.MiddleCenter,
                Spacing   = 10,
                Direction = PanelDirection.Horizontal,
                Margin    = margin
            };

            scheduleRow.AddChild(new PLabel("Schedule")
            {
                TextAlignment = TextAnchor.MiddleRight,
                ToolTip       = "TODO: Schedule Label Tooltip",
                Text          = "Schedule",
                TextStyle     = PUITuning.Fonts.TextDarkStyle
            });

            var scb = new PeterHan.PLib.UI.PComboBox <StringListOption>("Schedule Select")
            {
                Content          = schedules,
                MinWidth         = 100,
                InitialItem      = schedules[selectedSchedule],
                ToolTip          = "TODO: Schedule Select Tooltip",
                TextStyle        = PUITuning.Fonts.TextLightStyle,
                TextAlignment    = TextAnchor.MiddleLeft,
                OnOptionSelected = SetSchedule
            };

            scb.OnRealize += (obj) =>
            {
                scheduleCombo = obj;
            };
            scheduleRow.AddChild(scb);
            mainPanel.AddChild(scheduleRow);

            var groupRow = new PPanel("Group Select")
            {
                FlexSize  = Vector2.right,
                Alignment = TextAnchor.MiddleCenter,
                Spacing   = 10,
                Direction = PanelDirection.Horizontal,
                Margin    = margin
            };

            groupRow.AddChild(new PLabel("Group")
            {
                TextAlignment = TextAnchor.MiddleRight,
                ToolTip       = "TODO: Group Label Tooltip",
                Text          = "Group",
                TextStyle     = PUITuning.Fonts.TextDarkStyle
            });

            var bcb = new PComboBox <StringListOption>("Group Select")
            {
                Content          = groups,
                MinWidth         = 100,
                InitialItem      = groups[selectedGroup],
                ToolTip          = "TODO: Group Select Tooltip",
                TextStyle        = PUITuning.Fonts.TextLightStyle,
                TextAlignment    = TextAnchor.MiddleLeft,
                OnOptionSelected = SetGroup
            };

            bcb.OnRealize += (obj) =>
            {
                groupCombo = obj;
            };
            groupRow.AddChild(bcb);
            mainPanel.AddChild(groupRow);

            ContentContainer = mainPanel.Build();
            ContentContainer.SetParent(gameObject);

            if (scheduleCombo != null)
            {
                PComboBox <StringListOption> .SetSelectedItem(scheduleCombo, schedules[selectedSchedule]);
            }

            if (groupCombo != null)
            {
                PComboBox <StringListOption> .SetSelectedItem(groupCombo, groups[selectedGroup]);
            }
        }