Example #1
0
        public async Task Test()
        {
            var keyboard = new MathKeyboard <TestFont, char>(TestTypesettingContexts.Instance, new TestFont())
            {
                CaretState = MathKeyboardCaretState.Shown
            };

            Assert.Equal(MathKeyboardCaretState.Shown, keyboard.CaretState);

            keyboard.KeyPress(MathKeyboardInput.Subscript);
            var outer = Assert.IsType <Atom.Atoms.Placeholder>(Assert.Single(keyboard.MathList));
            var inner = Assert.IsType <Atom.Atoms.Placeholder>(Assert.Single(outer.Subscript));

            Assert.Equal(MathKeyboardCaretState.ShownThroughPlaceholder, keyboard.CaretState);
            Assert.Equal("\u25A1", outer.Nucleus);
            Assert.Equal("\u25A0", inner.Nucleus);

            await Task.Delay((int)MathKeyboard <TestFont, char> .DefaultBlinkMilliseconds + CaretBlinks.MillisecondBuffer);

            Assert.Equal(MathKeyboardCaretState.TemporarilyHidden, keyboard.CaretState);
            keyboard.KeyPress(MathKeyboardInput.Left);
            Assert.Equal(MathKeyboardCaretState.ShownThroughPlaceholder, keyboard.CaretState);
            Assert.Equal("\u25A0", outer.Nucleus);
            Assert.Equal("\u25A1", inner.Nucleus);

            Assert.Equal(MathKeyboardCaretState.ShownThroughPlaceholder, keyboard.CaretState);
            keyboard.KeyPress(MathKeyboardInput.Right);
            Assert.Equal("\u25A1", outer.Nucleus);
            Assert.Equal("\u25A0", inner.Nucleus);
        }
Example #2
0
        public async Task Test()
        {
            var keyboard = new MathKeyboard <TestFont, TGlyph>(TestTypesettingContexts.Instance, new TestFont())
            {
                InsertionPositionHighlighted = true
            };

            Assert.True(keyboard.ShouldDrawCaret);

            keyboard.StopBlinking();
            await Task.Delay((int)MathKeyboard <TestFont, TGlyph> .DefaultBlinkMilliseconds + CaretBlinks.MillisecondBuffer);

            Assert.True(keyboard.ShouldDrawCaret);

            keyboard.StartBlinking();
            await Task.Delay((int)MathKeyboard <TestFont, TGlyph> .DefaultBlinkMilliseconds + CaretBlinks.MillisecondBuffer);

            Assert.False(keyboard.ShouldDrawCaret);

            keyboard.StopBlinking();
            await Task.Delay((int)MathKeyboard <TestFont, TGlyph> .DefaultBlinkMilliseconds + CaretBlinks.MillisecondBuffer);

            Assert.False(keyboard.ShouldDrawCaret);

            keyboard.StartBlinking();
            await Task.Delay((int)MathKeyboard <TestFont, TGlyph> .DefaultBlinkMilliseconds + CaretBlinks.MillisecondBuffer);

            Assert.True(keyboard.ShouldDrawCaret);
        }
Example #3
0
        public async Task Test()
        {
            var keyboard = new MathKeyboard <TestFont, char>(TestTypesettingContexts.Instance, new TestFont())
            {
                CaretState = MathKeyboardCaretState.Shown
            };

            Assert.Equal(MathKeyboardCaretState.Shown, keyboard.CaretState);

            keyboard.StopBlinking();
            await Task.Delay((int)MathKeyboard <TestFont, char> .DefaultBlinkMilliseconds + CaretBlinks.MillisecondBuffer);

            Assert.Equal(MathKeyboardCaretState.Shown, keyboard.CaretState);

            keyboard.StartBlinking();
            await Task.Delay((int)MathKeyboard <TestFont, char> .DefaultBlinkMilliseconds + CaretBlinks.MillisecondBuffer);

            Assert.Equal(MathKeyboardCaretState.TemporarilyHidden, keyboard.CaretState);

            keyboard.StopBlinking();
            await Task.Delay((int)MathKeyboard <TestFont, char> .DefaultBlinkMilliseconds + CaretBlinks.MillisecondBuffer);

            Assert.Equal(MathKeyboardCaretState.TemporarilyHidden, keyboard.CaretState);

            keyboard.StartBlinking();
            await Task.Delay((int)MathKeyboard <TestFont, char> .DefaultBlinkMilliseconds + CaretBlinks.MillisecondBuffer);

            Assert.Equal(MathKeyboardCaretState.Shown, keyboard.CaretState);
        }
Example #4
0
        static void Test(string latex, K[] inputs)
        {
            var keyboard = new MathKeyboard <TestFont, char>(context, new TestFont());

            keyboard.KeyPress(inputs);
            Assert.Equal(latex, keyboard.LaTeX);
        }
Example #5
0
 public NonBlinkingPlaceholder()
 {
     LaTeXSettings.PlaceholderBlinks = false;
     keyboard = new MathKeyboard <TestFont, TGlyph>(TestTypesettingContexts.Instance, new TestFont())
     {
         InsertionPositionHighlighted = true
     };
 }
Example #6
0
        public void MathInputButton_KeyboardProperty()
        {
            var mathKeyboardClassThatProcessesKeyPresses = new MathKeyboard();
            var mathInputButton = new MathInputButton();

            mathInputButton.SetValue(MathInputButton.KeyboardProperty, mathKeyboardClassThatProcessesKeyPresses);
            Assert.Equal(mathKeyboardClassThatProcessesKeyPresses, mathInputButton.Keyboard);
        }
Example #7
0
 public CustomizablePlaceholder()
 {
     LaTeXSettings.PlaceholderActiveNucleus  = "😀";
     LaTeXSettings.PlaceholderRestingNucleus = "😐";
     LaTeXSettings.PlaceholderActiveColor    = System.Drawing.Color.Green;
     LaTeXSettings.PlaceholderRestingColor   = System.Drawing.Color.Blue;
     LaTeXSettings.PlaceholderBlinks         = true;
     keyboard = new MathKeyboard <TestFont, TGlyph>(TestTypesettingContexts.Instance, new TestFont());
 }
Example #8
0
        static void TestEvent(EventInteractor attach, EventInteractor detach, K[] inputs)
        {
            var keyboard = new MathKeyboard <TestFont, char>(context, new TestFont());

            Assert.Raises <EventArgs>(
                h => attach(keyboard, new EventHandler(h)),
                h => detach(keyboard, new EventHandler(h)),
                () => keyboard.KeyPress(inputs));
        }
Example #9
0
        public void Test()
        {
            var keyboard = new MathKeyboard <TestFont, TGlyph>(TestTypesettingContexts.Instance, new TestFont())
            {
                InsertionPositionHighlighted = false
            };

            keyboard.StopBlinking();
            Assert.False(keyboard.InsertionPositionHighlighted);
            keyboard.KeyPress(MathKeyboardInput.Power);
            Assert.True(keyboard.InsertionPositionHighlighted);
        }
Example #10
0
        public async Task Test()
        {
            var keyboard = new MathKeyboard <TestFont, char>(TestTypesettingContexts.Instance, new TestFont())
            {
                CaretState = MathKeyboardCaretState.Hidden
            };

            Assert.Equal(MathKeyboardCaretState.Hidden, keyboard.CaretState);
            keyboard.KeyPress(MathKeyboardInput.Power);
            Assert.Equal(MathKeyboardCaretState.ShownThroughPlaceholder, keyboard.CaretState);
            await Task.Delay((int)MathKeyboard <TestFont, char> .DefaultBlinkMilliseconds + CaretBlinks.MillisecondBuffer);

            Assert.Equal(MathKeyboardCaretState.TemporarilyHidden, keyboard.CaretState);
        }
Example #11
0
        public void MathInputButton_Command(MathKeyboardInput mathKeyboardInput)
        {
            var mathKeyboardClassThatProcessesKeyPresses = new MathKeyboard();
            var mathInputButton = new MathInputButton {
                Input = mathKeyboardInput, Keyboard = mathKeyboardClassThatProcessesKeyPresses
            };

            mathInputButton.Command.Execute(null); // Simulate a MathInputButton key press
            Assert.Equal(expectedResult(), mathKeyboardClassThatProcessesKeyPresses.LaTeX);
            string expectedResult()
            {
                var kb = new MathKeyboard();

                kb.KeyPress(mathKeyboardInput);
                return(kb.LaTeX);
            }
        }
Example #12
0
        public MainPage()
        {
            // Basic functionality
            var view = new SKCanvasView {
                HeightRequest = 225
            };
            var keyboard  = new MathKeyboard();
            var viewModel =
                (Rendering.MathKeyboard) typeof(MathKeyboard)
                .GetField("Keyboard", BindingFlags.NonPublic | BindingFlags.Instance)
                .GetValue(keyboard);

            view.EnableTouchEvents = true;
            view.Touch            +=
                (sender, e) => {
                if (e.ActionType == SKTouchAction.Pressed)
                {
                    viewModel.MoveCaretToPoint
                        (new System.Drawing.PointF(e.Location.X, e.Location.Y));
                }
            };
            keyboard.RedrawRequested += (_, __) => view.InvalidateSurface();
            view.PaintSurface        +=
                (sender, e) => {
                var c = e.Surface.Canvas;
                c.Clear();
                MathPainter.DrawDisplay(new MathPainter {
                    TextColor = SKColors.Black
                },
                                        keyboard.Display, c);
                keyboard.DrawCaret(c, CaretShape.IBeam);
            };

            // Input from physical keyboard
            var entry = new Entry {
                Placeholder = "Enter keystrokes..."
            };

            entry.TextChanged += (sender, e) => {
                entry.Text = "";
                foreach (var c in e.NewTextValue)
                {
                    viewModel.KeyPress((Editor.MathKeyboardInput)c);
                }
            };

            // Debug labels
            var latex = new Label {
                Text = "LaTeX = "
            };
            var ranges = new Label {
                Text = "Ranges = "
            };
            var index = new Label {
                Text = "Index = "
            };

            viewModel.RedrawRequested += (sender, e) => {
                latex.Text  = "LaTeX = " + viewModel.LaTeX;
                ranges.Text = "Ranges = " + string.Join(", ",
                                                        ((ListDisplay <Fonts, Glyph>)viewModel.Display).Displays.Select(x => x.Range));
                index.Text = "Index = " + viewModel.InsertionIndex;
            };

            // Assemble
            Content = new StackLayout
            {
                Children = { latex, ranges, index, view, keyboard, entry }
            };
        }