Skip to content

Commit 4967456

Browse files
committed
Fix bugs
1 parent 6ff9616 commit 4967456

File tree

3 files changed

+42
-15
lines changed

3 files changed

+42
-15
lines changed

Editor/Scripts/Window/Content/Detail/CodeExecutorWindowCodeEditor.cs

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using UnityEditor;
12
using UnityEngine;
23
using UnityEngine.UIElements;
34

@@ -145,6 +146,7 @@ private void InitCodeEditor()
145146
paddingBottom = 1,
146147
paddingLeft = 1,
147148
paddingRight = 1,
149+
opacity = 0.8f,
148150
}
149151
};
150152
m_CodeEditor.Add(m_CodeEditorClipboardButton);
@@ -165,8 +167,14 @@ private void InitCodeEditor()
165167
/// <param name="evt"></param>
166168
private void OnCodeScrollViewGeometryChangedEventChanged(GeometryChangedEvent evt)
167169
{
168-
float height = m_CodeScrollView.contentViewport.localBound.height;
169-
m_CodeTextField.style.minHeight = height;
170+
EditorApplication.delayCall += UpdateCodeTextFieldHeight;
171+
172+
void UpdateCodeTextFieldHeight()
173+
{
174+
if (m_CodeScrollView == null) return;
175+
float height = m_CodeScrollView.contentViewport.localBound.height;
176+
m_CodeTextField.style.minHeight = height;
177+
}
170178
}
171179

172180
/// <summary>
@@ -277,7 +285,9 @@ private void OnCodeEditorClipboardButtonClick()
277285
/// <param name="evt"></param>
278286
private void OnCodeEditorMouseEnter(MouseEnterEvent evt)
279287
{
280-
m_CodeEditorClipboardButton.style.display = DisplayStyle.Flex;
288+
m_CodeEditorClipboardButton.style.display = (
289+
m_CodeTextField.isReadOnly ? DisplayStyle.Flex : DisplayStyle.None
290+
);
281291
}
282292

283293
/// <summary>

Editor/Scripts/Window/Content/Detail/CodeExecutorWindowHeader.cs

+22-12
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public partial class CodeExecutorWindow
1919
/// <summary>
2020
/// 标题标签
2121
/// </summary>
22-
private Label m_TitleLabel = null;
22+
private TextField m_TitleTextField = null;
2323

2424
/// <summary>
2525
/// 按钮容器
@@ -57,39 +57,49 @@ private void InitHeadline()
5757
paddingBottom = 2,
5858
paddingLeft = 3,
5959
paddingRight = 3,
60-
flexDirection = FlexDirection.Column,
61-
alignItems = Align.FlexStart,
62-
justifyContent = Justify.Center,
60+
flexDirection = FlexDirection.Row,
61+
alignItems = Align.Center,
62+
justifyContent = Justify.SpaceBetween,
6363
},
6464
};
6565
m_Detail.Add(m_Header);
6666
// 监听元素尺寸变化
6767
m_Detail.RegisterCallback<GeometryChangedEvent>(OnHeaderGeometryChangedEventChanged);
6868

69-
// 标题
70-
m_TitleLabel = new Label()
69+
m_TitleTextField = new TextField()
7170
{
7271
name = "Title",
73-
text = string.Empty,
72+
value = string.Empty,
73+
multiline = true,
74+
isReadOnly = true,
7475
style =
7576
{
77+
flexShrink = 1,
7678
fontSize = 16,
7779
marginLeft = 0,
7880
unityFontStyleAndWeight = FontStyle.Bold,
7981
unityTextAlign = TextAnchor.UpperLeft,
8082
whiteSpace = WhiteSpace.Normal,
8183
},
8284
};
83-
m_Header.Add(m_TitleLabel);
85+
m_Header.Add(m_TitleTextField);
86+
{
87+
// 移除输入框的背景和边框
88+
VisualElement textInput = m_TitleTextField.Q<VisualElement>("unity-text-input");
89+
textInput.style.backgroundColor = StyleKeyword.None;
90+
textInput.style.borderTopWidth = 0;
91+
textInput.style.borderBottomWidth = 0;
92+
textInput.style.borderLeftWidth = 0;
93+
textInput.style.borderRightWidth = 0;
94+
}
8495

8596
m_HeaderButtonContainer = new VisualElement()
8697
{
8798
name = "Buttons",
8899
style =
89100
{
90101
flexDirection = FlexDirection.Row,
91-
position = Position.Absolute,
92-
right = 3,
102+
flexShrink = 0,
93103
alignItems = Align.Center,
94104
justifyContent = Justify.Center,
95105
}
@@ -234,8 +244,8 @@ private void SetEditButtonStatus(bool isShow)
234244
/// <param name="suffix"></param>
235245
private void SetTitleText(string text, string suffix = null)
236246
{
237-
m_TitleLabel.text = (suffix == null ? text : text + suffix);
238-
m_TitleLabel.tooltip = text;
247+
m_TitleTextField.value = (suffix == null ? text : text + suffix);
248+
m_TitleTextField.tooltip = text;
239249
}
240250

241251
/// <summary>

Editor/Scripts/Window/Content/Sidebar/CodeExecutorWindowSnippetTreeView.cs

+7
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,20 @@ private void InitSnippetTreeView()
6868

6969
// 代理GUI绘制调用
7070
m_SnippetTreeViewContainer.onGUIHandler = OnSnippetTreeViewContainerGUI;
71+
// 元素失焦回调
72+
m_SnippetTreeViewContainer.RegisterCallback<BlurEvent>(OnSnippetTreeViewContainerBlur);
7173
}
7274

7375
private void OnSnippetTreeViewContainerGUI()
7476
{
7577
m_SnippetTreeView.OnGUI(m_SnippetTreeViewContainer.contentRect);
7678
}
7779

80+
private void OnSnippetTreeViewContainerBlur(BlurEvent evt)
81+
{
82+
m_SnippetTreeView.EndRename();
83+
}
84+
7885
private void OnSnippetTreeViewKeyDown(Event evt)
7986
{
8087
// Ctrl + F

0 commit comments

Comments
 (0)