feat: уплотнить кнопки справки
This commit is contained in:
1 parent
a73d8f403d
commit
da0da91479
5 files changed
+51
-24
No files matched your search
+20
-12
@@ -64,11 +64,11 @@ HELP_SECTIONS: dict[str, tuple[str, str]] = {
|
||||
}
|
||||
|
||||
HELP_SECTION_ORDER: tuple[str, ...] = tuple(HELP_SECTIONS)
|
||||
HELP_MENU_BUTTON = "⌂ В меню"
|
||||
HELP_BUTTON_ROW_WIDTH = 24
|
||||
|
||||
|
||||
def _menu_buttons(current: str | None = None) -> str:
|
||||
rows = []
|
||||
buttons: list[tuple[str, str]] = []
|
||||
for section in HELP_SECTION_ORDER:
|
||||
title = HELP_SECTIONS[section][0]
|
||||
if section == current:
|
||||
@@ -78,18 +78,26 @@ def _menu_buttons(current: str | None = None) -> str:
|
||||
f'<tg-button type="callback_data" data="help:{section}" style="primary">'
|
||||
f"{title}</tg-button>"
|
||||
)
|
||||
rows.append(f'<tg-button-row align="left">{button}</tg-button-row>')
|
||||
buttons.append((title, button))
|
||||
|
||||
rows = []
|
||||
row: list[str] = []
|
||||
row_width = 0
|
||||
for title, button in buttons:
|
||||
button_width = len(title)
|
||||
separator_width = 1 if row else 0
|
||||
if row and row_width + separator_width + button_width > HELP_BUTTON_ROW_WIDTH:
|
||||
rows.append(f'<tg-button-row align="left">{"".join(row)}</tg-button-row>')
|
||||
row = []
|
||||
row_width = 0
|
||||
separator_width = 0
|
||||
row.append(button)
|
||||
row_width += separator_width + button_width
|
||||
if row:
|
||||
rows.append(f'<tg-button-row align="left">{"".join(row)}</tg-button-row>')
|
||||
return "".join(rows)
|
||||
|
||||
|
||||
def _menu_button_row() -> str:
|
||||
return (
|
||||
f'<tg-button-row align="left">'
|
||||
f'<tg-button type="callback_data" data="help:menu" style="primary">'
|
||||
f"{HELP_MENU_BUTTON}</tg-button></tg-button-row>"
|
||||
)
|
||||
|
||||
|
||||
def help_menu_html(current: str | None = None) -> str:
|
||||
return (
|
||||
f"<h1>{HELP_MENU_TITLE}</h1>"
|
||||
@@ -102,7 +110,7 @@ def help_menu_html(current: str | None = None) -> str:
|
||||
|
||||
def help_section_html(section: str) -> str:
|
||||
title, body = HELP_SECTIONS[section]
|
||||
return f"<h1>{title}</h1>{body}{_menu_button_row()}{_menu_buttons(section)}"
|
||||
return f"<h1>{title}</h1>{body}{_menu_buttons(section)}"
|
||||
|
||||
|
||||
def help_view(section: str | None = None) -> str:
|
||||
|
||||
Reference in new issue
Block a user