Beispiel #1
0
        private SSpinner(int initialValue)
        {
            StreamLoop <int> sSetValue = new StreamLoop <int>();
            STextBox         textField = new STextBox(sSetValue.Map(v => v.ToString()), initialValue.ToString())
            {
                VerticalContentAlignment = VerticalAlignment.Center
            };

            this.Value = textField.Text.Map(t =>
            {
                int result;
                if (int.TryParse(t, out result))
                {
                    return(result);
                }

                return(0);
            });
            SButton plus = new SButton {
                Content = "+", Width = 25
            };
            SButton minus = new SButton {
                Content = "-", Width = 25
            };

            this.RowDefinitions.Add(new RowDefinition {
                Height = GridLength.Auto
            });
            this.RowDefinitions.Add(new RowDefinition {
                Height = GridLength.Auto
            });
            this.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Star)
            });
            this.ColumnDefinitions.Add(new ColumnDefinition {
                Width = GridLength.Auto
            });

            SetRow(textField, 0);
            SetColumn(textField, 0);
            SetRowSpan(textField, 2);
            this.Children.Add(textField);

            SetRow(plus, 0);
            SetColumn(plus, 1);
            this.Children.Add(plus);

            SetRow(minus, 1);
            SetColumn(minus, 1);
            this.Children.Add(minus);

            Stream <int> sPlusDelta  = plus.SClicked.Map(_ => 1);
            Stream <int> sMinusDelta = minus.SClicked.Map(_ => - 1);
            Stream <int> sDelta      = sPlusDelta.OrElse(sMinusDelta);

            sSetValue.Loop(sDelta.Snapshot(this.Value, (d, v) => v + d));
        }
Beispiel #2
0
        public MainWindow()
        {
            this.InitializeComponent();

            STextBox msg = new STextBox("Hello") { Width = 150 };
            SLabel lbl = new SLabel(msg.Text) { Width = 150, Margin = new Thickness(5, 0, 0, 0) };

            this.Container.Children.Add(msg);
            this.Container.Children.Add(lbl);
        }
Beispiel #3
0
        public MainWindow()
        {
            this.InitializeComponent();

            Stream<string> sOnegai = this.OnegaiButton.SClicked.Map(_ => "Onegai shimasu");
            Stream<string> sThanks = this.ThanksButton.SClicked.Map(_ => "Thank you");
            Stream<string> sCanned = sOnegai.OrElse(sThanks);

            STextBox text = new STextBox(sCanned, string.Empty);
            this.TextPlaceholder.Children.Add(text);
        }
Beispiel #4
0
        public MainWindow()
        {
            this.InitializeComponent();

            SButton clear = new SButton { Content = "Clear", Width = 75 };
            Stream<string> sClearIt = clear.SClicked.Map(_ => string.Empty);
            STextBox text = new STextBox(sClearIt, "Hello") { Width = 100 };

            this.Container.Children.Add(text);
            this.Container.Children.Add(clear);
        }
Beispiel #5
0
        public MainWindow()
        {
            this.InitializeComponent();

            STextBox msg = new STextBox("Hello") { Width = 150 };
            Cell<string> reversed = msg.Text.Map(t => new string(t.Reverse().ToArray()));
            SLabel lbl = new SLabel(reversed) { Width = 150, Margin = new Thickness(5, 0, 0, 0) };

            this.Container.Children.Add(msg);
            this.Container.Children.Add(lbl);
        }
Beispiel #6
0
        public MainWindow()
        {
            this.InitializeComponent();

            STextBox english = new STextBox("I like FRP") { Width = 150 };
            this.TextBoxPlaceholder.Children.Add(english);

            Stream<string> sLatin = this.TranslateButton.SClicked.Snapshot(english.Text, (u, t) => Regex.Replace(t.Trim(), " |$", "us "));
            Cell<string> latin = sLatin.Hold(string.Empty);
            SLabel lblLatin = new SLabel(latin);
            this.TextPlaceholder.Children.Add(lblLatin);
        }
Beispiel #7
0
        public MainWindow()
        {
            this.InitializeComponent();

            STextBox txtA = new STextBox("5") { Width = 100 };
            STextBox txtB = new STextBox("10") { Width = 100 };

            Cell<int> a = txtA.Text.Map(ParseInt);
            Cell<int> b = txtB.Text.Map(ParseInt);
            Cell<int> sum = a.Lift(b, (x, y) => x + y);

            SLabel lblSum = new SLabel(sum.Map(i => i.ToString()));

            this.Container.Children.Add(txtA);
            this.Container.Children.Add(txtB);
            this.Container.Children.Add(lblSum);
        }
