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.OnCancel(dragGesture);
                }
                else if (IsMouseOverThisOrDescendant() || isDragging)
                {
                    WidgetContext.Current.MouseCursor = MouseCursor.SizeWE;
                }
            };
            LateTasks.Add(Task.Repeat(() => {
                dragGesture.Recognized += () => {
                    if (!GloballyEnabled)
                    {
                        return;
                    }
                    if (Focused != null && !this.SameOrDescendantOf(Focused))
                    {
                        Focused.RevokeFocus();
                    }
                    Tasks.Add(SpinByDragTask(dragGesture));
                };
                Editor.ClickableWidget.Gestures.Insert(0, dragGesture);
                return(false);
            }));
        }