protected override float PointToValue(float x, float y) { if (null == Thumb || null == Track) { return(0); } var range = Maximum - Minimum; var thumbRange = LayoutUtil.GetLayoutBoundsHeight(Track) - LayoutUtil.GetLayoutBoundsHeight(Thumb); return(Minimum + ((thumbRange != 0) ? ((thumbRange - y) / thumbRange) * range : 0)); }
protected override void UpdateSkinDisplayList() { if (null == Thumb || null == Track) { return; } var thumbRange = LayoutUtil.GetLayoutBoundsHeight(Track) - LayoutUtil.GetLayoutBoundsHeight(Thumb); var range = Maximum - Minimum; // calculate new thumb position. var thumbPosTrackY = (range > 0) ? thumbRange - ((PendingValue - Minimum) / range) * thumbRange : 0; // convert to parent's coordinates. var thumbPos = Track.LocalToGlobal(new Point(0, thumbPosTrackY)); var thumbPosParentY = Thumb.Parent.GlobalToLocal(thumbPos).Y; Thumb.SetLayoutBoundsPosition(LayoutUtil.GetLayoutBoundsX(Thumb), Mathf.Round(thumbPosParentY)); }
////---------------------------------- //// canScrollHorizontally ////---------------------------------- ///** // * // */ //private bool _canScrollHorizontally; ///** // * // * Helper function to determine whether the Viewport scrolls horizontally. // * // * <p>This is used for touch scrolling purposes to // * determine if one can scroll horizontally.</p> // * // * <p>The value is set in updateDisplayList()</p> // */ //internal bool canScrollHorizontally //{ // get // { // return _canScrollHorizontally; // } //} ////---------------------------------- //// canScrollVertically ////---------------------------------- ///** // * // */ //private bool _canScrollVertically; ///** // * // * Helper function to determine whether the Viewport scrolls vertically. // * // * <p>This is used for touch scrolling purposes to // * determine if one can scroll vertically.</p> // * // * <p>The value is set in updateDisplayList()</p> // */ //internal bool canScrollVertically //{ // get // { // return _canScrollVertically; // } //} //-------------------------------------------------------------------------- // // Overidden Methods // //-------------------------------------------------------------------------- /** * * Computes the union of the preferred size of the visible scrollbars * and the Viewport if target.measuredSizeIncludesScrollbars=true, otherwise * it's just the preferred size of the Viewport. * * This becomes the ScrollerSkin's measuredWidth,Height. * * The Viewport does not contribute to the minimum size unless its * explicit size has been set. */ override internal void Measure() { Scroller scroller = GetScroller(); if (null == scroller) { return; } float minViewportInset = scroller.MinViewportInset; // var mode = scroller.GetStyle("interactionMode"); // bool isMouseMode = null == mode || (InteractionMode)mode == InteractionMode.Mouse; bool measuredSizeIncludesScrollBars = scroller.MeasuredSizeIncludesScrollBars; // && isMouseMode; float measuredW = minViewportInset; float measuredH = minViewportInset; ScrollBarBase hsb = scroller.HorizontalScrollBar; bool showHsb = false; bool hAuto = false; if (measuredSizeIncludesScrollBars) { switch ((ScrollPolicy)scroller.GetStyle("horizontalScrollPolicy")) { case ScrollPolicy.On: if (null != hsb) { showHsb = true; } break; case ScrollPolicy.Auto: if (null != hsb) { showHsb = hsb.Visible; } hAuto = true; break; } } ScrollBarBase vsb = scroller.VerticalScrollBar; bool showVsb = false; bool vAuto = false; if (measuredSizeIncludesScrollBars) { switch ((ScrollPolicy)scroller.GetStyle("verticalScrollPolicy")) { case ScrollPolicy.On: if (null != vsb) { showVsb = true; } break; case ScrollPolicy.Auto: if (null != vsb) { showVsb = vsb.Visible; } vAuto = true; break; } } measuredH += (showHsb) ? HsbRequiredHeight() : minViewportInset; measuredW += (showVsb) ? VsbRequiredWidth() : minViewportInset; // The measured size of the Viewport is just its preferredBounds, except: // don't give up space if doing so would make an auto scrollbar visible. // In other words, if an auto scrollbar isn't already showing, and using // the preferred size would force it to show, and the current size would not, // then use its current size as the measured size. Note that a scrollbar // is only shown if the content size is greater than the Viewport size // by at least SDT. IViewport viewport = scroller.Viewport; if (null != viewport) { if (measuredSizeIncludesScrollBars) { Point contentSize = GetLayoutContentSize(viewport); float viewportPreferredW = LayoutUtil.GetPreferredBoundsWidth((InvalidationManagerClient)viewport); float viewportContentW = contentSize.X; float viewportW = LayoutUtil.GetLayoutBoundsWidth((InvalidationManagerClient)viewport); // "current" size bool currentSizeNoHsb = null != viewportW && ((viewportW + SDT) > viewportContentW); if (hAuto && !showHsb && ((viewportPreferredW + SDT) <= viewportContentW) && currentSizeNoHsb) { measuredW += viewportW; } else { measuredW += Math.Max(viewportPreferredW, (showHsb) ? LayoutUtil.GetMinBoundsWidth(hsb) : 0); } float viewportPreferredH = LayoutUtil.GetPreferredBoundsHeight((InvalidationManagerClient)viewport); float viewportContentH = contentSize.Y; float viewportH = LayoutUtil.GetLayoutBoundsHeight((InvalidationManagerClient)viewport); // "current" size bool currentSizeNoVsb = null != viewportH && ((viewportH + SDT) > viewportContentH); if (vAuto && !showVsb && ((viewportPreferredH + SDT) <= viewportContentH) && currentSizeNoVsb) { measuredH += viewportH; } else { measuredH += Math.Max(viewportPreferredH, (showVsb) ? LayoutUtil.GetMinBoundsHeight(vsb) : 0); } } else { measuredW += LayoutUtil.GetPreferredBoundsWidth((InvalidationManagerClient)viewport); measuredH += LayoutUtil.GetPreferredBoundsHeight((InvalidationManagerClient)viewport); } } float minW = minViewportInset * 2; float minH = minViewportInset * 2; // If the Viewport's explicit size is set, then // include that in the scroller's minimum size Component component = viewport as Component; float? explicitViewportW = (null != component) ? component.ExplicitWidth : null; float? explicitViewportH = (null != component) ? component.ExplicitHeight : null; if (null != explicitViewportW) { minW += (float)explicitViewportW; } if (null != explicitViewportH) { minH += (float)explicitViewportH; } GroupBase g = Target; g.MeasuredWidth = Mathf.Ceil(measuredW); g.MeasuredHeight = Mathf.Ceil(measuredH); g.MeasuredMinWidth = Mathf.Ceil(minW); g.MeasuredMinHeight = Mathf.Ceil(minH); }