Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion BuildVersion.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<!-- The release version: bump this, and merging to main tags and publishes vX.Y.Z.
CI passes a pre-release VersionSuffix for pull request builds (pr.12.34 -> 1.0.0-pr.12.34). -->
<VersionPrefix>1.1.2</VersionPrefix>
<VersionPrefix>1.2.0</VersionPrefix>
</PropertyGroup>

<PropertyGroup>
Expand Down
14 changes: 7 additions & 7 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
<HarfBuzzSharpVersion>14.4.0.100</HarfBuzzSharpVersion>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Avalonia" Version="12.1.4" />
<PackageVersion Include="Avalonia.Browser" Version="12.1.4" />
<PackageVersion Include="Avalonia.Desktop" Version="12.1.4" />
<PackageVersion Include="Avalonia.Fonts.Inter" Version="12.1.4" />
<PackageVersion Include="Avalonia.Headless" Version="12.1.4" />
<PackageVersion Include="Avalonia.Skia" Version="12.1.4" />
<PackageVersion Include="Avalonia.Themes.Fluent" Version="12.1.4" />
<PackageVersion Include="Avalonia" Version="12.2.0" />
<PackageVersion Include="Avalonia.Browser" Version="12.2.0" />
<PackageVersion Include="Avalonia.Desktop" Version="12.2.0" />
<PackageVersion Include="Avalonia.Fonts.Inter" Version="12.2.0" />
<PackageVersion Include="Avalonia.Headless" Version="12.2.0" />
<PackageVersion Include="Avalonia.Skia" Version="12.2.0" />
<PackageVersion Include="Avalonia.Themes.Fluent" Version="12.2.0" />
<PackageVersion Include="Silk.NET.OpenGL" Version="2.23.0" />
<!-- SkiaSharp 4 and its HarfBuzzSharp everywhere (pinned for the packages that bring an older one: Avalonia 12 brings
SkiaSharp 3), for the fixes of their native libraries -->
Expand Down
2 changes: 1 addition & 1 deletion docs/EDITOR.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ has the tools of the equations of Word: the structures and symbols to insert, th
the number of the equation, undo, copy in every format, examples, and the equation as MathML, UnicodeMath, LaTeX and
OMML as it is typed; a test opens it. Editing and Rendering have no dependency on a
user interface (they target netstandard2.0 and net10.0, with no package, as the core), so that they are tested without
a toolkit and could serve another one; only `SharpEquations.Avalonia` depends on Avalonia (12.1). Each is a project of
a toolkit and could serve another one; only `SharpEquations.Avalonia` depends on Avalonia (12.2). Each is a project of
its own in this repository; `samples/SharpEquations.Avalonia.Demo` is a window with the editor and the equation in every
format, and `tests/SharpEquations.Avalonia.Tests` tests the three.

Expand Down
2 changes: 1 addition & 1 deletion samples/SharpEquations.Avalonia.Demo/DemoView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ public DemoView()
Padding = new Thickness(22, 18),
BorderThickness = 0,
};
editor.Bind(MathEditBox.BackgroundProperty, editor.GetResourceObservable("EditorBrush"));
preview = new MathView { FontSize = 22, HorizontalAlignment = HorizontalAlignment.Center };
outputs = new (string, Func<Equation, string>, TextBox)[]
{
Expand Down Expand Up @@ -286,6 +285,7 @@ private Border EditorCard()
Child = editor,
};
editorFrame.Bind(Border.BorderBrushProperty, editorFrame.GetResourceObservable("EditorBorderBrush"));
editorFrame.Bind(Border.BackgroundProperty, editorFrame.GetResourceObservable("EditorBrush"));

