This project is read-only.

Textbox Grievances

Jan 21, 2010 at 3:14 AM

Cygon- Nice work with the Nuclex Framework, but I noticed a minor annoyance with the Textbox control.

I normally will use CONTROL+A, or SHIFT+HOME to select everything in a textbox, and then, of course, backspace to clear it (not to mention highlighting text). However, such shortcuts don't work with Nuclex controls.

I was wondering if you could implement this, or, preferably, tell me how I could go about doing that. I found the control code easy enough, but i'm not really sure how to utilize modifier keys.

Relevant code:

      switch(keyCode) {

        // Backspace: erase the character left of the caret
        case Keys.Back: {
          if(this.caretPosition > 0) {
            updateLastCaretMovementTicks();

            this.text.Remove(this.caretPosition - 1, 1);
            --this.caretPosition;
          }
          break;
        }

        // Delete: erase the character right of the caret
        case Keys.Delete: {
          if(this.caretPosition < text.Length) {
            updateLastCaretMovementTicks();

            this.text.Remove(this.caretPosition, 1);
          }
          break;
        }

        // Cursor left: move the caret to the left by one character
        case Keys.Left: {
          if(this.caretPosition > 0) {
            updateLastCaretMovementTicks();

            --this.caretPosition;
          }
          break;
        }

        // Cursor right: move the caret to the right by one character
        case Keys.Right: {
          if(this.caretPosition < this.text.Length) {
            updateLastCaretMovementTicks();

            ++this.caretPosition;
          }
          break;
        }

        // Home: place the caret before the first character
        case Keys.Home: {
          updateLastCaretMovementTicks();
          this.caretPosition = 0;
          break;
        }

        // Home: place the caret behind the last character
        case Keys.End: {
          updateLastCaretMovementTicks();
          this.caretPosition = this.text.Length;
          break;
        }

        // Keys that can be used to navigate the dialog
        case Keys.Tab:
        case Keys.Up:
        case Keys.Down:
        case Keys.Enter: {
          return false;
        }

      }

Thanks in advance.

Jan 21, 2010 at 7:53 AM
Edited Jan 21, 2010 at 7:54 AM

Heh, I didn't believe anyone would ever want text selection in a game and the fate of the text box would be to accept player name entries for highscore tables :)

Modifiers like Shift and Control should be reported like any other keys (I admit I haven't tested whether the "InputCapturer" actually does this), so the control would have to remember whether a modifier is being held down.

Then its just a matter of managing the selection (eg. by adding selectionStart and selectionCount fields) in the control and getting all the details right when coding the behavior.

To render the selection, the "FlatInputControlRenderer" needs to be modified to draw the selection: Calculate the pixel offsets the selection begins and ends at, then use the IFlatGuiGraphics.DrawElement() method to draw some highlight effect. You could either reuse the list box selection frame element for that or modify the XML theme to add a special input selection frame element.

-

If you want to avoid having to reintegrate your changes when you upgrade to releases of Nuclex.UserInterface.dll, you could clone the InputControl and FlatInputControlRenderer. It's as simple as adding the cloned input control to the dialog and registering its custom renderer by adding the assembly it is in via FlatGuiVisualizer.RendererRepository.AddAssembly(typeof(MyFlatInputControlRenderer).Assembly)). That means zero changes in Nuclex.UserInterface.dll.

I could also just add text selection support to my TODO list for the next release ;)