list_item.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package UI
  2. import (
  3. "github.com/veandco/go-sdl2/ttf"
  4. "github.com/cuu/gogame/draw"
  5. "github.com/cuu/gogame/color"
  6. )
  7. type ListItemInterface interface {
  8. Init(text string)
  9. Size() (int,int)
  10. NewSize(w,h int)
  11. Coord() (int,int)
  12. NewCoord(x,y int)
  13. GetLinkObj() PluginInterface
  14. Draw()
  15. }
  16. type ListItem struct {
  17. Widget
  18. Labels map[string]LabelInterface
  19. Icons map[string]IconItemInterface
  20. Fonts map[string]*ttf.Font
  21. LinkObj PluginInterface
  22. Parent PageInterface
  23. }
  24. func NewListItem() *ListItem {
  25. i := &ListItem{}
  26. i.Labels = make(map[string]LabelInterface)
  27. i.Icons = make( map[string]IconItemInterface)
  28. i.Fonts = make(map[string]*ttf.Font)
  29. i.Height = 30
  30. i.Width = 0
  31. return i
  32. }
  33. func (self *ListItem) Init(text string) {
  34. l := NewLabel()
  35. l.PosX = 16
  36. l.SetCanvasHWND(self.Parent.GetCanvasHWND())
  37. l.Init(text,self.Fonts["normal"],nil)
  38. self.Labels["Text"] = l
  39. }
  40. func (self *ListItem) Coord() (int,int) {
  41. return self.PosX,self.PosY
  42. }
  43. func (self *ListItem) Size() (int,int) {
  44. return self.Width,self.Height
  45. }
  46. func (self *ListItem) GetLinkObj() PluginInterface {
  47. return self.LinkObj
  48. }
  49. func (self *ListItem) Draw() {
  50. x_,_ := self.Labels["Text"].Coord()
  51. _,h_ := self.Labels["Text"].Size()
  52. self.Labels["Text"].NewCoord(x_, self.PosY+(self.Height - h_)/2)
  53. self.Labels["Text"].Draw()
  54. draw.Line(self.Parent.GetCanvasHWND(),&color.Color{169,169,169,255},
  55. self.PosX, (self.PosY+self.Height-1),
  56. (self.PosX+self.Width),(self.PosY+self.Height-1),1)
  57. }