Skip to content

Commit 627147e

Browse files
authored
[ME] Remove label from toggle if label string is empty (#351)
Mainly remove invisible yet clickable label from "persist search" toggle that ends up somewhere near close button
1 parent a818abf commit 627147e

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/UIUtility/UIUtility.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -206,13 +206,18 @@ public static Toggle CreateToggle(string objectName = "New Toggle", Transform pa
206206
go.name = objectName;
207207

208208
Text text = go.GetComponentInChildren<Text>(true);
209-
text.font = defaultFont;
210-
text.resizeTextForBestFit = true;
211-
text.resizeTextMinSize = 2;
212-
text.resizeTextMaxSize = 100;
213-
text.alignment = TextAnchor.MiddleCenter;
214-
text.rectTransform.SetRect(Vector2.zero, Vector2.one, new Vector2(23f, 1f), new Vector2(-5f, -2f));
215-
text.text = label;
209+
if (string.IsNullOrEmpty(label))
210+
Object.Destroy(text.gameObject);
211+
else
212+
{
213+
text.font = defaultFont;
214+
text.resizeTextForBestFit = true;
215+
text.resizeTextMinSize = 2;
216+
text.resizeTextMaxSize = 100;
217+
text.alignment = TextAnchor.MiddleCenter;
218+
text.rectTransform.SetRect(Vector2.zero, Vector2.one, new Vector2(23f, 1f), new Vector2(-5f, -2f));
219+
text.text = label;
220+
}
216221
go.transform.SetParent(parent, false);
217222

218223
return go.GetComponent<Toggle>();

0 commit comments

Comments
 (0)