Esempio n. 1
0
 void imageBox_EventScrollGesture(Widget source, EventArgs e)
 {
     context.addReference(); //Keep context alive even if this widget is disposed during this event
     try
     {
         Element element = context.GetFocusElement();
         //Find the parent element that scrolls
         while (element != null && element.ScrollHeight <= element.ClientHeight && element.ScrollWidth <= element.ClientWidth)
         {
             element = element.ParentNode;
         }
         if (element != null)
         {
             ScrollGestureEventArgs sgea = (ScrollGestureEventArgs)e;
             element.ScrollLeft -= sgea.DeltaX;
             element.ScrollTop  -= sgea.DeltaY;
         }
     }
     finally
     {
         context.removeReference();
     }
 }
Esempio n. 2
0
        private void OnScrollGesture(object sender, ScrollGestureEventArgs e)
        {
            if (Extent.Height > Viewport.Height || Extent.Width > Viewport.Width)
            {
                var  scrollable = Child as ILogicalScrollable;
                bool isLogical  = scrollable?.IsLogicalScrollEnabled == true;

                double x = Offset.X;
                double y = Offset.Y;

                Vector delta = default;
                if (isLogical)
                {
                    _activeLogicalGestureScrolls?.TryGetValue(e.Id, out delta);
                }
                delta += e.Delta;

                if (Extent.Height > Viewport.Height)
                {
                    double dy;
                    if (isLogical)
                    {
                        var logicalUnits = delta.Y / LogicalScrollItemSize;
                        delta = delta.WithY(delta.Y - logicalUnits * LogicalScrollItemSize);
                        dy    = logicalUnits * scrollable.ScrollSize.Height;
                    }
                    else
                    {
                        dy = delta.Y;
                    }


                    y += dy;
                    y  = Math.Max(y, 0);
                    y  = Math.Min(y, Extent.Height - Viewport.Height);
                }

                if (Extent.Width > Viewport.Width)
                {
                    double dx;
                    if (isLogical)
                    {
                        var logicalUnits = delta.X / LogicalScrollItemSize;
                        delta = delta.WithX(delta.X - logicalUnits * LogicalScrollItemSize);
                        dx    = logicalUnits * scrollable.ScrollSize.Width;
                    }
                    else
                    {
                        dx = delta.X;
                    }
                    x += dx;
                    x  = Math.Max(x, 0);
                    x  = Math.Min(x, Extent.Width - Viewport.Width);
                }

                if (isLogical)
                {
                    if (_activeLogicalGestureScrolls == null)
                    {
                        _activeLogicalGestureScrolls = new Dictionary <int, Vector>();
                    }
                    _activeLogicalGestureScrolls[e.Id] = delta;
                }

                Offset    = new Vector(x, y);
                e.Handled = true;
            }
        }
Esempio n. 3
0
 private void OnScrollGesture(object sender, ScrollGestureEventArgs e)
 {
     e.Handled = e.Handled || OwningGrid.UpdateScroll(-e.Delta);
 }