util.go 817 B

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