StickyNote.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. using System.Collections.Generic;
  2. using UnityEditor.Experimental.GraphView;
  3. using UnityEngine;
  4. using UnityEngine.UIElements;
  5. namespace UnityEditor.ShaderGraph.Drawing
  6. {
  7. interface IResizable
  8. {
  9. void OnStartResize();
  10. void OnResized();
  11. }
  12. class ResizableElementFactory : UxmlFactory<ResizableElement>
  13. {}
  14. class ElementResizer : Manipulator
  15. {
  16. // static MethodInfo m_ValidateLayoutMethod;
  17. // public static void InternalValidateLayout(IPanel panel)
  18. // {
  19. // if (m_ValidateLayoutMethod == null)
  20. // m_ValidateLayoutMethod = panel.GetType().GetMethod("ValidateLayout", BindingFlags.Instance | BindingFlags.FlattenHierarchy | BindingFlags.NonPublic | BindingFlags.Public);
  21. //
  22. // m_ValidateLayoutMethod.Invoke(panel, new object[] {});
  23. // }
  24. public readonly ResizableElement.Resizer direction;
  25. public readonly VisualElement resizedElement;
  26. public ElementResizer(VisualElement resizedElement, ResizableElement.Resizer direction)
  27. {
  28. this.direction = direction;
  29. this.resizedElement = resizedElement;
  30. }
  31. protected override void RegisterCallbacksOnTarget()
  32. {
  33. target.RegisterCallback<MouseDownEvent>(OnMouseDown);
  34. target.RegisterCallback<MouseUpEvent>(OnMouseUp);
  35. }
  36. protected override void UnregisterCallbacksFromTarget()
  37. {
  38. target.UnregisterCallback<MouseDownEvent>(OnMouseDown);
  39. target.UnregisterCallback<MouseUpEvent>(OnMouseUp);
  40. }
  41. Vector2 m_StartMouse;
  42. Vector2 m_StartSize;
  43. Vector2 m_MinSize;
  44. Vector2 m_MaxSize;
  45. Vector2 m_StartPosition;
  46. bool m_DragStarted = false;
  47. void OnMouseDown(MouseDownEvent e)
  48. {
  49. if (e.button == 0 && e.clickCount == 1)
  50. {
  51. VisualElement resizedTarget = resizedElement.parent;
  52. if (resizedTarget != null)
  53. {
  54. VisualElement resizedBase = resizedTarget.parent;
  55. if (resizedBase != null)
  56. {
  57. target.RegisterCallback<MouseMoveEvent>(OnMouseMove);
  58. e.StopPropagation();
  59. target.CaptureMouse();
  60. m_StartMouse = resizedBase.WorldToLocal(e.mousePosition);
  61. m_StartSize = new Vector2(resizedTarget.resolvedStyle.width, resizedTarget.resolvedStyle.height);
  62. m_StartPosition = new Vector2(resizedTarget.resolvedStyle.left, resizedTarget.resolvedStyle.top);
  63. bool minWidthDefined = resizedTarget.resolvedStyle.minWidth != StyleKeyword.Auto;
  64. bool maxWidthDefined = resizedTarget.resolvedStyle.maxWidth != StyleKeyword.None;
  65. bool minHeightDefined = resizedTarget.resolvedStyle.minHeight != StyleKeyword.Auto;
  66. bool maxHeightDefined = resizedTarget.resolvedStyle.maxHeight != StyleKeyword.None;
  67. m_MinSize = new Vector2(
  68. minWidthDefined ? resizedTarget.resolvedStyle.minWidth.value : Mathf.NegativeInfinity,
  69. minHeightDefined ? resizedTarget.resolvedStyle.minHeight.value : Mathf.NegativeInfinity);
  70. m_MaxSize = new Vector2(
  71. maxWidthDefined ? resizedTarget.resolvedStyle.maxWidth.value : Mathf.Infinity,
  72. maxHeightDefined ? resizedTarget.resolvedStyle.maxHeight.value : Mathf.Infinity);
  73. m_DragStarted = false;
  74. }
  75. }
  76. }
  77. }
  78. void OnMouseMove(MouseMoveEvent e)
  79. {
  80. VisualElement resizedTarget = resizedElement.parent;
  81. VisualElement resizedBase = resizedTarget.parent;
  82. Vector2 mousePos = resizedBase.WorldToLocal(e.mousePosition);
  83. if (!m_DragStarted)
  84. {
  85. if (resizedTarget is IResizable)
  86. {
  87. (resizedTarget as IResizable).OnStartResize();
  88. }
  89. m_DragStarted = true;
  90. }
  91. if ((direction & ResizableElement.Resizer.Right) != 0)
  92. {
  93. resizedTarget.style.width = Mathf.Min(m_MaxSize.x, Mathf.Max(m_MinSize.x, m_StartSize.x + mousePos.x - m_StartMouse.x));
  94. }
  95. else if ((direction & ResizableElement.Resizer.Left) != 0)
  96. {
  97. float delta = mousePos.x - m_StartMouse.x;
  98. if (m_StartSize.x - delta < m_MinSize.x)
  99. {
  100. delta = -m_MinSize.x + m_StartSize.x;
  101. }
  102. else if (m_StartSize.x - delta > m_MaxSize.x)
  103. {
  104. delta = -m_MaxSize.x + m_StartSize.x;
  105. }
  106. resizedTarget.style.left = delta + m_StartPosition.x;
  107. resizedTarget.style.width = -delta + m_StartSize.x;
  108. }
  109. if ((direction & ResizableElement.Resizer.Bottom) != 0)
  110. {
  111. resizedTarget.style.height = Mathf.Min(m_MaxSize.y, Mathf.Max(m_MinSize.y, m_StartSize.y + mousePos.y - m_StartMouse.y));
  112. }
  113. else if ((direction & ResizableElement.Resizer.Top) != 0)
  114. {
  115. float delta = mousePos.y - m_StartMouse.y;
  116. if (m_StartSize.y - delta < m_MinSize.y)
  117. {
  118. delta = -m_MinSize.y + m_StartSize.y;
  119. }
  120. else if (m_StartSize.y - delta > m_MaxSize.y)
  121. {
  122. delta = -m_MaxSize.y + m_StartSize.y;
  123. }
  124. resizedTarget.style.top = delta + m_StartPosition.y;
  125. resizedTarget.style.height = -delta + m_StartSize.y;
  126. }
  127. e.StopPropagation();
  128. }
  129. void OnMouseUp(MouseUpEvent e)
  130. {
  131. if (e.button == 0)
  132. {
  133. VisualElement resizedTarget = resizedElement.parent;
  134. if (resizedTarget.style.width != m_StartSize.x || resizedTarget.style.height != m_StartSize.y)
  135. {
  136. if (resizedTarget is IResizable)
  137. {
  138. (resizedTarget as IResizable).OnResized();
  139. }
  140. }
  141. target.UnregisterCallback<MouseMoveEvent>(OnMouseMove);
  142. target.ReleaseMouse();
  143. e.StopPropagation();
  144. }
  145. }
  146. }
  147. class ResizableElement : VisualElement
  148. {
  149. public ResizableElement() : this("uxml/Resizable")
  150. {
  151. pickingMode = PickingMode.Ignore;
  152. }
  153. public ResizableElement(string uiFile)
  154. {
  155. var tpl = Resources.Load<VisualTreeAsset>(uiFile);
  156. var sheet = Resources.Load<StyleSheet>("Resizable");
  157. styleSheets.Add(sheet);
  158. tpl.CloneTree(this);
  159. foreach (Resizer value in System.Enum.GetValues(typeof(Resizer)))
  160. {
  161. VisualElement resizer = this.Q(value.ToString().ToLower() + "-resize");
  162. if (resizer != null)
  163. resizer.AddManipulator(new ElementResizer(this, value));
  164. m_Resizers[value] = resizer;
  165. }
  166. foreach (Resizer vertical in new[] {Resizer.Top, Resizer.Bottom})
  167. foreach (Resizer horizontal in new[] {Resizer.Left, Resizer.Right})
  168. {
  169. VisualElement resizer = this.Q(vertical.ToString().ToLower() + "-" + horizontal.ToString().ToLower() + "-resize");
  170. if (resizer != null)
  171. resizer.AddManipulator(new ElementResizer(this, vertical | horizontal));
  172. m_Resizers[vertical | horizontal] = resizer;
  173. }
  174. }
  175. public enum Resizer
  176. {
  177. Top = 1 << 0,
  178. Bottom = 1 << 1,
  179. Left = 1 << 2,
  180. Right = 1 << 3,
  181. }
  182. Dictionary<Resizer, VisualElement> m_Resizers = new Dictionary<Resizer, VisualElement>();
  183. }
  184. class StickyNodeChangeEvent : EventBase<StickyNodeChangeEvent>
  185. {
  186. public static StickyNodeChangeEvent GetPooled(StickyNote target, Change change)
  187. {
  188. var evt = GetPooled();
  189. evt.target = target;
  190. evt.change = change;
  191. return evt;
  192. }
  193. public enum Change
  194. {
  195. title,
  196. contents,
  197. theme,
  198. textSize,
  199. }
  200. public Change change {get; protected set; }
  201. }
  202. class StickyNote : GraphElement, IResizable
  203. {
  204. GraphData m_Graph;
  205. public new StickyNoteData userData
  206. {
  207. get => (StickyNoteData)base.userData;
  208. set => base.userData = value;
  209. }
  210. public enum Theme
  211. {
  212. Classic,
  213. Black,
  214. Orange,
  215. Green,
  216. Blue,
  217. Red,
  218. Purple,
  219. Teal
  220. }
  221. Theme m_Theme = Theme.Classic;
  222. public Theme theme
  223. {
  224. get
  225. {
  226. return m_Theme;
  227. }
  228. set
  229. {
  230. if (m_Theme != value)
  231. {
  232. m_Theme = value;
  233. UpdateThemeClasses();
  234. }
  235. }
  236. }
  237. public enum TextSize
  238. {
  239. Small,
  240. Medium,
  241. Large,
  242. Huge
  243. }
  244. TextSize m_TextSize = TextSize.Medium;
  245. public TextSize textSize
  246. {
  247. get {return m_TextSize; }
  248. set
  249. {
  250. if (m_TextSize != value)
  251. {
  252. m_TextSize = value;
  253. UpdateSizeClasses();
  254. }
  255. }
  256. }
  257. public virtual void OnStartResize()
  258. {
  259. }
  260. public virtual void OnResized()
  261. {
  262. userData.position = new Rect(resolvedStyle.left, resolvedStyle.top, style.width.value.value, style.height.value.value);
  263. }
  264. Vector2 AllExtraSpace(VisualElement element)
  265. {
  266. return new Vector2(
  267. element.resolvedStyle.marginLeft + element.resolvedStyle.marginRight + element.resolvedStyle.paddingLeft + element.resolvedStyle.paddingRight + element.resolvedStyle.borderRightWidth + element.resolvedStyle.borderLeftWidth,
  268. element.resolvedStyle.marginTop + element.resolvedStyle.marginBottom + element.resolvedStyle.paddingTop + element.resolvedStyle.paddingBottom + element.resolvedStyle.borderBottomWidth + element.resolvedStyle.borderTopWidth
  269. );
  270. }
  271. void OnFitToText(DropdownMenuAction a)
  272. {
  273. FitText(false);
  274. }
  275. public void FitText(bool onlyIfSmaller)
  276. {
  277. Vector2 preferredTitleSize = Vector2.zero;
  278. if (!string.IsNullOrEmpty(m_Title.text))
  279. preferredTitleSize = m_Title.MeasureTextSize(m_Title.text, 0, MeasureMode.Undefined, 0, MeasureMode.Undefined); // This is the size of the string with the current title font and such
  280. preferredTitleSize += AllExtraSpace(m_Title);
  281. preferredTitleSize.x += m_Title.ChangeCoordinatesTo(this, Vector2.zero).x + resolvedStyle.width - m_Title.ChangeCoordinatesTo(this, new Vector2(m_Title.layout.width, 0)).x;
  282. Vector2 preferredContentsSizeOneLine = m_Contents.MeasureTextSize(m_Contents.text, 0, MeasureMode.Undefined, 0, MeasureMode.Undefined);
  283. Vector2 contentExtraSpace = AllExtraSpace(m_Contents);
  284. preferredContentsSizeOneLine += contentExtraSpace;
  285. Vector2 extraSpace = new Vector2(resolvedStyle.width, resolvedStyle.height) - m_Contents.ChangeCoordinatesTo(this, new Vector2(m_Contents.layout.width, m_Contents.layout.height));
  286. extraSpace += m_Title.ChangeCoordinatesTo(this, Vector2.zero);
  287. preferredContentsSizeOneLine += extraSpace;
  288. float width = 0;
  289. float height = 0;
  290. // The content in one line is smaller than the current width.
  291. // Set the width to fit both title and content.
  292. // Set the height to have only one line in the content
  293. if (preferredContentsSizeOneLine.x < Mathf.Max(preferredTitleSize.x, resolvedStyle.width))
  294. {
  295. width = Mathf.Max(preferredContentsSizeOneLine.x, preferredTitleSize.x);
  296. height = preferredContentsSizeOneLine.y + preferredTitleSize.y;
  297. }
  298. else // The width is not enough for the content: keep the width or use the title width if bigger.
  299. {
  300. width = Mathf.Max(preferredTitleSize.x + extraSpace.x, resolvedStyle.width);
  301. float contextWidth = width - extraSpace.x - contentExtraSpace.x;
  302. Vector2 preferredContentsSize = m_Contents.MeasureTextSize(m_Contents.text, contextWidth, MeasureMode.Exactly, 0, MeasureMode.Undefined);
  303. preferredContentsSize += contentExtraSpace;
  304. height = preferredTitleSize.y + preferredContentsSize.y + extraSpace.y;
  305. }
  306. if (!onlyIfSmaller || resolvedStyle.width < width)
  307. style.width = width;
  308. if (!onlyIfSmaller || resolvedStyle.height < height)
  309. style.height = height;
  310. OnResized();
  311. }
  312. void UpdateThemeClasses()
  313. {
  314. foreach (Theme value in System.Enum.GetValues(typeof(Theme)))
  315. {
  316. if (m_Theme != value)
  317. {
  318. RemoveFromClassList("theme-" + value.ToString().ToLower());
  319. }
  320. else
  321. {
  322. AddToClassList("theme-" + value.ToString().ToLower());
  323. }
  324. }
  325. }
  326. void UpdateSizeClasses()
  327. {
  328. foreach (TextSize value in System.Enum.GetValues(typeof(TextSize)))
  329. {
  330. if (m_TextSize != value)
  331. {
  332. RemoveFromClassList("size-" + value.ToString().ToLower());
  333. }
  334. else
  335. {
  336. AddToClassList("size-" + value.ToString().ToLower());
  337. }
  338. }
  339. }
  340. public static readonly Vector2 defaultSize = new Vector2(200, 160);
  341. public StickyNote(Rect position, GraphData graph) : this("UXML/StickyNote", position, graph)
  342. {
  343. styleSheets.Add(Resources.Load<StyleSheet>("Selectable"));
  344. styleSheets.Add(Resources.Load<StyleSheet>("StickyNote"));
  345. RegisterCallback<AttachToPanelEvent>(OnAttachToPanel);
  346. }
  347. public StickyNote(string uiFile, Rect position, GraphData graph)
  348. {
  349. m_Graph = graph;
  350. var tpl = Resources.Load<VisualTreeAsset>(uiFile);
  351. tpl.CloneTree(this);
  352. capabilities = Capabilities.Movable | Capabilities.Deletable | Capabilities.Ascendable | Capabilities.Selectable;
  353. m_Title = this.Q<Label>(name: "title");
  354. if (m_Title != null)
  355. {
  356. m_Title.RegisterCallback<MouseDownEvent>(OnTitleMouseDown);
  357. }
  358. m_TitleField = this.Q<TextField>(name: "title-field");
  359. if (m_TitleField != null)
  360. {
  361. m_TitleField.style.display = DisplayStyle.None;
  362. m_TitleField.Q("unity-text-input").RegisterCallback<BlurEvent>(OnTitleBlur);
  363. m_TitleField.RegisterCallback<ChangeEvent<string>>(OnTitleChange);
  364. }
  365. m_Contents = this.Q<Label>(name: "contents");
  366. if (m_Contents != null)
  367. {
  368. m_ContentsField = m_Contents.Q<TextField>(name: "contents-field");
  369. if (m_ContentsField != null)
  370. {
  371. m_ContentsField.style.display = DisplayStyle.None;
  372. m_ContentsField.multiline = true;
  373. m_ContentsField.Q("unity-text-input").RegisterCallback<BlurEvent>(OnContentsBlur);
  374. }
  375. m_Contents.RegisterCallback<MouseDownEvent>(OnContentsMouseDown);
  376. }
  377. SetPosition(new Rect(position.x, position.y, defaultSize.x, defaultSize.y));
  378. AddToClassList("sticky-note");
  379. AddToClassList("selectable");
  380. UpdateThemeClasses();
  381. UpdateSizeClasses();
  382. this.AddManipulator(new ContextualMenuManipulator(BuildContextualMenu));
  383. }
  384. public void BuildContextualMenu(ContextualMenuPopulateEvent evt)
  385. {
  386. if (evt.target is StickyNote)
  387. {
  388. /*foreach (Theme value in System.Enum.GetValues(typeof(Theme)))
  389. {
  390. evt.menu.AppendAction("Theme/" + value.ToString(), OnChangeTheme, e => DropdownMenu.MenuAction.StatusFlags.Normal, value);
  391. }*/
  392. if (theme == Theme.Black)
  393. evt.menu.AppendAction("Light Theme", OnChangeTheme, e => DropdownMenuAction.Status.Normal, Theme.Classic);
  394. else
  395. evt.menu.AppendAction("Dark Theme", OnChangeTheme, e => DropdownMenuAction.Status.Normal, Theme.Black);
  396. foreach (TextSize value in System.Enum.GetValues(typeof(TextSize)))
  397. {
  398. evt.menu.AppendAction(value.ToString() + " Text Size", OnChangeSize, e => DropdownMenuAction.Status.Normal, value);
  399. }
  400. evt.menu.AppendSeparator();
  401. evt.menu.AppendAction("Fit To Text", OnFitToText, e => DropdownMenuAction.Status.Normal);
  402. evt.menu.AppendSeparator();
  403. evt.menu.AppendAction("Delete", OnDelete, e => DropdownMenuAction.Status.Normal);
  404. evt.menu.AppendSeparator();
  405. }
  406. }
  407. void OnDelete(DropdownMenuAction menuAction)
  408. {
  409. m_Graph.owner.RegisterCompleteObjectUndo("Delete Sticky Note");
  410. m_Graph.RemoveStickyNote(userData);
  411. }
  412. void OnTitleChange(EventBase e)
  413. {
  414. //m_Graph.owner.RegisterCompleteObjectUndo("Title Changed");
  415. //title = m_TitleField.value;
  416. //userData.title = title;
  417. }
  418. const string fitTextClass = "fit-text";
  419. public override void SetPosition(Rect rect)
  420. {
  421. style.left = rect.x;
  422. style.top = rect.y;
  423. style.width = rect.width;
  424. style.height = rect.height;
  425. }
  426. public override Rect GetPosition()
  427. {
  428. return new Rect(resolvedStyle.left, resolvedStyle.top, resolvedStyle.width, resolvedStyle.height);
  429. }
  430. public string contents
  431. {
  432. get {return m_Contents.text; }
  433. set
  434. {
  435. if (m_Contents != null)
  436. {
  437. m_Contents.text = value;
  438. }
  439. }
  440. }
  441. public new string title
  442. {
  443. get {return m_Title.text; }
  444. set
  445. {
  446. if (m_Title != null)
  447. {
  448. m_Title.text = value;
  449. if (!string.IsNullOrEmpty(m_Title.text))
  450. {
  451. m_Title.RemoveFromClassList("empty");
  452. }
  453. else
  454. {
  455. m_Title.AddToClassList("empty");
  456. }
  457. //UpdateTitleHeight();
  458. }
  459. }
  460. }
  461. void OnChangeTheme(DropdownMenuAction action)
  462. {
  463. theme = (Theme)action.userData;
  464. NotifyChange(StickyNodeChangeEvent.Change.theme);
  465. }
  466. void OnChangeSize(DropdownMenuAction action)
  467. {
  468. textSize = (TextSize)action.userData;
  469. NotifyChange(StickyNodeChangeEvent.Change.textSize);
  470. //panel.InternalValidateLayout();
  471. FitText(true);
  472. }
  473. void OnAttachToPanel(AttachToPanelEvent e)
  474. {
  475. //UpdateTitleHeight();
  476. }
  477. void OnTitleBlur(BlurEvent e)
  478. {
  479. //bool changed = m_Title.text != m_TitleField.value;
  480. title = m_TitleField.value;
  481. m_TitleField.style.display = DisplayStyle.None;
  482. m_Title.UnregisterCallback<GeometryChangedEvent>(OnTitleRelayout);
  483. //Notify change
  484. //if( changed)
  485. {
  486. NotifyChange(StickyNodeChangeEvent.Change.title);
  487. }
  488. }
  489. void OnContentsBlur(BlurEvent e)
  490. {
  491. bool changed = m_Contents.text != m_ContentsField.value;
  492. m_Contents.text = m_ContentsField.value;
  493. m_ContentsField.style.display = DisplayStyle.None;
  494. //Notify change
  495. if (changed)
  496. {
  497. NotifyChange(StickyNodeChangeEvent.Change.contents);
  498. }
  499. }
  500. void OnTitleRelayout(GeometryChangedEvent e)
  501. {
  502. UpdateTitleFieldRect();
  503. }
  504. void UpdateTitleFieldRect()
  505. {
  506. Rect rect = m_Title.layout;
  507. m_Title.parent.ChangeCoordinatesTo(m_TitleField.parent, rect);
  508. m_TitleField.style.left = rect.xMin -1;
  509. m_TitleField.style.right = rect.yMin + m_Title.resolvedStyle.marginTop;
  510. m_TitleField.style.width = rect.width - m_Title.resolvedStyle.marginLeft - m_Title.resolvedStyle.marginRight;
  511. m_TitleField.style.height = rect.height - m_Title.resolvedStyle.marginTop - m_Title.resolvedStyle.marginBottom;
  512. }
  513. void OnTitleMouseDown(MouseDownEvent e)
  514. {
  515. if (e.clickCount == 2)
  516. {
  517. m_TitleField.RemoveFromClassList("empty");
  518. m_TitleField.value = m_Title.text;
  519. m_TitleField.style.display = DisplayStyle.Flex;
  520. UpdateTitleFieldRect();
  521. m_Title.RegisterCallback<GeometryChangedEvent>(OnTitleRelayout);
  522. m_TitleField.Q("unity-text-input").Focus();
  523. m_TitleField.SelectAll();
  524. e.StopPropagation();
  525. e.PreventDefault();
  526. }
  527. }
  528. void NotifyChange(StickyNodeChangeEvent.Change change)
  529. {
  530. m_Graph.owner.RegisterCompleteObjectUndo($"Change Sticky Note {change.ToString()}");
  531. if (change == StickyNodeChangeEvent.Change.title)
  532. {
  533. userData.title = title;
  534. }
  535. else if (change == StickyNodeChangeEvent.Change.contents)
  536. {
  537. userData.content = contents;
  538. }
  539. else if (change == StickyNodeChangeEvent.Change.textSize)
  540. {
  541. userData.textSize = (int)textSize;
  542. }
  543. else if (change == StickyNodeChangeEvent.Change.theme)
  544. {
  545. userData.theme = (int)theme;
  546. }
  547. }
  548. public System.Action<StickyNodeChangeEvent.Change> OnChange;
  549. void OnContentsMouseDown(MouseDownEvent e)
  550. {
  551. if (e.clickCount == 2)
  552. {
  553. m_ContentsField.value = m_Contents.text;
  554. m_ContentsField.style.display = DisplayStyle.Flex;
  555. m_ContentsField.Q("unity-text-input").Focus();
  556. e.StopPropagation();
  557. e.PreventDefault();
  558. }
  559. }
  560. Label m_Title;
  561. protected TextField m_TitleField;
  562. Label m_Contents;
  563. protected TextField m_ContentsField;
  564. }
  565. }