Skip to content

Commit 65129de

Browse files
committed
fix: Fixed an issue where you could not enter Chinese when searching for menu items
1 parent 2f88237 commit 65129de

File tree

4 files changed

+156
-6
lines changed

4 files changed

+156
-6
lines changed

Editor/Scripts/IMGUITextField.cs

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
using UnityEditor;
2+
using UnityEngine;
3+
using UnityEngine.UIElements;
4+
5+
namespace GBG.AssetQuickAccess.Editor
6+
{
7+
internal class IMGUITextField : VisualElement, INotifyValueChanged<string>
8+
{
9+
public string LabelText
10+
{
11+
get => LabelElement.text;
12+
set
13+
{
14+
LabelElement.text = value;
15+
RefreshLabelElementStyle();
16+
}
17+
}
18+
public string HintText
19+
{
20+
get => HintElement.text;
21+
set => HintElement.text = value;
22+
}
23+
24+
public string value
25+
{
26+
get => _value;
27+
set
28+
{
29+
if (_value == value)
30+
{
31+
return;
32+
}
33+
34+
string previousValue = _value;
35+
SetValueWithoutNotify(value);
36+
using (ChangeEvent<string> evt = ChangeEvent<string>.GetPooled(previousValue, _value))
37+
{
38+
evt.target = this;
39+
SendEvent(evt);
40+
}
41+
}
42+
}
43+
44+
public Label LabelElement { get; }
45+
public Label HintElement { get; }
46+
public IMGUIContainer InputFieldElement { get; }
47+
48+
private string _value;
49+
50+
51+
public IMGUITextField(string labelText = null, string hintText = null)
52+
{
53+
style.flexDirection = FlexDirection.Row;
54+
style.height = 21;
55+
56+
// label
57+
LabelElement = new Label
58+
{
59+
name = "imgui-text-field-label",
60+
pickingMode = PickingMode.Ignore,
61+
};
62+
Add(LabelElement);
63+
64+
// imgui input field
65+
InputFieldElement = new IMGUIContainer(DrawTextField)
66+
{
67+
name = "imgui-text-field-container",
68+
style =
69+
{
70+
flexGrow = 1,
71+
}
72+
};
73+
Add(InputFieldElement);
74+
75+
// hint label
76+
HintElement = new Label
77+
{
78+
name = "imgui-text-field-hint-label",
79+
pickingMode = PickingMode.Ignore,
80+
style =
81+
{
82+
flexGrow = 1,
83+
marginLeft = 2,
84+
marginRight = 2,
85+
marginTop = 1,
86+
marginBottom = 1,
87+
unityFontStyleAndWeight = FontStyle.Italic,
88+
}
89+
};
90+
InputFieldElement.Add(HintElement);
91+
92+
LabelText = labelText;
93+
HintText = hintText;
94+
}
95+
96+
public void SetValueWithoutNotify(string newValue)
97+
{
98+
_value = newValue;
99+
RefreshHintDisplay();
100+
}
101+
102+
public void RefreshHintDisplay()
103+
{
104+
HintElement.style.display = string.IsNullOrEmpty(_value)
105+
? DisplayStyle.Flex
106+
: DisplayStyle.None;
107+
}
108+
109+
public void RefreshLabelElementStyle()
110+
{
111+
if (string.IsNullOrEmpty(value))
112+
{
113+
LabelElement.style.paddingLeft = 0;
114+
LabelElement.style.paddingRight = 0;
115+
}
116+
else
117+
{
118+
LabelElement.style.paddingLeft = 3;
119+
LabelElement.style.paddingRight = 3;
120+
}
121+
}
122+
123+
private void DrawTextField()
124+
{
125+
string previousValue = _value;
126+
EditorGUI.BeginChangeCheck();
127+
_value = EditorGUILayout.TextField(_value);
128+
if (EditorGUI.EndChangeCheck())
129+
{
130+
RefreshHintDisplay();
131+
using (ChangeEvent<string> evt = ChangeEvent<string>.GetPooled(previousValue, _value))
132+
{
133+
evt.target = this;
134+
SendEvent(evt);
135+
}
136+
}
137+
}
138+
}
139+
}

Editor/Scripts/IMGUITextField.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/Scripts/MenuItemSelectWindow.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public static string RemoveShortcutSymbols(string menuPath)
108108

109109

110110
private SubmitHandler _onSubmit;
111-
private TextField _menuPathField;
111+
private IMGUITextField _menuPathField;
112112
private ListView _menuPathListView;
113113
private Label _statusLabel;
114114
private Button _addButton;
@@ -134,13 +134,13 @@ private void CreateGUI()
134134
rootVisualElement.RegisterCallback<KeyUpEvent>(HandleKeyUp);
135135

136136
// Menu path field
137-
_menuPathField = new TextField
137+
_menuPathField = new IMGUITextField
138138
{
139139
name = "MenuPathField",
140-
label = "Menu Item",
140+
LabelText = "Menu Item",
141141
};
142-
_menuPathField.Q<Label>().style.minWidth = 70;
143-
_menuPathField.Q<Label>().style.maxWidth = 70;
142+
_menuPathField.LabelElement.style.minWidth = 70;
143+
_menuPathField.LabelElement.style.maxWidth = 70;
144144
_menuPathField.RegisterValueChangedCallback(OnMenuPathChanged);
145145
rootVisualElement.Add(_menuPathField);
146146

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "com.greenbamboogames.assetquickaccess",
3-
"version": "1.4.0",
3+
"version": "1.4.1",
44
"displayName": "Asset Quick Access!",
55
"description": "Pin frequently used objects to a separate editor window. An enhanced version of Unity's Favorites feature.",
66
"unity": "2019.4",

0 commit comments

Comments
 (0)