Exemplo n.º 1
0
        public ThemedNumericEditBox()
        {
            ThemedEditBox.Decorate(this);
            MinWidth           = 0.0f;
            MaxWidth           = 105.0f;
            TextWidget.Padding = new Thickness(left: 5.0f, right: 5.0f, top: 2.0f, bottom: 2.0f);
            Layout             = new HBoxLayout();
            // Lime.EditorParams.MouseSelectionThreshold is 3 by default and this gesture should be recognized first.
            // To achieve that we're setting its drag threshold to 2.0f, add it to Editor.ClickableWidget (same collection
            // editor adds its widgets to) and do it in LateTasks.
            var dragGesture = new DragGesture(exclusive: true, dragThreshold: 2.0f);

            Updated += (delta) => {
                if (Editor.FocusableWidget.IsFocused())
                {
                    dragGesture.Cancel();
                }
                else if (IsMouseOverThisOrDescendant() || isDragging)
                {
                    WidgetContext.Current.MouseCursor = MouseCursor.SizeWE;
                }
            };
            LateTasks.Add(Task.Repeat(() => {
                dragGesture.Recognized += () => Tasks.Add(SpinByDragTask(dragGesture));
                Editor.ClickableWidget.Gestures.Insert(0, dragGesture);
                return(false);
            }));
        }
Exemplo n.º 2
0
        Widget CreateSpinButton(SpinButtonType type)
        {
            var button = new Widget {
                HitTestTarget = true,
                LayoutCell    = new LayoutCell {
                    StretchX = 0
                },
                MinWidth      = SpinButtonPresenter.ButtonWidth,
                PostPresenter = new SpinButtonPresenter(type)
            };

            button.Awoken += instance => {
                var dragGesture = new DragGesture();
                dragGesture.Recognized += () => Tasks.Add(SpinByDragTask(dragGesture));
                var clickGesture = new ClickGesture(() => {
                    var delta = (type == SpinButtonType.Additive ? 1 : -1) * Step;
                    if (Input.IsKeyPressed(Key.Shift))
                    {
                        delta *= 10f;
                    }
                    else if (Input.IsKeyPressed(Key.Control))
                    {
                        delta *= 0.1f;
                    }
                    if (!IsReadOnly)
                    {
                        Value += delta;
                    }
                });
                var gestures = ((Widget)instance).Gestures;
                gestures.Add(clickGesture);
                gestures.Add(dragGesture);
            };
            return(button);
        }
Exemplo n.º 3
0
 private IEnumerator <object> SpinByDragTask(DragGesture dragGesture)
 {
     RaiseBeginSpin();
     try {
         isDragging = true;
         var   startValue         = Value;
         var   startMousePosition = Application.DesktopMousePosition;
         float accumulator        = 0.0f;
         while (dragGesture.IsChanging())
         {
             var mousePosition = Application.DesktopMousePosition;
             var disp          = CommonWindow.Current.Display;
             var wrapped       = false;
             if (Application.DesktopMousePosition.X > disp.Position.X + disp.Size.X - 5)
             {
                 accumulator         += disp.Position.X + disp.Size.X - 5 - startMousePosition.X;
                 startMousePosition.X = mousePosition.X = disp.Position.X + 5;
                 wrapped = true;
             }
             if (Application.DesktopMousePosition.X < disp.Position.X + 5)
             {
                 accumulator         -= startMousePosition.X - disp.Position.X - 5;
                 startMousePosition.X = mousePosition.X = disp.Position.X + disp.Size.X - 5;
                 wrapped = true;
             }
             if (wrapped)
             {
                 Application.DesktopMousePosition = new Vector2(mousePosition.X, Application.DesktopMousePosition.Y);
             }
             var delta = (mousePosition.X - startMousePosition.X + accumulator).Round() * Step;
             if (Input.IsKeyPressed(Key.Shift))
             {
                 delta *= 10f;
             }
             else if (Input.IsKeyPressed(Key.Control))
             {
                 delta *= 0.1f;
             }
             if (!IsReadOnly)
             {
                 Value = startValue + delta;
             }
             yield return(null);
         }
     } finally {
         isDragging = false;
         RaiseEndSpin();
     }
 }
