Exemplo n.º 1
0
        public Sspinner(int initVal)
        {
            Transaction.RunVoid(() =>
            {
                StreamLoop <int> sSetValue = new StreamLoop <int>();
                STextBox textBox           = new STextBox(
                    sSetValue.Map(v => v.ToString()),
                    initVal.ToString(),
                    Cell.Constant(true));

                this.Value = textBox.CText.Map(txt => int.TryParse(txt, out int val) ? val : 0);

                //initializeComponent
                InitializeComponent();
                textBox.HorizontalContentAlignment = HorizontalAlignment.Center;
                textBox.VerticalAlignment          = VerticalAlignment.Center;
                this.valueTextBoxPlaceHolder.Children.Add(textBox);

                Stream <int> sPlusDelta  = this.plusButton.SClicked.Map(u => 1);
                Stream <int> sMinusDelta = this.minusButton.SClicked.Map(u => - 1);
                Stream <int> sDelta      = sPlusDelta.OrElse(sMinusDelta);
                sSetValue.Loop(
                    sDelta.Snapshot(
                        this.Value,
                        (delta, value) => delta + value));
            });
        }
Exemplo n.º 2
0
        public MainWindow()
        {
            this.InitializeComponent();

            Transaction.RunVoid(() =>
            {
                STextBox word           = new STextBox(string.Empty);
                CellLoop <bool> enabled = new CellLoop <bool>();
                SButton button          = new SButton(enabled)
                {
                    Content = "look up"
                };
                Stream <string> sWord = button.SClicked.Snapshot(word.Text);
                IsBusy <string, IMaybe <string> > ib = new IsBusy <string, IMaybe <string> >(Lookup, sWord);
                Stream <string> sDefinition          = ib.SOut.Map(o => o.Match(v => v, () => "ERROR!"));
                Cell <string> definition             = sDefinition.Hold(string.Empty);
                Cell <string> output = definition.Lift(ib.Busy, (def, bsy) => bsy ? "Looking up..." : def);
                enabled.Loop(ib.Busy.Map(b => !b));
                STextBox outputArea = new STextBox(Operational.Value(output), string.Empty, enabled)
                {
                    TextWrapping = TextWrapping.Wrap, AcceptsReturn = true
                };
                this.TextBoxPlaceholder.Child = word;
                this.ButtonPlaceholder.Child  = button;
                this.OutputPlaceholder.Child  = outputArea;
            });
        }
Exemplo n.º 3
0
 void updateHSV()
 {
     H = TruncateFloat(hue * 240, 0, 239);
     S = TruncateFloat(sat * 240, 0, 240);
     L = TruncateFloat(lig * 240, 0, 240);
     HTextBox.GetBindingExpression(TextBox.TextProperty).UpdateTarget();
     STextBox.GetBindingExpression(TextBox.TextProperty).UpdateTarget();
     LTextBox.GetBindingExpression(TextBox.TextProperty).UpdateTarget();
 }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
0
 private void STextBox_TextChanged(object sender, TextChangedEventArgs e)
 {
     if (!HSVfreez)
     {
         RGBfreez = true;
         if (S > 240)
         {
             S = 240;
             STextBox.GetBindingExpression(TextBox.TextProperty).UpdateTarget();
         }
         sat = S / 240.0f;
         ChangeHSV();
         updateRGB();
         buttonColor.Background = new SolidColorBrush(Color.FromRgb(R, G, B));
         RGBfreez = false;
     }
 }
Exemplo n.º 11
0
        void SetCross(Point p)
        {
            CrossTranslate.X = p.X / image1.ActualWidth;
            CrossTranslate.Y = p.Y / image1.ActualWidth;
            if (!HSVfreez)
            {
                RGBfreez = true;
                hue      = (float)CrossTranslate.X;
                sat      = 1 - (float)CrossTranslate.Y;
                if (hue < 0.001)
                {
                    hue = 0.001f;
                }
                if (sat < 0.001)
                {
                    sat = 0.001f;
                }
                if (hue >= 1)
                {
                    hue = 0.999f;
                }
                if (sat >= 1)
                {
                    sat = 0.999f;
                }
                H        = (byte)(hue * 240);
                S        = (byte)(sat * 240);
                HSVfreez = true;
                HTextBox.GetBindingExpression(TextBox.TextProperty).UpdateTarget();
                STextBox.GetBindingExpression(TextBox.TextProperty).UpdateTarget();
                HSVfreez = false;

                ChangeHSV();
                updateRGB();
                buttonColor.Background = new SolidColorBrush(Color.FromRgb(R, G, B));
                GradientStop.Color     = GetMaxColor();
                RGBfreez = false;
            }
        }
Exemplo n.º 12
0
        public MainWindow()
        {
            this.InitializeComponent();

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

            DiscreteCell <int> a   = txtA.Text.Map(ParseInt);
            DiscreteCell <int> b   = txtB.Text.Map(ParseInt);
            DiscreteCell <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);
        }
