Files
vaiola/modules/ui/gui/MainWindowSideMenu.py
2025-10-16 18:42:32 +07:00

98 lines
3.8 KiB
Python
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# side_menu.py
import os.path
import flet as ft
class NavPanel:
"""Пустая панель навигации. Добавьте свои пункты позже."""
def __init__(self, page: ft.Page):
self.page = page
def build(self) -> ft.Container:
"""Возвращаем контейнер с кнопками навигации."""
# Пример пунктов замените/добавьте свои
return ft.Container(
padding=ft.padding.symmetric(vertical=10, horizontal=5),
content=ft.Column(
controls=[
ft.TextButton(
text="Главная",
icon=ft.Icons.HOME,
on_click=lambda e: self.page.views.append(ft.View("/home")),
style=ft.ButtonStyle(overlay_color=ft.Colors.GREY_200)
),
ft.TextButton(
text="Настройки",
icon=ft.Icons.SETTINGS,
on_click=lambda e: self.page.views.append(ft.View("/settings")),
style=ft.ButtonStyle(overlay_color=ft.Colors.GREY_200)
),
],
spacing=5,
),
)
class SideMenu:
"""
Класс, представляющий боковое меню.
На данный момент оно «пустое», но можно легко добавить пункты в будущем.
"""
def __init__(self):
# Любые начальные данные можно хранить здесь
self.width = 200 # ширина меню
self.bgcolor = ft.Colors.SURFACE
self.logo_path = os.path.join('assets', 'side_menu_logo_dark.png')
def build(self, page: ft.Page) -> ft.Container:
"""
Возвращает контейнер, который можно вставить в страницу.
"""
logo = ft.Image(
src=self.logo_path,
width=self.width, # растягиваем до ширины меню
fit=ft.ImageFit.CONTAIN, # сохраняем пропорции
# height может быть не задан; Flet будет авто‑подбирать
)
# 2⃣ Панель навигации
nav_panel = NavPanel(page).build()
# 3⃣ Кнопка‑тогглер темы
def toggle_theme(e):
# Переключаем режим и обновляем страницу
page.theme_mode = (
ft.ThemeMode.DARK if page.theme_mode == ft.ThemeMode.LIGHT
else ft.ThemeMode.LIGHT
)
page.update()
toggle_btn = ft.TextButton(
text="Тёмная тема" if page.theme_mode == ft.ThemeMode.LIGHT else "Светлая тема",
icon=ft.Icons.BOOKMARK,
on_click=toggle_theme,
style=ft.ButtonStyle(
padding=ft.padding.all(10),
alignment=ft.alignment.center_left
)
)
# 4⃣ Ставим всё в колонку с выравниванием по краям
return ft.Container(
width=self.width,
bgcolor=self.bgcolor,
padding=ft.padding.symmetric(vertical=15, horizontal=10),
content=ft.Column(
controls=[
logo,
ft.Divider(height=15),
nav_panel,
ft.Divider(height=15),
ft.Container(
content=toggle_btn,
alignment=ft.alignment.bottom_left
),
],
spacing=10,
alignment=ft.MainAxisAlignment.START,
),
)