private NavigationItem ParseListItemBlock(ListItemBlock listItemBlock) { DisplayLink rootLink = default; List <NavigationItem> children = new List <NavigationItem>(); foreach (var listItemChild in listItemBlock) { switch (listItemChild) { case ParagraphBlock paragraphBlock: rootLink = ParseParagraph(paragraphBlock); break; case ListBlock listBlock: children.AddRange(ParseListBlock(listBlock)); break; default: throw new InvalidOperationException( $"Document contains invalid navigation document syntax at {listItemBlock.ToPositionText()}. Expected paragraph."); } } if (rootLink.Equals(default(DisplayLink))) { return(default);
// stops automatic scrolling private void InvalidatesScrollTimer() { if (DisplayLink == null) { return; } if (DisplayLink.Paused) { DisplayLink.Invalidate(); } userInfos.Remove(DisplayLink); DisplayLink = null; }
// sets up the scrolling in the correct direction // utilizes CSDisplayLink, a timer synchronized to the display refresh rate, to execute the smooth automated scrolling private void SetupScrollTimerInDirection(ScrollingDirection direction) { if (DisplayLink != null && !DisplayLink.Paused) { var userInfo = userInfos[DisplayLink]; var scrollingDirection = userInfo[ScrollingDirectionKey]; var number = (NSNumber)NSNumber.FromObject(scrollingDirection); ScrollingDirection oldDirection = (ScrollingDirection)number.Int32Value; if (direction == oldDirection) { return; } } InvalidatesScrollTimer(); DisplayLink = CADisplayLink.Create(HandleScroll); userInfos.Add(DisplayLink, NSDictionary.FromObjectAndKey(NSNumber.FromInt32((int)direction), new NSString(ScrollingDirectionKey))); DisplayLink.AddToRunLoop(NSRunLoop.Main, NSRunLoop.NSRunLoopCommonModes); }
public override void EnterMessageLoop(bool runInBackground) { DisplayLink = CADisplayLink.Create(Window, new Selector("Render")); DisplayLink.AddToRunLoop(NSRunLoop.Current, NSRunLoopMode.Default); NSRunLoop.Current.Run(); }
/// <summary> /// Adds a display mapping to this page. /// </summary> internal void AddDisplayLink( DisplayLink displayLink ) { displayLinks.Add( displayLink ); }
public override bool Match(InlineProcessor processor, ref StringSlice slice) { var startPosition = processor.GetSourcePosition(slice.Start, out var startLine, out var startCiColumn); var start = slice.Start; var end = start; // skip opening '[' var current = slice.NextChar(); while (current != ']' && current != '\0') { end = slice.Start; current = slice.NextChar(); } // label should end at ']' if (current != ']') { return(false); } // skip ']' current = slice.NextChar(); // uri part should start with '(' if (current != '(') { return(false); } // skip '(' current = slice.NextChar(); while (current != ')' && current != '\0') { end = slice.Start; current = slice.NextChar(); } // uri part should end with ')' if (current != ')') { return(false); } end = slice.Start; slice.NextChar(); var endPosition = processor.GetSourcePosition(slice.Start - 1); var linkText = new StringSlice(slice.Text, start, end).ToString(); try { var link = DisplayLinkParser.Parse(linkText); if (link.Link.IsXref) { var xref = link.Link.Xref !.Value; link = new DisplayLink( link.Title, new Link(_router.FullyQualify(xref))); } processor.Inline = new DisplayLinkInline { Span = new SourceSpan(startPosition, endPosition), Line = startLine, Column = startCiColumn, IsClosed = true, DisplayLink = link }; } catch (Exception x) { throw new InvalidOperationException( $"Invalid link '{linkText}'", x); } return(true); }