public EditorView() { // Basic functionality var view = new SKCanvasView { HeightRequest = 225 }; var keyboard = new MathKeyboard(Rendering.FrontEnd.PainterConstants.LargerFontSize); var viewModel = keyboard.Keyboard; viewModel.BindDisplay(view, new SkiaSharp.MathPainter { TextColor = SKColors.Black }, new SKColor(0, 0, 0, 153)); // Input from physical keyboard var entry = new Entry { Placeholder = "Enter keystrokes...", HorizontalOptions = LayoutOptions.FillAndExpand }; entry.TextChanged += (sender, e) => { entry.Text = ""; foreach (var c in e.NewTextValue) { // The (int) extra conversion seems to be required by Android or a crash occurs viewModel.KeyPress((Editor.MathKeyboardInput)(int) c); } }; // Evaluation var output = new MathView { FontSize = 32, EnableTouchEvents = true, EnablePanning = true }; keyboard.Keyboard.ReturnPressed += delegate { output.LaTeX = Evaluation.Interpret(keyboard.Keyboard.MathList); }; // Debug labels var latex = new Label { Text = "LaTeX = " }; var atomTypes = new Label { Text = "Atom Types = " }; var ranges = new Label { Text = "Ranges = " }; var index = new Label { Text = "Index = " }; viewModel.RedrawRequested += (sender, e) => Device.BeginInvokeOnMainThread(() => { latex.Text = "LaTeX = " + viewModel.LaTeX; atomTypes.Text = "Atom Types = " + string.Join (", ", viewModel.MathList.Select(x => x.GetType().Name)); ranges.Text = "Ranges = " + string.Join (", ", (viewModel.Display ?? throw new Structures.InvalidCodePathException("Invalid LaTeX")) .Displays.Select(x => x.Range)); index.Text = "Index = " + viewModel.InsertionIndex; });
public EditorView() { // Basic functionality var view = new SKCanvasView { HeightRequest = 225 }; var keyboard = new MathKeyboard(); var viewModel = keyboard.ViewModel; viewModel.BindDisplay(view, new SkiaSharp.MathPainter { TextColor = SKColors.Black }, new SKColor(0, 0, 0, 153)); // Input from physical keyboard var entry = new Entry { Placeholder = "Enter keystrokes..." }; entry.TextChanged += (sender, e) => { entry.Text = ""; foreach (var c in e.NewTextValue) { // The (int) extra conversion seems to be required by Android or a crash occurs viewModel.KeyPress((Editor.MathKeyboardInput)(int) c); } }; // Debug labels var latex = new Label { Text = "LaTeX = " }; var atomTypes = new Label { Text = "Atom Types = " }; var ranges = new Label { Text = "Ranges = " }; var index = new Label { Text = "Index = " }; viewModel.RedrawRequested += (sender, e) => { latex.Text = "LaTeX = " + viewModel.LaTeX; atomTypes.Text = "Atom Types = " + string.Join (", ", viewModel.MathList.Select(x => x.GetType().Name)); ranges.Text = "Ranges = " + string.Join (", ", viewModel.Display.Displays.Select(x => x.Range)); index.Text = "Index = " + viewModel.InsertionIndex; }; // Assemble Content = new StackLayout { Children = { latex, atomTypes, ranges, index, view, keyboard, entry } }; }
public EditorView() { // Basic functionality var view = new SKCanvasView { HeightRequest = 225 }; var keyboard = new MathKeyboard(); var viewModel = keyboard.Keyboard; viewModel.BindDisplay(view, new SkiaSharp.MathPainter { TextColor = SKColors.Black }, new SKColor(0, 0, 0, 153)); // Input from physical keyboard var entry = new Entry { Placeholder = "Enter keystrokes..." }; entry.TextChanged += (sender, e) => { entry.Text = ""; foreach (var c in e.NewTextValue) { // The (int) extra conversion seems to be required by Android or a crash occurs viewModel.KeyPress((Editor.MathKeyboardInput)(int) c); } }; // Debug labels var latex = new Label { Text = "LaTeX = " }; var atomTypes = new Label { Text = "Atom Types = " }; var ranges = new Label { Text = "Ranges = " }; var index = new Label { Text = "Index = " }; viewModel.RedrawRequested += (sender, e) => Device.BeginInvokeOnMainThread(() => { latex.Text = "LaTeX = " + viewModel.LaTeX; atomTypes.Text = "Atom Types = " + string.Join (", ", viewModel.MathList.Select(x => x.GetType().Name)); ranges.Text = "Ranges = " + string.Join (", ", (viewModel.Display ?? throw new Structures.InvalidCodePathException("Invalid LaTeX")) .Displays.Select(x => x.Range)); index.Text = "Index = " + viewModel.InsertionIndex; });
public EditorPage() { InitializeComponent(); var view = new global::SkiaSharp.Views.Forms.SKCanvasView { WidthRequest = 320, HeightRequest = 225 }; var painter = new SkiaSharp.MathPainter { TextColor = global::SkiaSharp.SKColors.Black }; var keyboard = new MathKeyboard(); keyboard.RedrawRequested += (_, __) => view.InvalidateSurface(); view.PaintSurface += (sender, e) => { e.Surface.Canvas.Clear(); SkiaSharp.MathPainter.DrawDisplay(painter, keyboard.Display, e.Surface.Canvas); keyboard.DrawCaret(e.Surface.Canvas, Rendering.CaretShape.UpArrow); }; Content = new StackLayout { Children = { view, keyboard } }; }