protected override void OnAutoSize() { if (_isDirty) { var style = Desktop.GetStyle(Style).Styles[State]; UpdateText(style); } if (AutoSize == AutoSize.Vertical) { Size = new Point(Size.X, _textSize.Y); } else if (AutoSize == AutoSize.Horizontal) { Size = new Point(_textSize.X, Size.Y); } else if (AutoSize == AutoSize.HorizontalVertical) { Size = _textSize; } }
protected override void OnLateUpdate() { if (!_isDirty) { _isDirty = _lastSize.X != Size.X || _lastSize.Y != Size.Y; } if (_isDirty) { var style = Desktop.GetStyle(Style).Styles[State]; UpdateText(style); } if (Desktop.HotControl == this) { var m = Gui.MousePosition; _activeHref = null; foreach (var line in _lines) { foreach (var element in line.Elements) { if (!element.IsLink) { continue; } if (element.Rectangle.Contains(m)) { Desktop.CurrentCursor = CursorNames.Link; _activeHref = element.Href; break; } } } } }
void TextBox_MouseDown(Control sender, MouseEventArgs args) { if (args.Button > 0) { return; } if (!_hasFocus) { _savedText = Text; _hasFocus = true; } var style = Desktop.GetStyle(Style).Styles[State]; var masked = Text; if (IsPassword) { masked = new string(PasswordChar, masked.Length); } if (string.IsNullOrEmpty(masked)) { return; } var font = Gui.Renderer.GetFont(style.Font); if (font < 0) { return; } var p = Gui.MousePosition - Location; var s1 = Gui.Renderer.GetTextSize(masked, font); var carex = p.X + _offset + s1.X; var x = 0; var text = string.Empty; for (var i = 1; i <= masked.Length; i++) { text = masked.Substring(0, i); x = _offset + Gui.Renderer.GetTextSize(text, font).X; if (x > p.X) { _caret = i - 1; break; } } if (x < p.X) { _caret = masked.Length; } if (Gui.CtrlPressed) { var left = FindIndexLeft(_caret, masked); var right = FindIndexRight(_caret, masked); if (char.IsWhiteSpace(masked, left) || char.IsPunctuation(masked, left)) { left++; } if (char.IsWhiteSpace(masked, right - 1) || char.IsPunctuation(masked, right - 1)) { right--; } _selectStart = left; _selectEnd = right; _caret = _selectEnd; } else if (Gui.ShiftPressed) { _selectEnd = _caret; } else { _selectStart = _caret; _selectEnd = _caret; } }
//protected override void Bind(object instance) //{ // if (string.IsNullOrEmpty(Aspect)) return; // if (instance == null) return; // Type type = instance.GetType(); // object value = null; // System.Reflection.PropertyInfo property = type.GetProperty(Aspect); // if (property != null) // { // value = property.GetValue(instance, null); // if (value != null) Text = value.ToString(); // } // else // { // System.Reflection.FieldInfo field = type.GetField(Aspect); // if (field != null) // { // value = field.GetValue(instance); // if (value != null) Text = value.ToString(); // } // } //} protected override void OnStateChanged() { var style = Desktop.GetStyle(Style).Styles[State]; UpdateText(style); }
void TextBox_MousePress(Control sender, MouseEventArgs args) { if (args.Button > 0) { return; } if (Gui.CtrlPressed) { return; } var style = Desktop.GetStyle(Style).Styles[State]; var masked = Text; if (IsPassword) { masked = new string(PasswordChar, masked.Length); } if (string.IsNullOrEmpty(masked)) { return; } var font = Gui.Renderer.GetFont(style.Font); if (font < 0) { return; } var p = Gui.MousePosition - Location; var s1 = Gui.Renderer.GetTextSize(masked, font); var carex = p.X + _offset + s1.X; var x = 0; var text = string.Empty; var caret = _caret; for (var i = 1; i <= masked.Length; i++) { text = masked.Substring(0, i); x = _offset + Gui.Renderer.GetTextSize(text, font).X; if (x > p.X) { _selectEnd = i - 1; break; } } if (x < p.X) { _selectEnd = masked.Length; } var start = Math.Min(_selectStart, _selectEnd); var end = Math.Max(_selectStart, _selectEnd); if (_selectEnd < _selectStart) { _caret = start; } else { _caret = end; } }