private void DoRulerLabelGUI(ref Rect previousArea, float time) { if (_RulerLabelStyle == null) { _RulerLabelStyle = new GUIStyle(GUI.skin.label) { padding = new RectOffset(), contentOffset = new Vector2(0, -2), alignment = TextAnchor.UpperLeft, fontSize = Mathf.CeilToInt(AnimancerGUI.LineHeight * 0.6f), } } ; var text = G2Cache.Convert(time); if (_TimeLabelWidthCache == null) { _TimeLabelWidthCache = AnimancerGUI.CreateWidthCache(_RulerLabelStyle); } var area = new Rect( SecondsToPixels(time), _Area.y, _TimeLabelWidthCache.Convert(text), _Area.height); if (area.x > _Area.x) { var tickY = _Area.yMax - TickHeight; EditorGUI.DrawRect(new Rect(area.x, tickY, 1, TickHeight), AnimancerGUI.TextColor); } if (area.xMax > _Area.xMax) { area.x = _Area.xMax - area.width; } if (area.x < 0) { area.x = 0; } if (area.x > previousArea.xMax + 2) { GUI.Label(area, text, _RulerLabelStyle); previousArea = area; } } /************************************************************************************************************************/ #endregion /************************************************************************************************************************/ }
/************************************************************************************************************************/ /// <summary>Calculate the index of the cache to use for the given parameters.</summary> private int CalculateCacheIndex(float value, float width) { //if (value > LargeExponentialThreshold || // value < -LargeExponentialThreshold) // return 0; var valueString = value.ToStringCached(); // It the approximated string wouldn't be shorter than the original, don't approximate. if (valueString.Length < 2 + ApproximateSuffix.Length) { return(0); } if (_SuffixWidth == 0) { if (_WidthCache == null) { _WidthCache = AnimancerGUI.CreateWidthCache(EditorStyles.numberField); _FieldPadding = EditorStyles.numberField.padding.horizontal; _ApproximateSymbolWidth = _WidthCache.Convert("~") - _FieldPadding; } _SuffixWidth = _WidthCache.Convert(Suffix); } // If the field is wide enough to fit the full value, don't approximate. width -= _FieldPadding + _ApproximateSymbolWidth * 0.75f; var valueWidth = _WidthCache.Convert(valueString) + _SuffixWidth; if (valueWidth <= width) { return(0); } // If the number of allowed characters would include the full value, don't approximate. var suffixedLength = valueString.Length + Suffix.Length; var allowedCharacters = (int)(suffixedLength * width / valueWidth); if (allowedCharacters + 2 >= suffixedLength) { return(0); } return(allowedCharacters); }
private void DoRulerLabelGUI(ref Rect previousArea, float time) { var text = G2Cache.Convert(time); if (_TimeLabelWidthCache == null) { _TimeLabelWidthCache = AnimancerGUI.CreateWidthCache(Styles.TimeLabel); } var area = new Rect( SecondsToPixels(time), _Area.y, _TimeLabelWidthCache.Convert(text), _Area.height); if (area.x > _Area.x) { var tickHeight = _Area.height * TickHeight; var tickY = _Area.yMax - tickHeight; EditorGUI.DrawRect(new Rect(area.x, tickY, 1, tickHeight), AnimancerGUI.TextColor); } if (area.xMax > _Area.xMax) { area.x = _Area.xMax - area.width; } if (area.x < 0) { area.x = 0; } if (area.x > previousArea.xMax + 2) { GUI.Label(area, text, Styles.TimeLabel); previousArea = area; } }