Created
July 6, 2025 11:31
-
-
Save arturboyun/839eef89280a98cc94573b97a5b7b601 to your computer and use it in GitHub Desktop.
aiogram_dialog: CustomScrollingGroup widget
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from aiogram.types import InlineKeyboardButton | |
from aiogram_dialog import DialogManager | |
from aiogram_dialog.api.internal import RawKeyboard | |
from aiogram_dialog.widgets.kbd import ScrollingGroup | |
class CustomScrollingGroup(ScrollingGroup): | |
async def _render_pager( | |
self, | |
pages: int, | |
manager: DialogManager, | |
) -> RawKeyboard: | |
if self.hide_pager: | |
return [] | |
if pages == 0 or (pages == 1 and self.hide_on_single_page): | |
return [] | |
last_page = pages - 1 | |
current_page = min(last_page, await self.get_page(manager)) | |
next_page = min(last_page, current_page + 1) | |
prev_page = max(0, current_page - 1) | |
return [ | |
[ | |
InlineKeyboardButton( | |
text="⏪️", | |
callback_data=self._item_callback_data("0"), | |
), | |
InlineKeyboardButton( | |
text="◀️", | |
callback_data=self._item_callback_data(prev_page), | |
), | |
InlineKeyboardButton( | |
text=str(current_page + 1), | |
callback_data=self._item_callback_data(current_page), | |
), | |
InlineKeyboardButton( | |
text="▶️", | |
callback_data=self._item_callback_data(next_page), | |
), | |
InlineKeyboardButton( | |
text="⏩️", | |
callback_data=self._item_callback_data(last_page), | |
), | |
], | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment