コード例 #1
0
ファイル: MainWindow.xaml.cs プロジェクト: Angeldude/sodium
        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);
        }
コード例 #2
0
ファイル: MainWindow.xaml.cs プロジェクト: Angeldude/sodium
        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);
        }
コード例 #3
0
ファイル: MainWindow.xaml.cs プロジェクト: Angeldude/sodium
        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);
        }
コード例 #4
0
ファイル: MainWindow.xaml.cs プロジェクト: Angeldude/sodium
        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);
        }
コード例 #5
0
ファイル: MainWindow.xaml.cs プロジェクト: Angeldude/sodium
        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);
        }
コード例 #6
0
ファイル: MainWindow.xaml.cs プロジェクト: Angeldude/sodium
        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);
        }
コード例 #7
0
ファイル: MainWindow.xaml.cs プロジェクト: Angeldude/sodium
        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));
            });
        }