var hint = new TextBlock
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,11 @@
<Setter Property="BorderThickness" Value="1.5" />
<Setter Property="ClipToBounds" Value="True" />
<Setter Property="BorderBrush" Value="{DynamicResource EditorBorderBrush}" />
<!-- the background of the editor is the frame's: drawn by the editor, its corners would cover the rounded border -->
<Setter Property="Background" Value="{DynamicResource EditorBrush}" />
</Style>
<Style Selector="math|MathEditBox.entry">
<Setter Property="BorderThickness" Value="0" />
<Setter Property="Background" Value="{DynamicResource EditorBrush}" />
</Style>
<!-- what is computed, on a background of its own -->
<Style Selector="Border.code">
Expand Down
11 changes: 2 additions & 9 deletions src/SharpEquations.Avalonia/MathEditBox.ContextMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ public sealed class MathContextMenuEventArgs : EventArgs
/// <summary>The context menu of the editor: right click, long press on touch, the Menu key or Shift+F10.</summary>
public partial class MathEditBox
{
/// <summary>Whether the editor opens its context menu.</summary>
public static readonly StyledProperty<bool> IsContextMenuEnabledProperty =
AvaloniaProperty.Register<MathEditBox, bool>(nameof(IsContextMenuEnabled), true);

private ContextMenu? openMenu;

/// <summary>
Expand All @@ -42,11 +38,8 @@ public partial class MathEditBox
public event EventHandler<MathContextMenuEventArgs>? ContextMenuOpening;

/// <summary>Whether the editor opens its context menu.</summary>
public bool IsContextMenuEnabled
{
get => GetValue(IsContextMenuEnabledProperty);
set => SetValue(IsContextMenuEnabledProperty, value);
}
[GeneratedStyledProperty(DefaultValue = true)]
public partial bool IsContextMenuEnabled { get; set; }

/// <summary>The context menu while it is open, or null.</summary>
public ContextMenu? OpenContextMenu => openMenu is { IsOpen: true } ? openMenu : null;
Expand Down
161 changes: 32 additions & 129 deletions src/SharpEquations.Avalonia/MathEditBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,46 +29,10 @@ namespace SharpEquations.Avalonia
[System.Diagnostics.CodeAnalysis.SuppressMessage("Reliability", "CA1001", Justification = "The drawing is released when the equation is laid out again and when the control leaves the visual tree.")]
public partial class MathEditBox : Control
{
/// <summary>The equation edited; null when the editor is empty. Two-way by default.</summary>
public static readonly StyledProperty<Equation?> EquationProperty =
AvaloniaProperty.Register<MathEditBox, Equation?>(nameof(Equation), defaultBindingMode: BindingMode.TwoWay);

/// <summary>The format of what is typed: UnicodeMath (the default) or LaTeX.</summary>
public static readonly StyledProperty<EquationFormat> InputFormatProperty =
AvaloniaProperty.Register<MathEditBox, EquationFormat>(nameof(InputFormat), EquationFormat.UnicodeMath, validate: f => f is EquationFormat.UnicodeMath or EquationFormat.LaTeX);

/// <summary>Whether the equation is shown built up or as linear text.</summary>
public static readonly StyledProperty<MathViewMode> ViewModeProperty =
AvaloniaProperty.Register<MathEditBox, MathViewMode>(nameof(ViewMode));

/// <summary>Whether the equation is a display equation rather than inline.</summary>
public static readonly StyledProperty<bool> IsDisplayProperty =
AvaloniaProperty.Register<MathEditBox, bool>(nameof(IsDisplay), true);

/// <summary>Whether the user cannot change the equation.</summary>
public static readonly StyledProperty<bool> IsReadOnlyProperty =
AvaloniaProperty.Register<MathEditBox, bool>(nameof(IsReadOnly));

/// <summary>The size of the font.</summary>
public static readonly StyledProperty<double> FontSizeProperty =
TextElement.FontSizeProperty.AddOwner<MathEditBox>();

/// <summary>The brush of the equation.</summary>
public static readonly StyledProperty<IBrush?> ForegroundProperty =
TextElement.ForegroundProperty.AddOwner<MathEditBox>();

/// <summary>The brush of the background.</summary>
public static readonly StyledProperty<IBrush?> BackgroundProperty =
AvaloniaProperty.Register<MathEditBox, IBrush?>(nameof(Background), Brushes.Transparent);

/// <summary>The brush of the border.</summary>
public static readonly StyledProperty<IBrush?> BorderBrushProperty =
AvaloniaProperty.Register<MathEditBox, IBrush?>(nameof(BorderBrush));

/// <summary>The thickness of the border.</summary>
public static readonly StyledProperty<double> BorderThicknessProperty =
AvaloniaProperty.Register<MathEditBox, double>(nameof(BorderThickness), 1);

/// <summary>The space between the border and the equation.</summary>
public static readonly StyledProperty<Thickness> PaddingProperty =
AvaloniaProperty.Register<MathEditBox, Thickness>(nameof(Padding), new Thickness(6, 4));
Expand All @@ -77,33 +41,10 @@ public partial class MathEditBox : Control
public static readonly StyledProperty<IBrush?> SelectionBrushProperty =
AvaloniaProperty.Register<MathEditBox, IBrush?>(nameof(SelectionBrush), new ImmutableSolidColorBrush(Color.FromArgb(0x60, 0x33, 0x99, 0xFF)));

/// <summary>The brush of the caret; null for the foreground.</summary>
public static readonly StyledProperty<IBrush?> CaretBrushProperty =
AvaloniaProperty.Register<MathEditBox, IBrush?>(nameof(CaretBrush));

/// <summary>The brush of the boxes of the empty slots.</summary>
public static readonly StyledProperty<IBrush?> PlaceholderBrushProperty =
AvaloniaProperty.Register<MathEditBox, IBrush?>(nameof(PlaceholderBrush), Brushes.Gray);

/// <summary>The math font, a family with an OpenType MATH table; null for <see cref="MathFonts.Default"/>.</summary>
public static readonly StyledProperty<FontFamily?> MathFontFamilyProperty =
AvaloniaProperty.Register<MathEditBox, FontFamily?>(nameof(MathFontFamily));

/// <summary>
/// The format of the text that <see cref="CopyAsync"/> puts on the clipboard; null (the default) for the input
/// format. MathML pastes as an equation into Word.
/// </summary>
public static readonly StyledProperty<EquationFormat?> CopyTextFormatProperty =
AvaloniaProperty.Register<MathEditBox, EquationFormat?>(nameof(CopyTextFormat), validate: f => f != EquationFormat.Mtef);

/// <summary>Whether the floating bar shows completions, structures, table commands and symbols at the caret.</summary>
public static readonly StyledProperty<bool> IsQuickBarEnabledProperty =
AvaloniaProperty.Register<MathEditBox, bool>(nameof(IsQuickBarEnabled), true);

/// <summary>Whether the math autocorrect (<see cref="AutoCorrect"/>) replaces sequences by their symbols as they are typed.</summary>
public static readonly StyledProperty<bool> IsAutoCorrectEnabledProperty =
AvaloniaProperty.Register<MathEditBox, bool>(nameof(IsAutoCorrectEnabled), true);

/// <summary>The gesture that switches between the built up and the linear view.</summary>
public static readonly StyledProperty<KeyGesture?> ToggleViewModeGestureProperty =
AvaloniaProperty.Register<MathEditBox, KeyGesture?>(nameof(ToggleViewModeGesture), new KeyGesture(Key.L, KeyModifiers.Control | KeyModifiers.Shift));
Expand All @@ -124,6 +65,10 @@ static MathEditBox()
AffectsRender<MathEditBox>(ForegroundProperty, BackgroundProperty, BorderBrushProperty, SelectionBrushProperty, CaretBrushProperty, PlaceholderBrushProperty);
}

private static bool IsValidInputFormat(EquationFormat f) => f is EquationFormat.UnicodeMath or EquationFormat.LaTeX;

private static bool IsValidCopyTextFormat(EquationFormat? f) => f != EquationFormat.Mtef;

/// <summary>An empty editor.</summary>
public MathEditBox()
{
Expand Down Expand Up @@ -181,53 +126,32 @@ public MathEditBox()
public MathEditorView View { get; }

/// <summary>The equation edited, with what is not built up yet built up where it parses; null when empty.</summary>
public Equation? Equation
{
get => GetValue(EquationProperty);
set => SetValue(EquationProperty, value);
}
[GeneratedStyledProperty(DefaultBindingMode = BindingMode.TwoWay)]
public partial Equation? Equation { get; set; }

/// <summary>The format of what is typed.</summary>
public EquationFormat InputFormat
{
get => GetValue(InputFormatProperty);
set => SetValue(InputFormatProperty, value);
}
[GeneratedStyledProperty(DefaultValue = EquationFormat.UnicodeMath, ValidateMethodName = nameof(IsValidInputFormat))]
public partial EquationFormat InputFormat { get; set; }

/// <summary>Whether the equation is shown built up or as linear text.</summary>
public MathViewMode ViewMode
{
get => GetValue(ViewModeProperty);
set => SetValue(ViewModeProperty, value);
}
[GeneratedStyledProperty]
public partial MathViewMode ViewMode { get; set; }

/// <summary>Whether the equation is a display equation rather than inline.</summary>
public bool IsDisplay
{
get => GetValue(IsDisplayProperty);
set => SetValue(IsDisplayProperty, value);
}
[GeneratedStyledProperty(DefaultValue = true)]
public partial bool IsDisplay { get; set; }

/// <summary>Whether the user cannot change the equation.</summary>
public bool IsReadOnly
{
get => GetValue(IsReadOnlyProperty);
set => SetValue(IsReadOnlyProperty, value);
}
[GeneratedStyledProperty]
public partial bool IsReadOnly { get; set; }

/// <summary>The size of the font.</summary>
public double FontSize
{
get => GetValue(FontSizeProperty);
set => SetValue(FontSizeProperty, value);
}
[GeneratedStyledProperty(AddOwnerFrom = typeof(TextElement))]
public partial double FontSize { get; set; }

/// <summary>The brush of the equation.</summary>
public IBrush? Foreground
{
get => GetValue(ForegroundProperty);
set => SetValue(ForegroundProperty, value);
}
[GeneratedStyledProperty(AddOwnerFrom = typeof(TextElement))]
public partial IBrush? Foreground { get; set; }

/// <summary>The brush of the background.</summary>
public IBrush? Background
Expand All @@ -237,18 +161,12 @@ public IBrush? Background
}

/// <summary>The brush of the border.</summary>
public IBrush? BorderBrush
{
get => GetValue(BorderBrushProperty);
set => SetValue(BorderBrushProperty, value);
}
[GeneratedStyledProperty]
public partial IBrush? BorderBrush { get; set; }

/// <summary>The thickness of the border.</summary>
public double BorderThickness
{
get => GetValue(BorderThicknessProperty);
set => SetValue(BorderThicknessProperty, value);
}
[GeneratedStyledProperty(DefaultValue = 1)]
public partial double BorderThickness { get; set; }

/// <summary>The space between the border and the equation.</summary>
public Thickness Padding
Expand All @@ -265,11 +183,8 @@ public IBrush? SelectionBrush
}

