浏览代码

Add keyboard enter event for TextField

habeebweeb 4 年之前
父节点
当前提交
55447c33fa
共有 1 个文件被更改,包括 6 次插入0 次删除
  1. 6 0
      COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/GUI/Controls/TextField.cs

+ 6 - 0
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/GUI/Controls/TextField.cs

@@ -1,14 +1,20 @@
+using System;
 using UnityEngine;
 
 namespace COM3D2.MeidoPhotoStudio.Plugin
 {
     internal class TextField : BaseControl
     {
+        private static int textFieldID = 961;
+        private static int ID => ++textFieldID;
+        private readonly string controlName = $"textField{ID}";
         public string Value { get; set; } = string.Empty;
         public void Draw(GUIStyle textFieldStyle, params GUILayoutOption[] layoutOptions)
         {
             if (!Visible) return;
+            GUI.SetNextControlName(controlName);
             Value = GUILayout.TextField(Value, textFieldStyle, layoutOptions);
+            if (Event.current.isKey && Event.current.keyCode == KeyCode.Return) OnControlEvent(EventArgs.Empty);
         }
 
         public override void Draw(params GUILayoutOption[] layoutOptions)