LayoutBounds can have a negative start
This causes the LayoutBounds of center-aligned, left-aligned text to be more accurate
This commit is contained in:
		
							parent
							
								
									f0adca5c37
								
							
						
					
					
						commit
						0342e25456
					
				
							
								
								
									
										51
									
								
								flow.go
									
									
									
									
									
								
							
							
						
						
									
										51
									
								
								flow.go
									
									
									
									
									
								
							@ -18,11 +18,14 @@ func reflow (
 | 
			
		||||
	metrics := face.Metrics()
 | 
			
		||||
	
 | 
			
		||||
	var dot fixed.Point26_6
 | 
			
		||||
	const notSeen = -1
 | 
			
		||||
	firstWord := notSeen
 | 
			
		||||
	lineStart := 0
 | 
			
		||||
	lineEnd   := 0
 | 
			
		||||
	lastWord  := 0
 | 
			
		||||
	lastToken := 0
 | 
			
		||||
	nLines    := 0
 | 
			
		||||
	firstLine := true
 | 
			
		||||
 | 
			
		||||
	newline := func () {
 | 
			
		||||
		// if the line isn't empty
 | 
			
		||||
@ -31,13 +34,31 @@ func reflow (
 | 
			
		||||
			alignLine (
 | 
			
		||||
				tokens[lineStart:lineEnd],
 | 
			
		||||
				size.X, xAlign, lineEnd == len(tokens))
 | 
			
		||||
			
 | 
			
		||||
 | 
			
		||||
			// calculate extents
 | 
			
		||||
			lineMax, lineMaxSpace := calculateLineExtents (
 | 
			
		||||
				tokens[lastWord],
 | 
			
		||||
				tokens[lastToken])
 | 
			
		||||
			if lineMax      > extents.Max.X      { extents.Max.X      = lineMax      }
 | 
			
		||||
			if lineMaxSpace > extentsSpace.Max.X { extentsSpace.Max.X = lineMaxSpace }
 | 
			
		||||
			var lineMin, lineMinSpace, lineMax, lineMaxSpace fixed.Int26_6
 | 
			
		||||
 | 
			
		||||
			lineMinSpace = tokens[lineStart].position.X
 | 
			
		||||
			if firstWord == notSeen {
 | 
			
		||||
				lineMin = lineMinSpace
 | 
			
		||||
			} else {
 | 
			
		||||
				lineMin = tokens[firstWord].position.X
 | 
			
		||||
			}
 | 
			
		||||
			
 | 
			
		||||
			lastWordTok   := tokens[lastWord]
 | 
			
		||||
			lastTokenTok  := tokens[lastToken]
 | 
			
		||||
			if lastWordTok.kind == tokenKindWord {
 | 
			
		||||
				// the line had a word in it
 | 
			
		||||
				lineMax = lastWordTok.position.X + lastWordTok.width
 | 
			
		||||
			}
 | 
			
		||||
			lineMaxSpace = lastTokenTok.position.X + lastTokenTok.width
 | 
			
		||||
			// println(lineMax.String(), lineMaxSpace.String())
 | 
			
		||||
				
 | 
			
		||||
			if lineMin      < extents.Min.X      || firstLine { extents.Min.X      = lineMin      }
 | 
			
		||||
			if lineMinSpace < extentsSpace.Min.X || firstLine { extentsSpace.Min.X = lineMinSpace }
 | 
			
		||||
			if lineMax      > extents.Max.X                   { extents.Max.X      = lineMax      }
 | 
			
		||||
			if lineMaxSpace > extentsSpace.Max.X              { extentsSpace.Max.X = lineMaxSpace }
 | 
			
		||||
			firstLine = false
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		// update dot
 | 
			
		||||
@ -47,6 +68,7 @@ func reflow (
 | 
			
		||||
		// update indices, counts
 | 
			
		||||
		lineStart = lineEnd
 | 
			
		||||
		lastWord  = lineEnd
 | 
			
		||||
		firstWord = notSeen
 | 
			
		||||
		nLines ++
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@ -59,6 +81,9 @@ func reflow (
 | 
			
		||||
			lastToken = index
 | 
			
		||||
			if token.kind == tokenKindWord {
 | 
			
		||||
				lastWord = index
 | 
			
		||||
				if firstWord == notSeen {
 | 
			
		||||
					firstWord = index
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
@ -111,14 +136,12 @@ func fixedRectDy (rect fixed.Rectangle26_6) fixed.Int26_6 {
 | 
			
		||||
	return rect.Max.Y - rect.Min.Y
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func calculateLineExtents (lastWord, lastToken token) (lineMax, lineMaxSpace fixed.Int26_6) {
 | 
			
		||||
	if lastWord.kind == tokenKindWord {
 | 
			
		||||
		// the line had a word in it
 | 
			
		||||
		lineMax = lastWord.position.X  + lastWord.width
 | 
			
		||||
	}
 | 
			
		||||
	lineMaxSpace = lastToken.position.X + lastToken.width
 | 
			
		||||
	// println(lineMax.String(), lineMaxSpace.String())
 | 
			
		||||
	return lineMax, lineMaxSpace
 | 
			
		||||
func calculateLineExtents (
 | 
			
		||||
	firstWord, firstToken, lastWord, lastToken token,
 | 
			
		||||
) (
 | 
			
		||||
	lineMin, lineMinSpace, lineMax, lineMaxSpace fixed.Int26_6,
 | 
			
		||||
) {
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func alignLinesVertically (tokens []token, height, contentHeight fixed.Int26_6, align Align) {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user