util.go 884 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package ui
  2. import (
  3. "github.com/ayn2op/discordo/internal/config"
  4. "github.com/ayn2op/tview"
  5. "github.com/gdamore/tcell/v2"
  6. )
  7. func NewConfiguredBox(box *tview.Box, cfg *config.Theme) *tview.Box {
  8. b := cfg.Border
  9. t := cfg.Title
  10. p := b.Padding
  11. box.
  12. SetBorderColor(tcell.GetColor(b.Color)).
  13. SetBorderPadding(p[0], p[1], p[2], p[3]).
  14. SetTitleAlign(int(t.Align)).
  15. SetFocusFunc(func() {
  16. box.SetBorderColor(tcell.GetColor(b.ActiveColor))
  17. box.SetTitleColor(tcell.GetColor(t.ActiveColor))
  18. }).
  19. SetBlurFunc(func() {
  20. box.SetBorderColor(tcell.GetColor(b.Color))
  21. box.SetTitleColor(tcell.GetColor(t.Color))
  22. })
  23. if b.Enabled {
  24. box.SetBorders(tview.BordersAll)
  25. }
  26. return box
  27. }
  28. func Centered(p tview.Primitive, width, height int) tview.Primitive {
  29. return tview.NewGrid().
  30. SetColumns(0, width, 0).
  31. SetRows(0, height, 0).
  32. AddItem(p, 1, 1, 1, 1, 0, 0, true)
  33. }