renderDepthBackground renders the depth background color.
(stln, edln int)
| 200 | |
| 201 | // renderDepthBackground renders the depth background color. |
| 202 | func (ed *Editor) renderDepthBackground(stln, edln int) { |
| 203 | if ed.Buffer == nil { |
| 204 | return |
| 205 | } |
| 206 | if !ed.Buffer.Options.DepthColor || ed.IsDisabled() || !ed.StateIs(states.Focused) { |
| 207 | return |
| 208 | } |
| 209 | buf := ed.Buffer |
| 210 | |
| 211 | bb := ed.renderBBox() |
| 212 | bln := buf.NumLines() |
| 213 | sty := &ed.Styles |
| 214 | isDark := matcolor.SchemeIsDark |
| 215 | nclrs := len(viewDepthColors) |
| 216 | lstdp := 0 |
| 217 | for ln := stln; ln <= edln; ln++ { |
| 218 | lst := ed.charStartPos(lexer.Pos{Ln: ln}).Y // note: charstart pos includes descent |
| 219 | led := lst + math32.Max(ed.renders[ln].BBox.Size().Y, ed.lineHeight) |
| 220 | if int(math32.Ceil(led)) < bb.Min.Y { |
| 221 | continue |
| 222 | } |
| 223 | if int(math32.Floor(lst)) > bb.Max.Y { |
| 224 | continue |
| 225 | } |
| 226 | if ln >= bln { // may be out of sync |
| 227 | continue |
| 228 | } |
| 229 | ht := buf.HiTags(ln) |
| 230 | lsted := 0 |
| 231 | for ti := range ht { |
| 232 | lx := &ht[ti] |
| 233 | if lx.Token.Depth > 0 { |
| 234 | var vdc color.RGBA |
| 235 | if isDark { // reverse order too |
| 236 | vdc = viewDepthColors[nclrs-1-lx.Token.Depth%nclrs] |
| 237 | } else { |
| 238 | vdc = viewDepthColors[lx.Token.Depth%nclrs] |
| 239 | } |
| 240 | bg := gradient.Apply(sty.Background, func(c color.Color) color.Color { |
| 241 | if isDark { // reverse order too |
| 242 | return colors.Add(c, vdc) |
| 243 | } |
| 244 | return colors.Sub(c, vdc) |
| 245 | }) |
| 246 | |
| 247 | st := min(lsted, lx.St) |
| 248 | reg := text.Region{Start: lexer.Pos{Ln: ln, Ch: st}, End: lexer.Pos{Ln: ln, Ch: lx.Ed}} |
| 249 | lsted = lx.Ed |
| 250 | lstdp = lx.Token.Depth |
| 251 | ed.renderRegionBoxStyle(reg, sty, bg, true) // full width alway |
| 252 | } |
| 253 | } |
| 254 | if lstdp > 0 { |
| 255 | ed.renderRegionToEnd(lexer.Pos{Ln: ln, Ch: lsted}, sty, sty.Background) |
| 256 | } |
| 257 | } |
| 258 | } |
| 259 |
no test coverage detected