Exemple #1
0
 private void StopDrag(IPropHolder widget, DragCtx ctx)
 {
     if (!ctx.IsDragging)
     {
         return;
     }
     ctx.IsDragging = false;
     widget.Props.RemoveSingleProp(_onUpdateDrag !);
 }
Exemple #2
0
        private void StartDrag(IPropHolder widget, bool isXFixed, bool isYFixed, DragCtx dragCtx)
        {
            if (isXFixed && isYFixed)
            {
                return;
            }

            var devLoc = _device.GetPointedLocation();

            if (dragCtx.IsDragging)
            {
                return;
            }
            dragCtx.IsDragging = true;
            dragCtx.Set(devLoc);
            widget.WithProp(_onUpdateDrag !);
        }
Exemple #3
0
        private void Dragging(IWidget widget, bool isXFixed, bool isYFixed, DragCtx dragCtx)
        {
            var devLoc = _device.GetPointedLocation();
            var devX   = devLoc.X;
            var devY   = devLoc.Y;

            var(x, y, w, h) = widget.Space;
            if (Math.Abs(dragCtx.DevX - devX) < 0.01f && Math.Abs(dragCtx.DevY - devY) < 0.01f)
            {
                return;
            }

            var nx = x + (isXFixed ? 0 : devX - dragCtx.DevX);
            var ny = y + (isYFixed ? 0 : devY - dragCtx.DevY);

            (nx, ny) = CheckBounds(widget, nx, ny, isXFixed, isYFixed);

            WidgetsSpaceHelper.UpdateSpace(widget, new RectangleF(nx, ny, w, h));
            dragCtx.Set(devLoc);
        }
Exemple #4
0
        /// <summary>
        /// Adds an OnPress and OnRelease actions to the widget that handle the dragging logic.
        /// </summary>
        /// <param name="widget"></param>
        public void ApplyOn(IWidget widget)
        {
            ApplicationDone = false;
            var dragCtx = new DragCtx();

            var foundFixX = widget.Props.SafeGetByProp <FixX>().TryGetValue(out var fixX);
            var foundFixY = widget.Props.SafeGetByProp <FixY>().TryGetValue(out var fixY);

            bool      isXFixed  = foundFixX && fixX.Count > 0;
            bool      isYFixed  = foundFixY && fixY.Count > 0;
            OnPress   onPress   = new OnPress(() => StartDrag(widget, isXFixed, isYFixed, dragCtx));
            OnRelease onRelease = new OnRelease(() => StopDrag(widget, dragCtx));
            OnExit    onExit    = new OnExit(() => StopDrag(widget, dragCtx));

            widget.WithProp(onPress);
            widget.WithProp(onRelease);
            widget.WithProp(onExit);

            _onUpdateDrag = new OnUpdate(() => Dragging(widget, isXFixed, isYFixed, dragCtx));

            ApplicationDone = true;
            OnApplied();
        }