github.com/jmigpin/editor@v1.6.0/util/drawutil/drawer4/visible.go (about) 1 package drawer4 2 3 import ( 4 "github.com/jmigpin/editor/util/mathutil" 5 ) 6 7 func header1PenBounds(d *Drawer, offset int) (mathutil.RectangleIntf, bool) { 8 d.st = State{} 9 fnIter := FnIter{} 10 iters := append(d.sIters(true), &fnIter) 11 d.loopInit(iters) 12 d.header1() 13 14 found := false 15 pen := mathutil.RectangleIntf{} 16 fnIter.fn = func() { 17 if d.iters.runeR.isNormal() { 18 if d.st.runeR.ri >= offset { 19 if d.st.runeR.ri == offset { 20 found = true 21 pen = d.iters.runeR.penBounds() 22 } 23 d.iterStop() 24 return 25 } 26 } 27 if !d.iterNext() { 28 return 29 } 30 } 31 32 d.loop() 33 34 return pen, found 35 } 36 37 //---------- 38 39 type PenVisibility struct { 40 not bool // not visible 41 full bool // fully visible 42 partial bool // partially visible 43 top bool // otherwise is bottom, valid in "full" and "partial" 44 } 45 46 func penVisibility(d *Drawer, offset int) *PenVisibility { 47 v := &PenVisibility{} 48 pb, ok := header1PenBounds(d, offset) 49 if !ok { 50 v.not = true 51 } else { 52 pr := pb.ToRectFloorCeil() 53 // allow intersection of empty x in penbounds (case of eof) 54 if pr.Dx() == 0 { 55 pr.Max.X = pr.Min.X + 1 56 } 57 58 // consider previous/next lines (allows cursor up/down to move 1 line instead of jumping the view aligned to the center) 59 b := d.bounds // copy 60 b.Min.Y-- 61 b.Max.Y++ 62 63 ir := b.Intersect(pr) 64 if ir.Empty() { 65 v.not = true 66 } else if ir == pr { 67 v.full = true 68 } else { 69 v.partial = true 70 if pr.Min.Y < b.Min.Y { 71 v.top = true 72 } 73 } 74 } 75 return v 76 }