Exemplo n.º 13
0
        public void AddRow()
        {
            Array.Resize <STextBox>(ref tbBarcode, tbBarcode.Length + 1);
            int i = tbBarcode.Length - 1;

            tbBarcode[i] = new STextBox();
            if (i == 0)
            {
                tbBarcode[i].Location = new Point(MessageLabel("BARCODE").Left, MessageLabel("BARCODE").Top + MessageLabel("BARCODE").Height + 10);
            }
            else
            {
                tbBarcode[i].Location = new Point(MessageLabel("BARCODE").Left, tbBarcode[i - 1].Top + tbBarcode[i - 1].Height + 5);
            }
            tbBarcode[i].Width       = MessageLabel("DESC").Left - MessageLabel("BARCODE").Left - 2;
            tbBarcode[i].BorderStyle = BorderStyle.None;
            tbBarcode[i].KeyDown    += new KeyEventHandler(BarcodeKeyDown);
            tbBarcode[i].GotFocus   += new EventHandler(BarcodeGotFocus);
            tbBarcode[i].nRowNum     = i;
            this.Controls.Add(tbBarcode[i]);
            Array.Resize <SLabel>(ref lblLineNo, lblLineNo.Length + 1);
            lblLineNo[i]           = new SLabel();
            lblLineNo[i].Location  = new Point(10, tbBarcode[i].Top);
            lblLineNo[i].Width     = 20;
            lblLineNo[i].BackColor = Color.Transparent;
            lblLineNo[i].ForeColor = Color.White;
            lblLineNo[i].nRowNum   = i;
            lblLineNo[i].Text      = (i + 1).ToString();
            this.Controls.Add(lblLineNo[i]);
            Array.Resize <SLabel>(ref lblDesc, lblDesc.Length + 1);
            lblDesc[i]           = new SLabel();
            lblDesc[i].Location  = new Point(MessageLabel("DESC").Left, tbBarcode[i].Top);
            lblDesc[i].Width     = MessageLabel("QTY").Left - MessageLabel("DESC").Left - 2;
            lblDesc[i].BackColor = Color.Transparent;
            lblDesc[i].ForeColor = Color.White;
            lblDesc[i].nRowNum   = i;
            this.Controls.Add(lblDesc[i]);
            Array.Resize <STextBox>(ref tbQty, tbQty.Length + 1);
            tbQty[i]             = new STextBox();
            tbQty[i].Location    = new Point(MessageLabel("QTY").Left, tbBarcode[i].Top);
            tbQty[i].Width       = MessageLabel("MORR").Left - MessageLabel("QTY").Left - 2;
            tbQty[i].BorderStyle = BorderStyle.None;
            tbQty[i].KeyDown    += new KeyEventHandler(QtyKeyDown);
            tbQty[i].GotFocus   += new EventHandler(QtyGotFocus);
            tbQty[i].nRowNum     = i;
            this.Controls.Add(tbQty[i]);
            Array.Resize <SLabel>(ref lblRRPEach, lblRRPEach.Length + 1);
            lblRRPEach[i]             = new SLabel();
            lblRRPEach[i].Location    = new Point(MessageLabel("RRP").Left, tbBarcode[i].Top);
            lblRRPEach[i].Width       = MessageLabel("FMARGIN").Left - MessageLabel("RRP").Left - 2;
            lblRRPEach[i].BackColor   = Color.Transparent;
            lblRRPEach[i].ForeColor   = Color.White;
            lblRRPEach[i].BorderStyle = BorderStyle.None;
            lblRRPEach[i].nRowNum     = i;
            this.Controls.Add(lblRRPEach[i]);
            Array.Resize <SLabel>(ref lblFullMargin, lblFullMargin.Length + 1);
            lblFullMargin[i]             = new SLabel();
            lblFullMargin[i].Location    = new Point(MessageLabel("FMARGIN").Left, tbBarcode[i].Top);
            lblFullMargin[i].Width       = MessageLabel("T-MARGIN").Left - MessageLabel("FMARGIN").Left - 2;
            lblFullMargin[i].BorderStyle = BorderStyle.None;
            lblFullMargin[i].BackColor   = Color.Transparent;
            lblFullMargin[i].ForeColor   = Color.White;
            lblFullMargin[i].nRowNum     = i;
            this.Controls.Add(lblFullMargin[i]);
            Array.Resize <STextBox>(ref tbMarginOrRRP, tbMarginOrRRP.Length + 1);
            tbMarginOrRRP[i]             = new STextBox();
            tbMarginOrRRP[i].Location    = new Point(MessageLabel("MORR").Left, tbBarcode[i].Top);
            tbMarginOrRRP[i].Width       = 50;
            tbMarginOrRRP[i].BorderStyle = BorderStyle.None;
            tbMarginOrRRP[i].KeyDown    += new KeyEventHandler(MarginOrRRPKeyDown);
            tbMarginOrRRP[i].nRowNum     = i;
            this.Controls.Add(tbMarginOrRRP[i]);
            Array.Resize <STextBox>(ref tbTargetMargin, tbTargetMargin.Length + 1);
            tbTargetMargin[i]             = new STextBox();
            tbTargetMargin[i].Location    = new Point(MessageLabel("T-MARGIN").Left, tbBarcode[i].Top);
            tbTargetMargin[i].Width       = 100;
            tbTargetMargin[i].BorderStyle = BorderStyle.None;
            tbTargetMargin[i].KeyDown    += new KeyEventHandler(TargetMarginKeyDown);
            tbTargetMargin[i].nRowNum     = i;
            this.Controls.Add(tbTargetMargin[i]);
            Array.Resize <SLabel>(ref lblFinalLinePrice, lblFinalLinePrice.Length + 1);
            lblFinalLinePrice[i]           = new SLabel();
            lblFinalLinePrice[i].Location  = new Point(800, tbBarcode[i].Top);
            lblFinalLinePrice[i].BackColor = Color.Transparent;
            lblFinalLinePrice[i].ForeColor = Color.White;
            lblFinalLinePrice[i].Width     = 100;
            lblFinalLinePrice[i].nRowNum   = i;
            this.Controls.Add(lblFinalLinePrice[i]);
            Array.Resize <SLabel>(ref lblFinalLineMargin, lblFinalLineMargin.Length + 1);
            lblFinalLineMargin[i]           = new SLabel();
            lblFinalLineMargin[i].Location  = new Point(900, tbBarcode[i].Top);
            lblFinalLineMargin[i].BackColor = Color.Transparent;
            lblFinalLineMargin[i].ForeColor = Color.White;
            lblFinalLineMargin[i].Width     = 100;
            lblFinalLineMargin[i].nRowNum   = i;
            this.Controls.Add(lblFinalLineMargin[i]);
            this.Refresh();
        }
