UnityStyles.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEditor;
  4. using UnityEditor.IMGUI.Controls;
  5. using UnityEngine;
  6. namespace Unity.PlasticSCM.Editor.UI
  7. {
  8. // Assumption: Members are called from an OnGUI method ( otherwise style composition will fail)
  9. internal static class UnityStyles
  10. {
  11. internal static void Initialize(
  12. Action repaintPlasticWindow)
  13. {
  14. mRepaintPlasticWindow = repaintPlasticWindow;
  15. mLazyBackgroundStyles.Add(WarningMessage);
  16. mLazyBackgroundStyles.Add(SplitterIndicator);
  17. mLazyBackgroundStyles.Add(PlasticWindow.ActiveTabUnderline);
  18. mLazyBackgroundStyles.Add(Notification.GreenNotification);
  19. mLazyBackgroundStyles.Add(Notification.RedNotification);
  20. mLazyBackgroundStyles.Add(CancelButton);
  21. mLazyBackgroundStyles.Add(Inspector.HeaderBackgroundStyle);
  22. mLazyBackgroundStyles.Add(Inspector.DisabledHeaderBackgroundStyle);
  23. }
  24. internal static class Colors
  25. {
  26. internal static Color Transparent = new Color(255f / 255, 255f / 255, 255f / 255, 0f / 255);
  27. internal static Color GreenBackground = new Color(34f / 255, 161f / 255, 63f / 255);
  28. internal static Color GreenText = new Color(0f / 255, 100f / 255, 0f / 255);
  29. internal static Color Red = new Color(194f / 255, 51f / 255, 62f / 255);
  30. internal static Color Warning = new Color(255f / 255, 255f / 255, 176f / 255);
  31. internal static Color Splitter = new Color(100f / 255, 100f / 255, 100f / 255);
  32. #if UNITY_2019
  33. internal static Color InspectorHeaderBackground = (EditorGUIUtility.isProSkin) ?
  34. new Color(60f / 255, 60f / 255, 60f / 255) :
  35. new Color(203f / 255, 203f / 255, 203f / 255);
  36. #else
  37. internal static Color InspectorHeaderBackground = Transparent;
  38. #endif
  39. #if UNITY_2019_1_OR_NEWER
  40. internal static Color InspectorHeaderBackgroundDisabled = (EditorGUIUtility.isProSkin) ?
  41. new Color(58f / 255, 58f / 255, 58f / 255) :
  42. new Color(199f / 255, 199f / 255, 199f / 255);
  43. #else
  44. internal static Color InspectorHeaderBackgroundDisabled = (EditorGUIUtility.isProSkin) ?
  45. new Color(60f / 255, 60f / 255, 60f / 255) :
  46. new Color(210f / 255, 210f / 255, 210f / 255);
  47. #endif
  48. internal static Color TabUnderline = new Color(0.128f, 0.456f, 0.776f);
  49. internal static Color Link = new Color(0f, 120f / 255, 218f / 255);
  50. internal static Color SecondaryLabel = (EditorGUIUtility.isProSkin) ?
  51. new Color(135f / 255, 135f / 255, 135f / 255) :
  52. new Color(105f / 255, 105f / 255, 105f / 255);
  53. }
  54. internal static class HexColors
  55. {
  56. internal const string LINK_COLOR = "#0078DA";
  57. }
  58. internal static class Dialog
  59. {
  60. internal static readonly LazyStyle MessageTitle = new LazyStyle(() =>
  61. {
  62. var style = new GUIStyle(EditorStyles.boldLabel);
  63. style.contentOffset = new Vector2(0, -5);
  64. style.wordWrap = true;
  65. style.fontSize = MODAL_FONT_SIZE + 1;
  66. return style;
  67. });
  68. internal static readonly LazyStyle MessageText = new LazyStyle(() =>
  69. {
  70. var style = new GUIStyle(EditorStyles.label);
  71. style.wordWrap = true;
  72. style.fontSize = MODAL_FONT_SIZE;
  73. return style;
  74. });
  75. internal static readonly LazyStyle Toggle = new LazyStyle(() =>
  76. {
  77. var style = new GUIStyle(EditorStyles.boldLabel);
  78. style.fontSize = MODAL_FONT_SIZE;
  79. style.clipping = TextClipping.Overflow;
  80. return style;
  81. });
  82. internal static readonly LazyStyle RadioToggle = new LazyStyle(() =>
  83. {
  84. var radioToggleStyle = new GUIStyle(EditorStyles.radioButton);
  85. radioToggleStyle.fontSize = MODAL_FONT_SIZE;
  86. radioToggleStyle.clipping = TextClipping.Overflow;
  87. radioToggleStyle.font = EditorStyles.largeLabel.font;
  88. return radioToggleStyle;
  89. });
  90. internal static readonly LazyStyle Foldout = new LazyStyle(() =>
  91. {
  92. GUIStyle paragraphStyle = Paragraph;
  93. var foldoutStyle = new GUIStyle(EditorStyles.foldout);
  94. foldoutStyle.fontSize = MODAL_FONT_SIZE;
  95. foldoutStyle.font = paragraphStyle.font;
  96. return foldoutStyle;
  97. });
  98. internal static readonly LazyStyle EntryLabel = new LazyStyle(() =>
  99. {
  100. var style = new GUIStyle(EditorStyles.textField);
  101. style.wordWrap = true;
  102. style.fontSize = MODAL_FONT_SIZE;
  103. return style;
  104. });
  105. internal static readonly LazyStyle AcceptButtonText = new LazyStyle(() =>
  106. {
  107. var style = new GUIStyle(GetEditorSkin().GetStyle("WhiteLabel"));
  108. style.alignment = TextAnchor.MiddleCenter;
  109. style.fontSize = MODAL_FONT_SIZE + 1;
  110. style.normal.background = null;
  111. return style;
  112. });
  113. internal static readonly LazyStyle NormalButton = new LazyStyle(() =>
  114. {
  115. var style = new GUIStyle(GetEditorSkin().button);
  116. style.alignment = TextAnchor.MiddleCenter;
  117. style.fontSize = MODAL_FONT_SIZE;
  118. return style;
  119. });
  120. }
  121. internal static class Tree
  122. {
  123. internal static readonly LazyStyle IconStyle = new LazyStyle(() =>
  124. {
  125. var style = new GUIStyle(EditorStyles.largeLabel);
  126. style.alignment = TextAnchor.MiddleLeft;
  127. return style;
  128. });
  129. internal static readonly LazyStyle Label = new LazyStyle(() =>
  130. {
  131. var style = new GUIStyle(TreeView.DefaultStyles.label);
  132. style.fontSize = 11;
  133. style.alignment = TextAnchor.MiddleLeft;
  134. return style;
  135. });
  136. internal static readonly LazyStyle SecondaryLabel = new LazyStyle(() =>
  137. {
  138. var style = new GUIStyle(TreeView.DefaultStyles.label);
  139. style.fontSize = 11;
  140. style.alignment = TextAnchor.MiddleLeft;
  141. style.active = new GUIStyleState() { textColor = Colors.SecondaryLabel };
  142. style.focused = new GUIStyleState() { textColor = Colors.SecondaryLabel };
  143. style.hover = new GUIStyleState() { textColor = Colors.SecondaryLabel };
  144. style.normal = new GUIStyleState() { textColor = Colors.SecondaryLabel };
  145. return style;
  146. });
  147. internal static readonly LazyStyle SecondaryBoldLabel = new LazyStyle(() =>
  148. {
  149. var style = new GUIStyle(SecondaryLabel);
  150. style.fontStyle = FontStyle.Bold;
  151. return style;
  152. });
  153. internal static readonly LazyStyle RedLabel = new LazyStyle(() =>
  154. {
  155. var style = new GUIStyle(Label);
  156. style.active = new GUIStyleState() { textColor = Colors.Red };
  157. style.focused = new GUIStyleState() { textColor = Colors.Red };
  158. style.hover = new GUIStyleState() { textColor = Colors.Red };
  159. style.normal = new GUIStyleState() { textColor = Colors.Red };
  160. return style;
  161. });
  162. internal static readonly LazyStyle GreenLabel = new LazyStyle(() =>
  163. {
  164. var style = new GUIStyle(Label);
  165. style.active = new GUIStyleState() { textColor = Colors.GreenText };
  166. style.focused = new GUIStyleState() { textColor = Colors.GreenText };
  167. style.hover = new GUIStyleState() { textColor = Colors.GreenText };
  168. style.normal = new GUIStyleState() { textColor = Colors.GreenText };
  169. return style;
  170. });
  171. internal static readonly LazyStyle BoldLabel = new LazyStyle(() =>
  172. {
  173. var style = new GUIStyle(TreeView.DefaultStyles.boldLabel);
  174. style.fontSize = 11;
  175. style.alignment = TextAnchor.MiddleLeft;
  176. return style;
  177. });
  178. internal static readonly LazyStyle LabelRightAligned = new LazyStyle(() =>
  179. {
  180. var style = new GUIStyle(TreeView.DefaultStyles.label);
  181. style.fontSize = 11;
  182. style.alignment = TextAnchor.MiddleRight;
  183. return style;
  184. });
  185. internal static readonly LazyStyle SecondaryLabelRightAligned = new LazyStyle(() =>
  186. {
  187. var style = new GUIStyle(SecondaryLabel);
  188. style.alignment = TextAnchor.MiddleRight;
  189. return style;
  190. });
  191. internal static readonly LazyStyle SecondaryLabelBoldRightAligned = new LazyStyle(() =>
  192. {
  193. var style = new GUIStyle(SecondaryLabelRightAligned);
  194. style.fontStyle = FontStyle.Bold;
  195. return style;
  196. });
  197. }
  198. public static class Inspector
  199. {
  200. public static readonly LazyStyle HeaderBackgroundStyle = new LazyStyle(() =>
  201. {
  202. return CreateUnderlineStyle(
  203. Colors.InspectorHeaderBackground,
  204. UnityConstants.INSPECTOR_ACTIONS_HEADER_BACK_RECTANGLE_HEIGHT);
  205. });
  206. public static readonly LazyStyle DisabledHeaderBackgroundStyle = new LazyStyle(() =>
  207. {
  208. return CreateUnderlineStyle(
  209. Colors.InspectorHeaderBackgroundDisabled,
  210. UnityConstants.INSPECTOR_ACTIONS_HEADER_BACK_RECTANGLE_HEIGHT);
  211. });
  212. }
  213. internal static class PlasticWindow
  214. {
  215. internal static readonly LazyStyle HeaderTitleLabel = new LazyStyle(() =>
  216. {
  217. var style = new GUIStyle(EditorStyles.label);
  218. return style;
  219. });
  220. internal static readonly LazyStyle ActiveTabButton = new LazyStyle(() =>
  221. {
  222. GUIStyle result = new GUIStyle(EditorStyles.toolbarButton);
  223. result.fontStyle = FontStyle.Bold;
  224. return result;
  225. });
  226. internal static readonly LazyStyle ActiveTabUnderline = new LazyStyle(() =>
  227. {
  228. return CreateUnderlineStyle(
  229. Colors.TabUnderline,
  230. UnityConstants.ACTIVE_TAB_UNDERLINE_HEIGHT);
  231. });
  232. }
  233. internal static class DiffPanel
  234. {
  235. internal static readonly LazyStyle HeaderLabel = new LazyStyle(() =>
  236. {
  237. var style = new GUIStyle(EditorStyles.label);
  238. style.fontSize = 10;
  239. style.fontStyle = FontStyle.Bold;
  240. #if UNITY_2019_1_OR_NEWER
  241. style.contentOffset = new Vector2(0, 1.5f);
  242. #endif
  243. return style;
  244. });
  245. }
  246. internal static class PendingChangesTab
  247. {
  248. internal static readonly LazyStyle CommentPlaceHolder = new LazyStyle(() =>
  249. {
  250. var style = new GUIStyle();
  251. style.normal = new GUIStyleState() { textColor = Color.gray };
  252. style.padding = new RectOffset(7, 0, 4, 0);
  253. return style;
  254. });
  255. internal static readonly LazyStyle CommentTextArea = new LazyStyle(() =>
  256. {
  257. var style = new GUIStyle(EditorStyles.textArea);
  258. style.margin = new RectOffset(7, 4, 0, 0);
  259. style.padding = new RectOffset(0, 0, 4, 0);
  260. return style;
  261. });
  262. internal static readonly LazyStyle CommentWarningIcon = new LazyStyle(() =>
  263. {
  264. var style = new GUIStyle(EditorStyles.label);
  265. style.fontSize = 10;
  266. #if !UNITY_2019_1_OR_NEWER
  267. style.margin = new RectOffset(0, 0, 0, 0);
  268. #endif
  269. return style;
  270. });
  271. internal static readonly LazyStyle HeaderLabel = new LazyStyle(() =>
  272. {
  273. var style = new GUIStyle(EditorStyles.label);
  274. style.fontSize = 10;
  275. style.fontStyle = FontStyle.Bold;
  276. #if UNITY_2019_1_OR_NEWER
  277. style.contentOffset = new Vector2(0, 1.5f);
  278. #endif
  279. return style;
  280. });
  281. }
  282. internal static class IncomingChangesTab
  283. {
  284. internal static readonly LazyStyle PendingConflictsLabel = new LazyStyle(() =>
  285. {
  286. var style = new GUIStyle(EditorStyles.label);
  287. style.fontSize = 10;
  288. style.fontStyle = FontStyle.Bold;
  289. return style;
  290. });
  291. internal static readonly LazyStyle RedPendingConflictsOfTotalLabel = new LazyStyle(() =>
  292. {
  293. var style = new GUIStyle(PendingConflictsLabel);
  294. style.normal = new GUIStyleState() { textColor = Colors.Red };
  295. return style;
  296. });
  297. internal static readonly LazyStyle GreenPendingConflictsOfTotalLabel = new LazyStyle(() =>
  298. {
  299. var style = new GUIStyle(PendingConflictsLabel);
  300. style.normal = new GUIStyleState() { textColor = Colors.GreenText };
  301. return style;
  302. });
  303. internal static readonly LazyStyle ChangesToApplySummaryLabel = new LazyStyle(() =>
  304. {
  305. var style = new GUIStyle(EditorStyles.label);
  306. style.fontSize = 10;
  307. return style;
  308. });
  309. internal readonly static LazyStyle HeaderWarningLabel
  310. = new LazyStyle(() =>
  311. {
  312. var style = new GUIStyle(EditorStyles.label);
  313. style.fontSize = 10;
  314. #if !UNITY_2019_1_OR_NEWER
  315. style.margin = new RectOffset(0, 0, 0, 0);
  316. #endif
  317. return style;
  318. });
  319. }
  320. internal static class ChangesetsTab
  321. {
  322. internal static readonly LazyStyle HeaderLabel = new LazyStyle(() =>
  323. {
  324. var style = new GUIStyle(EditorStyles.label);
  325. style.fontSize = 10;
  326. style.fontStyle = FontStyle.Bold;
  327. #if UNITY_2019_1_OR_NEWER
  328. style.contentOffset = new Vector2(0, 1.5f);
  329. #endif
  330. return style;
  331. });
  332. }
  333. internal static class HistoryTab
  334. {
  335. internal static readonly LazyStyle HeaderLabel = new LazyStyle(() =>
  336. {
  337. var style = new GUIStyle(EditorStyles.label);
  338. style.fontSize = 10;
  339. style.fontStyle = FontStyle.Bold;
  340. #if UNITY_2019_1_OR_NEWER
  341. style.contentOffset = new Vector2(0, 1.5f);
  342. #endif
  343. return style;
  344. });
  345. }
  346. internal static class DirectoryConflictResolution
  347. {
  348. internal readonly static LazyStyle WarningLabel
  349. = new LazyStyle(() =>
  350. {
  351. var style = new GUIStyle(EditorStyles.label);
  352. style.alignment = TextAnchor.MiddleLeft;
  353. #if !UNITY_2019_1_OR_NEWER
  354. style.margin = new RectOffset(0, 0, 0, 0);
  355. #endif
  356. return style;
  357. });
  358. }
  359. internal static class Notification
  360. {
  361. internal static readonly LazyStyle Label = new LazyStyle(() =>
  362. {
  363. var style = new GUIStyle(EditorStyles.label);
  364. #if !UNITY_2019_1_OR_NEWER
  365. style.fontSize = 10;
  366. #endif
  367. style.normal = new GUIStyleState() { textColor = Color.white };
  368. return style;
  369. });
  370. internal static readonly LazyStyle GreenNotification = new LazyStyle(() =>
  371. {
  372. var style = new GUIStyle();
  373. style.wordWrap = true;
  374. style.margin = new RectOffset();
  375. style.padding = new RectOffset(4, 4, 2, 2);
  376. style.stretchWidth = true;
  377. style.stretchHeight = true;
  378. style.alignment = TextAnchor.UpperLeft;
  379. var bg = new Texture2D(1, 1);
  380. bg.SetPixel(0, 0, Colors.GreenBackground);
  381. bg.Apply();
  382. style.normal.background = bg;
  383. return style;
  384. });
  385. internal static readonly LazyStyle RedNotification = new LazyStyle(() =>
  386. {
  387. var style = new GUIStyle();
  388. style.wordWrap = true;
  389. style.margin = new RectOffset();
  390. style.padding = new RectOffset(4, 4, 2, 2);
  391. style.stretchWidth = true;
  392. style.stretchHeight = true;
  393. style.alignment = TextAnchor.UpperLeft;
  394. var bg = new Texture2D(1, 1);
  395. bg.SetPixel(0, 0, Colors.Red);
  396. bg.Apply();
  397. style.normal.background = bg;
  398. return style;
  399. });
  400. }
  401. internal static class DirectoryConflicts
  402. {
  403. internal readonly static LazyStyle TitleLabel = new LazyStyle(() =>
  404. {
  405. var style = new GUIStyle(EditorStyles.largeLabel);
  406. RectOffset margin = new RectOffset(
  407. style.margin.left,
  408. style.margin.right,
  409. style.margin.top - 1,
  410. style.margin.bottom);
  411. style.margin = margin;
  412. style.fontStyle = FontStyle.Bold;
  413. return style;
  414. });
  415. internal readonly static LazyStyle BoldLabel = new LazyStyle(() =>
  416. {
  417. var style = new GUIStyle(EditorStyles.label);
  418. style.fontStyle = FontStyle.Bold;
  419. return style;
  420. });
  421. internal readonly static LazyStyle FileNameTextField = new LazyStyle(() =>
  422. {
  423. var style = new GUIStyle(EditorStyles.textField);
  424. RectOffset margin = new RectOffset(
  425. style.margin.left,
  426. style.margin.right,
  427. style.margin.top + 2,
  428. style.margin.bottom);
  429. style.margin = margin;
  430. return style;
  431. });
  432. }
  433. internal static readonly LazyStyle SplitterIndicator = new LazyStyle(() =>
  434. {
  435. return CreateUnderlineStyle(
  436. Colors.Splitter,
  437. UnityConstants.SPLITTER_INDICATOR_HEIGHT);
  438. });
  439. internal static readonly LazyStyle HelpBoxLabel = new LazyStyle(() =>
  440. {
  441. var style = new GUIStyle(EditorStyles.label);
  442. style.fontSize = 10;
  443. style.wordWrap = true;
  444. return style;
  445. });
  446. internal static readonly LazyStyle ProgressLabel = new LazyStyle(() =>
  447. {
  448. var style = new GUIStyle(EditorStyles.label);
  449. style.fontSize = 10;
  450. #if !UNITY_2019_1_OR_NEWER
  451. style.margin = new RectOffset(0, 0, 0, 0);
  452. #endif
  453. return style;
  454. });
  455. internal static readonly LazyStyle TextFieldWithWrapping = new LazyStyle(() =>
  456. {
  457. var style = new GUIStyle(EditorStyles.textField);
  458. style.wordWrap = true;
  459. return style;
  460. });
  461. internal static readonly LazyStyle Search = new LazyStyle(() =>
  462. {
  463. var style = new GUIStyle();
  464. style.normal = new GUIStyleState() { textColor = Color.gray };
  465. style.padding = new RectOffset(18, 0, 0, 0);
  466. return style;
  467. });
  468. internal static readonly LazyStyle WarningMessage = new LazyStyle(() =>
  469. {
  470. var style = new GUIStyle(GetEditorSkin().box);
  471. style.wordWrap = true;
  472. style.margin = new RectOffset();
  473. style.padding = new RectOffset(8, 8, 6, 6);
  474. style.stretchWidth = true;
  475. style.alignment = TextAnchor.UpperLeft;
  476. var bg = new Texture2D(1, 1);
  477. bg.SetPixel(0, 0, Colors.Warning);
  478. bg.Apply();
  479. style.normal.background = bg;
  480. return style;
  481. });
  482. internal static readonly LazyStyle CancelButton = new LazyStyle(() =>
  483. {
  484. var normalIcon = Images.GetImage(Images.Name.IconCloseButton);
  485. var pressedIcon = Images.GetImage(Images.Name.IconPressedCloseButton);
  486. var style = new GUIStyle();
  487. style.normal = new GUIStyleState() { background = normalIcon };
  488. style.onActive = new GUIStyleState() { background = pressedIcon };
  489. style.active = new GUIStyleState() { background = pressedIcon };
  490. return style;
  491. });
  492. internal static readonly LazyStyle MiniToggle = new LazyStyle(() =>
  493. {
  494. var style = new GUIStyle(EditorStyles.boldLabel);
  495. style.fontSize = MODAL_FONT_SIZE - 1;
  496. style.clipping = TextClipping.Overflow;
  497. return style;
  498. });
  499. internal static readonly LazyStyle Paragraph = new LazyStyle(() =>
  500. {
  501. var style = new GUIStyle(EditorStyles.largeLabel);
  502. style.wordWrap = true;
  503. style.richText = true;
  504. style.fontSize = MODAL_FONT_SIZE;
  505. return style;
  506. });
  507. static GUISkin GetEditorSkin()
  508. {
  509. GUISkin editorSkin = null;
  510. if (EditorGUIUtility.isProSkin)
  511. editorSkin = EditorGUIUtility.GetBuiltinSkin(EditorSkin.Scene);
  512. else
  513. editorSkin = EditorGUIUtility.GetBuiltinSkin(EditorSkin.Inspector);
  514. return editorSkin;
  515. }
  516. static GUIStyle CreateUnderlineStyle(Color color, int height)
  517. {
  518. GUIStyle style = new GUIStyle();
  519. Texture2D pixel = new Texture2D(1, height);
  520. for (int i = 0; i < height; i++)
  521. pixel.SetPixel(0, i, color);
  522. pixel.wrapMode = TextureWrapMode.Repeat;
  523. pixel.Apply();
  524. style.normal.background = pixel;
  525. style.fixedHeight = height;
  526. return style;
  527. }
  528. static void EnsureBackgroundStyles(LazyStyle lazy)
  529. {
  530. // The editor cleans the GUIStyleState.background property
  531. // when entering the edit mode (exiting the play mode)
  532. // and also in other situations (e.g when you use Zoom app)
  533. // Because of this, we have to reset them in order to
  534. // re-instantiate them the next time they're used
  535. if (!mLazyBackgroundStyles.Contains(lazy))
  536. return;
  537. bool needsRepaint = false;
  538. foreach (LazyStyle style in mLazyBackgroundStyles)
  539. {
  540. if (!style.IsInitialized)
  541. continue;
  542. if (style.Value.normal.background != null)
  543. continue;
  544. style.Reset();
  545. needsRepaint = true;
  546. }
  547. if (!needsRepaint)
  548. return;
  549. if (mRepaintPlasticWindow != null)
  550. mRepaintPlasticWindow();
  551. }
  552. static List<LazyStyle> mLazyBackgroundStyles = new List<LazyStyle>();
  553. internal class LazyStyle
  554. {
  555. internal bool IsInitialized { get; private set; }
  556. internal LazyStyle(Func<GUIStyle> builder)
  557. {
  558. mBuilder = builder;
  559. IsInitialized = false;
  560. }
  561. internal GUIStyle Value { get; private set; }
  562. internal void Reset()
  563. {
  564. IsInitialized = false;
  565. }
  566. public static implicit operator GUIStyle(LazyStyle lazy)
  567. {
  568. if (lazy.IsInitialized)
  569. {
  570. EnsureBackgroundStyles(lazy);
  571. return lazy.Value;
  572. }
  573. lazy.Value = lazy.mBuilder();
  574. lazy.IsInitialized = true;
  575. return lazy.Value;
  576. }
  577. readonly Func<GUIStyle> mBuilder;
  578. }
  579. static Action mRepaintPlasticWindow;
  580. const int MODAL_FONT_SIZE = 13;
  581. }
  582. }