1
This commit is contained in:
@@ -714,5 +714,48 @@ namespace BITKit
|
||||
|
||||
self.SetOpacity(visible ? 1 : 0);
|
||||
}
|
||||
|
||||
public static void ClearTooltipsOnPointerLeave(this VisualElement visualElement)
|
||||
{
|
||||
visualElement.RegisterCallback<PointerLeaveEvent>(OnLeave);
|
||||
return;
|
||||
|
||||
void OnLeave(PointerLeaveEvent evt)
|
||||
{
|
||||
if (string.IsNullOrEmpty(visualElement.tooltip) is false)
|
||||
visualElement.tooltip = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
public static void BlinkingCursor(this TextField tf,int interval=1000)
|
||||
{
|
||||
tf.schedule.Execute(() =>
|
||||
{
|
||||
if(tf.ClassListContains("transparentCursor"))
|
||||
tf.RemoveFromClassList("transparentCursor");
|
||||
else
|
||||
tf.AddToClassList("transparentCursor");
|
||||
}).Every(interval);
|
||||
}
|
||||
public static Vector2 GetAbsolutePositionInUI(this VisualElement element)
|
||||
{
|
||||
var position = Vector2.zero;
|
||||
var currentElement = element;
|
||||
|
||||
// 遍历每一个父元素,并累计位置
|
||||
while (currentElement != null)
|
||||
{
|
||||
var style = currentElement.resolvedStyle;
|
||||
|
||||
// 累加该元素相对于父元素的位置
|
||||
position.x += style.left;
|
||||
position.y += style.top;
|
||||
|
||||
// 移动到父元素
|
||||
currentElement = currentElement.parent;
|
||||
}
|
||||
|
||||
return position;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user