private void SelectAnimationBasedOnMousePosition() { scrollView.SetFocus(); var index = (scrollView.Content.LocalMousePosition().Y / rowHeight).Floor(); if (index < GetAnimations().Count) { SelectAnimation(index); } }
public override void Initialize() { Tab = new ThemedTab { Text = "Devices" }; Content = new Widget { Layout = new VBoxLayout(), Nodes = { (mainToolbar = new RemoteScriptingWidgets.Toolbar()), new Widget { Layout = new HBoxLayout(), Nodes = { (devicesScrollView = new ThemedScrollView { MinMaxWidth = 300, TabTravesable = new TabTraversable() }), (deviceWidgetPlaceholder = new Widget() { Layout = new HBoxLayout() }) } } } }; RefreshMainToolbar(); Content.AddChangeWatcher( () => CompiledAssembly.Instance, _ => { RefreshMainToolbar(); } ); void SelectDeviceBasedOnMousePosition() { devicesScrollView.SetFocus(); var index = (devicesScrollView.Content.LocalMousePosition().Y / rowHeight).Floor(); if (index < devices.Count) { SelectDevice(index); } } var mouseDownGesture = new ClickGesture(0); mouseDownGesture.Began += SelectDeviceBasedOnMousePosition; devicesScrollView.Gestures.Add(mouseDownGesture); devicesScrollView.Content.CompoundPresenter.Insert(0, new SyncDelegatePresenter <Widget>(w => { w.PrepareRendererState(); Renderer.DrawRect( 0, rowHeight * selectedDeviceIndex, w.Width, rowHeight * (selectedDeviceIndex + 1), devicesScrollView.IsFocused() ? Theme.Colors.SelectedBackground : Theme.Colors.SelectedInactiveBackground ); })); }
private void ScrollView_KeyRepeated(WidgetInput input, Key key) { if (history == null || history.Count < 1) { return; } if (key == Key.Mouse0) { scrollView.SetFocus(); selectedIndex = (resultPane.LocalMousePosition().Y / rowHeight).Floor().Clamp(0, history.Count - 1); } else if (Cmds.Down.WasIssued()) { selectedIndex++; Cmds.Down.Consume(); } else if (Cmds.Up.WasIssued()) { selectedIndex--; Cmds.Up.Consume(); } else if (Cmds.Cancel.WasIssued()) { scrollView.RevokeFocus(); Cmds.Cancel.Consume(); } else if (Cmds.Enter.WasIssued() || key == Key.Mouse0DoubleClick) { Document.Current.History.DoTransaction(() => NavigateToItem(selectedIndex)); Cmds.Enter.Consume(); } else { return; } selectedIndex = selectedIndex.Clamp(0, history?.Count - 1 ?? 0); EnsureRowVisible(selectedIndex); Window.Current.Invalidate(); }
void ScrollView_KeyRepeated(WidgetInput input, Key key) { if (Cmds.All.Contains(key)) { input.ConsumeKey(key); } if (results.Count == 0) { return; } if (key == Key.Mouse0) { scrollView.SetFocus(); selectedIndex = (resultPane.Input.LocalMousePosition.Y / rowHeight).Floor().Clamp(0, results.Count - 1); } else if (key == Cmds.Down) { selectedIndex++; } else if (key == Cmds.Up) { selectedIndex--; } else if (key == Cmds.Cancel) { scrollView.RevokeFocus(); } else if (key == Cmds.Enter || key == Key.Mouse0DoubleClick) { NavigateToItem(selectedIndex); } else { return; } selectedIndex = selectedIndex.Clamp(0, results != null ? results.Count - 1 : 0); EnsureRowVisible(selectedIndex); Window.Current.Invalidate(); }
private void ProcessDragState(float dt) { var input = scrollView.Input; switch (dragState) { case DragState.None: { if (scrollView.IsMouseOver()) { if (input.ConsumeKeyPress(Key.Mouse0)) { dragEndPosition = dragStartPosition = scrollView.Content.LocalMousePosition(); dragState = DragState.WaitingForSelecting; } if (input.ConsumeKeyRelease(Key.Mouse1)) { dragState = DragState.None; selection.Clear(); SystemShellContextMenu.Instance.Show(model.CurrentPath); } } break; } case DragState.Selecting: { if (Window.Current.Input.WasKeyReleased(Key.Mouse0)) { Window.Current.Input.ConsumeKey(Key.Mouse0); scrollView.SetFocus(); dragState = DragState.None; } dragEndPosition = scrollView.Content.LocalMousePosition(); var scrollOffset = 0.0f; if (scrollView.LocalMousePosition().Y < 0) { scrollOffset = scrollView.LocalMousePosition().Y; } else if (scrollView.LocalMousePosition().Y > scrollView.Size.Y) { scrollOffset = scrollView.LocalMousePosition().Y - scrollView.Size.Y; } scrollView.ScrollPosition += Math.Sign(scrollOffset) * Mathf.Sqr(scrollOffset) * 0.1f * dt; scrollView.ScrollPosition = Mathf.Clamp(scrollView.ScrollPosition, scrollView.MinScrollPosition, scrollView.MaxScrollPosition); Window.Current.Invalidate(); } break; case DragState.WaitingForDragging: if ((dragStartPosition - Window.Current.Input.MousePosition).Length > 5.0f) { dragState = DragState.Dragging; CommonWindow.Current.DragFiles(selection.ToArray()); } if ( Window.Current.Input.WasKeyReleased(Key.Mouse0) || Window.Current.Input.WasKeyReleased(Key.Mouse0DoubleClick) ) { dragState = DragState.None; Window.Current.Input.ConsumeKey(Key.Mouse0); } break; case DragState.WaitingForSelecting: if (input.ConsumeKeyRelease(Key.Mouse0)) { dragState = DragState.None; if (!input.IsKeyPressed(Key.Control) && !input.IsKeyPressed(Key.Shift)) { selection.Clear(); } } else if (input.IsKeyPressed(Key.Mouse0)) { if ((scrollView.Content.LocalMousePosition() - dragStartPosition).Length > 6.0f) { dragState = DragState.Selecting; if (input.IsKeyPressed(Key.Control)) { savedSelection = selection.Clone(); } else { savedSelection = null; } } } break; case DragState.Dragging: if (Window.Current.Input.WasKeyReleased(Key.Mouse0)) { Window.Current.Input.ConsumeKey(Key.Mouse0); dragState = DragState.None; } break; } }