Skip to content

Commit abc6209

Browse files
committed
fix(multilineinput): fix caret outside frame and hide with empty text
1 parent 665b944 commit abc6209

1 file changed

Lines changed: 19 additions & 14 deletions

File tree

SharpEngine.Core/Widget/MultiLineInput.cs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,13 @@ public override void Draw()
7878

7979
var finalFont = Scene?.Window?.FontManager.GetFont(Font);
8080

81-
if (Text.Length <= 0 || Font.Length <= 0 || finalFont == null)
81+
if (Font.Length <= 0 || finalFont == null)
8282
return;
8383

8484
var finalFontSize = FontSize ?? finalFont.Value.BaseSize;
8585

8686
var textSize = Raylib.MeasureTextEx(finalFont.Value, Text.Split("\n")[^1], finalFontSize, 2);
87+
var realTextSize = Raylib.MeasureTextEx(finalFont.Value, "A", finalFontSize, 2);
8788

8889
var finalPosition = new Vec2(RealPosition.X - Size.X / 2 + 4, RealPosition.Y - Size.Y / 2 + 4);
8990

@@ -98,21 +99,25 @@ public override void Draw()
9899
(int)Size.Y - 8,
99100
InstructionSource.UI,
100101
ZLayer + 0.00002f,
101-
() => DrawLines(finalFont!.Value, finalFontSize, finalPosition, lines, offsetX, offsetY)
102+
() =>
103+
{
104+
DrawLines(finalFont!.Value, finalFontSize, finalPosition, lines, offsetX, offsetY);
105+
106+
if (Focused)
107+
{
108+
SERender.DrawRectangle(
109+
finalPosition.X + 6 + textSize.X - (offsetX > 0 ? offsetX : 0),
110+
finalPosition.Y + realTextSize.Y * (lines.Length == 0 ? 1 : lines.Length - 1) - (offsetY > 0 ? offsetY : 0),
111+
5,
112+
realTextSize.Y,
113+
Color.Black,
114+
InstructionSource.UI,
115+
ZLayer + 0.00003f
116+
);
117+
}
118+
}
102119
);
103120

104-
if (Focused)
105-
SERender.DrawRectangle(
106-
(int)(finalPosition.X + 6 + textSize.X - (offsetX > 0 ? offsetX : 0)),
107-
(int)(
108-
finalPosition.Y + textSize.Y * (lines.Length - 1) - (offsetY > 0 ? offsetY : 0)
109-
),
110-
5,
111-
(int)textSize.Y,
112-
Color.Black,
113-
InstructionSource.UI,
114-
ZLayer + 0.00003f
115-
);
116121
}
117122

118123
private void DrawLines(Font finalFont, int finalFontSize, Vec2 finalPosition, string[] lines, float offsetX, float offsetY)

0 commit comments

Comments
 (0)