Skip to content

Commit

Permalink
Fix overwriting built in editor styles and improve dark theme support
Browse files Browse the repository at this point in the history
  • Loading branch information
oneVR committed Oct 5, 2020
1 parent d337d58 commit bb96fc6
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 28 deletions.
12 changes: 4 additions & 8 deletions Scripts/Editor/BuildReportTreeView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
using System.Linq;
using UnityEditor;
using UnityEditor.Build.Reporting;
using UnityEditor.Callbacks;
using UnityEditor.IMGUI.Controls;
using UnityEngine;
using UnityEngine.Assertions;
using UnityEngine.EventSystems;
using VRWorldToolkit.DataStructures;

namespace VRWorldToolkit
{
Expand Down Expand Up @@ -327,12 +325,10 @@ protected override void RowGUI(RowGUIArgs args)
var rect = args.GetCellRect(visibleColumnIndex);
var columnIndex = (TreeColumns)args.GetColumn(visibleColumnIndex);

// Set label style to white if cell is selected if selected
var labelStyle = args.selected ? EditorStyles.whiteLabel : EditorStyles.label;
labelStyle.alignment = TextAnchor.MiddleLeft;
labelStyle.wordWrap = false;
//Set label style to white if cell is selected otherwise to normal
var labelStyle = args.selected ? Styles.TreeViewLabelSelected : Styles.TreeViewLabel;

// Handle drawing of the columns
//Handle drawing of the columns
switch (columnIndex)
{
case TreeColumns.Type:
Expand Down
8 changes: 2 additions & 6 deletions Scripts/Editor/VRWTAbout.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using UnityEditor;
using UnityEngine;
using VRWorldToolkit.DataStructures;

namespace VRWorldToolkit
{
Expand Down Expand Up @@ -30,17 +31,12 @@ public void OnEnable()
fixedHeight = 140
};

Text = new GUIStyle
Text = new GUIStyle("Label")
{
padding = new RectOffset(5, 5, 5, 5),
wordWrap = true,
richText = true
};

// Set text to white on black theme for readability
if (EditorGUIUtility.isProSkin)
Text.normal.textColor = Color.white;

IconTwitter = Resources.Load("SplashTextures/IconTwitter") as Texture2D;
IconDiscord = Resources.Load("SplashTextures/IconDiscord") as Texture2D;
IconGithub = Resources.Load("SplashTextures/IconGithub") as Texture2D;
Expand Down
30 changes: 28 additions & 2 deletions Scripts/Editor/VRWTDataStructures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ public static class Styles
{
public static GUIStyle HelpBoxRichText { get; internal set; }
public static GUIStyle HelpBoxPadded { get; internal set; }
public static GUIStyle LabelRichText { get; internal set; }
public static GUIStyle RichText { get; internal set; }
public static GUIStyle RichTextWrap { get; internal set; }
public static GUIStyle RedLabel { get; internal set; }
public static GUIStyle WhiteLabel { get; internal set; }
public static GUIStyle TreeViewLabel { get; internal set; }
public static GUIStyle TreeViewLabelSelected { get; internal set; }

static Styles()
{
Expand All @@ -30,6 +33,12 @@ static void Reload()
richText = true
};

LabelRichText = new GUIStyle("Label")
{
richText = true,
margin = new RectOffset(5, 5, 0, 0),
};

RichText = new GUIStyle
{
richText = true
Expand All @@ -41,8 +50,25 @@ static void Reload()
wordWrap = true
};

RedLabel = new GUIStyle { };
RedLabel.normal.textColor = Color.red;
RedLabel = new GUIStyle
{
normal =
{
textColor = Color.red,
},
};

TreeViewLabel = new GUIStyle("Label")
{
alignment = TextAnchor.MiddleLeft,
wordWrap = false,
};

TreeViewLabelSelected = new GUIStyle("WhiteLabel")
{
alignment = TextAnchor.MiddleLeft,
wordWrap = false,
};
}
}
}
17 changes: 5 additions & 12 deletions Scripts/Editor/WorldDebugger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2249,26 +2249,19 @@ private void RefreshBuild()

private void DrawBuildSummary(BuildReport report)
{
var richText = Styles.RichText;

if (EditorGUIUtility.isProSkin)
{
richText.normal.textColor = Color.white;
}

GUILayout.BeginVertical(EditorStyles.helpBox);

if (report != null)
{
GUILayout.Label("<b>Build size:</b> " + EditorUtility.FormatBytes((long)report.summary.totalSize), richText);
GUILayout.Label("<b>Build size:</b> " + EditorUtility.FormatBytes((long)report.summary.totalSize), Styles.LabelRichText);

GUILayout.Label("<b>Build done:</b> " + report.summary.buildEndedAt.ToLocalTime(), richText);
GUILayout.Label("<b>Build done:</b> " + report.summary.buildEndedAt.ToLocalTime(), Styles.LabelRichText);

GUILayout.Label("<b>Errors during build:</b> " + report.summary.totalErrors.ToString(), richText);
GUILayout.Label("<b>Errors during build:</b> " + report.summary.totalErrors.ToString(), Styles.LabelRichText);

GUILayout.Label("<b>Warnings during build:</b> " + report.summary.totalWarnings.ToString(), richText);
GUILayout.Label("<b>Warnings during build:</b> " + report.summary.totalWarnings.ToString(), Styles.LabelRichText);

GUILayout.Label("<b>Build result:</b> " + report.summary.result, richText);
GUILayout.Label("<b>Build result:</b> " + report.summary.result, Styles.LabelRichText);
}

GUILayout.EndVertical();
Expand Down

0 comments on commit bb96fc6

Please sign in to comment.