viewcell.monkey2 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. Namespace mojox
  2. Class ViewCell
  3. Method New()
  4. End
  5. Method New( text:String,icon:Image=null )
  6. _text=text
  7. _icon=icon
  8. End
  9. Property Text:String()
  10. Return _text
  11. Setter( text:String )
  12. _text=text
  13. OnModified()
  14. End
  15. Property Icon:Image()
  16. Return _icon
  17. Setter( icon:Image )
  18. _icon=icon
  19. OnModified()
  20. End
  21. Method Measure:Vec2i( style:Style ) Virtual
  22. Local size:=style.MeasureText( _text )
  23. If _icon
  24. size.x+=_icon.Width+style.Font.TextWidth( " " )
  25. size.y=Max( size.y,Int( _icon.Height ) )
  26. Endif
  27. size+=style.Bounds.Size
  28. Return size
  29. End
  30. Method Render( canvas:Canvas,rect:Recti,style:Style,textGravity:Vec2f ) Virtual
  31. style.Render( canvas,rect )
  32. rect-=style.Bounds
  33. If _icon
  34. Local y:=(rect.Height-_icon.Height)/2
  35. style.DrawIcon( canvas,_icon,rect.min.x,rect.min.y+y )
  36. rect.min.x+=_icon.Width+style.Font.TextWidth( " " )
  37. Endif
  38. style.DrawText( canvas,_text,rect,textGravity )
  39. End
  40. Protected
  41. Method OnModified() Virtual
  42. End
  43. Private
  44. Field _text:String
  45. Field _icon:Image
  46. End