mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
widget: define incrementing combinedPos and test
This commit restructures seekPosition from a complex state-manipulating loop into a simple loop of iteratively applying an increment operation to the combinedPos. The increment operation itself is now tested, and much easier to understand. Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
This commit is contained in:
@@ -32,11 +32,17 @@ type screenPos image.Point
|
||||
|
||||
const inf = 1e6
|
||||
|
||||
// posIsAbove returns whether the position described in pos by the lineCol and
|
||||
// y fields is above the given y coordinate. It is invalid to call this function
|
||||
// unless both the lineCol and (x,y) fields of pos are populated.
|
||||
func posIsAbove(lines []text.Line, pos combinedPos, y int) bool {
|
||||
line := lines[pos.lineCol.Y]
|
||||
return pos.y+line.Bounds.Max.Y.Ceil() < y
|
||||
}
|
||||
|
||||
// posIsAbove returns whether the position described in pos by the lineCol and
|
||||
// y fields is below the given y coordinate. It is invalid to call this function
|
||||
// unless both the lineCol and (x,y) fields of pos are populated.
|
||||
func posIsBelow(lines []text.Line, pos combinedPos, y int) bool {
|
||||
line := lines[pos.lineCol.Y]
|
||||
return pos.y+line.Bounds.Min.Y.Floor() > y
|
||||
@@ -84,6 +90,9 @@ func subLayout(line text.Line, start, end combinedPos) text.Layout {
|
||||
//
|
||||
// The results can be counterinuitive due to the fact that meaning
|
||||
// of alignment changes depending on the text direction.
|
||||
//
|
||||
// The returned pos can be considered valid only for the first line
|
||||
// of a body of text.
|
||||
func firstPos(line text.Line, alignment text.Alignment, width int) combinedPos {
|
||||
p := combinedPos{
|
||||
x: align(alignment, line.Layout.Direction, line.Width, width),
|
||||
|
||||
Reference in New Issue
Block a user