/// <summary> /// Create thumb for page number, if it isn't exists /// </summary> /// <param name="pageNumber">Page number</param> /// <returns></returns> private ThumbWithPageNumberView CreateThumbForPageIfNotExists(int pageNumber) { if ((pageNumber <= 0) || (pageNumber > PDFDocument.PageCount)) { return(null); } // Checks thumb existing foreach (var thumbView in _ThumbViews) { if (thumbView.PageNumber == pageNumber) { return(thumbView); } } // Create new thumb RectangleF viewRect = GetThumbFrameByPage(pageNumber); var newThumbView = new ThumbWithPageNumberView(viewRect, pageNumber, ThumbSelected); if (pageNumber == PDFDocument.CurrentPageNumber) { _CurrentThumbView = newThumbView; newThumbView.SetAsSelected(); } // Insert view to first or last position of the list (according direction) _ScrollView.AddSubview(newThumbView); if (_ScrollDirection > 0) { _ThumbViews.Add(newThumbView); } else { _ThumbViews.Insert(0, newThumbView); } #if DEBUG WriteMessageToDebugLog("CreateThumb", string.Format("page={0}, viewRect={1}", pageNumber, viewRect)); #endif // Pack thumbs size to ThumbsBufferSize (only one extra item can be created - remove it) if (_ThumbViews.Count > MgrAccessor.OptionsMgr.Options.ThumbsBufferSize) { // Remove view from first or last position of the list (according direction) if (_ScrollDirection > 0) { _ThumbViews [0].RemoveFromSuperview(); _ThumbViews.RemoveAt(0); } else { _ThumbViews [_ThumbViews.Count - 1].RemoveFromSuperview(); _ThumbViews.RemoveAt(_ThumbViews.Count - 1); } } #if DEBUG WriteMessageToDebugLog("CreateThumb", string.Format("currentBufferSize={0}", _ThumbViews.Count)); #endif return(newThumbView); }
/// <summary> /// Callback called when user clicks by thumb /// </summary> /// <param name="thumbView">Clicked thumb</param> private void ThumbSelected(ThumbWithPageNumberView thumbView) { if (thumbView != _CurrentThumbView) { // Unselect old thumb if (_CurrentThumbView != null) { _CurrentThumbView.SetAsUnselected(); } // Select and store current thumb _CurrentThumbView = thumbView; _CurrentThumbView.SetAsSelected(); // Open selected page _OpenPageCallback(_CurrentThumbView.PageNumber); } }
/// <summary> /// Create thumb for page number, if it isn't exists /// </summary> /// <param name="pageNumber">Page number</param> /// <returns></returns> private ThumbWithPageNumberView CreateThumbForPageIfNotExists(int pageNumber) { if ((pageNumber <= 0) || (pageNumber > PDFDocument.PageCount)) { return null; } // Checks thumb existing foreach (var thumbView in _ThumbViews) { if (thumbView.PageNumber == pageNumber) { return thumbView; } } // Create new thumb RectangleF viewRect = GetThumbFrameByPage(pageNumber); var newThumbView = new ThumbWithPageNumberView(viewRect, pageNumber, ThumbSelected); if (pageNumber == PDFDocument.CurrentPageNumber) { _CurrentThumbView = newThumbView; newThumbView.SetAsSelected(); } // Insert view to first or last position of the list (according direction) _ScrollView.AddSubview(newThumbView); if (_ScrollDirection > 0) { _ThumbViews.Add(newThumbView); } else { _ThumbViews.Insert(0, newThumbView); } #if DEBUG WriteMessageToDebugLog("CreateThumb", string.Format("page={0}, viewRect={1}", pageNumber, viewRect)); #endif // Pack thumbs size to ThumbsBufferSize (only one extra item can be created - remove it) if (_ThumbViews.Count > MgrAccessor.OptionsMgr.Options.ThumbsBufferSize) { // Remove view from first or last position of the list (according direction) if (_ScrollDirection > 0) { _ThumbViews [0].RemoveFromSuperview(); _ThumbViews.RemoveAt(0); } else { _ThumbViews [_ThumbViews.Count - 1].RemoveFromSuperview(); _ThumbViews.RemoveAt(_ThumbViews.Count - 1); } } #if DEBUG WriteMessageToDebugLog("CreateThumb", string.Format("currentBufferSize={0}", _ThumbViews.Count)); #endif return newThumbView; }
private void thumbSelected(ThumbWithPageNumberView thumbView) { thumbView.SetAsSelected(); _openPageCallback(thumbView.PageNumber); DismissViewController(true, null); }
private void createThumbsPage(int thumbsPageNumber) { var thumbsPageInfo = getThumbsPageInfo(); var thumbViews = new List<UIView>(); var pageNumber = ThumbCols * thumbsPageInfo.ThumbRows * thumbsPageNumber + 1; var top = ThumbMargin; for (var r = 0; r < thumbsPageInfo.ThumbRows; r++) { var left = ThumbMargin; for (var c = 0; c < ThumbCols; c++) { var thumbRect = new RectangleF(left, top, thumbsPageInfo.ThumbSize, thumbsPageInfo.ThumbSize); var thumbView = new ThumbWithPageNumberView(thumbRect, pageNumber, thumbSelected); if (pageNumber == PDFDocument.CurrentPageNumber) { thumbView.SetAsSelected(); } thumbViews.Add(thumbView); left += thumbsPageInfo.ThumbSize + ThumbMargin; pageNumber++; if (pageNumber > PDFDocument.PageCount) { break; } } top += thumbsPageInfo.ThumbSize + ThumbMargin; if (pageNumber > PDFDocument.PageCount) { break; } } foreach (var view in _thumbsViewContainer.Subviews) { view.RemoveFromSuperview(); } _thumbsViewContainer.AddSubviews(thumbViews.ToArray()); }