-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(lyrics)!: newline calculation for the new lyric-stile
- Loading branch information
1 parent
c9ea05e
commit aeb64b8
Showing
5 changed files
with
95 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using Avalonia; | ||
using Avalonia.Media; | ||
using DevBase.Generics; | ||
|
||
namespace OpenLyricsClient.Frontend.Utils; | ||
|
||
public class StringUtils | ||
{ | ||
public static AList<string> SplitTextToLines(string text, double width, double height, Typeface typeface, TextAlignment alignment, double fontSize) | ||
{ | ||
string[] words = text.Split(' '); | ||
|
||
AList<string> lines = new AList<string>(); | ||
|
||
StringBuilder currentLine = new StringBuilder(); | ||
|
||
TextWrapping textWrapping = TextWrapping.NoWrap; | ||
Size constraint = new Size(width, height); | ||
|
||
for (int i = 0; i < words.Length; i++) | ||
{ | ||
string word = words[i]; | ||
|
||
StringBuilder candidateLine = new StringBuilder(currentLine.ToString()); | ||
|
||
if (candidateLine.Length > 0) | ||
candidateLine.Append(' '); | ||
candidateLine.Append(word); | ||
|
||
FormattedText formattedCandidateLine = new FormattedText(candidateLine.ToString(), typeface, fontSize, alignment, textWrapping, constraint); | ||
if (formattedCandidateLine.Bounds.Width <= width) | ||
{ | ||
currentLine = candidateLine; | ||
} | ||
else | ||
{ | ||
lines.Add(currentLine.ToString()); | ||
currentLine.Clear(); | ||
currentLine.Append(word); | ||
} | ||
} | ||
|
||
if (currentLine.Length > 0) | ||
{ | ||
lines.Add(currentLine.ToString()); | ||
} | ||
|
||
return lines; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters