Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Math Input (MathEditor port) #11

Closed
charlesroddie opened this issue Jun 26, 2018 · 22 comments
Closed

Math Input (MathEditor port) #11

charlesroddie opened this issue Jun 26, 2018 · 22 comments
Labels
Resolution/Implemented The described enhancement or housekeeping work has been implemented. Type/Enhancement

Comments

@charlesroddie
Copy link
Collaborator

Just as CSharpMath started as a port of iosMath, MathEditor, which builds on iosMath, could be ported to add editing support to CSharpMath.

@verybadcat can you keep us updated about your thoughts on doing this port? Thanks!

@verybadcat
Copy link
Owner

As we discussed on the phone, it's not likely a priority for me at the moment.

@Happypig375 Happypig375 added this to the 0.2.0 Unity Update milestone Jun 26, 2018
@Happypig375
Copy link
Collaborator

I'm targeting this for 0.2.0 for now.

@Happypig375
Copy link
Collaborator

I'm afraid that this will take longer than expected. Can you please allow a few more days?

@Happypig375
Copy link
Collaborator

0.2.0-alpha has been put on NuGet.
Touch response (navigation) is still being worked on.
The main property is CSharpMath.Forms.EditableMathView.Default.

@charlesroddie
Copy link
Collaborator Author

Great! Is this ready to test? We are a bit overloaded here for the next few days but can test soon.

@Happypig375
Copy link
Collaborator

0.2.0-alpha2 is ready!
Still bugfixes to go though.

@Happypig375
Copy link
Collaborator

0.2.0-alpha3 brings an editor which left/right buttons are usable.
Please test~

ezgif-5-168f0fc3866b

@Happypig375
Copy link
Collaborator

I intend to wrap this up very soon. Touch insertion will be pushed to the F# version. Is there an API shape that you would like to be seen?

@charlesroddie
Copy link
Collaborator Author

Gif looks good @Happypig375 . Could we have a normal cursor?

This is the API that I would like:

  • A view with Skiasharp dependency only (not Forms).
  • Properties and instance methods on the input View for inserts/commands.
  • A property for getting latex (perhaps to be replaced with a structural version in the future F# version).
  • A method for setting the cursor position based on a coordinate (understood that this is pushed to the F# version).

Inserts/commands needed:

  • Left, right, up, down, backspace, clear
  • left bracket "(", right bracket ")", 0-9, decimal place, divide, times (cdot), minus, plus
  • Characters a-z, A-Z, greek
  • Functions including sin, cos, tan ,sin^-1, cos^-1, tan^-1, power, sqrt, nth root, modulus ("| |"), sinh, cosh, tanh, exp ("e^"), ln, log, "!".

Some intelligence will be needed eventually about combining inputs. E.g. if the user types "s" then "i" then "n" it should get combined into the sin function. (To accomodate keyboard usage.) MathQuill is a good reference for good behavior.

Does this conform to what you had in mind?

@Happypig375
Copy link
Collaborator

Usage as of 0.2.0-beta1:

  1. Having a custom keyboard:
//from XAML
SkiaSharp.Views.Forms.SKCanvasView canvasView = ...;
Xamarin.Forms.Button button = ...;

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
2. Using the default keyboard:

//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

Happypig375 added a commit that referenced this issue Jan 6, 2019
@Happypig375
Copy link
Collaborator

To anyone following this thread, please cast a vote on #4 - I'm starting the F# project really soon.

@Happypig375
Copy link
Collaborator

@charlesroddie Any suggestions for improvement? I intend this to be the final API of 0.2.0.

@charlesroddie
Copy link
Collaborator Author

Great. We'll take a look today.

@charlesroddie
Copy link
Collaborator Author

The CSharpMath.Editor.MathKeyboardInput enum is clunky to use with all the separate characters. It suggests that consuming code would need to write out all the mapping between a char and the MathKeyboardInput enum.
Perhaps just add a FromChar method? This would just be one line FromChar c = EnumOfValue(int c) but it would make it clearer how to use the keyboard.
In the future F# library it would have a DU where single character a-z, α-ω... input is its own case.

@charlesroddie
Copy link
Collaborator Author

Otherwise the API looks very usable.

@charlesroddie
Copy link
Collaborator Author

Accepting physical keyboard input on Xamarin.Forms depends on xamarin/Xamarin.Forms#3444

@charlesroddie
Copy link
Collaborator Author

To respond to touch/mouseclicks, we need a method to set the current edit/cursor location based on position. This should be doable but any idea how hard it will be @Happypig375 ?

@Happypig375
Copy link
Collaborator

There exists such a method in MathKeyboard but its result is awfully wrong. I plan to rewrite it in MathDisplay.NET.

@Happypig375
Copy link
Collaborator

For the FromChar method, currently just using keyboard.KeyPress((CSharpMath.Editor.MathKeyboardInput)'x') works just fine, because the enum values are specifically defined as the Unicode codepoints of the characters.

@Happypig375
Copy link
Collaborator

@charlesroddie All issues seem to be resolved. Any more issues?

@Happypig375
Copy link
Collaborator

If there are no more issues, I'll be releasing 0.2.0 the next few days.

@Happypig375
Copy link
Collaborator

Implemented, closing.

@Happypig375 Happypig375 added the Resolution/Implemented The described enhancement or housekeeping work has been implemented. label Jan 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution/Implemented The described enhancement or housekeeping work has been implemented. Type/Enhancement
Projects
None yet
Development

No branches or pull requests

3 participants