Skip to content

Add TextColor property to BaseButton and make MathInputButton's color customizable #164

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

Merged
merged 45 commits into from
Jun 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
cd3c5c7
Add TextColor property to BaseButton and make MathInputButton's color…
SymboLinker Sep 15, 2020
083350f
Add a few ButtonTests and refactor out use-once functions from BaseBu…
SymboLinker Sep 16, 2020
04abe53
Fix typo in unit test name MathInputButtonsHaveBlackTextColorByDefault
SymboLinker Sep 16, 2020
aa41a64
ButtonTests: use [ClassData] attribute, use NotNull<T>() extension, i…
SymboLinker Sep 16, 2020
4a56307
Update CSharpMath.CrossPlatform.slnf (suggested commit))
SymboLinker Sep 18, 2020
0271ae8
ButtonTests: use the [MemberData] attribute and MathKeyboardInput enu…
SymboLinker Sep 18, 2020
6aa2ddd
Rename and move file from TestHelpers/NotNull.cs to /Extensions.cs
SymboLinker Sep 18, 2020
f00fa3a
Add ButtonBase.TextColorProperty Xaml Tests to CSharpMath.Forms.Tests
SymboLinker Sep 18, 2020
99417ce
Add MathInputButton_Command unit test and do the suggested cleaning
SymboLinker Sep 19, 2020
fe0f460
MathInputButton_Command test: use the MathInputButton's Keyboard getter
SymboLinker Sep 19, 2020
132e19f
MathInputButton_Command test: no variable is needed anymore for the M…
SymboLinker Sep 19, 2020
d3f7b93
Revert "MathInputButton_Command test: no variable is needed anymore f…
SymboLinker Sep 19, 2020
bca8b4d
Revert "MathInputButton_Command test: use the MathInputButton's Keybo…
SymboLinker Sep 19, 2020
4223835
Add MathButton unit tests that check that the image color is correctl…
SymboLinker Sep 19, 2020
8c486dd
Attempt/test 1: also reference SkiaSharp from the CSharpMath.Forms.cs…
SymboLinker Sep 20, 2020
350fc9b
Attempt/test 2: also reference SkiaSharp from CSharpMath.Forms.Test.c…
SymboLinker Sep 20, 2020
b43a974
Attempt/test 3: Reference SkiaSharp & SkiaSharp.Views.Forms from test…
SymboLinker Sep 20, 2020
6ccb10b
Revert "Attempt/test 3: Reference SkiaSharp & SkiaSharp.Views.Forms f…
SymboLinker Sep 20, 2020
fc639d4
Revert "Attempt/test 2: also reference SkiaSharp from CSharpMath.Form…
SymboLinker Sep 20, 2020
e009029
Revert "Attempt/test 1: also reference SkiaSharp from the CSharpMath.…
SymboLinker Sep 20, 2020
31cc12a
Update SkiaSharp and SkiaSharp.View.Forms to 2.80.2 in all referencin…
SymboLinker Sep 20, 2020
593d677
Add libSkiaSharp.dll to test project CSharpMath.Forms.Tests
SymboLinker Sep 20, 2020
ae84658
Revert "Add libSkiaSharp.dll to test project CSharpMath.Forms.Tests"
SymboLinker Sep 20, 2020
e2dc966
Revert "Update SkiaSharp and SkiaSharp.View.Forms to 2.80.2 in all re…
SymboLinker Sep 20, 2020
1a05de8
Customize buttons for MathKeyboardInput even more
SymboLinker Sep 23, 2020
1991402
Make blinking Placeholder's Nucleus and ForeColor customizable in bot…
SymboLinker Oct 4, 2020
ddb5e4e
MathInputButtons with customized placeholders: what you see is what y…
SymboLinker Oct 3, 2020
a3e6838
Merge pull request #2 from verybadcat/master
SymboLinker Oct 4, 2020
0047a83
Correct comment
SymboLinker Oct 4, 2020
d58072c
MathInputButton: only perform the placeholder color logic if defaults…
SymboLinker Oct 26, 2020
2a9951c
Merge pull request #4 from verybadcat/master
SymboLinker Oct 26, 2020
7ee69ff
Comment out 2 ButtonTests that have Linux failures
SymboLinker Oct 26, 2020
3bb9e34
Use FactAttribute.Skip
SymboLinker Oct 26, 2020
da8b291
Delete NullableColorBindablePropertyHelper (I am afraid I did not try…
SymboLinker Oct 30, 2020
a8c6f8d
Revert "Delete NullableColorBindablePropertyHelper (I am afraid I did…
SymboLinker Oct 30, 2020
b928f4d
Use "foreach" instead of Xamarin.Forms.Internals.ForEach
SymboLinker Oct 30, 2020
afa9f55
First call SetButtonsTextColor and then SetClearButtonImageSource
SymboLinker Oct 30, 2020
e229992
Update CSharpMath.Forms.Example/CSharpMath.Forms.Example/Controls/Mat…
SymboLinker Oct 30, 2020
86c9bbb
Merge pull request #6 from verybadcat/master
SymboLinker Oct 30, 2020
3c76e83
Add unit tests MathButtonTextColorCanChangeMultipleTimes and MathInpu…
SymboLinker Oct 31, 2020
486ac0f
Introduce interface IButtonDraw for bindablePropertyChanged
SymboLinker Nov 1, 2020
ae04c89
Shut CSharpMath.Ios.Tests
Happypig375 Nov 1, 2020
1426a9a
add lock for now
FoggyFinder Jun 15, 2021
edfed19
Create and use method SubStringCount() instead of Regex.Matches().Count
SymboLinker Jun 20, 2021
db93ac9
Customized placeholder colors: add unit test
SymboLinker Jun 21, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CSharpMath.CrossPlatform.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"CSharpMath.Avalonia.Example/CSharpMath.Avalonia.Example.csproj",
"CSharpMath.SkiaSharp/CSharpMath.SkiaSharp.csproj",
"CSharpMath.Forms/CSharpMath.Forms.csproj",
"CSharpMath.Forms.Example/CSharpMath.Forms.Example/CSharpMath.Forms.Example.csproj"
"CSharpMath.Forms.Example/CSharpMath.Forms.Example/CSharpMath.Forms.Example.csproj",
"CSharpMath.Forms.Tests/CSharpMath.Forms.Tests.csproj"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@
<Compile Include="..\..\CSharpMath.Rendering.Tests\TestRenderingSharedData.cs" Link="Examples\TestRenderingSharedData.cs" />
</ItemGroup>

<ItemGroup>
<Content Include="Controls\ImageSourceMathInputButtons\flame.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Controls\ImageSourceMathInputButtons\metaltrashcan.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Controls\ImageSourceMathInputButtons\recyclebin.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Xamarin.Forms" Version="4.3.0.908675" />
<ProjectReference Include="..\..\CSharpMath.Forms\CSharpMath.Forms.csproj" />
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:r="clr-namespace:CSharpMath.Rendering.FrontEnd;assembly=CSharpMath.Rendering"
xmlns:e="clr-namespace:CSharpMath.Forms.Example"
xmlns:f="clr-namespace:CSharpMath.Forms;assembly=CSharpMath.Forms"
x:Class="CSharpMath.Forms.Example.MathKeyboard"
Expand Down Expand Up @@ -113,12 +112,14 @@
<!--Right row of first 3 tabs-->
<Style TargetType="f:MathInputButton" Class="Back">
<Setter Property="Input" Value="Backspace"/>
<Setter Property="TextColor" Value="Red" />
<Setter Property="Grid.Column" Value="5"/>
<Setter Property="Grid.Row" Value="0"/>
<Setter Property="Keyboard" Value="{StaticResource Keyboard}"/>
</Style>
<Style TargetType="f:MathInputButton" Class="Clear">
<Style TargetType="f:ImageSourceMathInputButton" Class="Clear">
<Setter Property="Input" Value="Clear"/>
<Setter Property="Source" Value="Controls/ImageSourceMathInputButtons/recyclebin.png" />
<Setter Property="Grid.Column" Value="5"/>
<Setter Property="Grid.Row" Value="1"/>
<Setter Property="Keyboard" Value="{StaticResource Keyboard}"/>
Expand Down Expand Up @@ -155,7 +156,7 @@
<ColumnDefinition Width="*"/>
</ColumnDefinitionCollection>
</Grid.ColumnDefinitions>
<f:MathInputButton Input="Left" Grid.Column="0" Keyboard="{StaticResource Keyboard}"/>
<f:MathInputButton x:Name="LeftButton" Input="Left" Grid.Column="0" Keyboard="{StaticResource Keyboard}"/>
<f:MathButton x:Name="NumbersButton" Grid.Column="1" Command="{e:SwitchToTab Self={Reference this}, Target=Numbers}">
<f:MathView LaTeX="123"/>
</f:MathButton>
Expand All @@ -181,7 +182,7 @@
<f:MathInputButton Input="Equals" Grid.Row="3" Grid.Column="3" Keyboard="{StaticResource Keyboard}"/>
<f:MathInputButton Input="Plus" Grid.Row="3" Grid.Column="4" Keyboard="{StaticResource Keyboard}"/>
<f:MathInputButton StyleClass="Back"/>
<f:MathInputButton StyleClass="Clear"/>
<f:ImageSourceMathInputButton StyleClass="Clear"/>
<f:MathInputButton StyleClass="Dismiss"/>
<f:MathInputButton StyleClass="Enter"/>
</Grid>
Expand Down Expand Up @@ -210,7 +211,7 @@
<f:MathInputButton Input="Ratio" Grid.Row="3" Grid.Column="3" Keyboard="{StaticResource Keyboard}"/>
<f:MathInputButton Input="Comma" Grid.Row="3" Grid.Column="4" Keyboard="{StaticResource Keyboard}"/>
<f:MathInputButton StyleClass="Back"/>
<f:MathInputButton StyleClass="Clear"/>
<f:ImageSourceMathInputButton StyleClass="Clear"/>
<f:MathInputButton StyleClass="Dismiss"/>
<f:MathInputButton StyleClass="Enter"/>
</Grid>
Expand Down Expand Up @@ -239,7 +240,7 @@
<f:MathInputButton Input="NthRoot" Grid.Row="3" Grid.Column="3" Keyboard="{StaticResource Keyboard}"/>
<f:MathInputButton Input="Degree" Grid.Row="3" Grid.Column="4" Keyboard="{StaticResource Keyboard}"/>
<f:MathInputButton StyleClass="Back"/>
<f:MathInputButton StyleClass="Clear"/>
<f:ImageSourceMathInputButton StyleClass="Clear"/>
<f:MathInputButton StyleClass="Dismiss"/>
<f:MathInputButton StyleClass="Enter"/>
</Grid>
Expand Down Expand Up @@ -268,7 +269,7 @@
<f:MathInputButton Input="Up" Grid.Row="3" Grid.Column="3" Keyboard="{StaticResource Keyboard}"/>
<f:MathInputButton Input="Up" Grid.Row="3" Grid.Column="4" Keyboard="{StaticResource Keyboard}"/>
<f:MathInputButton StyleClass="Back"/>
<f:MathInputButton StyleClass="Clear"/>
<f:ImageSourceMathInputButton StyleClass="Clear"/>
<f:MathInputButton StyleClass="Dismiss"/>
<f:MathInputButton StyleClass="Enter"/>
</Grid>
Expand Down Expand Up @@ -349,10 +350,10 @@
<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:ImageSourceMathInputButton 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"/>
</Grid>
<f:MathInputButton Input="Right" Grid.Column="6" Keyboard="{StaticResource Keyboard}"/>
<f:MathInputButton x:Name="RightButton" Input="Right" Grid.Column="6" Keyboard="{StaticResource Keyboard}"/>
</Grid>
</ContentView>
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using System;
using System.Linq;
using CSharpMath.Editor;
using Xamarin.Forms;
using Xamarin.Forms.Internals;
using Xamarin.Forms.Xaml;

namespace CSharpMath.Forms.Example {
Expand All @@ -20,12 +23,8 @@ public MathKeyboard(float fontSize = Rendering.FrontEnd.PainterConstants.Default
public Tab CurrentTab {
get => _tab;
set {
foreach (var grid in new[] {
Numbers, Symbols, Functions, Operations, Letters, LettersCapitals
}) grid.IsVisible = false;
foreach (var gridButton in new[] {
NumbersButton, SymbolsButton, FunctionsButton, OperationsButton, LettersButton
}) gridButton.BackgroundColor = Color.Transparent;
foreach (var buttonGrid in ButtonGrids) buttonGrid.IsVisible = false;
foreach (var tabButton in TabButtons) tabButton.BackgroundColor = Color.Transparent;
var (selectedGrid, selectedGridButton) =
value switch {
Tab.Numbers => (Numbers, NumbersButton),
Expand All @@ -43,6 +42,27 @@ public Tab CurrentTab {
_tab = value;
}
}
public void SetButtonsTextColor(Color color, Color? placeholderRestingColor = null, Color? placeholderActiveColor = null) {
foreach (var button in new MathButton[] { ShiftButton, ShiftCapitalsButton }.Concat(TabButtons))
button.TextColor = color;
foreach (var button in new[] { LeftButton, RightButton}
.Concat(ButtonGrids.SelectMany(grid => grid.Children)
.Where(child => child is MathInputButton button && button.Input != MathKeyboardInput.Backspace)
.Cast<MathInputButton>())) {
button.TextColor = color;
button.PlaceholderRestingColor = placeholderRestingColor;
button.PlaceholderActiveColor = placeholderActiveColor;
button.ButtonDraw(/* If the LaTeXSettings change but the button's appearance properties don't, there's no event that causes the execution of this method. */);
};
}
public void SetClearButtonImageSource(ImageSource imageSource) {
foreach(var button in ButtonGrids.SelectMany(grid => grid.Children)
.OfType<ImageSourceMathInputButton>()
.Where(button => button.Input == MathKeyboardInput.Clear))
button.Source = imageSource;
}
MathButton[] TabButtons => new[] { NumbersButton, SymbolsButton, FunctionsButton, OperationsButton, LettersButton };
Grid[] ButtonGrids => new[] { Numbers, Symbols, Functions, Operations, Letters, LettersCapitals };
}
[AcceptEmptyServiceProvider]
public class SwitchToTabExtension : IMarkupExtension<Command> {
Expand All @@ -54,4 +74,4 @@ public Command ProvideValue(IServiceProvider _) =>
new Command(() => Self.CurrentTab = Target);
object IMarkupExtension.ProvideValue(IServiceProvider _) => ProvideValue(_);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using CSharpMath.SkiaSharp;
using SkiaSharp;
using SkiaSharp.Views.Forms;
using Xamarin.Forms;
Expand All @@ -13,14 +16,13 @@ public EditorPage() {
}
}
public class EditorView : ContentView {
public MathPainter OutputMathPainter = new MathPainter { TextColor = SKColors.Black };
MathKeyboard keyboard = new MathKeyboard(Rendering.FrontEnd.PainterConstants.LargerFontSize);
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));
viewModel.BindDisplay(view, OutputMathPainter, new SKColor(0, 0, 0, 153));

// Input from physical keyboard
var entry = new Entry {
Expand Down Expand Up @@ -84,6 +86,7 @@ static View GridItem(int row, int col, View view) {
new StackLayout {
Orientation = StackOrientation.Horizontal,
Children = {
new Button { Text = "Change appearance", Command = new Command(ChangeAppearance) },
entry,
new Button {
Text = "Reset answer pan",
Expand All @@ -96,5 +99,44 @@ static View GridItem(int row, int col, View view) {
}
};
}
int CurrentThemeIndex = 0;
public void ChangeAppearance() {
CurrentThemeIndex = (CurrentThemeIndex + 1) % Themes.Count;
Themes[CurrentThemeIndex].Invoke();
keyboard.Keyboard.InsertionIndex = keyboard.Keyboard.InsertionIndex; // Hack to redraw placeholders in the output.
}
IList<Action> Themes => new Action[] {
() => { // This theme is the default. For a round-trip through the themes we need to set them again:
OutputMathPainter.TextColor = SKColors.Black;
Atom.LaTeXSettings.PlaceholderBlinks = false;
Atom.LaTeXSettings.PlaceholderActiveColor = null;
Atom.LaTeXSettings.PlaceholderRestingColor = null;
Atom.LaTeXSettings.PlaceholderActiveNucleus = "■";
Atom.LaTeXSettings.PlaceholderRestingNucleus = "□";
keyboard.SetButtonsTextColor(Color.Black);
keyboard.SetClearButtonImageSource("Controls/ImageSourceMathInputButtons/recyclebin.png");
},
() => {
UseMyCustomizedPlaceholderAppearance();
keyboard.SetButtonsTextColor(Color.Black); // Placeholder appearance on the keys is the same as in the output by default.
keyboard.SetClearButtonImageSource("Controls/ImageSourceMathInputButtons/metaltrashcan.png");
},
() => {
Atom.LaTeXSettings.PlaceholderBlinks = true;
OutputMathPainter.TextColor = SKColors.DarkGreen;
UseMyCustomizedPlaceholderAppearance();
// If you'd like to use different keyboard colors than output colors and you specified a placeholder color,
// probably you'll not want to use the same placeholder color on the keyboard:
keyboard.SetButtonsTextColor(Color.Brown, CalculateMyPlaceholderRestingColorFromSurroundingTextColor(Color.Brown));
keyboard.SetClearButtonImageSource("Controls/ImageSourceMathInputButtons/flame.png");
}
};

public void UseMyCustomizedPlaceholderAppearance() {
// You could also customize the "Active" placeholder nucleus and color, but for this example we don't.
Atom.LaTeXSettings.PlaceholderRestingNucleus = "■";
Atom.LaTeXSettings.PlaceholderRestingColor = CalculateMyPlaceholderRestingColorFromSurroundingTextColor(OutputMathPainter.TextColor.ToFormsColor());
}
public static Color CalculateMyPlaceholderRestingColorFromSurroundingTextColor(Color textColor) => textColor.WithLuminosity(textColor.Luminosity > 0.5 ? 0.2 : 0.8);
}
}
Loading