43 lines
1.6 KiB
Python
43 lines
1.6 KiB
Python
# -*- coding: utf-8 -*-
|
|
# view/layout_mode.py
|
|
from __future__ import annotations
|
|
|
|
COMPACT_WIDTH_THRESHOLD = 920
|
|
COMPACT_HEIGHT_THRESHOLD = 680
|
|
_HYSTERESIS_PX = 12
|
|
|
|
|
|
class LayoutMode:
|
|
"""
|
|
Zentraler Regler für Desktop-Rahmenansicht vs. rahmenlose Kompakt-/Mobile-Ansicht
|
|
(z. B. 658x768 Split-Screen oder spätere Android/iOS-Screens).
|
|
"""
|
|
|
|
_last_compact_state: bool = False
|
|
|
|
@classmethod
|
|
def is_compact(cls, width: int, height: int) -> bool:
|
|
w, h = int(width), int(height)
|
|
if cls._last_compact_state:
|
|
# Erst wieder auf Desktop schalten, wenn klar über der Schwelle (+Hysterese)
|
|
if w >= (COMPACT_WIDTH_THRESHOLD + _HYSTERESIS_PX) and h >= (
|
|
COMPACT_HEIGHT_THRESHOLD + _HYSTERESIS_PX
|
|
):
|
|
cls._last_compact_state = False
|
|
else:
|
|
if w < COMPACT_WIDTH_THRESHOLD or h < COMPACT_HEIGHT_THRESHOLD:
|
|
cls._last_compact_state = True
|
|
return cls._last_compact_state
|
|
|
|
@classmethod
|
|
def outer_pad_x(cls, width: int, height: int, desktop_ratio: float = 0.08, desktop_min: int = 72) -> int:
|
|
"""Liefert schmale Ränder ohne Spinnennetz-Rahmen im Kompaktmodus."""
|
|
if cls.is_compact(width, height):
|
|
return max(14, int(width * 0.028))
|
|
return max(desktop_min, int(width * desktop_ratio))
|
|
|
|
@classmethod
|
|
def top_content_y(cls, width: int, height: int, desktop_ratio: float = 0.09, desktop_min: int = 56) -> int:
|
|
if cls.is_compact(width, height):
|
|
return 34
|
|
return max(desktop_min, int(height * desktop_ratio)) |