Singularity/Library/PackageCache/com.unity.collab-proxy@2.0.3/Editor/PlasticSCM/UI/DrawActionHelpBox.cs
2024-05-06 11:45:45 -07:00

77 lines
1.8 KiB
C#

using System;
using UnityEditor;
using UnityEngine;
namespace Unity.PlasticSCM.Editor.UI
{
internal static class DrawActionHelpBox
{
internal static void For(
Texture image,
string labelText,
string buttonText,
Action buttonAction)
{
EditorGUILayout.BeginHorizontal(
EditorStyles.helpBox, GUILayout.MinHeight(40));
DoNotificationLabel(image, labelText);
GUILayout.Space(10);
DoActionButton(buttonText, buttonAction);
GUILayout.FlexibleSpace();
EditorGUILayout.EndHorizontal();
}
static void DoNotificationLabel(
Texture image, string labelText)
{
GUILayout.BeginVertical();
GUILayout.FlexibleSpace();
GUILayout.Label(
new GUIContent(labelText, image),
UnityStyles.HelpBoxLabel);
GUILayout.FlexibleSpace();
GUILayout.EndVertical();
}
static void DoActionButton(
string buttonText, Action buttonAction)
{
GUILayout.BeginVertical();
GUILayout.FlexibleSpace();
GUIContent buttonContent = new GUIContent(buttonText);
float width = GetButtonWidth(
buttonContent, EditorStyles.miniButton);
if (GUILayout.Button(
buttonContent, EditorStyles.miniButton,
GUILayout.MinWidth(Math.Max(50, width))))
{
buttonAction();
}
GUILayout.FlexibleSpace();
GUILayout.EndVertical();
}
static float GetButtonWidth(
GUIContent buttonContent, GUIStyle buttonStyle)
{
return buttonStyle.CalcSize(buttonContent).x + 10;
}
}
}