Files
tgex-backend/tg_bot/screens/ui/buttons.go
2026-01-20 15:16:06 +03:00

22 lines
641 B
Go

package ui
import "github.com/NicoNex/echotron/v3"
// BuildGrid builds button rows from items using a callback builder.
func BuildGrid[T any](items []T, itemsPerRow, itemsPerPage, totalPages int, itemFn func(T) (title string, callback string)) [][]echotron.InlineKeyboardButton {
if len(items) == 0 {
return nil
}
buttons := make([]echotron.InlineKeyboardButton, 0, len(items))
for _, item := range items {
title, callback := itemFn(item)
buttons = append(buttons, echotron.InlineKeyboardButton{
Text: title,
CallbackData: callback,
})
}
return BuildPageRows(buttons, itemsPerRow, itemsPerPage, totalPages)
}