Skip to content

Commit

Permalink
Compose: Fix raw editor highlights
Browse files Browse the repository at this point in the history
  • Loading branch information
0thElement committed Jul 28, 2024
1 parent 0871d9a commit 33be573
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Assets/Materials/Compose/Waveform.mat
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Material:
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _ToSample: 13918327
- _ToSample: 0
- _UVSec: 0
- _ZWrite: 1
m_Colors:
Expand Down
4 changes: 2 additions & 2 deletions Assets/Scenes/Compose.unity
Original file line number Diff line number Diff line change
Expand Up @@ -95253,7 +95253,7 @@ MonoBehaviour:
m_TargetGraphic: {fileID: 342982843}
m_HandleRect: {fileID: 342982842}
m_Direction: 2
m_Value: 0
m_Value: 1
m_Size: 1
m_NumberOfSteps: 0
m_OnValueChanged:
Expand Down Expand Up @@ -106478,7 +106478,7 @@ MonoBehaviour:
m_HandleRect: {fileID: 505154476}
m_Direction: 2
m_Value: 1.000001
m_Size: 0.92044705
m_Size: 0.9204472
m_NumberOfSteps: 0
m_OnValueChanged:
m_PersistentCalls:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class LineHighlightComponent : MonoBehaviour, IPointerEnterHandler
private string text;
private Severity severity;

public void SetPosition(TextGenerator gen, Option<int> lineNumber, Option<int> startCharPos, Option<int> length)
public void SetPosition(TextGenerator gen, float pixelPerUnit, Option<int> lineNumber, Option<int> startCharPos, Option<int> length)
{
if (rect == null)
{
Expand All @@ -36,7 +36,7 @@ public void SetPosition(TextGenerator gen, Option<int> lineNumber, Option<int> s
UILineInfo lineInfo = lineInfoArray[lineNumVal];
UILineInfo firstLineInfo = lineInfoArray[0];

float ascender = firstLineInfo.topY - lineInfo.topY - (lineInfo.leading * lineNumVal);
float ascender = (firstLineInfo.topY - lineInfo.topY) / pixelPerUnit;

if (!startCharPos.HasValue)
{
Expand All @@ -45,7 +45,7 @@ public void SetPosition(TextGenerator gen, Option<int> lineNumber, Option<int> s
rect.offsetMin = new Vector2(0, rect.offsetMin.y);
rect.offsetMax = new Vector2(0, rect.offsetMax.y);
rect.anchoredPosition = new Vector2(rect.anchoredPosition.x, -ascender);
rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, lineInfo.height);
rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, lineInfo.height / pixelPerUnit);
}
else
{
Expand All @@ -63,13 +63,13 @@ public void SetPosition(TextGenerator gen, Option<int> lineNumber, Option<int> s

float left = (leftIndex >= 0 && leftIndex < charInfoArray.Count) ? charInfoArray[leftIndex].cursorPos.x : 0;
float right = (rightIndex >= 0 && rightIndex < charInfoArray.Count) ? charInfoArray[rightIndex].cursorPos.x + charInfoArray[rightIndex].charWidth : left + MinWidth;
left += (leftIndex - lineInfo.startCharIdx) * 0.4f;
right += (rightIndex - lineInfo.startCharIdx) * 0.4f;
left /= pixelPerUnit;
right /= pixelPerUnit;

rect.anchorMin = new Vector2(0f, 1f);
rect.anchorMax = new Vector2(0f, 1f);
rect.anchoredPosition = new Vector2((left + right) / 2, -ascender);
rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, lineInfo.height);
rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, lineInfo.height / pixelPerUnit);
rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, Mathf.Abs(right - left));
}
}
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/Compose/Project/RawEditor/RawEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ private async UniTask OnValueChangedTask(string val, CancellationToken ct)
private void DisplayFault(ChartFault fault)
{
LineHighlightComponent line = lineHighlightPool.Get();
line.SetPosition(inputField.TextGenerator, fault.LineNumber, fault.StartCharPos, fault.Length);
line.SetPosition(inputField.TextGenerator, inputField.PixelPerUnit, fault.LineNumber, fault.StartCharPos, fault.Length);
line.SetContent(fault.Severity, fault.Description);

ScrollHighlightComponent scroll = scrollHighlightPool.Get();
Expand Down
4 changes: 3 additions & 1 deletion Assets/Scripts/Utility/Components/FastInputField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public class FastInputField : InputField, IScrollHandler

public TextGenerator TextGenerator => cachedInputTextGenerator;

public float PixelPerUnit => m_TextComponent.pixelsPerUnit;

private RectTransform Rect
{
get
Expand Down Expand Up @@ -341,7 +343,7 @@ private void UpdateScrollbarVerticalPosition()
TextGenerator gen = cachedInputTextGenerator;
UILineInfo firstLine = gen.lines[0];
UILineInfo startLine = gen.lines[line];
float y = firstLine.topY - startLine.topY - (startLine.leading * line);
float y = (firstLine.topY - startLine.topY) / m_TextComponent.pixelsPerUnit;
float val = y / (contentSize.y - gen.rectExtents.size.y);
OnScrollVerticalChanged?.Invoke(y);
verticalScrollbar.SetValueWithoutNotify(val);
Expand Down

0 comments on commit 33be573

Please sign in to comment.