예제 #1
0
 private void HighlightButton(SelectionButton button)
 {
     button.SetBackgroundColor(selected);
 }
예제 #2
0
        public ControlsTest() : base(80, 23)
        {
            var prog1 = new ProgressBar(10, 1, HorizontalAlignment.Left)
            {
                Position = new Point(16, 5)
            };

            Controls.Add(prog1);

            var prog2 = new ProgressBar(1, 6, VerticalAlignment.Bottom)
            {
                Position = new Point(18, 7)
            };

            Controls.Add(prog2);

            var slider = new ScrollBar(Orientation.Horizontal, 10)
            {
                Position = new Point(16, 3),
                Maximum  = 18
            };

            Controls.Add(slider);

            slider = new ScrollBar(Orientation.Vertical, 6)
            {
                Position = new Point(16, 7),
                Maximum  = 6
            };
            Controls.Add(slider);

            progressTimer = new SadConsole.Components.Timer(TimeSpan.FromSeconds(0.5));
            progressTimer.TimerElapsed += (timer, e) => { prog1.Progress = prog1.Progress >= 1f ? 0f : prog1.Progress + 0.1f; prog2.Progress = prog2.Progress >= 1f ? 0f : prog2.Progress + 0.1f; };

            SadComponents.Add(progressTimer);

            var listbox = new ListBox(20, 6)
            {
                Position = new Point(28, 3)
            };

            listbox.Items.Add("item 1");
            listbox.Items.Add("item 2");
            listbox.Items.Add("item 3");
            listbox.Items.Add("item 4");
            listbox.Items.Add("item 5");
            listbox.Items.Add("item 6");
            listbox.Items.Add("item 7");
            listbox.Items.Add("item 8");
            listbox.Items.Add("item 9");

            Controls.Add(listbox);

            var radioButton = new RadioButton(20, 1)
            {
                Text     = "Group 1 Option 1",
                Position = new Point(28, 12)
            };

            Controls.Add(radioButton);

            radioButton = new RadioButton(20, 1)
            {
                Text     = "Group 1 Option 2",
                Position = new Point(28, 13)
            };
            Controls.Add(radioButton);

            var selButton = new SelectionButton(24, 1)
            {
                Text     = "Selection Button 1",
                Position = new Point(51, 3)
            };

            Controls.Add(selButton);

            var selButton1 = new SelectionButton(24, 1)
            {
                Text     = "Selection Button 2",
                Position = new Point(51, 4)
            };

            Controls.Add(selButton1);

            var selButton2 = new SelectionButton(24, 1)
            {
                Text     = "Selection Button 3",
                Position = new Point(51, 5)
            };

            Controls.Add(selButton2);

            selButton.PreviousSelection  = selButton2;
            selButton.NextSelection      = selButton1;
            selButton1.PreviousSelection = selButton;
            selButton1.NextSelection     = selButton2;
            selButton2.PreviousSelection = selButton1;
            selButton2.NextSelection     = selButton;

            var input = new TextBox(10)
            {
                Position = new Point(51, 9)
            };

            Controls.Add(input);

            var password = new TextBox(10)
            {
                Mask     = '*',
                Position = new Point(65, 9)
            };

            Controls.Add(password);

            var button = new Button(11, 1)
            {
                Text     = "Click",
                Position = new Point(1, 3)
            };

            button.Click += (s, a) => SadConsole.UI.Window.Message("This has been clicked -- and your password field contains '" + password.Text + "'", "Close");
            Controls.Add(button);

            button = new Button(11, 3)
            {
                Text     = "Click",
                Position = new Point(1, 5),
                Theme    = new Button3dTheme()
            };
            button.Click += (s, a) => listbox.ScrollToSelectedItem();
            //button.AlternateFont = SadConsole.Global.LoadFont("Fonts/Cheepicus12.font").GetFont(Font.FontSizes.One);
            Controls.Add(button);

            button = new Button(11, 3)
            {
                Text     = "Click",
                Position = new Point(1, 10),
                Theme    = new ButtonLinesTheme()
            };
            Controls.Add(button);

            var checkbox = new CheckBox(13, 1)
            {
                Text     = "Check box",
                Position = new Point(51, 13)
            };

            Controls.Add(checkbox);

            Controls.FocusedControl = null;
            //DisableControlFocusing = true;

            List <Tuple <Color, string> > colors = new List <Tuple <Color, string> >
            {
                new Tuple <Color, string>(Library.Default.Colors.Red, "Red"),
                new Tuple <Color, string>(Library.Default.Colors.RedDark, "DRed"),
                new Tuple <Color, string>(Library.Default.Colors.Purple, "Prp"),
                new Tuple <Color, string>(Library.Default.Colors.PurpleDark, "DPrp"),
                new Tuple <Color, string>(Library.Default.Colors.Blue, "Blu"),
                new Tuple <Color, string>(Library.Default.Colors.BlueDark, "DBlu"),
                new Tuple <Color, string>(Library.Default.Colors.Cyan, "Cya"),
                new Tuple <Color, string>(Library.Default.Colors.CyanDark, "DCya"),
                new Tuple <Color, string>(Library.Default.Colors.Green, "Gre"),
                new Tuple <Color, string>(Library.Default.Colors.GreenDark, "DGre"),
                new Tuple <Color, string>(Library.Default.Colors.Yellow, "Yel"),
                new Tuple <Color, string>(Library.Default.Colors.YellowDark, "DYel"),
                new Tuple <Color, string>(Library.Default.Colors.Orange, "Ora"),
                new Tuple <Color, string>(Library.Default.Colors.OrangeDark, "DOra"),
                new Tuple <Color, string>(Library.Default.Colors.Brown, "Bro"),
                new Tuple <Color, string>(Library.Default.Colors.BrownDark, "DBrow"),
                new Tuple <Color, string>(Library.Default.Colors.Gray, "Gray"),
                new Tuple <Color, string>(Library.Default.Colors.GrayDark, "DGray"),
                new Tuple <Color, string>(Library.Default.Colors.White, "White"),
                new Tuple <Color, string>(Library.Default.Colors.Black, "Black")
            };

            backgroundcycle = colors.Select(i => i.Item1).ToArray();
            backIndex       = 5;


            //int y = 25 - 20;
            //int x = 0;
            //int colorLength = 4;
            //foreach (var color1 in colors)
            //{
            //    foreach (var color2 in colors)
            //    {
            //        _Print(x, y, new ColoredString(color2.Item2.PadRight(colorLength).Substring(0, colorLength), color2.Item1, color1.Item1, null));
            //        y++;
            //    }

            //    y = 25 -20;
            //    x += colorLength;
            //}

            OnInvalidated();
        }
