Init
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
namespace QFSW.QC.QGUI
|
||||
{
|
||||
public interface IGUIItem
|
||||
{
|
||||
void DrawGUI(LayoutController layout);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 506cdc118faa64bd7b040644b69c623b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,140 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QFSW.QC.QGUI
|
||||
{
|
||||
public class LayoutController
|
||||
{
|
||||
public static float HorizontalPadding => 4;
|
||||
public static float RowPadding => EditorGUIUtility.standardVerticalSpacing;
|
||||
public static float RowHeight => EditorGUIUtility.singleLineHeight;
|
||||
|
||||
public bool IsValid
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_currentRect.width < 0) { return false; }
|
||||
if (_currentRect.height < 0) { return false; }
|
||||
if (_currentRect.x < TotalDrawRect.x) { return false; }
|
||||
if (_currentRect.y < TotalDrawRect.y) { return false; }
|
||||
if (_currentRect.x + _currentRect.width > TotalDrawRect.x + TotalDrawRect.width) { return false; }
|
||||
if (_currentRect.y + _currentRect.height > TotalDrawRect.y + TotalDrawRect.height) { return false; }
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public Rect TotalDrawRect { get; }
|
||||
public Rect CurrentRect => _currentRect;
|
||||
|
||||
private Rect _currentRect;
|
||||
|
||||
public LayoutController(Rect drawRect)
|
||||
{
|
||||
TotalDrawRect = drawRect;
|
||||
_currentRect = drawRect;
|
||||
_currentRect.height = RowHeight;
|
||||
}
|
||||
|
||||
public Rect BeginNewLine()
|
||||
{
|
||||
_currentRect.y += RowPadding + RowHeight;
|
||||
_currentRect.x = TotalDrawRect.x;
|
||||
_currentRect.width = TotalDrawRect.width;
|
||||
return _currentRect;
|
||||
}
|
||||
|
||||
public Rect ReserveHorizontal(float width)
|
||||
{
|
||||
Rect drawRect = _currentRect;
|
||||
drawRect.width = width;
|
||||
drawRect.width -= HorizontalPadding;
|
||||
|
||||
_currentRect.x += width;
|
||||
_currentRect.width -= width;
|
||||
|
||||
return drawRect;
|
||||
}
|
||||
|
||||
public Rect ReserveHorizontalPercentage(float widthPercentage)
|
||||
{
|
||||
float width = _currentRect.width * widthPercentage;
|
||||
return ReserveHorizontal(width);
|
||||
}
|
||||
|
||||
public Rect ReserveHorizontalReversed(float width)
|
||||
{
|
||||
Rect drawRect = _currentRect;
|
||||
drawRect.x += drawRect.width;
|
||||
drawRect.x -= width;
|
||||
drawRect.width = width;
|
||||
|
||||
_currentRect.width -= HorizontalPadding;
|
||||
_currentRect.width -= width;
|
||||
|
||||
return drawRect;
|
||||
}
|
||||
|
||||
public Rect ReserveHorizontalReversedPercentage(float widthPercentage)
|
||||
{
|
||||
float width = _currentRect.width * widthPercentage;
|
||||
return ReserveHorizontalReversed(width);
|
||||
}
|
||||
|
||||
public Rect ResizeRectHeight(Rect rect, float height)
|
||||
{
|
||||
rect.y += (rect.height - height) / 2;
|
||||
rect.height = height;
|
||||
|
||||
return rect;
|
||||
}
|
||||
|
||||
public Rect ReserveHorizontal(float width, float height)
|
||||
{
|
||||
return ResizeRectHeight(ReserveHorizontal(width), height);
|
||||
}
|
||||
|
||||
public Rect ReserveHorizontalReversed(float width, float height)
|
||||
{
|
||||
return ResizeRectHeight(ReserveHorizontalReversed(width), height);
|
||||
}
|
||||
|
||||
public Rect ReserveSquare()
|
||||
{
|
||||
return ReserveHorizontal(RowHeight);
|
||||
}
|
||||
|
||||
public Rect ReserveSquareReversed()
|
||||
{
|
||||
return ReserveHorizontalReversed(RowHeight);
|
||||
}
|
||||
|
||||
public Rect ReserveAuto(GUIContent content, GUIStyle style)
|
||||
{
|
||||
Vector2 size = style.CalcSize(content);
|
||||
return ReserveHorizontal(size.x, size.y);
|
||||
}
|
||||
|
||||
public Rect ReserveAutoReversed(GUIContent content, GUIStyle style)
|
||||
{
|
||||
Vector2 size = style.CalcSize(content);
|
||||
return ReserveHorizontalReversed(size.x, size.y);
|
||||
}
|
||||
|
||||
public void SpliceRow(int colCount, ref Rect[] rects)
|
||||
{
|
||||
float width = _currentRect.width / colCount;
|
||||
for (int i = 0; i < rects.Length; i++)
|
||||
{
|
||||
rects[i] = ReserveHorizontal(width);
|
||||
}
|
||||
}
|
||||
|
||||
public Rect[] SpliceRow(int colCount)
|
||||
{
|
||||
Rect[] rects = new Rect[colCount];
|
||||
SpliceRow(colCount, ref rects);
|
||||
return rects;
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 481da05e0c09175429ec2db6589454a5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "QFSW.QC.QGUI",
|
||||
"references": [],
|
||||
"optionalUnityReferences": [],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": []
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2c8115fef53c440a1873e4077e45b326
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QFSW.QC.QGUI
|
||||
{
|
||||
public static class QGUILayout
|
||||
{
|
||||
public static T EnumPopup<T>(T selected, params GUILayoutOption[] options) where T : Enum
|
||||
{
|
||||
return (T)EditorGUILayout.EnumPopup(selected, options);
|
||||
}
|
||||
|
||||
public static T EnumPopup<T>(GUIContent content, T selected, params GUILayoutOption[] options) where T : Enum
|
||||
{
|
||||
return (T)EditorGUILayout.EnumPopup(content, selected, options);
|
||||
}
|
||||
|
||||
public static T EnumFlagsField<T>(GUIContent content, T enumValue, params GUILayoutOption[] options) where T : Enum
|
||||
{
|
||||
return (T)EditorGUILayout.EnumFlagsField(content, enumValue, options);
|
||||
}
|
||||
|
||||
public static bool ButtonAuto(GUIContent content, GUIStyle style)
|
||||
{
|
||||
Vector2 size = style.CalcSize(content);
|
||||
return GUILayout.Button(content, style, GUILayout.Width(size.x));
|
||||
}
|
||||
|
||||
public static bool ButtonAuto(LayoutController layout, GUIContent content, GUIStyle style)
|
||||
{
|
||||
Rect rect = layout.ReserveAuto(content, style);
|
||||
return GUI.Button(rect, content, style);
|
||||
}
|
||||
|
||||
public static Vector2 GetMaxContentSize(GUIStyle style, params GUIContent[] contents)
|
||||
{
|
||||
Vector2 maxSize = new Vector2();
|
||||
foreach (GUIContent content in contents)
|
||||
{
|
||||
Vector2 size = style.CalcSize(content);
|
||||
maxSize.x = Mathf.Max(maxSize.x, size.x);
|
||||
maxSize.y = Mathf.Max(maxSize.y, size.y);
|
||||
}
|
||||
|
||||
return maxSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: df613967b4fdf486d9a4e932822cec60
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user