Exemplo n.º 14
0
        public GridValidForm()
        {
            InitializeComponent();

            Transaction.RunVoid(() =>
            {
                STextBox nameBox        = new STextBox();
                Cell <string> nameLabel = nameBox.CText.Map(t =>
                {
                    if (string.IsNullOrWhiteSpace(t))
                    {
                        return("입력해라");
                    }
                    else if (t.Trim().IndexOf(" ") < 0)
                    {
                        return("성씨가 뭐냐 스페이스바를 넣어라.");
                    }
                    else
                    {
                        return(string.Empty);
                    }
                });
                SLabel nameCheckLabel = new SLabel(nameLabel);

                this.nameBox.Children.Add(nameBox);
                this.nameValidateLabel.Children.Add(nameCheckLabel);

                Sspinner emailCounter         = new Sspinner(1);
                Cell <string> emailCountLabel = emailCounter.Value.Map(v =>
                                                                       v <1 || v> maxEmails ?
                                                                       "이메일은 1개부터 4개다잉~ 잘해라잉" :
                                                                       string.Empty);
                SLabel CounterCheckLabel = new SLabel(emailCountLabel);

                this.spinner.Children.Add(emailCounter);
                this.numberValidateLabel.Children.Add(CounterCheckLabel);


                var emailLists = new List <Tuple <Grid, Grid> >()
                {
                    new Tuple <Grid, Grid>(this.eMailBox1, this.eMailValidateLabel1),
                    new Tuple <Grid, Grid>(this.eMailBox2, this.eMailValidateLabel2),
                    new Tuple <Grid, Grid>(this.eMailBox3, this.eMailValidateLabel3),
                    new Tuple <Grid, Grid>(this.eMailBox4, this.eMailValidateLabel4),
                };

                var emailValids = emailLists.Select((t, i) =>
                {
                    Cell <bool> enabled      = emailCounter.Value.Map(v => v > i);
                    var emailBox             = new STextBox(string.Empty, enabled);
                    Cell <string> emailLabel = enabled.Lift(emailBox.CText.Map(t_ =>
                    {
                        if (string.IsNullOrWhiteSpace(t_))
                        {
                            return("입력해라");
                        }
                        else if (t_.Trim().IndexOf("@") < 0)
                        {
                            return("골뱅이 어따 팔아먹었냐~ 넣지??");
                        }
                        else
                        {
                            return(string.Empty);
                        }
                    }),
                                                            (_1, _2) => _1 ? _2 : string.Empty);
                    var emailCheckLabel = new SLabel(emailLabel);

                    t.Item1.Children.Add(emailBox);
                    t.Item2.Children.Add(emailCheckLabel);
                    return(emailLabel);
                });

                var allOk = emailValids.Concat(new [] { nameLabel, emailCountLabel }).Lift(v => v.All(string.IsNullOrWhiteSpace));

                var OkButton = new SButton(allOk)
                {
                    Content = "확인"
                };
                this.okButton.Children.Add(OkButton);
            });
        }