本文整理汇总了C#中IContext.GetTextDimensions方法的典型用法代码示例。如果您正苦于以下问题:C# IContext.GetTextDimensions方法的具体用法?C# IContext.GetTextDimensions怎么用?C# IContext.GetTextDimensions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IContext
的用法示例。
在下文中一共展示了IContext.GetTextDimensions方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Click
public override void Click(double x, double y, IContext context)
{
if (ContainsPoint(x, y))
{
if (OnClick != null)
{
OnClick();
}
Active = true;
}
else
{
Active = false;
}
if (Active == false && Text.Length == 0)
Text = placeholder;
if (ContainsPoint (x, y)) {
if (Active == true && string.Compare (Text, placeholder) == 0)
Text = "";
for(int i = 0; i <= Text.Length; i++) {
if(context.GetTextDimensions (hidden? GetHiddenText().Substring(0, i) : Text.Substring(0, i), Width, Height).X > x - this.X) {
cursorPos = i-1;
break;
}
if (i == Text.Length)
cursorPos = i;
}
}
}
示例2: DrawWithContext
public override void DrawWithContext(IContext context, double offsetX, double offsetY)
{
Color backupColor = TextColor;
if (IsDefault ())
TextColor = placeholderColor;
if (!hidden)
base.DrawWithContext (context, offsetX, offsetY);
else {
string TextBackup = Text;
if (Text == placeholder)
Text = placeholder;
else
Text = GetHiddenText ();
base.DrawWithContext (context, offsetX, offsetY);
Text = TextBackup;
}
if (Active) {
double textWidth = 0;
if (cursorPos > 0 && Text.Length != 0) {
textWidth = context.GetTextDimensions (hidden? GetHiddenText().Substring(0, cursorPos) : Text.Substring (0, cursorPos), Width, Height).X;
}
context.DrawLine (new Vector2 (textWidth + offsetX + X + 1, Y + offsetY), new Vector2 (textWidth + offsetX + X + 1, offsetY + Y + Height), new Color (0, 0, 0), 1);
}
if (IsDefault ())
TextColor = backupColor;
}
示例3: KeyPressed
public override void KeyPressed(string key, IContext context)
{
base.KeyPressed(key, context);
if(Active) {
switch (key) {
case "Back":
if(cursorPos > 0)
Text = Text.Remove(--cursorPos, 1);
break;
case "Right":
if (cursorPos < Text.Length)
cursorPos++;
break;
case "Space":
Text = Text.Insert (cursorPos, " ");
cursorPos++;
break;
case "Left":
if (cursorPos > 0)
cursorPos--;
break;
default:
if (key.Length == 1) {
Text = Text.Insert (cursorPos, key);
cursorPos++;
if (context.GetTextDimensions (hidden ? GetHiddenText () : Text, Width, Height).X > Width - 5) {
KeyPressed ("Back", context);
}
} else {
Console.WriteLine ("Unknown key: " + key);
}
break;
}
}
}