Exemple #1
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);
        }
Exemple #2
0
        public MainWindow()
        {
            this.InitializeComponent();

            SDateField dep = new SDateField();
            SDateField ret = new SDateField();
            Cell<bool> valid = dep.SelectedDate.Lift(ret.SelectedDate, (d, r) => d <= r);
            SButton ok = new SButton(valid) { Content = "OK", Width = 75 };

            this.DeparturePlaceholder.Children.Add(dep);
            this.ReturnPlaceholder.Children.Add(ret);
            this.ButtonPlaceholder.Children.Add(ok);
        }
Exemple #3
0
        public MainWindow()
        {
            this.InitializeComponent();

            SDateField dep = new SDateField();
            SDateField ret = new SDateField();
            Rule r1 = new Rule((d, r) => d <= r);
            Rule r2 = new Rule((d, r) => !Unlucky(d) && !Unlucky(r));
            Rule rule = r1.And(r2);
            Cell<bool> valid = rule.Reify(dep.SelectedDate, ret.SelectedDate);
            SButton ok = new SButton(valid) { Content = "OK", Width = 75 };

            this.DeparturePlaceholder.Children.Add(dep);
            this.ReturnPlaceholder.Children.Add(ret);
            this.ButtonPlaceholder.Children.Add(ok);
        }
Exemple #4
0
        public MainWindow()
        {
            this.InitializeComponent();

            SButton red = new SButton { Content = "red", Width = 75 };
            SButton green = new SButton { Content = "green", Width = 75, Margin = new Thickness(5, 0, 0, 0) };
            Stream<string> sRed = red.SClicked.Map(_ => "red");
            Stream<string> sGreen = green.SClicked.Map(_ => "green");
            Stream<string> sColor = sRed.OrElse(sGreen);
            Cell<string> color = sColor.Hold(string.Empty);
            SLabel lbl = new SLabel(color) { Width = 75, Margin = new Thickness(5, 0, 0, 0) };

            this.Container.Children.Add(red);
            this.Container.Children.Add(green);
            this.Container.Children.Add(lbl);
        }
Exemple #5
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);
        }
Exemple #6
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));
        }
Exemple #7
0
        public MainWindow()
        {
            this.InitializeComponent();

            Transaction.RunVoid(() =>
            {
                CellLoop<int> value = new CellLoop<int>();
                SLabel lblValue = new SLabel(value.Map(i => i.ToString()));
                SButton plus = new SButton { Content = "+", Width = 25, Margin = new Thickness(5, 0, 0, 0) };
                SButton minus = new SButton { Content = "-", Width = 25, Margin = new Thickness(5, 0, 0, 0) };

                this.Container.Children.Add(lblValue);
                this.Container.Children.Add(plus);
                this.Container.Children.Add(minus);

                Stream<int> sPlusDelta = plus.SClicked.Map(_ => 1);
                Stream<int> sMinusDelta = minus.SClicked.Map(_ => -1);
                Stream<int> sDelta = sPlusDelta.OrElse(sMinusDelta);
                Stream<int> sUpdate = sDelta.Snapshot(value, (d, v) => v + d).Filter(n => n >= 0);
                value.Loop(sUpdate.Hold(0));
            });
        }