Exemple #1
0
        public ReplPage(object context = null)
        {
            evaluatorHost = new EvaluatorHost(context ?? "a");
            evaluatorHost.Evaluate("1");

            Content =

                new Grid
            {
                RowSpacing      = 2,
                ColumnSpacing   = 2,
                BackgroundColor = Color.Gray,
                RowDefinitions  =
                {
                    new RowDefinition()
                    {
                        Height = new GridLength(50, GridUnitType.Absolute)
                    },
                    new RowDefinition(),
                    new RowDefinition {
                        Height = new GridLength(100, GridUnitType.Absolute)
                    },
                    new RowDefinition {
                        Height = new GridLength(30, GridUnitType.Absolute)
                    }
                },
                ColumnDefinitions =
                {
                    new ColumnDefinition(),
                    new ColumnDefinition {
                        Width = new GridLength(80, GridUnitType.Absolute)
                    }
                },

                Children =
                {
                    new Grid
                    {
                        BackgroundColor = Color.Black,
                        Children        =
                        {
                            new Label
                            {
                                TextColor  = Color.White,
                                Text       = "HAPPY HAPPY REPL",
                                FontFamily = "Apple-Kid",
                                FontSize   = 42,
                                HorizontalTextAlignment = TextAlignment.Center,
                                VerticalTextAlignment   = TextAlignment.Center,
                            }
                        }
                    }.Row(0).ColSpan(2),

                    new Grid
                    {
                        BackgroundColor = Color.Black
                    }.Row(3).ColSpan(2),

                    new CollectionView
                    {
                        BackgroundColor = Color.Black,
                        ItemsSource     = Evaluations,
                        ItemTemplate    = new DataTemplate(() =>
                        {
                            var cell = new EvaluationCell();
                            cell.Bind(EvaluationCell.EvaluationProperty);

                            return(cell);
                        }),
                        IsVisible = false
                    }
                    .Assign(out CollectionView)
                    .Row(1).ColSpan(2),

                    GetReplView(),

                    new Editor
                    {
                        IsSpellCheckEnabled = false,
                        Keyboard            = Keyboard.Create(KeyboardFlags.None),
                        BackgroundColor     = Color.Black,
                        TextColor           = Color.White,
                    }.Row(2)
                    .Invoke(x =>
                    {
                        x.TextChanged += async delegate
                        {
                            if (string.IsNullOrWhiteSpace(x.Text))
                            {
                                return;
                            }

                            var lastChar = x.Text.LastOrDefault();
                            if (lastChar == '\n')
                            {
                                await Evaluate(Editor.Text);
                                return;
                            }
                        };
                    })
                    .Assign(out Editor),

                    new Button
                    {
                        Text            = "Eval",
                        TextColor       = Color.White,
                        FontFamily      = "Apple-Kid",
                        FontSize        = 38,
                        BackgroundColor = Color.Black
                    }.Row(2).Col(1)
                    .Invoke(x =>
                    {
                        x.Clicked += async delegate{ await Evaluate(Editor.Text);                         };
                    }),
                }
            }.Assign(out MainGrid);
        }