gutterview.monkey2 1005 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. Namespace ted2
  2. Class GutterView Extends View
  3. Method New( textView:TextView )
  4. Style=GetStyle( "GutterView" )
  5. _textView=textView
  6. End
  7. Protected
  8. Method OnValidateStyle() Override
  9. Local font:=RenderStyle.Font
  10. _width=font.TextWidth( "1234567" )
  11. _size=New Vec2i( font.TextWidth( "12345678" ),0 )
  12. End
  13. Method OnMeasure:Vec2i() Override
  14. Return _size
  15. End
  16. Method OnRender( canvas:Canvas ) Override
  17. canvas.Color=RenderStyle.BackgroundColor
  18. canvas.DrawRect( Rect.X,Rect.Y,Rect.Width,Rect.Height )
  19. canvas.Color=RenderStyle.TextColor
  20. Local vrect:=_textView.VisibleRect
  21. Local firstLine:=_textView.LineAtPoint( vrect.TopLeft )
  22. Local lastLine:=_textView.LineAtPoint( vrect.BottomLeft )+1
  23. canvas.Translate( 0,-vrect.Top )
  24. For Local i:=firstLine Until lastLine
  25. Local rect:=_textView.LineRect( i )
  26. canvas.DrawText( i+1,_width,rect.Top,1,0 )
  27. Next
  28. End
  29. Private
  30. Field _width:Int
  31. Field _size:Vec2i
  32. Field _textView:TextView
  33. End