예제 #3
0
 private void ShowButton(SelectionButton button)
 {
     button.gameObject.SetActive(true);
 }
예제 #4
0
 public void Select(SelectionButton selectionButton)
 {
     Select(IndexOf(selectionButton));
 }
예제 #5
0
 public int IndexOf(SelectionButton selectionButton)
 {
     return(SelectionButtons.IndexOf(selectionButton));
 }
예제 #6
0
 public SelectMessage(Entity sender, SelectionButton selectionButton, SelectionGroup selectionGroup) : base(sender)
 {
     Selection      = selectionButton;
     SelectionGroup = selectionGroup;
 }
        private void InitializeContent(IToast toastContent)
        {
            _currContent = toastContent;
            HasContent   = false;

            TextBlockTitle.Text         = "";
            TextBlockTitle.MaxLines     = 3;
            TextBlockTitle.TextWrapping = TextWrapping.WrapWholeWords;

            TextBlockBody.Text         = "";
            TextBlockBody.MaxLines     = 3;
            TextBlockBody.TextWrapping = TextWrapping.WrapWholeWords;

            TextBlockBody2.Visibility   = Visibility.Collapsed;
            TextBlockBody2.MaxLines     = 3;
            TextBlockBody2.TextWrapping = TextWrapping.WrapWholeWords;

            StackPanelInlineImages.Children.Clear();

            DefaultImageAppLogo.Visibility = Visibility.Visible;
            ImageAppLogo.Visibility        = Visibility.Collapsed;
            CircleImageAppLogo.Visibility  = Visibility.Collapsed;

            _elementsWithIds = new Dictionary <string, FrameworkElement>();

            _currLaunch         = "";
            _currActivationType = ActivationType.Foreground;

            _buttons.Clear();
            _buttons.Add(CreateButton("Launch", toastContent?.Launch, null, toastContent != null ? toastContent.ActivationType.GetValueOrDefault(ActivationType.Foreground) : ActivationType.Foreground, Scenario.Default));



            if (toastContent != null)
            {
                _currLaunch         = toastContent.Launch;
                _currActivationType = toastContent.ActivationType.GetValueOrDefault(ActivationType.Foreground);

                if (toastContent.Visual != null)
                {
                    var visual = toastContent.Visual;

                    AdaptiveBinding binding;

                    if (toastContent.Context == NotificationType.Toast)
                    {
                        binding = visual.Bindings.FirstOrDefault();
                    }

                    else
                    {
                        binding = visual.Bindings.FirstOrDefault(i => i.Template == Model.Enums.Template.ToastGeneric);
                    }

                    if (binding != null)
                    {
                        HasContent = true;

                        var container = binding.Container;


                        var texts = container.Children.OfType <AdaptiveTextField>().ToList();
                        List <AdaptiveImage> appLogoOverrides = null;
                        List <AdaptiveImage> heroImages       = new List <AdaptiveImage>();
                        var attributionTexts = container.Children.OfType <AdaptiveTextField>().Where(i => i.Placement == Model.Enums.TextPlacement.Attribution).ToList();

                        appLogoOverrides = new List <AdaptiveImage>();

                        // First pull out images with placements and attribution text
                        for (int i = 0; i < container.Children.Count; i++)
                        {
                            var child = container.Children[i];

                            if (child is AdaptiveImage)
                            {
                                AdaptiveImage img = child as AdaptiveImage;

                                switch (img.Placement)
                                {
                                case Model.Enums.Placement.AppLogoOverride:
                                    appLogoOverrides.Add(img);
                                    container.RemoveChildAt(i);
                                    i--;
                                    break;

                                case Model.Enums.Placement.Hero:
                                    heroImages.Add(img);
                                    container.RemoveChildAt(i);
                                    i--;
                                    break;
                                }
                            }

                            else if (child is AdaptiveTextField)
                            {
                                AdaptiveTextField txt = child as AdaptiveTextField;

                                if (txt.Placement != Model.Enums.TextPlacement.Inline)
                                {
                                    container.RemoveChildAt(i);
                                    i--;
                                }
                            }
                        }

                        // Assign hero
                        if (heroImages.Any())
                        {
                            ImageHero.Visibility       = Visibility.Visible;
                            ImageHeroBrush.ImageSource = ImageHelper.GetBitmap(heroImages.First().Src);
                        }

                        else
                        {
                            ImageHero.Visibility       = Visibility.Collapsed;
                            ImageHeroBrush.ImageSource = null;
                        }


                        texts = new List <AdaptiveTextField>();

                        // Pull out all texts
                        for (int i = 0; i < container.Children.Count; i++)
                        {
                            var child = container.Children[i];

                            if (child is AdaptiveTextField && (child as AdaptiveTextField).Placement == Model.Enums.TextPlacement.Inline)
                            {
                                texts.Add(child as AdaptiveTextField);
                                container.RemoveChildAt(i);
                                i--;
                            }
                        }

                        var titleText = texts.ElementAtOrDefault(0);
                        if (titleText != null)
                        {
                            TextBlockTitle.Text = titleText.Text;

                            var bodyTextLine1 = texts.ElementAtOrDefault(1);
                            if (bodyTextLine1 != null)
                            {
                                TextBlockBody.Text = bodyTextLine1.Text;

                                var bodyTextLine2 = texts.ElementAtOrDefault(2);
                                if (bodyTextLine2 != null)
                                {
                                    TextBlockBody2.Text       = bodyTextLine2.Text;
                                    TextBlockBody2.Visibility = Visibility.Visible;
                                }

                                TextBlockBody.Visibility = Visibility.Visible;
                            }

                            else
                            {
                                TextBlockBody.Visibility = Visibility.Collapsed;
                            }
                        }

                        else
                        {
                            TextBlockTitle.Text      = Properties.DisplayName;
                            TextBlockBody.Text       = "New notification";
                            TextBlockBody.Visibility = Visibility.Visible;
                        }

                        var images = container.Children.OfType <AdaptiveImage>().ToList();


                        if (appLogoOverrides == null)
                        {
                            appLogoOverrides = images.Where(i => i.Placement == Model.Enums.Placement.AppLogoOverride).ToList();
                        }

                        var appLogoOverride = appLogoOverrides.FirstOrDefault();
                        if (appLogoOverride != null)
                        {
                            DefaultImageAppLogo.Visibility = Visibility.Collapsed;

                            var source = ImageHelper.GetBitmap(appLogoOverride.Src);

                            if (appLogoOverride.HintCrop == Model.Enums.HintCrop.Circle)
                            {
                                CircleImageAppLogo.Source     = source;
                                CircleImageAppLogo.Visibility = Visibility.Visible;
                            }

                            else
                            {
                                ImageAppLogo.Source     = source;
                                ImageAppLogo.Visibility = Visibility.Visible;
                            }
                        }

                        foreach (var image in images.Where(i => i.Placement == Model.Enums.Placement.Inline))
                        {
                            var uiImage = new Image()
                            {
                                Source              = ImageHelper.GetBitmap(image.Src),
                                MaxHeight           = 100,
                                Stretch             = Stretch.Uniform,
                                HorizontalAlignment = HorizontalAlignment.Stretch,
                                Margin              = new Thickness(0, 0, 0, 6)
                            };

                            StackPanelInlineImages.Children.Add(uiImage);
                        }

                        // Attribution
                        if (toastContent.SupportedFeatures.RS1_Style_Toasts)
                        {
                            if (attributionTexts.Any())
                            {
                                TextBlockAttributionSeparationDot.Visibility = Visibility.Visible;
                                TextBlockAttributionSecondPart.Visibility    = Visibility.Visible;
                                TextBlockAttributionSecondPart.Text          = attributionTexts.First().Text;
                            }

                            else
                            {
                                TextBlockAttributionSeparationDot.Visibility = Visibility.Collapsed;
                                TextBlockAttributionSecondPart.Visibility    = Visibility.Collapsed;
                            }
                        }
                    }
                }


                if (toastContent.Actions != null)
                {
                    var actions = toastContent.Actions;

                    if (actions.HintSystemCommands == Model.Enums.HintSystemCommands.SnoozeAndDismiss)
                    {
                        //AddInput(CreateComboBox("systemSnoozeSelection", null, new Selection[]
                        //{
                        //    new Selection(NotificationType.Toast, CurrFeatureSet)
                        //    {
                        //        Content = "5 minutes",
                        //        Id = "5"
                        //    },

                        //    new Selection(NotificationType.Toast, CurrFeatureSet)
                        //    {
                        //        Content = "9 minutes",
                        //        Id = "9"
                        //    },

                        //    new Selection(NotificationType.Toast, CurrFeatureSet)
                        //    {
                        //        Content = "10 minutes",
                        //        Id = "10"
                        //    },

                        //    new Selection(NotificationType.Toast, CurrFeatureSet)
                        //    {
                        //        Content = "1 hour",
                        //        Id = "60"
                        //    },

                        //    new Selection(NotificationType.Toast, CurrFeatureSet)
                        //    {
                        //        Content = "4 hours",
                        //        Id = "240"
                        //    },

                        //    new Selection(NotificationType.Toast, CurrFeatureSet)
                        //    {
                        //        Content = "1 day",
                        //        Id = "1440"
                        //    }
                        //}, "9", true));

                        AddButton(CreateButton("Snooze", "snooze", null, ActivationType.System, toastContent.Scenario));
                        AddButton(CreateButton("Dismiss", "dismiss", null, ActivationType.System, toastContent.Scenario));
                    }

                    else
                    {
                        List <Model.BaseElements.Action> actionElements = actions.ActionElements.ToList();

                        if (toastContent.SupportedFeatures.RS1_Style_Toasts)
                        {
                            actionElements.RemoveAll(i => i.Placement != Model.Enums.ActionPlacement.Inline);
                        }

                        // Initialize inputs
                        foreach (var i in actions.Inputs)
                        {
                            ListViewButton button;

                            switch (i.Type)
                            {
                            case Model.BaseElements.InputType.Text:

                                button = new TextBoxButton(i);
                                break;

                            case Model.BaseElements.InputType.Selection:

                                button = new SelectionButton(i);
                                break;

                            default:
                                throw new NotImplementedException();
                            }

                            AddButton(button);
                        }

                        // Initialize buttons
                        foreach (var a in actionElements)
                        {
                            ListViewButton uiButton = CreateButton(a.Content, a.Arguments, a.ImageUri, a.ActivationType, toastContent.Scenario);

                            //AssignId(uiButton, a.Id);

                            //if (!a.HintVisible)
                            //    uiButton.Visibility = Visibility.Collapsed;

                            AddButton(uiButton);
                        }
                    }
                }
            }

            ListViewButtons.SelectedIndex = 0;
        }