Files
pristontale-eu-linux/ptlinux/ui/components/news_panel.py
2026-09-03 19:07:09 +02:00

109 lines
3.0 KiB
Python

"""Official news and patch-note viewport construction."""
from __future__ import annotations
from dataclasses import dataclass
from typing import Any
MAX_NEWS_CARDS = 3
NEWS_CARD_HEIGHT = 242
NEWS_IMAGE_WIDTH = 292
NEWS_IMAGE_HEIGHT = 118
PATCH_CARD_WRAP_LENGTH = 900
PATCH_CHANGE_WRAP_LENGTH = 790
@dataclass(frozen=True)
class NewsPanel:
container: Any
news_tab_button: Any
patches_tab_button: Any
canvas: Any
scrollbar: Any
content_host: Any
news_content: Any
patches_content: Any
canvas_window: int
def build_news_panel(
parent: Any,
*,
ttk_module: Any,
tk_module: Any,
controls: Any,
ui_scale: float,
) -> NewsPanel:
news_panel = ttk_module.Frame(parent, style="Surface.TFrame", padding=(10, 8))
news_panel.pack(fill="both", expand=True, pady=(0, 8), before=controls)
news_heading = ttk_module.Frame(news_panel, style="Surface.TFrame")
news_heading.pack(fill="x")
ttk_module.Label(news_heading, text="LATEST NEWS", style="Section.TLabel").pack(side="left")
news_tabs = ttk_module.Frame(news_heading, style="Surface.TFrame")
news_tabs.pack(side="left", padx=(14, 0))
news_tab_button = ttk_module.Button(
news_tabs,
text="NEWS",
style="NewsTabActive.TButton",
underline=0,
)
news_tab_button.pack(side="left")
patches_tab_button = ttk_module.Button(
news_tabs,
text="PATCHES",
style="NewsTab.TButton",
underline=0,
)
patches_tab_button.pack(side="left", padx=(5, 0))
ttk_module.Label(
news_heading,
text="OFFICIAL FEED",
style="Muted.TLabel",
).pack(side="right")
news_viewport = ttk_module.Frame(news_panel, style="Surface.TFrame")
news_viewport.pack(fill="both", expand=True, pady=(6, 0))
news_viewport.grid_columnconfigure(0, weight=1)
news_viewport.grid_rowconfigure(0, weight=1)
news_canvas = tk_module.Canvas(
news_viewport,
background="#191311",
highlightthickness=0,
borderwidth=0,
height=round(252 * ui_scale),
takefocus=True,
)
news_canvas.grid(row=0, column=0, sticky="nsew")
news_scrollbar = ttk_module.Scrollbar(
news_viewport,
orient="vertical",
style="News.Vertical.TScrollbar",
command=news_canvas.yview,
)
news_scrollbar.grid(row=0, column=1, sticky="ns", padx=(5, 0))
news_scrollbar.grid_remove()
news_canvas.configure(yscrollcommand=news_scrollbar.set)
news_content_host = ttk_module.Frame(news_canvas, style="Surface.TFrame")
news_content_host.grid_columnconfigure(0, weight=1)
news_content = ttk_module.Frame(news_content_host, style="Surface.TFrame")
patches_content = ttk_module.Frame(news_content_host, style="Surface.TFrame")
news_content.grid(row=0, column=0, sticky="nsew")
patches_content.grid(row=0, column=0, sticky="nsew")
patches_content.grid_remove()
news_window = news_canvas.create_window(
(0, 0),
window=news_content_host,
anchor="nw",
)
return NewsPanel(
container=news_panel,
news_tab_button=news_tab_button,
patches_tab_button=patches_tab_button,
canvas=news_canvas,
scrollbar=news_scrollbar,
content_host=news_content_host,
news_content=news_content,
patches_content=patches_content,
canvas_window=news_window,
)