Exemplo n.º 4
0
        void Advance()
        {
            if (Thumb == null)
            {
                return;
            }
            var draggingJustBegun = false;

            if (GloballyEnabled && RangeMax > RangeMin)
            {
                if (dragGestureThumb.WasRecognized())
                {
                    activeDragGesture = dragGestureThumb;
                    TryStartDrag();
                    draggingJustBegun = true;
                }
                else
                {
                    if (clickGesture.WasBegan())
                    {
                        TryStartDrag();
                        SetValueFromCurrentMousePosition(false);
                    }
                    if (clickGesture.WasRecognizedOrCanceled() && !dragGestureSlider.WasRecognized())
                    {
                        TryEndDrag();
                    }
                    if (dragGestureSlider.WasRecognized())
                    {
                        activeDragGesture = dragGestureSlider;
                        TryStartDrag();
                        dragInitialDelta  = 0;
                        dragInitialOffset = (Value - RangeMin) / (RangeMax - RangeMin);
                        draggingJustBegun = false;
                    }
                }
            }
            if (activeDragGesture?.WasEnded() ?? false)
            {
                TryEndDrag();
            }
            if (Enabled && (activeDragGesture?.IsChanging() ?? false))
            {
                SetValueFromCurrentMousePosition(draggingJustBegun);
            }
            InterpolateGraphicsBetweenMinAndMaxMarkers();
            RefreshThumbPosition();
        }
Exemplo n.º 5
0
 private IEnumerator <object> SpinByDragTask(DragGesture dragGesture)
 {
     RaiseBeginSpin();
     try {
         var prevMousePos = Application.DesktopMousePosition;
         while (dragGesture.IsChanging())
         {
             var disp    = CommonWindow.Current.Display;
             var wrapped = false;
             if (Application.DesktopMousePosition.X > disp.Position.X + disp.Size.X - 5)
             {
                 prevMousePos.X = disp.Position.X + 5;
                 wrapped        = true;
             }
             if (Application.DesktopMousePosition.X < disp.Position.X + 5)
             {
                 prevMousePos.X = disp.Position.X + disp.Size.X - 5;
                 wrapped        = true;
             }
             if (wrapped)
             {
                 Application.DesktopMousePosition = new Vector2(prevMousePos.X, Application.DesktopMousePosition.Y);
             }
             var delta = (Application.DesktopMousePosition.X - prevMousePos.X).Round() * Step;
             if (Input.IsKeyPressed(Key.Shift))
             {
                 delta *= 10f;
             }
             else if (Input.IsKeyPressed(Key.Control))
             {
                 delta *= 0.1f;
             }
             if (!IsReadOnly)
             {
                 Value += delta;
             }
             prevMousePos = Application.DesktopMousePosition;
             yield return(null);
         }
     } finally {
         RaiseEndSpin();
     }
 }
Exemplo n.º 6
0
        public ScrollView(Frame frame, ScrollDirection scrollDirection = ScrollDirection.Vertical, bool processChildrenFirst = false)
        {
            ScrollDirection       = scrollDirection;
            RejectOrtogonalSwipes = true;
            Frame = frame;
            Frame.Input.AcceptMouseBeyondWidget       = false;
            Frame.Input.AcceptMouseThroughDescendants = true;
            Frame.HitTestTarget     = true;
            Frame.ClipChildren      = ClipMethod.ScissorTest;
            CanScroll               = true;
            Content                 = CreateContentWidget();
            Content.ScrollDirection = ScrollDirection;
            if (ScrollDirection == ScrollDirection.Vertical)
            {
                Content.Width  = Frame.Width;
                Content.Height = 0;
            }
            else
            {
                Content.Width  = 0;
                Content.Height = Frame.Height;
            }
            Content.PushToNode(Frame);
            if (processChildrenFirst)
            {
                Content.LateTasks.Add(MainTask());
            }
            else
            {
                Content.Tasks.Add(MainTask());
            }
#if MAC || WIN
            Content.Tasks.Add(WheelScrollingTask());
#endif
            Frame.Layout = new Layout(scrollDirection, Content);
            dragGesture  = new DragGesture(0, (DragDirection)ScrollDirection);
            Frame.Gestures.Add(dragGesture);
        }
