Skip to content

Commit

Permalink
Finalized MathButton API
Browse files Browse the repository at this point in the history
  • Loading branch information
Happypig375 committed Apr 7, 2020
1 parent c629355 commit 824d0df
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 92 deletions.
28 changes: 0 additions & 28 deletions CSharpMath.Avalonia/MathButton.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@
</ColumnDefinitionCollection>
</Grid.ColumnDefinitions>
<f:MathInputButton Input="Left" Grid.Column="0" Keyboard="{StaticResource Keyboard}"/>
<f:MathButton LaTeX="123" x:Name="NumbersButton" Grid.Column="1" Command="{e:SwitchToTab Self={Reference this}, Target=Numbers}"/>
<f:MathButton x:Name="NumbersButton" Grid.Column="1" Command="{e:SwitchToTab Self={Reference this}, Target=Numbers}">
<f:MathView LaTeX="123"/>
</f:MathButton>
<Grid x:Name="Numbers" Style="{StaticResource Tab}" IsVisible="True">
<f:MathInputButton StyleClass="x"/>
<f:MathInputButton StyleClass="y"/>
Expand All @@ -183,7 +185,9 @@
<f:MathInputButton StyleClass="Dismiss"/>
<f:MathInputButton StyleClass="Enter"/>
</Grid>
<f:MathButton LaTeX="()&lt;&gt;" x:Name="SymbolsButton" Grid.Column="2" Command="{e:SwitchToTab Self={Reference this}, Target=Symbols}"/>
<f:MathButton x:Name="SymbolsButton" Grid.Column="2" Command="{e:SwitchToTab Self={Reference this}, Target=Symbols}">
<f:MathView LaTeX="()&lt;&gt;"/>
</f:MathButton>
<Grid x:Name="Symbols" Style="{StaticResource Tab}">
<f:MathInputButton StyleClass="x"/>
<f:MathInputButton StyleClass="y"/>
Expand All @@ -210,7 +214,9 @@
<f:MathInputButton StyleClass="Dismiss"/>
<f:MathInputButton StyleClass="Enter"/>
</Grid>
<f:MathButton LaTeX="f(x)" x:Name="FunctionsButton" Grid.Column="3" Command="{e:SwitchToTab Self={Reference this}, Target=Functions}"/>
<f:MathButton x:Name="FunctionsButton" Grid.Column="3" Command="{e:SwitchToTab Self={Reference this}, Target=Functions}">
<f:MathView LaTeX="f(x)"/>
</f:MathButton>
<Grid x:Name="Functions" Style="{StaticResource Tab}">
<f:MathInputButton StyleClass="x"/>
<f:MathInputButton StyleClass="y"/>
Expand All @@ -237,7 +243,9 @@
<f:MathInputButton StyleClass="Dismiss"/>
<f:MathInputButton StyleClass="Enter"/>
</Grid>
<f:MathButton LaTeX="\int\sum" x:Name="OperationsButton" Grid.Column="4" Command="{e:SwitchToTab Self={Reference this}, Target=Operations}"/>
<f:MathButton x:Name="OperationsButton" Grid.Column="4" Command="{e:SwitchToTab Self={Reference this}, Target=Operations}">
<f:MathView LaTeX="\int\sum"/>
</f:MathButton>
<Grid x:Name="Operations" Style="{StaticResource Tab}">
<f:MathInputButton StyleClass="x"/>
<f:MathInputButton StyleClass="y"/>
Expand All @@ -264,7 +272,9 @@
<f:MathInputButton StyleClass="Dismiss"/>
<f:MathInputButton StyleClass="Enter"/>
</Grid>
<f:MathButton LaTeX="abc" x:Name="LettersButton" Grid.Column="5" Command="{e:SwitchToTab Self={Reference this}, Target=Letters}"/>
<f:MathButton x:Name="LettersButton" Grid.Column="5" Command="{e:SwitchToTab Self={Reference this}, Target=Letters}">
<f:MathView LaTeX="abc"/>
</f:MathButton>
<Grid x:Name="Letters" Style="{StaticResource Tab_Letters}">
<f:MathInputButton Input="SmallQ" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Keyboard="{StaticResource Keyboard}"/>
<f:MathInputButton Input="SmallW" Grid.Row="0" Grid.Column="2" Grid.ColumnSpan="2" Keyboard="{StaticResource Keyboard}"/>
Expand Down Expand Up @@ -297,7 +307,9 @@
<f:MathInputButton Input="SmallSigma" Grid.Row="3" Grid.Column="9" Grid.ColumnSpan="2" Keyboard="{StaticResource Keyboard}"/>
<f:MathInputButton Input="SmallMu" Grid.Row="3" Grid.Column="11" Grid.ColumnSpan="2" Keyboard="{StaticResource Keyboard}"/>
<f:MathInputButton Input="SmallLambda" Grid.Row="3" Grid.Column="13" Grid.ColumnSpan="2" Keyboard="{StaticResource Keyboard}"/>
<f:MathButton LaTeX="" Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="3" Command="{e:SwitchToTab Self={Reference this}, Target=LettersCapitals}" x:Name="ShiftButton"/>
<f:MathButton Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="3" Command="{e:SwitchToTab Self={Reference this}, Target=LettersCapitals}" x:Name="ShiftButton">
<f:MathView LaTeX=""/>
</f:MathButton>
<f:MathInputButton StyleClass="Back" Grid.Row="2" Grid.Column="17" Grid.ColumnSpan="3"/>
<f:MathInputButton StyleClass="Dismiss" Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="5"/>
<f:MathInputButton StyleClass="Enter" Grid.Row="3" Grid.Column="15" Grid.RowSpan="1" Grid.ColumnSpan="5"/>
Expand Down Expand Up @@ -334,7 +346,9 @@
<f:MathInputButton Input="SmallPhi" Grid.Row="3" Grid.Column="9" Grid.ColumnSpan="2" Keyboard="{StaticResource Keyboard}"/>
<f:MathInputButton Input="SmallNu" Grid.Row="3" Grid.Column="11" Grid.ColumnSpan="2" Keyboard="{StaticResource Keyboard}"/>
<f:MathInputButton Input="SmallBeta" Grid.Row="3" Grid.Column="13" Grid.ColumnSpan="2" Keyboard="{StaticResource Keyboard}"/>
<f:MathButton LaTeX="" Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="3" Command="{e:SwitchToTab Self={Reference this}, Target=Letters}" x:Name="ShiftCapitalsButton"/>
<f:MathButton Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="3" Command="{e:SwitchToTab Self={Reference this}, Target=Letters}" x:Name="ShiftCapitalsButton">
<f:MathView LaTeX=""/>
</f:MathButton>
<f:MathInputButton StyleClass="Clear" Grid.Row="2" Grid.Column="17" Grid.ColumnSpan="3"/>
<f:MathInputButton StyleClass="Dismiss" Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="5"/>
<f:MathInputButton StyleClass="Enter" Grid.Row="3" Grid.Column="15" Grid.RowSpan="1" Grid.ColumnSpan="5"/>
Expand Down
32 changes: 32 additions & 0 deletions CSharpMath.Forms/Buttons.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using SkiaSharp;
using Xamarin.Forms;
namespace CSharpMath.Forms {
using SkiaSharp;
[ContentProperty(nameof(Content))]
public abstract class BaseButton<TView, TPainter, TContent> : ImageButton
where TView : BaseView<TPainter, TContent>
where TPainter : Rendering.FrontEnd.Painter<SKCanvas, TContent, SKColor>, new()
where TContent : class {
public BaseButton() {
Aspect = Aspect.AspectFit;
// Color.Default will be ugly: https://github.com/verybadcat/CSharpMath/issues/111
BackgroundColor = Color.Transparent;
Source = ImageSource.FromStream(() => {
if (Content is { } c) {
var latex = c.Painter.LaTeX;
// Appropriate positioning for non-full characters, e.g. prime, degree
// Also acts as spacing between MathButtons next to each other
c.Painter.LaTeX = @"{\color{#0000}|}" + latex + @"{\color{#0000}|}";
var stream = c.Painter.DrawAsStream();
c.Painter.LaTeX = latex;
return stream;
}
return null;
});
}
public TView? Content { get => (TView?)GetValue(ContentProperty); set => SetValue(ContentProperty, value); }
public static readonly BindableProperty ContentProperty = BindableProperty.Create(nameof(Content), typeof(TView), typeof(BaseButton<TView, TPainter, TContent>));
}
public class MathButton : BaseButton<MathView, MathPainter, Atom.MathList> { }
public class TextButton : BaseButton<TextView, TextPainter, Rendering.Text.TextAtom> { }
}
32 changes: 0 additions & 32 deletions CSharpMath.Forms/MathButton.cs

