-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "Gilzoide.FlexUi.Editor", | ||
"rootNamespace": "Gilzoide.FlexUi.Editor", | ||
"references": [ | ||
"GUID:f5764d172907845189231762597f67e6" | ||
], | ||
"includePlatforms": [ | ||
"Editor" | ||
], | ||
"excludePlatforms": [], | ||
"allowUnsafeCode": false, | ||
"overrideReferences": false, | ||
"precompiledReferences": [], | ||
"autoReferenced": true, | ||
"defineConstraints": [], | ||
"versionDefines": [], | ||
"noEngineReferences": false | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
using System; | ||
using Gilzoide.FlexUi.Yoga; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace Gilzoide.FlexUi.Editor | ||
{ | ||
[CustomPropertyDrawer(typeof(YGValue))] | ||
public class YGValuePropertyDrawer : PropertyDrawer | ||
{ | ||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) | ||
{ | ||
string value = GetValueAsString(property); | ||
string newValue = EditorGUI.DelayedTextField(position, label, value).ToLowerInvariant().Trim(); | ||
if (newValue == "auto") | ||
{ | ||
SetValue(property, YGValue.Auto); | ||
} | ||
else if (newValue == "" || newValue == "none" || newValue == "undefined") | ||
{ | ||
SetValue(property, YGValue.Undefined); | ||
} | ||
else if (newValue.EndsWith('%') && float.TryParse(newValue.Substring(0, newValue.Length - 1), out float percentValue)) | ||
{ | ||
SetValue(property, new YGValue(percentValue, Unit.Percent)); | ||
} | ||
else if (float.TryParse(newValue, out float pointValue)) | ||
{ | ||
SetValue(property, new YGValue(pointValue, Unit.Point)); | ||
} | ||
} | ||
|
||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) | ||
{ | ||
return EditorGUI.GetPropertyHeight(SerializedPropertyType.String, label); | ||
} | ||
|
||
private static string GetValueAsString(SerializedProperty property) | ||
{ | ||
int unit = property.FindPropertyRelative(nameof(YGValue.Unit)).enumValueIndex; | ||
float value = property.FindPropertyRelative(nameof(YGValue.Value)).floatValue; | ||
switch ((Unit) unit) | ||
{ | ||
case Unit.Undefined: | ||
return "none"; | ||
|
||
case Unit.Point: | ||
if (float.IsNaN(value)) | ||
{ | ||
return "none"; | ||
} | ||
else | ||
{ | ||
return value.ToString(); | ||
} | ||
|
||
case Unit.Percent: | ||
if (float.IsNaN(value)) | ||
{ | ||
return "none"; | ||
} | ||
else | ||
{ | ||
return value.ToString() + '%'; | ||
} | ||
|
||
case Unit.Auto: | ||
return "auto"; | ||
|
||
default: | ||
throw new ArgumentOutOfRangeException(nameof(YGValue.Unit)); | ||
} | ||
} | ||
|
||
private void SetValue(SerializedProperty property, YGValue value) | ||
{ | ||
property.FindPropertyRelative(nameof(YGValue.Value)).floatValue = value.Value; | ||
property.FindPropertyRelative(nameof(YGValue.Unit)).enumValueIndex = (int) value.Unit; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.