Example #1
0
        /// <summary>
        ///    Public constructor that creates a text field, with layout controlled with X, Y, Width and Height.
        /// </summary>
        /// <param name="text">Initial text contents.</param>
        public TextField(ustring text)
        {
            if (text == null)
            {
                text = "";
            }

            this.text = TextModel.ToRunes(text);
            point     = text.Length;
            CanFocus  = true;
        }
Example #2
0
        /// <summary>
        ///    Public constructor that creates a text field at an absolute position and size.
        /// </summary>
        /// <param name="x">The x coordinate.</param>
        /// <param name="y">The y coordinate.</param>
        /// <param name="w">The width.</param>
        /// <param name="text">Initial text contents.</param>
        public TextField(int x, int y, int w, ustring text) : base(new Rect(x, y, w, 1))
        {
            if (text == null)
            {
                text = "";
            }

            this.text = TextModel.ToRunes(text);
            point     = text.Length;
            first     = point > w ? point - w : 0;
            CanFocus  = true;
        }
Example #3
0
        bool SetText(Rune key)
        {
            var text    = TextModel.ToRunes(Text);
            var newText = text.GetRange(0, CursorPosition);

            newText.Add(key);
            if (CursorPosition < FieldLen)
            {
                newText = newText.Concat(text.GetRange(CursorPosition + 1, text.Count - (CursorPosition + 1))).ToList();
            }
            return(SetText(ustring.Make(newText)));
        }
Example #4
0
        /// <summary>
        ///     Public constructor that creates a text field at an absolute position and size.
        /// </summary>
        /// <param name="x">The x coordinate.</param>
        /// <param name="y">The y coordinate.</param>
        /// <param name="w">The width.</param>
        /// <param name="text">Initial text contents.</param>
        public TextField(int x, int y, int w, ustring text) : base(new Rect(x, y, w, 1))
        {
            if (text == null)
            {
                text = "";
            }

            this.text      = TextModel.ToRunes(text);
            CursorPosition = text.Length;
            first          = CursorPosition > w ? CursorPosition - w : 0;
            CanFocus       = true;
        }
Example #5
0
        public override bool ProcessKey(KeyEvent kb)
        {
            switch (kb.Key)
            {
            case Key.DeleteChar:
            case Key.ControlD:
                SetText('0');
                break;

            case Key.Delete:
            case Key.Backspace:
                SetText('0');
                DecCursorPosition();
                break;

            // Home, C-A
            case Key.Home:
            case Key.ControlA:
                CursorPosition = 1;
                break;

            case Key.CursorLeft:
            case Key.ControlB:
                DecCursorPosition();
                break;

            case Key.End:
            case Key.ControlE:             // End
                CursorPosition = FieldLen;
                break;

            case Key.CursorRight:
            case Key.ControlF:
                IncCursorPosition();
                break;

            default:
                // Ignore non-numeric characters.
                if (kb.Key < (Key)((int)'0') || kb.Key > (Key)((int)'9'))
                {
                    return(false);
                }
                if (SetText(TextModel.ToRunes(ustring.Make((uint)kb.Key)).First()))
                {
                    IncCursorPosition();
                }
                return(true);
            }
            return(true);
        }
Example #6
0
        void Initialize(ustring text, int w)
        {
            if (text == null)
            {
                text = "";
            }

            this.text = TextModel.ToRunes(text);
            point     = text.RuneCount;
            first     = point > w ? point - w : 0;
            CanFocus  = true;
            Used      = true;
            WantMousePositionReports = true;
        }