This file was deleted.

6 changes: 5 additions & 1 deletion CSharpMath.Forms/MathInputButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ static string InputToLaTeX(MathKeyboardInput input) {
}
}
public static readonly BindableProperty InputProperty =
BindableProperty.Create(nameof(Input), typeof(MathKeyboardInput), typeof(MathInputButton), propertyChanged:(b, o, n) => ((MathInputButton)b).LaTeX = InputToLaTeX((MathKeyboardInput)n));
BindableProperty.Create(nameof(Input), typeof(MathKeyboardInput), typeof(MathInputButton), propertyChanged:(b, o, n) => {
var button = (MathInputButton)b;
button.Content ??= new MathView();
button.Content.LaTeX = InputToLaTeX((MathKeyboardInput)n);
});
public MathKeyboardInput Input { get => (MathKeyboardInput)GetValue(InputProperty); set => SetValue(InputProperty, value); }
}
}
1 change: 0 additions & 1 deletion CSharpMath.Rendering.Tests/Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ protected void Run<TContent>(

// Prevent black background behind black rendered output in File Explorer preview
painter.HighlightColor = painter.UnwrapColor(new Structures.Color(0xF0, 0xF0, 0xF0));
painter.FontSize = 50f;
painter.LaTeX = latex;

var actualFile = new FileInfo(System.IO.Path.Combine(folder, inFile + "." + frontEnd + ".png"));
Expand Down
2 changes: 1 addition & 1 deletion CSharpMath.Rendering/FrontEnd/MathKeyboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace CSharpMath.Rendering.FrontEnd {

public enum CaretShape { IBeam, UpArrow }
public class MathKeyboard : MathKeyboard<Fonts, Glyph> {
public MathKeyboard(float fontSize = PainterConstants.DefaultFontSize * 3 / 2, double blinkMilliseconds = DefaultBlinkMilliseconds)
public MathKeyboard(float fontSize = PainterConstants.DefaultFontSize, double blinkMilliseconds = DefaultBlinkMilliseconds)
: base(TypesettingContext.Instance,
new Fonts(Array.Empty<Typography.OpenFont.Typeface>(), fontSize), blinkMilliseconds) { }

Expand Down
2 changes: 1 addition & 1 deletion CSharpMath.Rendering/FrontEnd/Painter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace CSharpMath.Rendering.FrontEnd {
using BackEnd;

public static class PainterConstants {
public const float DefaultFontSize = 20f;
public const float DefaultFontSize = 50f;
}
public abstract class Painter<TCanvas, TContent, TColor> : ICSharpMathAPI<TContent, TColor> where TContent : class {
public const float DefaultFontSize = PainterConstants.DefaultFontSize;
Expand Down
1 change: 0 additions & 1 deletion CSharpMath.Xaml/CSharpMath.Xaml.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<Import_RootNamespace>CSharpMath.Xaml</Import_RootNamespace>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)ICSharpMathView.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Views.cs" />
</ItemGroup>
</Project>
19 changes: 0 additions & 19 deletions CSharpMath.Xaml/ICSharpMathView.cs

This file was deleted.

2 changes: 1 addition & 1 deletion CSharpMath.Xaml/Views.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace CSharpMath.Avalonia {
namespace CSharpMath.Forms {
[Xamarin.Forms.ContentProperty(nameof(LaTeX))]
#endif
public class BaseView<TPainter, TContent> : XInheritControl, ICSharpMathView<TContent, XColor, XCanvasColor, XCanvas, TPainter>
public class BaseView<TPainter, TContent> : XInheritControl, ICSharpMathAPI<TContent, XColor>
where TPainter : Painter<XCanvas, TContent, XCanvasColor>, new() where TContent : class {
public TPainter Painter { get; } = new TPainter();

Expand Down

0 comments on commit 824d0df

Please sign in to comment.