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); }
protected override void Awake() { // On the current frame the button contents may not be loaded, // so delay its initialization until the next frame. SetState(InitialState()); textPresentersFeeder = new TextPresentersFeeder(this); clickGesture = new ClickGesture(); Gestures.Add(clickGesture); }
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); } }
protected override void Awake() { Thumb?.Gestures.Add(dragGestureThumb = new DragGesture()); Gestures.Add(dragGestureSlider = new DragGesture()); Gestures.Add(clickGesture = new ClickGesture()); }