Beispiel #8
0
        public MainWindow()
        {
            this.InitializeComponent();

            IReadOnlyList<Tuple<Grid, Grid>> emailAndValidationPlaceholders = new[]
            {
                Tuple.Create(this.Email1Placeholder, this.Email1ValidationPlaceholder),
                Tuple.Create(this.Email2Placeholder, this.Email2ValidationPlaceholder),
                Tuple.Create(this.Email3Placeholder, this.Email3ValidationPlaceholder),
                Tuple.Create(this.Email4Placeholder, this.Email4ValidationPlaceholder)
            };
            int maxEmails = emailAndValidationPlaceholders.Count;

            STextBox name = new STextBox(string.Empty) { Width = 200 };
            this.NamePlaceholder.Children.Add(name);
            Cell<string> nameValidationError = name.Text.Map(t => string.IsNullOrEmpty(t.Trim()) ? "<-- enter something" : t.Trim().IndexOf(' ') < 0 ? "<-- must contain space" : string.Empty);
            Cell<bool> isNameValid = nameValidationError.Map(string.IsNullOrEmpty);
            SLabel validName = new SLabel(nameValidationError);
            this.NameValidationPlaceholder.Children.Add(validName);

            SSpinner number = SSpinner.Create(1);
            this.NumberOfEmailAddressesPlaceholder.Children.Add(number);
            Cell<string> numberOfEmailAddressesValidationError = number.Value.Map(n => n < 1 || n > maxEmails ? "<-- must be 1 to " + maxEmails : string.Empty);
            Cell<bool> isNumberOfEmailAddressesValid = numberOfEmailAddressesValidationError.Map(string.IsNullOrEmpty);
            SLabel validNumber = new SLabel(numberOfEmailAddressesValidationError);
            this.NumberOfEmailAddressesValidationPlaceholder.Children.Add(validNumber);

            IReadOnlyList<Cell<bool>> validEmails = emailAndValidationPlaceholders.Select((p, i) =>
            {
                Cell<bool> enabled = number.Value.Map(n => i < n);
                STextBox email = new STextBox(string.Empty, enabled) { Width = 200 };
                p.Item1.Children.Add(email);
                Cell<string> validText = email.Text.Lift(number.Value, (e, n) => i >= n ? string.Empty : string.IsNullOrEmpty(e.Trim()) ? "<-- enter something" : e.IndexOf('@') < 0 ? "<-- must contain @" : string.Empty);
                SLabel validEmail = new SLabel(validText);
                p.Item2.Children.Add(validEmail);
                return validText.Map(string.IsNullOrEmpty);
            }).ToArray();

            Cell<bool> allValid = validEmails.Concat(new[] { isNameValid, isNumberOfEmailAddressesValid }).Lift(vv => vv.All(v => v));
            SButton ok = new SButton(allValid) { Content = "OK", Width = 75 };
            this.ButtonPlaceholder.Children.Add(ok);
        }
Beispiel #9
0
        private SSpinner(int initialValue)
        {
            StreamLoop<int> sSetValue = new StreamLoop<int>();
            STextBox textField = new STextBox(sSetValue.Map(v => v.ToString()), initialValue.ToString()) { VerticalContentAlignment = VerticalAlignment.Center };
            this.Value = textField.Text.Map(t =>
            {
                int result;
                if (int.TryParse(t, out result))
                {
                    return result;
                }

                return 0;
            });
            SButton plus = new SButton { Content = "+", Width = 25 };
            SButton minus = new SButton { Content = "-", Width = 25 };

            this.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
            this.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
            this.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
            this.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });

            SetRow(textField, 0);
            SetColumn(textField, 0);
            SetRowSpan(textField, 2);
            this.Children.Add(textField);

            SetRow(plus, 0);
            SetColumn(plus, 1);
            this.Children.Add(plus);

            SetRow(minus, 1);
            SetColumn(minus, 1);
            this.Children.Add(minus);

            Stream<int> sPlusDelta = plus.SClicked.Map(_ => 1);
            Stream<int> sMinusDelta = minus.SClicked.Map(_ => -1);
            Stream<int> sDelta = sPlusDelta.OrElse(sMinusDelta);
            sSetValue.Loop(sDelta.Snapshot(this.Value, (d, v) => v + d));
        }