Skip to content

Commit

Permalink
Merge pull request #18 from Haruma-K/feature/improve_tmppro
Browse files Browse the repository at this point in the history
Add support for Auto Size Options of TMP.
  • Loading branch information
Haruma-K authored May 24, 2023
2 parents d7cc8b1 + d50b954 commit 0226aa0
Show file tree
Hide file tree
Showing 13 changed files with 420 additions and 71 deletions.
45 changes: 45 additions & 0 deletions Assets/Demo/PaletteStore.asset
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ MonoBehaviour:
fontStyle: 1
fontSize: 48
enableAutoSizing: 0
enableAutoSizeOptions: 1
fontSizeMin: 18
fontSizeMax: 72
characterWidthAdjustment: 0
lineSpacingAdjustment: 0
characterSpacing: 0
wordSpacing: 0
lineSpacing: 0
Expand All @@ -215,6 +220,11 @@ MonoBehaviour:
fontStyle: 1
fontSize: 48
enableAutoSizing: 0
enableAutoSizeOptions: 1
fontSizeMin: 18
fontSizeMax: 72
characterWidthAdjustment: 0
lineSpacingAdjustment: 0
characterSpacing: 0
wordSpacing: 0
lineSpacing: 0
Expand All @@ -224,6 +234,11 @@ MonoBehaviour:
fontStyle: 1
fontSize: 48
enableAutoSizing: 0
enableAutoSizeOptions: 1
fontSizeMin: 18
fontSizeMax: 72
characterWidthAdjustment: 0
lineSpacingAdjustment: 0
characterSpacing: 0
wordSpacing: 0
lineSpacing: 0
Expand All @@ -242,6 +257,11 @@ MonoBehaviour:
fontStyle: 32
fontSize: 136.1
enableAutoSizing: 0
enableAutoSizeOptions: 1
fontSizeMin: 18
fontSizeMax: 72
characterWidthAdjustment: 0
lineSpacingAdjustment: 0
characterSpacing: 0
wordSpacing: 0
lineSpacing: 0
Expand All @@ -251,6 +271,11 @@ MonoBehaviour:
fontStyle: 32
fontSize: 134.7
enableAutoSizing: 0
enableAutoSizeOptions: 1
fontSizeMin: 18
fontSizeMax: 72
characterWidthAdjustment: 0
lineSpacingAdjustment: 0
characterSpacing: 15.6
wordSpacing: 0
lineSpacing: 0
Expand All @@ -260,6 +285,11 @@ MonoBehaviour:
fontStyle: 33
fontSize: 162.84
enableAutoSizing: 0
enableAutoSizeOptions: 1
fontSizeMin: 18
fontSizeMax: 72
characterWidthAdjustment: 0
lineSpacingAdjustment: 0
characterSpacing: 3.78
wordSpacing: 0
lineSpacing: 0
Expand All @@ -278,6 +308,11 @@ MonoBehaviour:
fontStyle: 32
fontSize: 80
enableAutoSizing: 0
enableAutoSizeOptions: 1
fontSizeMin: 18
fontSizeMax: 72
characterWidthAdjustment: 0
lineSpacingAdjustment: 0
characterSpacing: 0
wordSpacing: 0
lineSpacing: 0
Expand All @@ -287,6 +322,11 @@ MonoBehaviour:
fontStyle: 32
fontSize: 80.83
enableAutoSizing: 0
enableAutoSizeOptions: 1
fontSizeMin: 18
fontSizeMax: 72
characterWidthAdjustment: 0
lineSpacingAdjustment: 0
characterSpacing: 10.9
wordSpacing: 0
lineSpacing: 0
Expand All @@ -296,6 +336,11 @@ MonoBehaviour:
fontStyle: 33
fontSize: 80
enableAutoSizing: 0
enableAutoSizeOptions: 1
fontSizeMin: 18
fontSizeMax: 72
characterWidthAdjustment: 0
lineSpacingAdjustment: 0
characterSpacing: 5.05
wordSpacing: 0
lineSpacing: 0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using TMPro;
using UnityEditor;
using UnityEngine;
using uPalette.Editor.Core.Updater;
Expand Down Expand Up @@ -81,6 +82,30 @@ public override void OnGUI(string searchContext)
EditorGUILayout.HelpBox(
$"\"Automatic Runtime Data Loading\" is turned off, so you must load the \"{nameof(PaletteStore)}\" manually before loading GUIs that use uPalette.",
MessageType.Warning);