/// <summary>The brush of the caret; null for the foreground.</summary>
public IBrush? CaretBrush
{
get => GetValue(CaretBrushProperty);
set => SetValue(CaretBrushProperty, value);
}
[GeneratedStyledProperty]
public partial IBrush? CaretBrush { get; set; }

/// <summary>The brush of the boxes of the empty slots.</summary>
public IBrush? PlaceholderBrush
Expand All @@ -279,11 +194,8 @@ public IBrush? PlaceholderBrush
}

/// <summary>The math font; null for <see cref="MathFonts.Default"/>.</summary>
public FontFamily? MathFontFamily
{
get => GetValue(MathFontFamilyProperty);
set => SetValue(MathFontFamilyProperty, value);
}
[GeneratedStyledProperty]
public partial FontFamily? MathFontFamily { get; set; }

/// <summary>The gesture that switches between the built up and the linear view (Ctrl+Shift+L by default).</summary>
public KeyGesture? ToggleViewModeGesture
Expand All @@ -293,11 +205,8 @@ public KeyGesture? ToggleViewModeGesture
}

/// <summary>Whether the floating bar (<see cref="QuickBar"/>) shows at the caret.</summary>
public bool IsQuickBarEnabled
{
get => GetValue(IsQuickBarEnabledProperty);
set => SetValue(IsQuickBarEnabledProperty, value);
}
[GeneratedStyledProperty(DefaultValue = true)]
public partial bool IsQuickBarEnabled { get; set; }

