private void UpdateCursor(int change) { if (m_needLayout) { return; } if (IsFocused) { m_cursorPosition += change; if (m_cursorPosition < m_preffix.Length) { m_cursorPosition = m_preffix.Length; } if (m_cursorPosition > m_text.Length) { m_cursorPosition = m_text.Length; } float cursorY = 0; float cursorX; var frame = m_label.GetCharFrame(m_cursorPosition == m_text.Length ? m_text.Length - 1 : m_cursorPosition); if (m_cursorPosition == m_text.Length) { cursorX = frame.X + frame.Width; } else { cursorX = frame.X; } cursorX *= FontSize; if (cursorX + (frame.Width + Font.SpaceWidth) * FontSize + m_contentOffset.X > Size.X) { m_contentOffset.X = Size.X - cursorX - (frame.Width + Font.SpaceWidth) * FontSize; } else if (cursorX + m_contentOffset.X < 0) { m_contentOffset.X = -cursorX; } m_cursor.Position = TextPadding.TopLeft + m_contentOffset + new Vector2(cursorX - (m_cursor.Sprite.FrameSize.X / 2) * FontSize, cursorY - 4 * FontSize); // Nomad: 4 is magic constant. Don't like it at all } UpdateTextPosition(); }
private void UpdateCursor(int change) { if (m_needLayout) { return; } if (m_focused) { m_cursorPosition += change; if (m_cursorPosition < m_preffix.Length) { m_cursorPosition = m_preffix.Length; } if (m_cursorPosition > m_text.Length) { m_cursorPosition = m_text.Length; } m_label.Text = MaskText(m_text.Substring(0, m_cursorPosition) + '\0' + m_text.Substring(m_cursorPosition)); var frame = m_label.GetCharFrame(m_cursorPosition); float nsize = Size.X / m_fontSize; if (m_label.Size.X > nsize) { float from = -m_label.Position.X / m_fontSize; float to = from + nsize; if (frame.X > from && frame.X < to) { } else { if (frame.X > from) { float nx = (nsize - frame.X) * m_fontSize - m_padding.Width; if (nx > m_padding.Left) { nx = m_padding.Left; } m_label.Position = new Vector2(nx, m_padding.Top); } else if (frame.X < to) { float nx = -frame.X * m_fontSize; if (nx > m_padding.Left) { nx = m_padding.Left; } m_label.Position = new Vector2(nx, m_padding.Top); } } } else { m_label.Position = m_padding.TopLeft; } m_cursor.Position = m_label.Position + new Vector2(frame.X * m_fontSize - 2, 0); } else { m_label.Text = MaskText(m_text); m_label.Position = m_padding.TopLeft; } }