util.go 861 B

12345678910111213141516171819202122232425262728293031323334
  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. SetBorder(cfg.Border.Enabled).
  13. SetBorderColor(tcell.GetColor(b.Color)).
  14. SetBorderPadding(p[0], p[1], p[2], p[3]).
  15. SetTitleAlign(int(t.Align)).
  16. SetFocusFunc(func() {
  17. box.SetBorderColor(tcell.GetColor(b.ActiveColor))
  18. box.SetTitleColor(tcell.GetColor(t.ActiveColor))
  19. }).
  20. SetBlurFunc(func() {
  21. box.SetBorderColor(tcell.GetColor(b.Color))
  22. box.SetTitleColor(tcell.GetColor(t.Color))
  23. })
  24. return box
  25. }
  26. func Centered(p tview.Primitive, width, height int) tview.Primitive {
  27. return tview.NewGrid().
  28. SetColumns(0, width, 0).
  29. SetRows(0, height, 0).
  30. AddItem(p, 1, 1, 1, 1, 0, 0, true)
  31. }