/// <summary> /// Sets the currently-selected component or controller. /// </summary> /// <param name="newSelection"></param> public void SetSelectedIndex(int newSelection) { // do nothing if there are no components if (Components.Count == 0 || newSelection == -1) { selectedIndex = -1; return; } DebugLog.LogComponent("New Selection: " + newSelection); int oldSelection = selectedIndex; selectedIndex = newSelection; // Update selection focus SetActive(oldSelection, false); SetActive(selectedIndex, true); // Try to invoke SelectionChange if (SelectionChange != null) { SelectionChange(this, new ReferenceArgs <int>(selectedIndex)); } }
private void Run() { double last_key_time = 0; DateTime UNIX_EPOCH = new DateTime(1970, 1, 1); while (running) { ConsoleKeyInfo key = Console.ReadKey(true); DebugLog.LogComponent("Handling KEY: " + key.Key); if (Container != null) { double current_millis = (DateTime.UtcNow - UNIX_EPOCH).TotalMilliseconds; if (current_millis - last_key_time > KEY_DELAY) { Container.OnKeyPressed(this, new ConsoleKeyEventArgs(key)); last_key_time = current_millis; } } else { DebugLog.LogComponent("Warning: RootContainer is null"); } if (ExitKey != 0 && key.Key == ExitKey) { running = false; } } }
protected override bool HandleKeyPress(object sender, ConsoleKeyEventArgs args) { bool handled = false; if (HasFocus && args.Key.Key == ConsoleKey.Enter) { double current_millis = (DateTime.UtcNow - UNIX_EPOCH).TotalMilliseconds; if (current_millis - LAST_ACTIVATION > ACTIVATION_DELAY) { if (Action != null) { Action(sender, new ComponentEventArgs(this)); } else { DebugLog.LogComponent("Warning: button with text '" + Text + "' has no action"); } LAST_ACTIVATION = current_millis; handled = true; } } return(handled); }