verybadcat / CSharpMath

LaTeX. in C#. (ported from the wonderful iosMath project).
MIT License
384 stars 64 forks source link

0.2.0 Editor Update has been released! #29

Closed Happypig375 closed 4 years ago

Happypig375 commented 5 years ago

0.2.0 Editor Update - the final minor update of CSharpMath before becoming MathDisplay.NET (Edit by the time of 0.3.0 release: Not yet... I'll do it when I have time.).

Features

var painter = new CSharpMath.SkiaSharp.MathPainter { /set all properties aside from LocalTypefaces, FontSize, LineStyle, MathList, LaTeX and Source (these are ignored)/ }; var keyboard = new CSharpMath.Rendering.MathKeyboard(/optional fontSize/) { /set Fonts, LineStyle and InsertionIndex here/ }; button.Pressed += (sender, e) => keyboard.KeyPress(CSharpMath.Editor.MathKeyboardInput.SmallX /or any key/); keyboard.RedrawRequested += (sender, e) => canvasView.InvalidateSurface(); canvasView.PaintSurface += (sender, e) => { e.Surface.Canvas.Clear(); //for any DrawDisplay overload, arguments after canvas are the same as Draw CSharpMath.SkiaSharp.MathPainter.DrawDisplay(painter, keyboard.Display, e.Surface.Canvas); keyboard.DrawCaret( new CSharpMath.SkiaSharp.SkiaCanvas(e.Surface.Canvas, SkiaSharp.SKStrokeCap.Butt, false), CSharpMath.Rendering.CaretShape.IBeam); };

![screen](https://user-images.githubusercontent.com/19922066/50734289-f5251600-11d7-11e9-9d48-01dba5b3c2cc.gif)
2. Using the default keyboard:
```cs
//from XAML
SkiaSharp.Views.Forms.SKCanvasView canvasView = ...;
CSharpMath.Forms.MathKeyboard keyboard = ...;

var painter = new CSharpMath.SkiaSharp.MathPainter
{ /*set all properties aside from LocalTypefaces, FontSize, LineStyle,
    MathList, LaTeX and Source (these are ignored)*/ };
keyboard.RedrawRequested += (sender, e) => canvasView.InvalidateSurface();
canvasView.PaintSurface += (sender, e) => {
  e.Surface.Canvas.Clear();
  //for any DrawDisplay overload, arguments after canvas are the same as Draw
  CSharpMath.SkiaSharp.MathPainter.DrawDisplay(painter, keyboard.Display, e.Surface.Canvas);
  keyboard.DrawCaret(e.Surface.Canvas, CSharpMath.Rendering.CaretShape.IBeam);
};

screen

Supersedes #21.

sadqiang commented 5 years ago

In the animation given above, instead of showing xxxxxx... (typing x multiple times), why don't we show something like \int_a^b f(x)\, \mathrm{d}x=F(b)-F(a), for example such that we can see the practical purposes?

Happypig375 commented 5 years ago

To show the actual code for implementing one button, small x in this case.

charlesroddie commented 5 years ago

Great work @Happypig375. For keyboard input into a Xamarin.Forms control I think the best thing is an Effect (or otherwise custom renderer) on UWP that handles focus and keyboard input. Looking into this.

Happypig375 commented 4 years ago

Superceded by #104