void showTooltip() { if (GUI.tooltip.Equals("") || floatingItem != null) { return; } float mouseX = Input.mousePosition.x; float mouseY = Screen.height - Input.mousePosition.y; GUIStyle style = skin.GetStyle("tooltip"); float height = style.CalcHeight(new GUIContent(GUI.tooltip), 190f); float maxWidth = 0; float minWidth = 0; style.CalcMinMaxWidth(new GUIContent(GUI.tooltip), out minWidth, out maxWidth); float yOffset = 0; float xOffset = 0; if (mouseY + height > Screen.height) { yOffset = mouseY + height - Screen.height; } if (mouseX + 210 > Screen.width) { xOffset = 220; } if (mouseX + maxWidth + 18 > Screen.width) { xOffset = maxWidth + 31; } else { xOffset = 0; } int nameLength = GUI.tooltip.IndexOf('\n'); if (nameLength > -1) { string itemName = GUI.tooltip.Substring(0, nameLength); string description = GUI.tooltip.Replace(itemName + '\n', ""); GUI.Box(new Rect(mouseX + 11 - xOffset, mouseY - yOffset - 7, maxWidth + 18, height + 14), ""); GUI.Label(new Rect(mouseX + 20 - xOffset, mouseY - yOffset, 160, 23), itemName, "tooltip"); skin.FindStyle("tooltip").normal.textColor = Color.yellow; GUI.Label(new Rect(mouseX + 20 - xOffset, mouseY + 17 - yOffset, 160, height - 23), description, "tooltip"); skin.FindStyle("tooltip").normal.textColor = new Color(203f / 255f, 220f / 255f, 220f / 255f); } else { GUI.Box(new Rect(mouseX + 11 - xOffset, mouseY - yOffset - 7, maxWidth + 18, height + 14), ""); GUI.Label(new Rect(mouseX + 20 - xOffset, mouseY - yOffset, 190, height), GUI.tooltip, "tooltip"); } }
private float GetTabWidth(GUIStyle tabStyle, EditorWindow tabWindow) { float minWidth, expectedWidth; tabStyle.CalcMinMaxWidth(tabWindow.titleContent, out minWidth, out expectedWidth); return(Mathf.Max(Mathf.Min(expectedWidth, Styles.tabMaxWidth), Styles.tabMinWidth) + Styles.tabWidthPadding); }
public static void CalcGUIContentSize(GUIContent content, GUIStyle style, out float width, out float height) { float minWidth; float maxWidth; //GetPadding(); style.CalcMinMaxWidth(content, out minWidth, out maxWidth); float threshold = 250; if (maxWidth < threshold) { style.wordWrap = false; Vector2 size = style.CalcSize(content); style.wordWrap = true; maxWidth = size.x; } width = Mathf.Clamp(maxWidth, 0, threshold); height = Mathf.Clamp(style.CalcHeight(content, width), 21, 150); //Debug.LogWarning(string.Format("min: {0}, max: {1} => w: {2}, isHeightDependentonwidht: {3}", minWidth, maxWidth, width, style)); //SetPadding(l, t, r, b); }
// Unity api is insufficient. Time for hacks. /// <summary> /// returns fitting size of the wrapped text /// </summary> /// <param name="style">used style</param> /// <param name="content">content with text to measure</param> /// <param name="size">size to fit</param> /// <returns>fitting size</returns> public static Vector2 CalcSize(this GUIStyle style, GUIContent content, Vector2 size) { if (!style.wordWrap) { return(style.CalcSize(content)); } else { float lower = 0; float upper = 0; style.CalcMinMaxWidth(content, out lower, out upper); if (Prefs.UIScale != 1.0) // fix of upper size being too small { var v2 = style.CalcSize(content); upper = Mathf.Max(upper, v2.x); } // TODO: invalid CalcMinMaxWidth result // hypothesize: CalcMinMaxWidth uses different font texture to calc size. // question: Why single character ('G') is wrapped? // Maybe it is possimle to create custom GUIStyle with custom font fitting actual size? var x = Mathf.Min(upper, size.x); var result = new Vector2(x, style.CalcHeight(content, x)); return(result); } }
private GUILayoutOption MinWidth(string text, GUIStyle style) { GUIContent content = new GUIContent(text); style.CalcMinMaxWidth(content, out float minWidth, out float maxWidth); return(GUILayout.Width(minWidth)); }
/************************************************************************************************************************/ /// <summary> /// Calls <see cref="GUIStyle.CalcMinMaxWidth"/> and returns the max width. /// </summary> public static float CalculateWidth(this GUIStyle style, GUIContent content) { float _, width; style.CalcMinMaxWidth(content, out _, out width); return(width); }
private static void ShowTooltip() { if (!string.IsNullOrEmpty(_tooltipText) && (DateTime.UtcNow - _tooltipBeginDt).TotalMilliseconds > TooltipShowDelay) { if (_isTooltipChanged) { var c = new GUIContent(_tooltipText); _tooltipStyle.CalcMinMaxWidth(c, out _, out float width); width = Math.Min(width, TooltipMaxWidth); float height = _tooltipStyle.CalcHeight(c, TooltipMaxWidth); _tooltipRect = new Rect( Input.mousePosition.x + 15, Screen.height - Input.mousePosition.y + 10, width, height); _isTooltipChanged = false; } int id = WindowHelper.NextWindowId("DrawTooltipWindow"); GUI.Window( id, _tooltipRect, (_) => { }, _tooltipText, _tooltipStyle); GUI.BringWindowToFront(id); } }
void OnGUI() { CustomSkin = Resources.Load <GUISkin> ("CustomSkin") as GUISkin; if (CustomSkin != null) { Debug.Log("Not null" + CustomSkin.ToString()); } GUI.skin = CustomSkin; GUILayout.Button("Testing Button Custom Skin"); GUI.skin = null; GUILayout.Button("Default Button"); GUIStyle a = (new GUIStyle("Label")); a.CalcMinMaxWidth(new GUIContent("Player "), out size, out temp); //a.fixedHeight = 250; a.alignment = TextAnchor.MiddleCenter; GUILayout.Label("Test"); GUILayout.Box("BOX", a); OnGUILayoutLabel(); //OnEditorGUILayoutLabel (); GUILayout.BeginVertical("Box"); selGridInt = GUILayout.SelectionGrid(selGridInt, selStrings, 2); if (GUILayout.Button("Start")) { Debug.Log("You chose " + selStrings[selGridInt]); } GUILayout.EndVertical(); }
/// <summary> /// Calculates text height by ignoring bold style of the font. This will not work with inline bold tags. /// NOTE: This will not fix occasional new line when text ends right before end. /// </summary> /// <param name="content">Text content.</param> /// <param name="style">Text style.</param> /// <param name="width">Fixed width of text container.</param> /// <returns>Returns calculated height of the text.</returns> public static float CalculateHeight(GUIContent content, GUIStyle style, float width) { float height; // Bold fonts have much higher chance of having one new line to many than normal font. // There were no issues with missing new lines even with couple of extreme cases. (but extra new lines can occur) if (style.fontStyle == FontStyle.Bold) { style.fontStyle = FontStyle.Normal; style.wordWrap = true; style.fixedWidth = width; style.fixedHeight = 0; Texture2D t = new Texture2D(1, 1); content.image = t; style.imagePosition = ImagePosition.ImageLeft; float min, max; style.CalcMinMaxWidth(content, out min, out max); style.clipping = TextClipping.Overflow; height = style.CalcHeight(content, min); style.fontStyle = FontStyle.Bold; } else { height = style.CalcHeight(content, width); } return(height); }
public static bool LayoutButtonLink(GUIContent content, params GUILayoutOption[] options) { var controlId = GUIUtility.GetControlID(FocusType.Passive) + 1; // @Hack, predicting the next control id... may not always work. var clicked = GUILayout.Button(content, linkStyle, options); var rect = GUILayoutUtility.GetLastRect(); var widthOffset = 0f; var widthContent = content; if (content.image != null) { widthContent = new GUIContent(content.text); widthOffset = EditorGUIUtility.GetIconSize().x; } float min, max; linkStyle.CalcMinMaxWidth(widthContent, out min, out max); var start = new Vector2(rect.x + 2 + widthOffset, rect.y + rect.height - 2); var end = new Vector2(rect.x - 2 + min + widthOffset, start.y); var color = linkStyle.normal.textColor; if (GUIUtility.hotControl == controlId) { color = linkStyle.active.textColor; } Handles.BeginGUI(); Handles.color = color; Handles.DrawLine(start, end); Handles.EndGUI(); return(clicked); }
public static GUILayoutOption[] CalcMinMaxWidth(GUIContent content, GUIStyle style) { float minWidth, maxWidth; style.CalcMinMaxWidth(content, out minWidth, out maxWidth); return(new[] { GUILayout.MinWidth(minWidth), GUILayout.MaxWidth(maxWidth) }); }
public override Vector2 GetWindowSize() { GUIStyle style = menuStyle; if (style == null) { return(Vector2.one); } float windowHeight; if (showExtraOptions) { windowHeight = 2f * kFrameWidth + kSingleLineHeight * flags.lines; } else { windowHeight = 2f * kFrameWidth + kSingleLineHeight * flags.flagValues.Length; } float width = 0; for (int i = 0; i < flags.flagContents.Length; i++) { float minWidth; float maxWidth; style.CalcMinMaxWidth(flags.flagContents[i], out minWidth, out maxWidth); width = Mathf.Max(minWidth, width); } var windowSize = new Vector2(width + 4, windowHeight); return(windowSize); }
public static void Hyperlink(string Label, string Url, GUIStyle gsBase) { if (GUILayout.Button(Label, gsBase)) { Application.OpenURL(Url); } Rect r = GUILayoutUtility.GetLastRect(); float mw, Mw; float h = gsBase.CalcHeight(new GUIContent(Label), r.width) - gsBase.padding.top - gsBase.padding.bottom; gsBase.CalcMinMaxWidth(new GUIContent(Label), out mw, out Mw); //Vector2 v = gsBase.CalcSize(new GUIContent(Label)); Rect nr = new Rect( r.x + gsBase.padding.left, r.y + gsBase.padding.top + h, Mw - gsBase.padding.left - gsBase.padding.right, 1); Color oldC = GUI.color; GUI.color = gsBase.normal.textColor; GUI.DrawTexture(nr, wHiteTex); GUI.color = oldC; #if UNITY_EDITOR UnityEditor.EditorGUIUtility.AddCursorRect(r, UnityEditor.MouseCursor.Link); #endif }
public static float CalcMaxWidth(this GUIStyle style, GUIContent content) { float min, max; style.CalcMinMaxWidth(content, out min, out max); return(max); }
private static float CalcMinWidth(GUIStyle style, string str, float redundant = 0) { float min, max; style.CalcMinMaxWidth(GUIContents.Temp1(str), out min, out max); return(min + redundant); }
void DrawToolTip(string tooltipText) { if (tooltipText != lastTooltip) { hoverTime = 0; } if (lastTooltip == tooltipText && Event.current.type == EventType.Repaint && tooltipText != "") { hoverTime += Time.deltaTime; } lastTooltip = tooltipText; if (tooltipText == "" || hoverTime < 0.5f) { return; } //Log.Info(tooltipText); GUIContent tooltip = new GUIContent(tooltipText); Rect tooltipPosition = new Rect(mousePos.x + 15, mousePos.y + 15, 0, 0); float maxw, minw; tooltipStyle.CalcMinMaxWidth(tooltip, out minw, out maxw); tooltipPosition.width = Math.Min(Math.Max(200, minw), maxw); tooltipPosition.height = tooltipStyle.CalcHeight(tooltip, tooltipPosition.width); GUI.Label(/*new Rect(EditorPanels.Instance.partsPanelWidth + 5, Screen.height - 60, 100, 60)*/ tooltipPosition, tooltip, tooltipStyle); GUI.depth = 0; }
private static Vector2 CalcLineWrappedContentSize(GUIContent content, GUIStyle guiStyle) { float num; float num2; guiStyle.CalcMinMaxWidth(content, out num, out num2); return(new Vector2(num2, guiStyle.CalcHeight(content, num2))); }
public static float GetMinWidth(GUIContent content, GUIStyle style = null) { style = style != null ? style : GUI.skin.label; float min, max; style.CalcMinMaxWidth(content, out min, out max); return(min); }
public void DrawWindow(int windowId, DebugConsole debugConsole) { labelStyle = GUI.skin.label; this.innerRect.height = this.innerHeight < debugConsole.ScrollRect.height ? debugConsole.ScrollRect.height : this.innerHeight; this.scrollPosition = GUI.BeginScrollView(debugConsole.ScrollRect, this.scrollPosition, this.innerRect, false, true); this.nameRect.x = this.messageLine.x; this.nameRect.y = this.valueRect.y = 0; float totalWidth = this.messageLine.width - this.messageLine.x; float nameMin, nameMax, valueMin, valueMax, stepHeight; GUIStyle textAreaStyle = GUI.skin.textArea; foreach (var watchvar in debugConsole.WatchVars) { GUIContent nameContent = new GUIContent(String.Format("{0}:", watchvar.Value.Name)); GUIContent valueContent = new GUIContent(watchvar.Value.ToString()); this.labelStyle.CalcMinMaxWidth(nameContent, out nameMin, out nameMax); textAreaStyle.CalcMinMaxWidth(valueContent, out valueMin, out valueMax); if (nameMax > totalWidth) { this.nameRect.width = totalWidth - valueMin; this.valueRect.width = valueMin; } else if (valueMax + nameMax > totalWidth) { this.nameRect.width = nameMin; this.valueRect.width = totalWidth - nameMin; } else { this.nameRect.width = nameMax; this.valueRect.width = valueMax; } this.nameRect.height = this.labelStyle.CalcHeight(nameContent, this.nameRect.width); this.valueRect.height = textAreaStyle.CalcHeight(valueContent, this.valueRect.width); this.valueRect.x = totalWidth - this.valueRect.width + this.nameRect.x; GUI.Label(this.nameRect, nameContent); GUI.TextArea(this.valueRect, valueContent.text); stepHeight = Mathf.Max(this.nameRect.height, this.valueRect.height) + 4; this.nameRect.y += stepHeight; this.valueRect.y += stepHeight; this.innerHeight = this.valueRect.y > debugConsole.ScrollRect.height ? (int)this.valueRect.y : (int)debugConsole.ScrollRect.height; } GUI.EndScrollView(); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { EditorGUI.BeginProperty(position, label, property); SerializedProperty minProp = property.FindPropertyRelative("MinValue"); SerializedProperty maxProp = property.FindPropertyRelative("MaxValue"); position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label); Rect drawRect = position; bool drawLabels = position.width > 200; int oldIndentLevel = EditorGUI.indentLevel; EditorGUI.indentLevel = 0; GUIStyle labelStyle = new GUIStyle(GUI.skin.label); if (drawLabels) { float minWidth, maxWidth = 0; labelStyle.CalcMinMaxWidth(new GUIContent("Min"), out minWidth, out maxWidth); drawRect.width = minWidth; EditorGUI.LabelField(drawRect, "Min", labelStyle); drawRect.x += drawRect.width + 5; } drawRect.width = 50; EditorGUI.PropertyField(drawRect, minProp, GUIContent.none); drawRect.x += drawRect.width + 10; if (drawLabels) { float minWidth, maxWidth = 0; labelStyle.CalcMinMaxWidth(new GUIContent("Max"), out minWidth, out maxWidth); drawRect.width = minWidth; EditorGUI.LabelField(drawRect, "Max", labelStyle); drawRect.x += drawRect.width + 5; } drawRect.width = 50; EditorGUI.PropertyField(drawRect, maxProp, GUIContent.none); EditorGUI.indentLevel = oldIndentLevel; EditorGUI.EndProperty(); }
private float GetTabWidth(GUIStyle tabStyle, int tabIndex) { Debug.Assert(0 <= tabIndex && tabIndex < m_Panes.Count); float minWidth, expectedWidth; tabStyle.CalcMinMaxWidth(m_Panes[tabIndex].titleContent, out minWidth, out expectedWidth); return(Mathf.Max(Mathf.Min(expectedWidth, Styles.tabMaxWidth), Styles.tabMinWidth) + Styles.tabWidthPadding); }
private static Rect GetSliderRect(GUIContent label, GUIStyle style, params GUILayoutOption[] options) { float minLabelW = 0, maxLabelW = 0; if (label != GUIContent.none) { style.CalcMinMaxWidth(label, out minLabelW, out maxLabelW); } return(GUILayoutUtility.GetRect(getFieldWidth() + minLabelW + 5, getFieldWidth() + maxLabelW + 5 + 100, textFieldHeight, textFieldHeight, options)); }
public static float GetTextWidth(string s, GUIStyle style) { float min, max; GUIContent content = new GUIContent(s); style.CalcMinMaxWidth(content, out min, out max); return(max); }
private static Rect GetSliderRect(GUIContent label, GUIStyle style, params GUILayoutOption[] options) { float minWidth = 0f; float maxWidth = 0f; if (label != GUIContent.none) { style.CalcMinMaxWidth(label, out minWidth, out maxWidth); } return(GUILayoutUtility.GetRect(getFieldWidth() + minWidth + 5f, getFieldWidth() + maxWidth + 5f + 100f, textFieldHeight, textFieldHeight, options)); }
private static float CalculateContentMaxWidth(GUIStyle rowStyle, IEnumerable <GUIContent> guiContents) { var maxWidth = 0f; foreach (var guiContent in guiContents) { float min, max; rowStyle.CalcMinMaxWidth(guiContent, out min, out max); maxWidth = Mathf.Max(maxWidth, max); } return(maxWidth); }
private void WatchVarWindow(int windowID) { GUI.Box(this.scrollRect, string.Empty); this.innerRect.height = (((float)this.innerHeight >= this.scrollRect.height) ? ((float)this.innerHeight) : this.scrollRect.height); this._watchVarsScrollPos = GUI.BeginScrollView(this.scrollRect, this._watchVarsScrollPos, this.innerRect, false, true); int num = 0; float y = 0f; this.valueRect.y = y; this.nameRect.y = y; this.nameRect.x = this.messageLine.x; float num2 = this.messageLine.width - this.messageLine.x; GUIStyle textArea = GUI.skin.textArea; foreach (KeyValuePair <string, WatchVarBase> current in this._watchVarTable) { GUIContent content = new GUIContent(string.Format("{0}:", current.Value.Name)); GUIContent gUIContent = new GUIContent(current.Value.ToString()); float num3; float num4; this.labelStyle.CalcMinMaxWidth(content, out num3, out num4); float num5; float num6; textArea.CalcMinMaxWidth(gUIContent, out num5, out num6); if (num4 > num2) { this.nameRect.width = num2 - num5; this.valueRect.width = num5; } else if (num6 + num4 > num2) { this.valueRect.width = num2 - num3; this.nameRect.width = num3; } else { this.valueRect.width = num6; this.nameRect.width = num4; } this.nameRect.height = this.labelStyle.CalcHeight(content, this.nameRect.width); this.valueRect.height = textArea.CalcHeight(gUIContent, this.valueRect.width); this.valueRect.x = num2 - this.valueRect.width + this.nameRect.x; GUI.Label(this.nameRect, content); GUI.TextArea(this.valueRect, gUIContent.text); float num7 = Mathf.Max(this.nameRect.height, this.valueRect.height) + 4f; this.nameRect.y = this.nameRect.y + num7; this.valueRect.y = this.valueRect.y + num7; this.innerHeight = ((this.valueRect.y <= this.scrollRect.height) ? ((int)this.scrollRect.height) : ((int)this.valueRect.y)); num++; } GUI.EndScrollView(); this.DrawBottomControls(); }
private void UpdateElementIndexLabelStyle() { // Clear fixed width and update it based on widest content _elementIndexLabelStyle.fixedWidth = 0; float minWidth, _; int finalIndex = List.count - 1; var content = new GUIContent(finalIndex.ToString()); _elementIndexLabelStyle.CalcMinMaxWidth(content, out minWidth, out _); _elementIndexLabelStyle.fixedWidth = minWidth; }
private void ESP_Gui() { if (m_enabled) { if (!m_styleSetup) { SetupStyle(); m_styleSetup = !m_styleSetup; } foreach (Player p in m_players) { if (p == null || p.ApiUser() == null) { continue; } string CleanPlayerName(string name) { name = name.Replace("VRCPlayer[Local]", "").Replace("VRCPlayer[Remote]", ""); List <string> nameParts = name.Split(' ').ToList(); nameParts.RemoveAt(nameParts.Count() - 1); name = string.Join(" ", nameParts.ToArray()); return(name); } string targetName = CleanPlayerName(p.name); // draw player tag Vector3 pos = p.transform.position; Vector3 playerPosScreen = VRCVrCamera.GetInstance().screenCamera.WorldToScreenPoint(pos); float newY = InvertY(playerPosScreen.y); if (playerPosScreen.z <= 0) { continue; } Color newColour = GetGroupColour(p); m_style.normal.background = m_texture; m_style.CalcMinMaxWidth(new GUIContent(targetName), out float minWidth, out float maxWidth); m_style.normal.textColor = newColour; GUI.Label(new Rect(playerPosScreen.x - (maxWidth / 2), newY, maxWidth + 10, 30), targetName, m_style); } } }
public static float GetStyleHeight(this GUIStyle style, string text) { float max; float min; var content = new GUIContent(text); style.CalcMinMaxWidth(content, out min, out max); return (style.padding.top + style.padding.bottom + style.CalcHeight(content, max)); }
public static float GetStyleWith(this GUIStyle style, string text) { float max; float min; style.CalcMinMaxWidth(new GUIContent(text), out min, out max); return (style.padding.left + style.padding.right + style.border.left + style.border.right + max); }