Skip to content

Commit 09203b5

Browse files
authored
Hotfix for DPI scaling issues with layout titles
1 parent 8b5ea66 commit 09203b5

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

com.unity.visualeffectgraph/Editor/Utils/VFXSystemBorder.cs

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,20 @@ void OnTitleMouseDown(MouseDownEvent e)
130130

131131
void OnTitleRelayout(GeometryChangedEvent e)
132132
{
133+
Rect oldRoundedRect = new Rect(Mathf.Floor(e.oldRect.x), Mathf.Floor(e.oldRect.y), Mathf.Floor(e.oldRect.width), Mathf.Floor(e.oldRect.height));
134+
Rect newRoundedRect = new Rect(Mathf.Floor(e.newRect.x), Mathf.Floor(e.newRect.y), Mathf.Floor(e.newRect.width), Mathf.Floor(e.newRect.height));
135+
if (oldRoundedRect == newRoundedRect)
136+
{
137+
return;
138+
}
139+
133140
UpdateTitleFieldRect();
134141
RecomputeBounds();
135142
}
136143

137144
void UpdateTitleFieldRect()
138145
{
139146
Rect rect = m_Title.layout;
140-
141147
m_Title.parent.ChangeCoordinatesTo(m_TitleField.parent, rect);
142148

143149

@@ -186,16 +192,18 @@ public override string title
186192
}
187193

188194
public bool m_WaitingRecompute;
195+
private Rect m_previousBounds;
189196

190197
public void RecomputeBounds()
191198
{
192199
if (m_WaitingRecompute)
193200
return;
201+
194202
visible = true;
195203
//title width should be at least as wide as a context to be valid.
196204
float titleWidth = m_Title.layout.width;
197-
bool invalidTitleWidth = float.IsNaN(titleWidth) || titleWidth < 50;
198-
bool titleEmpty = string.IsNullOrEmpty(m_Title.text) || invalidTitleWidth;
205+
bool shouldDeferRecompute = float.IsNaN(titleWidth) || titleWidth < 50;
206+
bool titleEmpty = string.IsNullOrEmpty(m_Title.text) || shouldDeferRecompute;
199207
if (titleEmpty)
200208
{
201209
m_Title.AddToClassList("empty");
@@ -226,22 +234,24 @@ public void RecomputeBounds()
226234
}
227235

228236
if (float.IsNaN(rect.xMin) || float.IsNaN(rect.yMin) || float.IsNaN(rect.width) || float.IsNaN(rect.height))
237+
{
229238
rect = Rect.zero;
239+
shouldDeferRecompute = true;
240+
}
230241

242+
231243
rect = RectUtils.Inflate(rect, 20, titleEmpty ? 20 : m_Title.layout.height, 20, 20);
232-
233-
if (invalidTitleWidth)
244+
rect = new Rect(Mathf.Floor(rect.x), Mathf.Floor(rect.y), Mathf.Floor(rect.width), Mathf.Floor(rect.height));
245+
if (rect != m_previousBounds)
234246
{
235247
SetPosition(rect);
236-
if (!m_WaitingRecompute)
237-
{
238-
m_WaitingRecompute = true;
239-
schedule.Execute(() => { m_WaitingRecompute = false; RecomputeBounds(); }).ExecuteLater(0); // title height might have changed if width have changed
240-
}
248+
m_previousBounds = rect;
241249
}
242-
else
250+
251+
if (shouldDeferRecompute && !m_WaitingRecompute)
243252
{
244-
SetPosition(rect);
253+
m_WaitingRecompute = true;
254+
schedule.Execute(() => { m_WaitingRecompute = false; RecomputeBounds(); }).ExecuteLater(0); // title height might have changed if width have changed
245255
}
246256
}
247257

0 commit comments

Comments
 (0)