list_item.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. package TimeZone
  2. import (
  3. //"fmt"
  4. //"strings"
  5. //"io/ioutil"
  6. "github.com/veandco/go-sdl2/ttf"
  7. "path/filepath"
  8. //"github.com/veandco/go-sdl2/sdl"
  9. //"github.com/cuu/gogame/surface"
  10. //"github.com/cuu/gogame/rect"
  11. "github.com/cuu/gogame/color"
  12. "github.com/clockworkpi/LauncherGoDev/sysgo/UI"
  13. "github.com/cuu/gogame/draw"
  14. )
  15. var TimeZoneListPageListItemDefaultHeight = 30
  16. type TimeZoneListPageInterface interface {
  17. UI.PageInterface
  18. GetMapIcons() map[string]UI.IconItemInterface
  19. }
  20. type TimeZoneListPageListItem struct {
  21. UI.HierListItem
  22. Parent TimeZoneListPageInterface
  23. }
  24. func NewTimeZoneListPageListItem() *TimeZoneListPageListItem {
  25. p := &TimeZoneListPageListItem{}
  26. p.Labels = make(map[string]UI.LabelInterface)
  27. p.Icons = make(map[string]UI.IconItemInterface)
  28. p.Fonts = make(map[string]*ttf.Font)
  29. p.MyType = UI.ICON_TYPES["EXE"]
  30. p.Height = TimeZoneListPageListItemDefaultHeight
  31. p.Width = 0
  32. return p
  33. }
  34. func (self *TimeZoneListPageListItem) Init(text string) {
  35. l := UI.NewLabel()
  36. l.PosX = 20
  37. l.SetCanvasHWND(self.Parent.GetCanvasHWND())
  38. if self.IsDir() == true || self.IsFile() == true {
  39. self.Path = text
  40. }
  41. label_text := filepath.Base(text)
  42. if self.IsDir() == true {
  43. l.Init(label_text, self.Fonts["normal"], nil)
  44. } else {
  45. l.Init(label_text, self.Fonts["normal"], nil)
  46. }
  47. self.Labels["Text"] = l
  48. }
  49. func (self *TimeZoneListPageListItem) Draw() {
  50. x, y := self.Labels["Text"].Coord()
  51. _, h := self.Labels["Text"].Size()
  52. if self.Path != "[..]" {
  53. self.Labels["Text"].NewCoord(23, y)
  54. } else {
  55. self.Labels["Text"].NewCoord(3, y)
  56. }
  57. x, y = self.Labels["Text"].Coord()
  58. self.Labels["Text"].NewCoord(x, self.PosY+(self.Height-h)/2)
  59. self.Labels["Text"].Draw()
  60. parent_icons := self.Parent.GetMapIcons()
  61. _, h = parent_icons["sys"].Size()
  62. if self.IsDir() == true && self.Path != "[..]" {
  63. parent_icons["sys"].SetIconIndex(0)
  64. parent_icons["sys"].NewCoord(self.PosX+12, self.PosY+(self.Height-h)/2+h/2)
  65. parent_icons["sys"].Draw()
  66. }
  67. if self.IsFile() == true {
  68. parent_icons["sys"].SetIconIndex(1)
  69. parent_icons["sys"].NewCoord(self.PosX+12, self.PosY+(self.Height-h)/2+h/2)
  70. parent_icons["sys"].Draw()
  71. }
  72. draw.Line(self.Parent.GetCanvasHWND(), &color.Color{169, 169, 169, 255},
  73. self.PosX, self.PosY+self.Height-1, self.PosX+self.Width, self.PosY+self.Height-1, 1)
  74. }