User interface toolkit for Go with support for SDL2 and HTML Canvas render targets.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

52 lines
1.4 KiB

  1. package ui_test
  2. import (
  3. "git.kirsle.net/go/render"
  4. "git.kirsle.net/go/ui"
  5. )
  6. // Example of using the Supervisor Window Manager.
  7. func ExampleWindow() {
  8. mw, err := ui.NewMainWindow("Window Manager Example", 800, 600)
  9. if err != nil {
  10. panic(err)
  11. }
  12. // Create a window as normal.
  13. window := ui.NewWindow("Hello world!")
  14. window.Configure(ui.Config{
  15. Width: 320,
  16. Height: 240,
  17. })
  18. // Configure its title bar colors (optional; these are the defaults)
  19. window.ActiveTitleBackground = render.Blue
  20. window.ActiveTitleForeground = render.White
  21. window.InactiveTitleBackground = render.DarkGrey
  22. window.InactiveTitleForeground = render.Grey
  23. // Configure its window buttons (optional); default has no window buttons.
  24. // Window buttons are only functional in managed windows.
  25. window.SetButtons(ui.CloseButton | ui.MaximizeButton | ui.MinimizeButton)
  26. // Add some widgets to the window.
  27. btn := ui.NewButton("My Button", ui.NewLabel(ui.Label{
  28. Text: "Hello world!",
  29. }))
  30. window.Place(btn, ui.Place{
  31. Center: true,
  32. Middle: true,
  33. })
  34. // To enable the window manager controls, the key step is to give it
  35. // the Supervisor so it can be managed:
  36. window.Compute(mw.Engine)
  37. window.Supervise(mw.Supervisor())
  38. // Each loop you must then:
  39. // - Call Supervisor.Loop() as normal to handle events.
  40. // - Call Supervisor.Present() to draw the managed windows.
  41. // MainLoop() of the MainWindow does this for you.
  42. mw.MainLoop()
  43. }