Skip to content

Commit

Permalink
Typing caret's width should be fixed and in the center between texts.
Browse files Browse the repository at this point in the history
  • Loading branch information
andy840119 committed Aug 24, 2024
1 parent 68f92d1 commit 6cd8bfd
Showing 1 changed file with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public partial class DrawableTypingCaret : DrawableRangeCaret<TypingCaretPositio
private const float fading_time = 200;
private const float caret_move_time = 60;
private const float caret_resize_time = 60;
private const float caret_width = 3;
private const float caret_width = 2;

private readonly Box drawableCaret;
private readonly TypingCaretEventHandler? typingCaretEventHandler;
Expand Down Expand Up @@ -75,7 +75,7 @@ protected override void ApplyCaretPosition(TypingCaretPosition caret)
typingCaretEventHandler?.ChangeCharGapAndOffset(caret.CharGap);
typingCaretEventHandler?.FocusInputCaretTextBox();

var rect = LyricPositionProvider.GetRectByCharIndicator(caret.CharGap);
var rect = toRectWithFixedWidth(LyricPositionProvider.GetRectByCharIndicator(caret.CharGap));
changeTheSizeByRect(rect);
}

Expand All @@ -88,10 +88,21 @@ protected override void ApplyRangeCaretPosition(RangeCaretPosition<TypingCaretPo
typingCaretEventHandler?.ChangeCharGapAndOffset(maxGap, maxGap - minGap);
typingCaretEventHandler?.FocusInputCaretTextBox();

var rect = RectangleF.Union(LyricPositionProvider.GetRectByCharIndicator(minGap), LyricPositionProvider.GetRectByCharIndicator(maxGap));
var minGapRect = toRectWithFixedWidth(LyricPositionProvider.GetRectByCharIndicator(minGap));
var maxGapRect = toRectWithFixedWidth(LyricPositionProvider.GetRectByCharIndicator(maxGap));

var rect = RectangleF.Union(minGapRect, maxGapRect);
changeTheSizeByRect(rect);
}

private RectangleF toRectWithFixedWidth(RectangleF rect)
{
var position = rect.TopLeft + new Vector2(rect.Width / 2 - caret_width / 2, 0);
var size = new Vector2(caret_width, rect.Height);

return new RectangleF(position, size);
}

private void changeTheSizeByRect(RectangleF rect)
{
var position = rect.TopLeft - new Vector2(caret_width / 2, 0);
Expand Down

0 comments on commit 6cd8bfd

Please sign in to comment.