public static TSnapPointsType ToPlatform(this SnapPointsType snapPointsType) { switch (snapPointsType) { case SnapPointsType.Mandatory: return(TSnapPointsType.Mandatory); case SnapPointsType.MandatorySingle: return(TSnapPointsType.MandatorySingle); default: return(TSnapPointsType.None); } }
WSnapPointsType GetWindowsSnapPointsType(SnapPointsType snapPointsType) { switch (snapPointsType) { case SnapPointsType.Mandatory: return(WSnapPointsType.Mandatory); case SnapPointsType.MandatorySingle: return(WSnapPointsType.MandatorySingle); case SnapPointsType.None: return(WSnapPointsType.None); } return(WSnapPointsType.None); }
protected virtual SnapHelper CreateSnapHelper(SnapPointsType snapPointsType, SnapPointsAlignment alignment) { if (snapPointsType == SnapPointsType.Mandatory) { switch (alignment) { case SnapPointsAlignment.Start: return(new StartSnapHelper()); case SnapPointsAlignment.Center: return(new CenterSnapHelper()); case SnapPointsAlignment.End: return(new EndSnapHelper()); default: throw new ArgumentOutOfRangeException(nameof(alignment), alignment, null); } } if (snapPointsType == SnapPointsType.MandatorySingle) { switch (alignment) { case SnapPointsAlignment.Start: return(new StartSingleSnapHelper()); case SnapPointsAlignment.Center: return(new SingleSnapHelper()); case SnapPointsAlignment.End: return(new EndSingleSnapHelper()); default: throw new ArgumentOutOfRangeException(nameof(alignment), alignment, null); } } // Use center snapping as the default return(new CenterSnapHelper()); }
public static T SnapPoints <T>(this T element, SnapPointsAlignment alignment, SnapPointsType type) where T : ItemsLayout { element.SnapPointsAlignment = alignment; element.SnapPointsType = type; return(element); }
private void GetScrollSnapPoints( bool isForHorizontalSnapPoints, SnapPointsType snapPointsType, float zoomFactor, float staticZoomFactor, double targetExtentDimension, double viewportDimension, out bool areSnapPointsOptional, out bool areSnapPointsSingle, out bool areSnapPointsRegular, out float regularOffset, out float regularInterval, out IReadOnlyList <float> resultSnapPoints) { var shouldProcessSnapPoint = false; SnapPointsAlignment alignment = default; float offset = 0; float interval = 0; IReadOnlyList <float> irregularSnapPoints = default; areSnapPointsOptional = default; areSnapPointsSingle = default; regularOffset = default; regularInterval = default; resultSnapPoints = default; if (isForHorizontalSnapPoints) { if (snapPointsType != SnapPointsType.None) { alignment = HorizontalSnapPointsAlignment; areSnapPointsRegular = _snapPointsInfo.AreHorizontalSnapPointsRegular; if (areSnapPointsRegular) { interval = _snapPointsInfo.GetRegularSnapPoints(Orientation.Horizontal, alignment, out offset); irregularSnapPoints = null; } else { if (targetExtentDimension < 0) { // TODO } // TODO: cache this call irregularSnapPoints = _snapPointsInfo.GetIrregularSnapPoints(Orientation.Horizontal, alignment); regularInterval = 0; regularOffset = 0; } shouldProcessSnapPoint = true; } else { areSnapPointsRegular = false; } } else { if (snapPointsType != SnapPointsType.None) { alignment = VerticalSnapPointsAlignment; areSnapPointsRegular = _snapPointsInfo.AreVerticalSnapPointsRegular; if (areSnapPointsRegular) { interval = _snapPointsInfo.GetRegularSnapPoints(Orientation.Vertical, alignment, out offset); irregularSnapPoints = null; } else { if (targetExtentDimension < 0) { // TODO } // TODO: cache this call irregularSnapPoints = _snapPointsInfo.GetIrregularSnapPoints(Orientation.Vertical, alignment); regularInterval = 0; regularOffset = 0; } shouldProcessSnapPoint = true; } else { areSnapPointsRegular = false; } } if (shouldProcessSnapPoint) { if (areSnapPointsRegular) { switch (alignment) { case SnapPointsAlignment.Near: regularOffset = offset * staticZoomFactor; break; case SnapPointsAlignment.Center: // When snap points alignment is Center, the snap points need to align // with the center of the viewport. Adjust the offset accordingly. // Both static and manipulatable zoom factors need to be taken into account. if (interval <= 0f) { // Do not handle negative interval in this case interval = 0f; } else { if (viewportDimension >= interval * zoomFactor) { offset *= zoomFactor; offset -= (float)(viewportDimension / 2f); if (staticZoomFactor == 1f) { offset /= zoomFactor; } while (offset < 0) { offset += interval * staticZoomFactor; } } else { offset -= (float)(viewportDimension / (2f * zoomFactor)); offset *= staticZoomFactor; } regularOffset = offset; } break; case SnapPointsAlignment.Far: regularOffset = offset * staticZoomFactor; break; } regularInterval = interval * staticZoomFactor; areSnapPointsRegular = true; } else { areSnapPointsRegular = false; resultSnapPoints = CopyMotionSnapPoints( false, irregularSnapPoints, alignment, viewportDimension, targetExtentDimension, zoomFactor, staticZoomFactor); } areSnapPointsOptional = snapPointsType == SnapPointsType.Optional || snapPointsType == SnapPointsType.OptionalSingle; } }