root.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package widget
  2. import . "gitlab.com/beoran/ebsgo/zori/types"
  3. import "gitlab.com/beoran/ebsgo/zori/event"
  4. import "gitlab.com/beoran/ebsgo/zori/backend"
  5. // import "gitlab.com/beoran/ebsgo/zori/state"
  6. import "gitlab.com/beoran/ebsgo/zori/style"
  7. import "gitlab.com/beoran/ebsgo/monolog"
  8. /*
  9. * Root level widget, my spread out over several displays.
  10. * In Zori, there can only be a single root level widget active.
  11. * It's ID is always 0;
  12. */
  13. type Root struct {
  14. * Basic
  15. Icons map[string]Bitmap
  16. MyConsole Console
  17. UITheme style.Theme
  18. Cursors
  19. Active *PageWidget
  20. }
  21. func NewRoot (backend backend.Backend, theme * style.Theme) * Root {
  22. root := &Root{}
  23. if theme != nil {
  24. root.UITheme = * theme
  25. }
  26. root.Basic = NewBasicWithTheme(nil, nil, theme, nil)
  27. root.Be = backend
  28. root.MyRoot= root // Root widget is self-rooted.
  29. return root
  30. }
  31. func NewRootWidget(backend backend.Backend, theme * style.Theme) Widget {
  32. return Widget(NewRoot(backend, theme))
  33. }
  34. func (root * Root) Dispatch(ev event.Event) event.Result {
  35. return DispatchRecursive(root, ev)
  36. }
  37. func (root * Root) Draw(ev event.Draw) event.Result {
  38. monolog.Debug("Root.Draw")
  39. return event.Pass
  40. }
  41. func (root * Root) Update(ev event.Update) event.Result {
  42. return event.Pass
  43. }
  44. func (root * Root) MouseCursor() Cursor {
  45. return root.Cursors.Mouse
  46. }
  47. func (root * Root) KeyjoyCursor() Cursor {
  48. return root.Cursors.Keyjoy
  49. }
  50. /* Gets the theme to use for a marked widget. Looks for the
  51. * cursor to determine this. */
  52. func (root Root) MarkedTheme() style.Theme {
  53. return root.Cursors.Keyjoy.TargetTheme
  54. }
  55. /* Gets the style to use for a hovered widget. Looks up the cursor
  56. * to determine this. */
  57. func (root Root) HoveredTheme() style.Theme {
  58. return root.Cursors.Mouse.TargetTheme
  59. }