/// <summary>The floating bar at the caret: completions of commands, structures for the selection, table commands, symbols.</summary>
public MathQuickBar QuickBar { get; }
Expand All @@ -309,11 +218,8 @@ public bool IsQuickBarEnabled
public IList<string> QuickSymbols { get; } = new List<string> { "α", "β", "θ", "π", "∞", "±", "×", "≤", "≥", "≠", "≈", "→", "∈", "∂", "∑", "∫" };

/// <summary>The format of the text copied to the clipboard; null for the input format.</summary>
public EquationFormat? CopyTextFormat
{
get => GetValue(CopyTextFormatProperty);
set => SetValue(CopyTextFormatProperty, value);
}
[GeneratedStyledProperty(ValidateMethodName = nameof(IsValidCopyTextFormat))]
public partial EquationFormat? CopyTextFormat { get; set; }

/// <summary>The layout of the equation, after a measure.</summary>
public MathLayout? Layout => View.Layout;
Expand Down Expand Up @@ -344,11 +250,8 @@ public MathAutoCorrect AutoCorrect
}

/// <summary>Whether the math autocorrect (<see cref="AutoCorrect"/>) replaces sequences as they are typed; true by default.</summary>
public bool IsAutoCorrectEnabled
{
get => GetValue(IsAutoCorrectEnabledProperty);
set => SetValue(IsAutoCorrectEnabledProperty, value);
}
[GeneratedStyledProperty(DefaultValue = true)]
public partial bool IsAutoCorrectEnabled { get; set; }

/// <summary>The number of the equation, shown at the right of its line; null without one (<see cref="MathEditor.EquationNumber"/>).</summary>
public string? EquationNumber
Expand Down
Loading
Loading