caption.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package widget
  2. import . "gitlab.com/beoran/ebsgo/zori/types"
  3. // import _ "gitlab.com/beoran/ebsgo/zori/backend"
  4. // import "gitlab.com/beoran/ebsgo/zori/state"
  5. import "gitlab.com/beoran/ebsgo/zori/style"
  6. import "gitlab.com/beoran/ebsgo/zori/event"
  7. import "gitlab.com/beoran/ebsgo/monolog"
  8. /* Caption helper struct for use by widgets that have captions. */
  9. type Caption struct {
  10. Label string
  11. LabelTheme style.Theme
  12. LabelBox Box
  13. }
  14. /* Widget with a caption. */
  15. type Captioned struct {
  16. * Basic
  17. Caption
  18. }
  19. func (cap Captioned) Update(ev event.Update) event.Result {
  20. return event.Pass
  21. }
  22. func (cap Captioned) Draw(ev event.Draw) event.Result {
  23. them := cap.LabelTheme
  24. font := them.Text.Font
  25. colo := them.Text.Color
  26. lh := font.LineHeight()
  27. y := cap.Caption.LabelBox.X + lh
  28. x := cap.Caption.LabelBox.Y + 5 // Needs to use margin
  29. cap.Be.DrawText(font, colo, x, y, cap.Label)
  30. monolog.Debug("Draw Caption: %d %d %s", x, y, cap.Label)
  31. return event.Pass
  32. }
  33. func NewCaptioned(parent Widget, bounds * Box, text string) * Captioned {
  34. cap := &Captioned{}
  35. cap.Basic = NewBasic(parent, bounds, nil)
  36. cap.Caption.Label = text
  37. cap.Caption.LabelTheme = * cap.Basic.Theme()
  38. if bounds != nil {
  39. cap.Caption.LabelBox = *bounds
  40. }
  41. return cap
  42. }