Layout Metrics¶
Source: ui/layout_metrics.py
Responsive measurements, cached metric access, platform checks, and field sizing helpers used throughout the UI. See the Layout guide.
Compute and cache responsive dimensions for route body controls.
LayoutMetrics
dataclass
¶
Snapshot of dimensions used by responsive route layouts.
Attributes:
| Name | Type | Description |
|---|---|---|
viewport_width |
float
|
Current page or window width in logical pixels. |
viewport_height |
float
|
Current page or window height in logical pixels. |
body_width |
float
|
Width allocated to general shell content. |
form_width |
float
|
Width allocated to deep forms. |
settings_width |
float
|
Width allocated to settings content. |
content_height |
float
|
Viewport height remaining after visible chrome and configured padding are subtracted. |
breakpoint |
str
|
Responsive category: |
platform |
PagePlatform | None
|
Current Flet page platform when known. |
Source code in src/learning_app/ui/layout_metrics.py
LayoutMetricsStore ¶
Process-wide cache of the most recently computed layout metrics.
Source code in src/learning_app/ui/layout_metrics.py
refresh
classmethod
¶
refresh(page: Page) -> LayoutMetrics
Recompute and cache metrics for a page.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
page
|
Page
|
Page whose current layout state should be measured. |
required |
Returns:
| Type | Description |
|---|---|
LayoutMetrics
|
The newly computed metrics. |
Source code in src/learning_app/ui/layout_metrics.py
get
classmethod
¶
get() -> LayoutMetrics
Return cached metrics or a default pre-layout snapshot.
Returns:
| Type | Description |
|---|---|
LayoutMetrics
|
The latest metrics, or token-based defaults before the first |
LayoutMetrics
|
refresh. |
Source code in src/learning_app/ui/layout_metrics.py
compute_layout_metrics ¶
compute_layout_metrics(page: Page) -> LayoutMetrics
Calculate a responsive layout snapshot for a page.
Visible shared chrome, page padding, and active-view padding are subtracted from viewport height. Widths are ratio-based and capped by layout tokens.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
page
|
Page
|
Page supplying viewport, platform, route, chrome, and padding state. |
required |
Returns:
| Type | Description |
|---|---|
LayoutMetrics
|
The calculated immutable layout metrics. |
Source code in src/learning_app/ui/layout_metrics.py
is_windows_platform ¶
Return whether the explicit or cached platform is Windows.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
page
|
Page | None
|
Optional page whose platform takes precedence over cached metrics. |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in src/learning_app/ui/layout_metrics.py
is_android_platform ¶
Return whether the explicit or cached platform is Android.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
page
|
Page | None
|
Optional page whose platform takes precedence over cached metrics. |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in src/learning_app/ui/layout_metrics.py
learn_words_field_width ¶
Calculate the words exercise field width for a platform.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
form_width
|
float
|
Available form width in logical pixels. |
required |
page
|
Page | None
|
Optional page used to resolve the platform. |
None
|
Returns:
| Type | Description |
|---|---|
float
|
The field width after applying the platform-specific ratio. |
Source code in src/learning_app/ui/layout_metrics.py
learn_definition_field_width ¶
Calculate the definition exercise field width for a platform.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
form_width
|
float
|
Available form width in logical pixels. |
required |
page
|
Page | None
|
Optional page used to resolve the platform. |
None
|
Returns:
| Type | Description |
|---|---|
float
|
The field width after applying the platform-specific ratio. |