util.go 881 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package ui
  2. import (
  3. "github.com/ayn2op/discordo/internal/config"
  4. "github.com/ayn2op/tview"
  5. )
  6. func NewConfiguredBox(box *tview.Box, cfg *config.Theme) *tview.Box {
  7. b := cfg.Border
  8. t := cfg.Title
  9. p := b.Padding
  10. box.
  11. SetBorderStyle(b.Style.Style).
  12. SetBorderSet(b.Set.BorderSet).
  13. SetBorderPadding(p[0], p[1], p[2], p[3]).
  14. SetTitleStyle(t.Style.Style).
  15. SetTitleAlignment(t.Alignment.Alignment).
  16. SetFocusFunc(func() {
  17. box.SetBorderStyle(b.ActiveStyle.Style)
  18. box.SetTitleStyle(t.ActiveStyle.Style)
  19. }).
  20. SetBlurFunc(func() {
  21. box.SetBorderStyle(b.Style.Style)
  22. box.SetTitleStyle(t.Style.Style)
  23. })
  24. if b.Enabled {
  25. box.SetBorders(tview.BordersAll)
  26. }
  27. return box
  28. }
  29. func Centered(p tview.Primitive, width, height int) tview.Primitive {
  30. return tview.NewGrid().
  31. SetColumns(0, width, 0).
  32. SetRows(0, height, 0).
  33. AddItem(p, 1, 1, 1, 1, 0, 0, true)
  34. }