// ///////////////////////////////////////////////////////////////////////////////// #endregion #region Constructors // ///////////////////////////////////////////////////////////////////////////////// /// <summary> /// Construct an Entry instance from the given template. /// </summary> /// <param name="template"></param> public Entry(EntryTemplate template) : base(template) { this.Label = template.Label; if (this.Size.Width < 3 || this.Size.Height < 3) { template.HasFrameBorder = false; } this.HasFrame = template.HasFrameBorder; MaximumCharacters = template.CalculateMaxCharacters(); CommitOnLostFocus = template.CommitOnLostFocus; ReplaceOnFirstKey = template.ReplaceOnFirstKey; this.CanHaveKeyboardFocus = template.CanHaveKeyboardFocus; this.HilightWhenMouseOver = template.HilightWhenMouseOver; this.VerticalAlign = template.VerticalAlign; this.LabelAlign = template.LabelAlign; this.CurrentText = ""; this.waitingToCommitText = false; this.TextInput = CurrentText; CalcMetrics(template); }
private void CalcMetrics(EntryTemplate template) { Rect viewRect = this.LocalRect; if (template.HasFrameBorder) { viewRect = Rect.Inflate(viewRect, -1, -1); } int remaining = viewRect.Size.Width; int labelLength = template.Label.Length; int fieldLength = template.CalculateMaxCharacters(); remaining -= fieldLength; if (remaining < 0) { fieldLength += remaining; labelLength = 0; } else { remaining -= labelLength; labelLength += remaining - 1; } if (labelLength < 1) { Label = ""; labelLength = 0; } labelRect = new Rect(viewRect.UpperLeft, new Size(labelLength, viewRect.Size.Height)); fieldRect = new Rect(labelRect.UpperRight.Shift(1, 0), new Size(fieldLength, viewRect.Size.Height)); switch (VerticalAlign) { case VerticalAlignment.Top: cursorY = fieldRect.Top; break; case VerticalAlignment.Center: cursorY = fieldRect.Center.Y; break; case VerticalAlignment.Bottom: cursorY = fieldRect.Bottom; break; } }