util.go 860 B

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