widget: test firstPos

This commit adds a test to lock in the correct behavior of the
firstPos helper method.

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
This commit is contained in:
Chris Waldon
2022-10-12 16:59:22 -04:00
committed by Elias Naur
parent b46c0f5907
commit 1be58a2bc4
2 changed files with 152 additions and 4 deletions
+8 -4
View File
@@ -76,6 +76,14 @@ func subLayout(line text.Line, start, end combinedPos) text.Layout {
return line.Layout.Slice(startCluster, endCluster)
}
// firstPos returns a combinedPos with *only* the x and y
// fields populated. They will be set to the location of the
// dot at the beginning of the line, with text alignment taken
// into account. For RTL text, this will
// be on the right edge of the available space.
//
// The results can be counterinuitive due to the fact that meaning
// of alignment changes depending on the text direction.
func firstPos(line text.Line, alignment text.Alignment, width int) combinedPos {
p := combinedPos{
x: align(alignment, line.Layout.Direction, line.Width, width),
@@ -88,10 +96,6 @@ func firstPos(line text.Line, alignment text.Alignment, width int) combinedPos {
return p
}
func (p1 screenPos) Less(p2 screenPos) bool {
return p1.Y < p2.Y || (p1.Y == p2.Y && p1.X < p2.X)
}
func (l Label) Layout(gtx layout.Context, s text.Shaper, font text.Font, size unit.Sp, txt string) layout.Dimensions {
cs := gtx.Constraints
textSize := fixed.I(gtx.Sp(size))