// This is an implementation for backward compatibility.
var message =
"Enable TextMeshPro Auto Size Options for all data and set the initial value for each option. Is it OK?";
if (GUILayout.Button("Enable TextMeshPro Auto Size Options")
&& EditorUtility.DisplayDialog("Enable TextMeshPro Auto Size Options", message, "OK", "Cancel"))
{
foreach (var entry in store.CharacterStyleTMPPalette.Entries.Values)
foreach (var value in entry.Values.Values)
{
if (value.Value.enableAutoSizeOptions)
continue;

var style = value.Value;
style.enableAutoSizeOptions = true;
style.fontSizeMin = TMP_Settings.defaultFontSize * TMP_Settings.defaultTextAutoSizingMinRatio;
style.fontSizeMax = TMP_Settings.defaultFontSize * TMP_Settings.defaultTextAutoSizingMaxRatio;
style.characterWidthAdjustment = 0.0f;
style.lineSpacingAdjustment = 0.0f;
value.Value = style;
}

EditorUtility.SetDirty(store);
}
}
}

Expand Down
8 changes: 7 additions & 1 deletion Assets/uPalette/Editor/Core/ThemeEditor.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ private void OnGUI()
var fontStyleDisplayName = ObjectNames.NicifyVariableName(nameof(_characterStyle.fontStyle));
var fontSizeDisplayName = ObjectNames.NicifyVariableName(nameof(_characterStyle.fontSize));
var enableAutoSizingDisplayName = "Auto Size";
var fontSizeMinDisplayName = "Min";
var fontSizeMaxDisplayName = "Max";
var characterWidthAdjustmentDisplayName = "WD%";
var lineSpacingAdjustmentDisplayName = "Line";
var characterSpacingDisplayName = "Character";
var wordSpacingDisplayName = "Word";
var lineSpacingDisplayName = "Line";
Expand All @@ -34,6 +38,23 @@ private void OnGUI()
EditorGUI.indentLevel++;
_characterStyle.enableAutoSizing =
EditorGUILayout.Toggle(enableAutoSizingDisplayName, _characterStyle.enableAutoSizing);
if (_characterStyle.enableAutoSizing)
{
GUI.enabled = _characterStyle.enableAutoSizeOptions;
EditorGUI.indentLevel++;
var min = EditorGUILayout.FloatField(fontSizeMinDisplayName, _characterStyle.fontSizeMin);
_characterStyle.fontSizeMin = Mathf.Min(min, _characterStyle.fontSizeMax);
var max = EditorGUILayout.FloatField(fontSizeMaxDisplayName, _characterStyle.fontSizeMax);
_characterStyle.fontSizeMax = Mathf.Max(max, _characterStyle.fontSizeMin);
var wd = EditorGUILayout.FloatField(characterWidthAdjustmentDisplayName,
_characterStyle.characterWidthAdjustment);
_characterStyle.characterWidthAdjustment = Mathf.Max(wd, 0.0f);
var line = EditorGUILayout.FloatField(lineSpacingAdjustmentDisplayName,
_characterStyle.lineSpacingAdjustment);
_characterStyle.lineSpacingAdjustment = Mathf.Min(line, 0.0f);
EditorGUI.indentLevel--;
GUI.enabled = true;
}
EditorGUI.indentLevel--;
EditorGUILayout.LabelField("Spacing Options (em)");
EditorGUI.indentLevel++;
Expand Down Expand Up @@ -113,6 +134,19 @@ private static float GetHeight()
// Enable Auto Sizing
height += EditorGUIUtility.singleLineHeight;
height += EditorGUIUtility.standardVerticalSpacing;
// Min Font Size
height += EditorGUIUtility.singleLineHeight;
height += EditorGUIUtility.standardVerticalSpacing;
// Max Font Size
height += EditorGUIUtility.singleLineHeight;
height += EditorGUIUtility.standardVerticalSpacing;
// Character Width Adjustment
height += EditorGUIUtility.singleLineHeight;
height += EditorGUIUtility.standardVerticalSpacing;
// Line Spacing Adjustment
height += EditorGUIUtility.singleLineHeight;
height += EditorGUIUtility.standardVerticalSpacing;

// Spacing Option Titles
height += EditorGUIUtility.singleLineHeight;
height += EditorGUIUtility.standardVerticalSpacing;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ protected internal override Foundation.CharacterStyles.CharacterStyleTMP GetValu
{
font = Component.font,
fontStyle = Component.fontStyle,
fontSize = Component.fontSize,
enableAutoSizing = Component.enableAutoSizing,
fontSize = Component.fontSize,
fontSizeMin = Component.fontSizeMin,
fontSizeMax = Component.fontSizeMax,
characterWidthAdjustment = Component.characterWidthAdjustment,
lineSpacingAdjustment = Component.lineSpacingAdjustment,
characterSpacing = Component.characterSpacing,
wordSpacing = Component.wordSpacing,
lineSpacing = Component.lineSpacing,
Expand All @@ -28,8 +32,15 @@ protected internal override void SetValue(Foundation.CharacterStyles.CharacterSt
{
Component.font = value.font;
Component.fontStyle = value.fontStyle;
Component.fontSize = value.fontSize;
Component.enableAutoSizing = value.enableAutoSizing;
Component.fontSize = value.fontSize;
if (value.enableAutoSizeOptions)
{
Component.fontSizeMin = value.fontSizeMin;
Component.fontSizeMax = value.fontSizeMax;
Component.characterWidthAdjustment = value.characterWidthAdjustment;
Component.lineSpacingAdjustment = value.lineSpacingAdjustment;
}
Component.characterSpacing = value.characterSpacing;
Component.wordSpacing = value.wordSpacing;
Component.lineSpacing = value.lineSpacing;
Expand All @@ -43,16 +54,22 @@ protected override bool EqualsToCurrentValue(Foundation.CharacterStyles.Characte
return false;
}

if (Component.fontStyle != value.fontStyle
|| Component.fontSize != value.fontSize
|| Component.enableAutoSizing != value.enableAutoSizing
|| Component.characterSpacing != value.characterSpacing
|| Component.wordSpacing != value.wordSpacing
|| Component.lineSpacing != value.lineSpacing
|| Component.paragraphSpacing != value.paragraphSpacing)
return false;
var isNotEquals = Component.fontStyle != value.fontStyle
|| Component.enableAutoSizing != value.enableAutoSizing
|| Component.fontSize != value.fontSize
|| Component.characterSpacing != value.characterSpacing
|| Component.wordSpacing != value.wordSpacing
|| Component.lineSpacing != value.lineSpacing
|| Component.paragraphSpacing != value.paragraphSpacing;

if (value.enableAutoSizeOptions)
isNotEquals = isNotEquals
|| Component.fontSizeMin != value.fontSizeMin
|| Component.fontSizeMax != value.fontSizeMax
|| Component.characterWidthAdjustment != value.characterWidthAdjustment
|| Component.lineSpacingAdjustment != value.lineSpacingAdjustment;

return true;
return !isNotEquals;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ public struct CharacterStyleTMP
public FontStyles fontStyle;
public float fontSize;
public bool enableAutoSizing;

// For backward compatibility.
// Synchronize "Auto Size Options" of TextMesh Pro.
[SerializeField] internal bool enableAutoSizeOptions;

public float fontSizeMin;
public float fontSizeMax;
public float characterWidthAdjustment;
public float lineSpacingAdjustment;
public float characterSpacing;
public float wordSpacing;
public float lineSpacing;
Expand All @@ -28,8 +37,13 @@ public static CharacterStyleTMP Default
{
font = font,
fontStyle = 0,
fontSize = 36.0f,
enableAutoSizing = false,
fontSize = TMP_Settings.defaultFontSize,
enableAutoSizeOptions = true,
fontSizeMin = TMP_Settings.defaultFontSize * TMP_Settings.defaultTextAutoSizingMinRatio,
fontSizeMax = TMP_Settings.defaultFontSize * TMP_Settings.defaultTextAutoSizingMaxRatio,
characterWidthAdjustment = 0.0f,
lineSpacingAdjustment = 0.0f,
characterSpacing = 0.0f,
wordSpacing = 0.0f,
lineSpacing = 0.0f,
Expand Down
16 changes: 8 additions & 8 deletions Packages/manifest.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"dependencies": {
"com.unity.2d.sprite": "1.0.0",
"com.unity.collab-proxy": "1.3.9",
"com.unity.ide.rider": "3.0.12",
"com.unity.ide.visualstudio": "2.0.5",
"com.unity.ide.vscode": "1.2.3",
"com.unity.mobile.android-logcat": "1.2.1",
"com.unity.test-framework": "1.1.19",
"com.unity.textmeshpro": "3.0.1",
"com.unity.timeline": "1.3.6",
"com.unity.collab-proxy": "1.17.2",
"com.unity.ide.rider": "3.0.15",
"com.unity.ide.visualstudio": "2.0.16",
"com.unity.ide.vscode": "1.2.5",
"com.unity.mobile.android-logcat": "1.3.2",
"com.unity.test-framework": "1.1.31",
"com.unity.textmeshpro": "3.0.6",
"com.unity.timeline": "1.4.8",
"com.unity.ugui": "1.0.0",
"com.unity.modules.ai": "1.0.0",
"com.unity.modules.androidjni": "1.0.0",
Expand Down
Loading

0 comments on commit 0226aa0

Please sign in to comment.