Exemplo n.º 7
0
        private IEnumerator <object> HandleInputTask()
        {
            bool wasFocused = false;

            var rightClickGesture  = new ClickGesture(1);
            var clickGesture       = new ClickGesture();
            var doubleClickGesture = new DoubleClickGesture();
            var dragGesture        = new DragGesture(0, DragDirection.Any, dragThreshold: EditorParams.MouseSelectionThreshold);

            ClickableWidget.Gestures.Add(rightClickGesture);
            ClickableWidget.Gestures.Add(clickGesture);
            ClickableWidget.Gestures.Add(doubleClickGesture);
            ClickableWidget.Gestures.Add(dragGesture);

            while (true)
            {
                if (EditorParams.SelectAllOnFocus && !wasFocused && FocusableWidget.IsFocused())
                {
                    SelectAll();
                    CaretPos.TextPos = TextLength;
                }
                if (FocusableWidget.IsFocused())
                {
                    HandleKeys();
                    HandleTextInput();
                }
                if (clickGesture.WasRecognized())
                {
                    if (!FocusableWidget.IsFocused())
                    {
                        if (EditorParams.SelectAllOnFocus)
                        {
                            SelectAll();
                        }
                    }
                    else
                    {
                        HideSelection();
                    }
                    FocusableWidget.SetFocus();
                    CaretPos.WorldPos = DisplayWidget.LocalMousePosition();
                }
                if (doubleClickGesture.WasRecognized())
                {
                    if (IsTextReadable)
                    {
                        SelectWord();
                    }
                    else
                    {
                        SelectAll();
                    }
                }
                if (rightClickGesture.WasRecognized())
                {
                    FocusableWidget.SetFocus();
                    ShowContextMenu(true);
                }
                if (dragGesture.WasRecognized())
                {
                    FocusableWidget.SetFocus();
                    CaretPos.WorldPos = DisplayWidget.ToLocalMousePosition(dragGesture.MousePressPosition);
                    HideSelection();
                    EnsureSelection();
                    SelectionStart.AssignFrom(CaretPos);
                }
                else if (dragGesture.WasChanged())
                {
                    CaretPos.WorldPos = DisplayWidget.LocalMousePosition();
                    EnsureSelection();
                    SelectionEnd.AssignFrom(CaretPos);
                }
                Text.SyncCaretPosition();
                AdjustSizeAndScrollToCaret();
                var isFocused = CaretPos.IsVisible = FocusableWidget.IsFocused();
                if (wasFocused && !isFocused)
                {
                    HideSelection();
                    if (History.CanUndo())
                    {
                        History.Clear();
                        Text.Submit();
                    }
                }
                wasFocused = isFocused;
                yield return(null);
            }
        }
Exemplo n.º 8
0
 protected override void Awake()
 {
     Thumb?.Gestures.Add(dragGestureThumb = new DragGesture());
     Gestures.Add(dragGestureSlider       = new DragGesture());
     Gestures.Add(clickGesture            = new ClickGesture());
 }
Exemplo n.º 9
0
 public TabBar()
 {
     gesture = new DragGesture(direction: DragDirection.Horizontal);
     Gestures.Add(gesture);
     Tasks.Add(DragTabProcessor());
 }
Exemplo n.º 10
0
        private IEnumerator <object> HandleDragTask(VelocityMeter velocityMeter, float mouseProjectedPosition, DragGesture dragGesture)
        {
            if (!CanScroll || !ScrollWhenContentFits && MaxScrollPosition == 0 || ScrollBySlider)
            {
                yield break;
            }
            // Do not block scrollview on refresh gesture
            IsBeingRefreshed = false;
            IsDragging       = true;
            float realScrollPosition = ScrollPosition;

            wheelScrollState = WheelScrollState.Stop;
            while (dragGesture.IsChanging())
            {
                var newMouseProjectedPosition = ProjectToScrollAxisWithFrameRotation(Input.MousePosition);
                realScrollPosition += mouseProjectedPosition - newMouseProjectedPosition;
                // Round scrolling position to prevent blurring
                ScrollPosition         = ClampScrollPositionWithinBounceZone(realScrollPosition).Round();
                mouseProjectedPosition = newMouseProjectedPosition;
                velocityMeter.AddSample(realScrollPosition);
                yield return(null);
            }
            StartScrolling(InertialScrollingTask(velocityMeter.CalcVelocity()));
            IsDragging = false;
        }