diff --git a/frontend/code/components/componentBase.ts b/frontend/code/components/componentBase.ts index 2e6d0ec4..f51793be 100644 --- a/frontend/code/components/componentBase.ts +++ b/frontend/code/components/componentBase.ts @@ -28,7 +28,7 @@ export type ComponentState = { // Explicit size request, if any _min_size_?: [number, number]; // Maximum size, if any - _max_size_?: [number | null, number | null]; + // MAX-SIZE-BRANCH _max_size_?: [number | null, number | null]; // Alignment of the component within its parent, if any _align_?: [number | null, number | null]; // Scrolling behavior @@ -119,9 +119,9 @@ export abstract class ComponentBase { this.element.style.minHeight = `${deltaState._min_size_[1]}rem`; } - if (deltaState._max_size_ !== undefined) { - this._updateMaxSize(deltaState._max_size_); - } + // MAX-SIZE-BRANCH if (deltaState._max_size_ !== undefined) { + // MAX-SIZE-BRANCH this._updateMaxSize(deltaState._max_size_); + // MAX-SIZE-BRANCH } if (deltaState._align_ !== undefined) { this._updateAlign(deltaState._align_); diff --git a/frontend/code/components/image.ts b/frontend/code/components/image.ts index 3d730575..2642a2f7 100644 --- a/frontend/code/components/image.ts +++ b/frontend/code/components/image.ts @@ -59,9 +59,18 @@ export class ImageComponent extends ComponentBase { deltaState.imageUrl !== undefined && imgElement.src !== deltaState.imageUrl ) { - // imgElement.classList.add('rio-content-loading'); + // this.element.classList.add('rio-content-loading'); imgElement.src = deltaState.imageUrl; + // Until the image is loaded and we get access to its resolution, + // let it fill the entire space. This is the correct size for all + // `fill_mode`s except `"fit"` anyway, so there's no harm in setting + // it now rather than later. (SVGs might temporarily render content + // outside of the viewbox, but the only way to prevent that would be + // to make the image invisible until loaded.) + this.imageElement.style.width = '100%'; + this.imageElement.style.height = '100%'; + // If we're currently displaying an error icon, remove it if (this.element.firstElementChild !== imgElement) { this.element.firstElementChild!.remove(); @@ -89,7 +98,7 @@ export class ImageComponent extends ComponentBase { } private _onLoad(): void { - this.imageElement.classList.remove('rio-content-loading'); + // this.element.classList.remove('rio-content-loading'); this._updateSize(); } @@ -128,7 +137,7 @@ export class ImageComponent extends ComponentBase { } private _onError(event: string | Event): void { - this.imageElement.classList.remove('rio-content-loading'); + this.element.classList.remove('rio-content-loading'); applyIcon(this.element, 'material/broken_image'); diff --git a/rio/component_meta.py b/rio/component_meta.py index 01c72876..dcc39eef 100644 --- a/rio/component_meta.py +++ b/rio/component_meta.py @@ -158,6 +158,7 @@ class ComponentMeta(RioDataclassMeta): deprecations._remap_kwargs( cls.__name__, kwargs, cls._deprecated_parameter_names_ ) + deprecations.remap_width_and_height(kwargs) component: C = object.__new__(cls) diff --git a/rio/components/component.py b/rio/components/component.py index f709fed2..fc833afa 100644 --- a/rio/components/component.py +++ b/rio/components/component.py @@ -217,11 +217,8 @@ class Component(abc.ABC, metaclass=ComponentMeta): min_width: float | None = None min_height: float | None = None - max_width: float | None = None - max_height: float | None = None - - width: float | Literal["grow", "natural"] | None = None - height: float | Literal["grow", "natural"] | None = None + # MAX-SIZE-BRANCH max_width: float | None = None + # MAX-SIZE-BRANCH max_height: float | None = None grow_x: bool = False grow_y: bool = False @@ -825,7 +822,7 @@ class Component(abc.ABC, metaclass=ComponentMeta): # Separator rio.Rectangle( fill=self.session.theme.primary_color, - height=0.2, + min_height=0.2, ), # Content wrapped_content, @@ -951,7 +948,7 @@ class Component(abc.ABC, metaclass=ComponentMeta): title, style="heading2", wrap=True, - width="grow", + grow_x=True, ) ) @@ -968,7 +965,7 @@ class Component(abc.ABC, metaclass=ComponentMeta): main_column.add( rio.Rectangle( fill=self.session.theme.primary_color, - height=0.2, + min_height=0.2, ), ) diff --git a/rio/components/devel_component.py b/rio/components/devel_component.py index 47944be4..925ecdd1 100644 --- a/rio/components/devel_component.py +++ b/rio/components/devel_component.py @@ -6,7 +6,7 @@ import tempfile from collections.abc import Iterable from dataclasses import field from pathlib import Path -from typing import Literal, Sequence +from typing import Sequence import rio @@ -47,10 +47,8 @@ class DevelComponent(FundamentalComponent): margin_bottom: float | None = None, min_width: float | None = None, min_height: float | None = None, - max_width: float | None = None, - max_height: float | None = None, - width: float | Literal["grow", "natural"] | None = None, - height: float | Literal["grow", "natural"] | None = None, + # MAX-SIZE-BRANCH max_width: float | None = None, + # MAX-SIZE-BRANCH max_height: float | None = None, grow_x: bool = False, grow_y: bool = False, align_x: float | None = None, @@ -69,10 +67,8 @@ class DevelComponent(FundamentalComponent): margin_bottom=margin_bottom, min_width=min_width, min_height=min_height, - max_width=max_width, - max_height=max_height, - width=width, - height=height, + # MAX-SIZE-BRANCH max_width=max_width, + # MAX-SIZE-BRANCH max_height=max_height, grow_x=grow_x, grow_y=grow_y, align_x=align_x, diff --git a/rio/components/dropdown.py b/rio/components/dropdown.py index a517baa5..2dd61c6a 100644 --- a/rio/components/dropdown.py +++ b/rio/components/dropdown.py @@ -2,7 +2,7 @@ from __future__ import annotations from collections.abc import Mapping, Sequence from dataclasses import KW_ONLY, dataclass -from typing import Any, Generic, Literal, TypeVar, final +from typing import Any, Generic, TypeVar, final from uniserde import JsonDoc @@ -149,10 +149,8 @@ class Dropdown(FundamentalComponent, Generic[T]): margin_bottom: float | None = None, min_width: float | None = None, min_height: float | None = None, - max_width: float | None = None, - max_height: float | None = None, - width: float | Literal["grow", "natural"] | None = None, - height: float | Literal["grow", "natural"] | None = None, + # MAX-SIZE-BRANCH max_width: float | None = None, + # MAX-SIZE-BRANCH max_height: float | None = None, grow_x: bool = False, grow_y: bool = False, align_x: float | None = None, @@ -174,10 +172,8 @@ class Dropdown(FundamentalComponent, Generic[T]): margin_bottom=margin_bottom, min_width=min_width, min_height=min_height, - max_width=max_width, - max_height=max_height, - width=width, - height=height, + # MAX-SIZE-BRANCH max_width=max_width, + # MAX-SIZE-BRANCH max_height=max_height, grow_x=grow_x, grow_y=grow_y, align_x=align_x, diff --git a/rio/components/flow_container.py b/rio/components/flow_container.py index 9bd4454d..dd3389b5 100644 --- a/rio/components/flow_container.py +++ b/rio/components/flow_container.py @@ -75,10 +75,8 @@ class FlowContainer(FundamentalComponent): margin_bottom: float | None = None, min_width: float | None = None, min_height: float | None = None, - max_width: float | None = None, - max_height: float | None = None, - width: float | Literal["grow", "natural"] | None = None, - height: float | Literal["grow", "natural"] | None = None, + # MAX-SIZE-BRANCH max_width: float | None = None, + # MAX-SIZE-BRANCH max_height: float | None = None, grow_x: bool = False, grow_y: bool = False, align_x: float | None = None, @@ -99,10 +97,8 @@ class FlowContainer(FundamentalComponent): margin_bottom=margin_bottom, min_width=min_width, min_height=min_height, - max_width=max_width, - max_height=max_height, - width=width, - height=height, + # MAX-SIZE-BRANCH max_width=max_width, + # MAX-SIZE-BRANCH max_height=max_height, grow_x=grow_x, grow_y=grow_y, align_x=align_x, diff --git a/rio/components/grid.py b/rio/components/grid.py index 72f96a92..da033c47 100644 --- a/rio/components/grid.py +++ b/rio/components/grid.py @@ -3,7 +3,7 @@ from __future__ import annotations import math from collections.abc import Iterable from dataclasses import KW_ONLY, dataclass -from typing import Literal, final +from typing import final from typing_extensions import Self from uniserde import JsonDoc @@ -115,10 +115,8 @@ class Grid(FundamentalComponent): margin_bottom: float | None = None, min_width: float | None = None, min_height: float | None = None, - max_width: float | None = None, - max_height: float | None = None, - width: float | Literal["grow", "natural"] | None = None, - height: float | Literal["grow", "natural"] | None = None, + # MAX-SIZE-BRANCH max_width: float | None = None, + # MAX-SIZE-BRANCH max_height: float | None = None, grow_x: bool = False, grow_y: bool = False, align_x: float | None = None, @@ -137,10 +135,8 @@ class Grid(FundamentalComponent): margin_bottom=margin_bottom, min_width=min_width, min_height=min_height, - max_width=max_width, - max_height=max_height, - width=width, - height=height, + # MAX-SIZE-BRANCH max_width=max_width, + # MAX-SIZE-BRANCH max_height=max_height, grow_x=grow_x, grow_y=grow_y, align_x=align_x, diff --git a/rio/components/icon.py b/rio/components/icon.py index 60b9c3bc..b8972293 100644 --- a/rio/components/icon.py +++ b/rio/components/icon.py @@ -119,10 +119,8 @@ class Icon(FundamentalComponent): margin_bottom: float | None = None, min_width: float | None = 1.3, min_height: float | None = 1.3, - max_width: float | None = None, - max_height: float | None = None, - width: float | Literal["grow", "natural"] | None = None, - height: float | Literal["grow", "natural"] | None = None, + # MAX-SIZE-BRANCH max_width: float | None = None, + # MAX-SIZE-BRANCH max_height: float | None = None, grow_x: bool = False, grow_y: bool = False, align_x: float | None = None, @@ -141,10 +139,8 @@ class Icon(FundamentalComponent): margin_bottom=margin_bottom, min_width=min_width, min_height=min_height, - max_width=max_width, - max_height=max_height, - width=width, - height=height, + # MAX-SIZE-BRANCH max_width=max_width, + # MAX-SIZE-BRANCH max_height=max_height, grow_x=grow_x, grow_y=grow_y, align_x=align_x, diff --git a/rio/components/image.py b/rio/components/image.py index af974306..06663744 100644 --- a/rio/components/image.py +++ b/rio/components/image.py @@ -130,10 +130,8 @@ class Image(FundamentalComponent): margin_bottom: float | None = None, min_width: float | None = 2, min_height: float | None = 2, - max_width: float | None = None, - max_height: float | None = None, - width: float | Literal["grow", "natural"] | None = None, - height: float | Literal["grow", "natural"] | None = None, + # MAX-SIZE-BRANCH max_width: float | None = None, + # MAX-SIZE-BRANCH max_height: float | None = None, grow_x: bool = False, grow_y: bool = False, align_x: float | None = None, @@ -152,10 +150,8 @@ class Image(FundamentalComponent): margin_bottom=margin_bottom, min_width=min_width, min_height=min_height, - max_width=max_width, - max_height=max_height, - width=width, - height=height, + # MAX-SIZE-BRANCH max_width=max_width, + # MAX-SIZE-BRANCH max_height=max_height, grow_x=grow_x, grow_y=grow_y, align_x=align_x, diff --git a/rio/components/labeled_column.py b/rio/components/labeled_column.py index 6a30e528..6575961d 100644 --- a/rio/components/labeled_column.py +++ b/rio/components/labeled_column.py @@ -2,7 +2,7 @@ from __future__ import annotations from collections.abc import Mapping from dataclasses import field -from typing import Literal, final +from typing import final from typing_extensions import Self @@ -59,10 +59,8 @@ class LabeledColumn(Component): margin_bottom: float | None = None, min_width: float | None = None, min_height: float | None = None, - max_width: float | None = None, - max_height: float | None = None, - width: float | Literal["grow", "natural"] | None = None, - height: float | Literal["grow", "natural"] | None = None, + # MAX-SIZE-BRANCH max_width: float | None = None, + # MAX-SIZE-BRANCH max_height: float | None = None, grow_x: bool = False, grow_y: bool = False, align_x: float | None = None, @@ -81,10 +79,8 @@ class LabeledColumn(Component): margin_bottom=margin_bottom, min_width=min_width, min_height=min_height, - max_width=max_width, - max_height=max_height, - width=width, - height=height, + # MAX-SIZE-BRANCH max_width=max_width, + # MAX-SIZE-BRANCH max_height=max_height, grow_x=grow_x, grow_y=grow_y, align_x=align_x, diff --git a/rio/components/linear_containers.py b/rio/components/linear_containers.py index b95f5787..2cc07762 100644 --- a/rio/components/linear_containers.py +++ b/rio/components/linear_containers.py @@ -133,10 +133,8 @@ class Row(_LinearContainer): margin_bottom: float | None = None, min_width: float | None = None, min_height: float | None = None, - max_width: float | None = None, - max_height: float | None = None, - width: float | Literal["grow", "natural"] | None = None, - height: float | Literal["grow", "natural"] | None = None, + # MAX-SIZE-BRANCH max_width: float | None = None, + # MAX-SIZE-BRANCH max_height: float | None = None, grow_x: bool = False, grow_y: bool = False, align_x: float | None = None, @@ -155,10 +153,8 @@ class Row(_LinearContainer): margin_bottom=margin_bottom, min_width=min_width, min_height=min_height, - max_width=max_width, - max_height=max_height, - width=width, - height=height, + # MAX-SIZE-BRANCH max_width=max_width, + # MAX-SIZE-BRANCH max_height=max_height, grow_x=grow_x, grow_y=grow_y, align_x=align_x, @@ -291,10 +287,8 @@ class Column(_LinearContainer): margin_bottom: float | None = None, min_width: float | None = None, min_height: float | None = None, - max_width: float | None = None, - max_height: float | None = None, - width: float | Literal["grow", "natural"] | None = None, - height: float | Literal["grow", "natural"] | None = None, + # MAX-SIZE-BRANCH max_width: float | None = None, + # MAX-SIZE-BRANCH max_height: float | None = None, grow_x: bool = False, grow_y: bool = False, align_x: float | None = None, @@ -313,10 +307,8 @@ class Column(_LinearContainer): margin_bottom=margin_bottom, min_width=min_width, min_height=min_height, - max_width=max_width, - max_height=max_height, - width=width, - height=height, + # MAX-SIZE-BRANCH max_width=max_width, + # MAX-SIZE-BRANCH max_height=max_height, grow_x=grow_x, grow_y=grow_y, align_x=align_x, diff --git a/rio/components/link.py b/rio/components/link.py index 8b32afd1..07474223 100644 --- a/rio/components/link.py +++ b/rio/components/link.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import Literal, final +from typing import final from uniserde import JsonDoc @@ -68,10 +68,8 @@ class Link(FundamentalComponent): margin_bottom: float | None = None, min_width: float | None = None, min_height: float | None = None, - max_width: float | None = None, - max_height: float | None = None, - width: float | Literal["grow", "natural"] | None = None, - height: float | Literal["grow", "natural"] | None = None, + # MAX-SIZE-BRANCH max_width: float | None = None, + # MAX-SIZE-BRANCH max_height: float | None = None, grow_x: bool = False, grow_y: bool = False, align_x: float | None = None, @@ -97,10 +95,8 @@ class Link(FundamentalComponent): margin_bottom=margin_bottom, min_width=min_width, min_height=min_height, - max_width=max_width, - max_height=max_height, - width=width, - height=height, + # MAX-SIZE-BRANCH max_width=max_width, + # MAX-SIZE-BRANCH max_height=max_height, grow_x=grow_x, grow_y=grow_y, align_x=align_x, diff --git a/rio/components/list_items.py b/rio/components/list_items.py index df798541..eaa2d771 100644 --- a/rio/components/list_items.py +++ b/rio/components/list_items.py @@ -178,10 +178,8 @@ class SimpleListItem(Component): on_press: rio.EventHandler[[]] = None, min_width: float | None = None, min_height: float | None = None, - max_width: float | None = None, - max_height: float | None = None, - width: float | Literal["grow", "natural"] | None = None, - height: float | Literal["grow", "natural"] | None = None, + # MAX-SIZE-BRANCH max_width: float | None = None, + # MAX-SIZE-BRANCH max_height: float | None = None, grow_x: bool = False, grow_y: bool = False, # SCROLLING-REWORK scroll_x: Literal["never", "auto", "always"] = "never", @@ -190,10 +188,8 @@ class SimpleListItem(Component): super().__init__( min_width=min_width, min_height=min_height, - max_width=max_width, - max_height=max_height, - width=width, - height=height, + # MAX-SIZE-BRANCH max_width=max_width, + # MAX-SIZE-BRANCH max_height=max_height, grow_x=grow_x, grow_y=grow_y, # SCROLLING-REWORK scroll_x=scroll_x, @@ -348,10 +344,8 @@ class CustomListItem(FundamentalComponent): on_press: rio.EventHandler[[]] = None, min_width: float | None = None, min_height: float | None = None, - max_width: float | None = None, - max_height: float | None = None, - width: float | Literal["grow", "natural"] | None = None, - height: float | Literal["grow", "natural"] | None = None, + # MAX-SIZE-BRANCH max_width: float | None = None, + # MAX-SIZE-BRANCH max_height: float | None = None, grow_x: bool = False, grow_y: bool = False, # SCROLLING-REWORK scroll_x: Literal["never", "auto", "always"] = "never", @@ -360,10 +354,8 @@ class CustomListItem(FundamentalComponent): super().__init__( min_width=min_width, min_height=min_height, - max_width=max_width, - max_height=max_height, - width=width, - height=height, + # MAX-SIZE-BRANCH max_width=max_width, + # MAX-SIZE-BRANCH max_height=max_height, grow_x=grow_x, grow_y=grow_y, # SCROLLING-REWORK scroll_x=scroll_x, diff --git a/rio/components/list_view.py b/rio/components/list_view.py index abe7065a..8e9a6a0d 100644 --- a/rio/components/list_view.py +++ b/rio/components/list_view.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import Literal, final +from typing import final from typing_extensions import Self @@ -108,10 +108,8 @@ class ListView(FundamentalComponent): margin_bottom: float | None = None, min_width: float | None = None, min_height: float | None = None, - max_width: float | None = None, - max_height: float | None = None, - width: float | Literal["grow", "natural"] | None = None, - height: float | Literal["grow", "natural"] | None = None, + # MAX-SIZE-BRANCH max_width: float | None = None, + # MAX-SIZE-BRANCH max_height: float | None = None, grow_x: bool = False, grow_y: bool = False, align_x: float | None = None, @@ -130,10 +128,8 @@ class ListView(FundamentalComponent): margin_bottom=margin_bottom, min_width=min_width, min_height=min_height, - max_width=max_width, - max_height=max_height, - width=width, - height=height, + # MAX-SIZE-BRANCH max_width=max_width, + # MAX-SIZE-BRANCH max_height=max_height, grow_x=grow_x, grow_y=grow_y, align_x=align_x, diff --git a/rio/components/media_player.py b/rio/components/media_player.py index 843d67a9..3ba0a030 100644 --- a/rio/components/media_player.py +++ b/rio/components/media_player.py @@ -1,7 +1,7 @@ from __future__ import annotations import pathlib -from typing import Literal, final +from typing import final from uniserde import JsonDoc @@ -117,10 +117,8 @@ class MediaPlayer(KeyboardFocusableFundamentalComponent): margin_bottom: float | None = None, min_width: float | None = None, min_height: float | None = None, - max_width: float | None = None, - max_height: float | None = None, - width: float | Literal["grow", "natural"] | None = None, - height: float | Literal["grow", "natural"] | None = None, + # MAX-SIZE-BRANCH max_width: float | None = None, + # MAX-SIZE-BRANCH max_height: float | None = None, grow_x: bool = False, grow_y: bool = False, align_x: float | None = None, @@ -139,10 +137,8 @@ class MediaPlayer(KeyboardFocusableFundamentalComponent): margin_bottom=margin_bottom, min_width=min_width, min_height=min_height, - max_width=max_width, - max_height=max_height, - width=width, - height=height, + # MAX-SIZE-BRANCH max_width=max_width, + # MAX-SIZE-BRANCH max_height=max_height, grow_x=grow_x, grow_y=grow_y, align_x=align_x, diff --git a/rio/components/node_input.py b/rio/components/node_input.py index 6da30389..cd8fa778 100644 --- a/rio/components/node_input.py +++ b/rio/components/node_input.py @@ -39,10 +39,8 @@ class NodeInput(FundamentalComponent): margin_bottom: float | None = None, min_width: float | None = None, min_height: float | None = None, - max_width: float | None = None, - max_height: float | None = None, - width: float | Literal["grow", "natural"] | None = None, - height: float | Literal["grow", "natural"] | None = None, + # MAX-SIZE-BRANCH max_width: float | None = None, + # MAX-SIZE-BRANCH max_height: float | None = None, grow_x: bool = False, grow_y: bool = False, # SCROLLING-REWORK scroll_x: Literal["never", "auto", "always"] = "never", @@ -62,10 +60,8 @@ class NodeInput(FundamentalComponent): margin_bottom=margin_bottom, min_width=min_width, min_height=min_height, - max_width=max_width, - max_height=max_height, - width=width, - height=height, + # MAX-SIZE-BRANCH max_width=max_width, + # MAX-SIZE-BRANCH max_height=max_height, grow_x=grow_x, grow_y=grow_y, # SCROLLING-REWORK scroll_x=scroll_x, diff --git a/rio/components/node_output.py b/rio/components/node_output.py index 5bf38c27..87cf7ce6 100644 --- a/rio/components/node_output.py +++ b/rio/components/node_output.py @@ -39,10 +39,8 @@ class NodeOutput(FundamentalComponent): margin_bottom: float | None = None, min_width: float | None = None, min_height: float | None = None, - max_width: float | None = None, - max_height: float | None = None, - width: float | Literal["grow", "natural"] | None = None, - height: float | Literal["grow", "natural"] | None = None, + # MAX-SIZE-BRANCH max_width: float | None = None, + # MAX-SIZE-BRANCH max_height: float | None = None, grow_x: bool = False, grow_y: bool = False, # SCROLLING-REWORK scroll_x: Literal["never", "auto", "always"] = "never", @@ -62,10 +60,8 @@ class NodeOutput(FundamentalComponent): margin_bottom=margin_bottom, min_width=min_width, min_height=min_height, - max_width=max_width, - max_height=max_height, - width=width, - height=height, + # MAX-SIZE-BRANCH max_width=max_width, + # MAX-SIZE-BRANCH max_height=max_height, grow_x=grow_x, grow_y=grow_y, # SCROLLING-REWORK scroll_x=scroll_x, diff --git a/rio/components/plot.py b/rio/components/plot.py index 7230b031..5bf7b1da 100644 --- a/rio/components/plot.py +++ b/rio/components/plot.py @@ -1,7 +1,7 @@ from __future__ import annotations import io -from typing import TYPE_CHECKING, Literal, cast, final +from typing import TYPE_CHECKING, cast, final from uniserde import JsonDoc @@ -92,10 +92,8 @@ class Plot(FundamentalComponent): margin_bottom: float | None = None, min_width: float | None = None, min_height: float | None = None, - max_width: float | None = None, - max_height: float | None = None, - width: float | Literal["grow", "natural"] | None = None, - height: float | Literal["grow", "natural"] | None = None, + # MAX-SIZE-BRANCH max_width: float | None = None, + # MAX-SIZE-BRANCH max_height: float | None = None, grow_x: bool = False, grow_y: bool = False, align_x: float | None = None, @@ -114,10 +112,8 @@ class Plot(FundamentalComponent): margin_bottom=margin_bottom, min_width=min_width, min_height=min_height, - max_width=max_width, - max_height=max_height, - width=width, - height=height, + # MAX-SIZE-BRANCH max_width=max_width, + # MAX-SIZE-BRANCH max_height=max_height, grow_x=grow_x, grow_y=grow_y, align_x=align_x, diff --git a/rio/components/progress_bar.py b/rio/components/progress_bar.py index d2b3df48..94022aa9 100644 --- a/rio/components/progress_bar.py +++ b/rio/components/progress_bar.py @@ -72,10 +72,8 @@ class ProgressBar(FundamentalComponent): margin_bottom: float | None = None, min_width: float | None = None, min_height: float | None = None, - max_width: float | None = None, - max_height: float | None = None, - width: float | Literal["grow", "natural"] | None = None, - height: float | Literal["grow", "natural"] | None = None, + # MAX-SIZE-BRANCH max_width: float | None = None, + # MAX-SIZE-BRANCH max_height: float | None = None, grow_x: bool = False, grow_y: bool = False, align_x: float | None = None, @@ -107,10 +105,8 @@ class ProgressBar(FundamentalComponent): margin_bottom=margin_bottom, min_width=min_width, min_height=min_height, - max_width=max_width, - max_height=max_height, - width=width, - height=height, + # MAX-SIZE-BRANCH max_width=max_width, + # MAX-SIZE-BRANCH max_height=max_height, grow_x=grow_x, grow_y=grow_y, align_x=align_x, diff --git a/rio/components/slider.py b/rio/components/slider.py index a482a506..6e82bd0f 100644 --- a/rio/components/slider.py +++ b/rio/components/slider.py @@ -2,7 +2,7 @@ from __future__ import annotations import math from dataclasses import dataclass -from typing import Literal, final +from typing import final from uniserde import JsonDoc @@ -123,10 +123,8 @@ class Slider(FundamentalComponent): margin_bottom: float | None = None, min_width: float | None = 1.3, min_height: float | None = 1.3, - max_width: float | None = None, - max_height: float | None = None, - width: float | Literal["grow", "natural"] | None = None, - height: float | Literal["grow", "natural"] | None = None, + # MAX-SIZE-BRANCH max_width: float | None = None, + # MAX-SIZE-BRANCH max_height: float | None = None, grow_x: bool = False, grow_y: bool = False, align_x: float | None = None, @@ -145,10 +143,8 @@ class Slider(FundamentalComponent): margin_bottom=margin_bottom, min_width=min_width, min_height=min_height, - max_width=max_width, - max_height=max_height, - width=width, - height=height, + # MAX-SIZE-BRANCH max_width=max_width, + # MAX-SIZE-BRANCH max_height=max_height, grow_x=grow_x, grow_y=grow_y, align_x=align_x, diff --git a/rio/components/slideshow.py b/rio/components/slideshow.py index 2e5a11a0..ca84bdf9 100644 --- a/rio/components/slideshow.py +++ b/rio/components/slideshow.py @@ -2,7 +2,7 @@ from __future__ import annotations from dataclasses import KW_ONLY from datetime import timedelta -from typing import Literal, final +from typing import final from uniserde import JsonDoc @@ -73,10 +73,8 @@ class Slideshow(FundamentalComponent): margin_bottom: float | None = None, min_width: float | None = None, min_height: float | None = None, - max_width: float | None = None, - max_height: float | None = None, - width: float | Literal["grow", "natural"] | None = None, - height: float | Literal["grow", "natural"] | None = None, + # MAX-SIZE-BRANCH max_width: float | None = None, + # MAX-SIZE-BRANCH max_height: float | None = None, grow_x: bool = False, grow_y: bool = False, align_x: float | None = None, @@ -98,10 +96,8 @@ class Slideshow(FundamentalComponent): margin_bottom=margin_bottom, min_width=min_width, min_height=min_height, - max_width=max_width, - max_height=max_height, - width=width, - height=height, + # MAX-SIZE-BRANCH max_width=max_width, + # MAX-SIZE-BRANCH max_height=max_height, grow_x=grow_x, grow_y=grow_y, align_x=align_x, diff --git a/rio/components/spacer.py b/rio/components/spacer.py index ca60a497..63796562 100644 --- a/rio/components/spacer.py +++ b/rio/components/spacer.py @@ -42,18 +42,18 @@ class Spacer(class_container.ClassContainer): *, min_width: float | None = None, min_height: float | None = None, - max_width: float | None = None, - max_height: float | None = None, - width: float | Literal["grow", "natural"] | None = None, - height: float | Literal["grow", "natural"] | None = None, + # MAX-SIZE-BRANCH max_width: float | None = None, + # MAX-SIZE-BRANCH max_height: float | None = None, grow_x: bool = True, grow_y: bool = True, key: str | int | None = None, ): """ ## Parameters - width: How much space the spacer should take up horizontally. - height: How much space the spacer should take up vertically. + + `width`: How much space the spacer should take up horizontally. + + `height`: How much space the spacer should take up vertically. """ super().__init__( @@ -62,10 +62,8 @@ class Spacer(class_container.ClassContainer): key=key, min_width=min_width, min_height=min_height, - max_width=max_width, - max_height=max_height, - width=width, - height=height, + # MAX-SIZE-BRANCH max_width=max_width, + # MAX-SIZE-BRANCH max_height=max_height, grow_x=grow_x, grow_y=grow_y, ) diff --git a/rio/components/stack.py b/rio/components/stack.py index c1c4ce6b..08cd29ac 100644 --- a/rio/components/stack.py +++ b/rio/components/stack.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import Literal, final +from typing import final from typing_extensions import Self @@ -75,10 +75,8 @@ class Stack(FundamentalComponent): margin_bottom: float | None = None, min_width: float | None = None, min_height: float | None = None, - max_width: float | None = None, - max_height: float | None = None, - width: float | Literal["grow", "natural"] | None = None, - height: float | Literal["grow", "natural"] | None = None, + # MAX-SIZE-BRANCH max_width: float | None = None, + # MAX-SIZE-BRANCH max_height: float | None = None, grow_x: bool = False, grow_y: bool = False, align_x: float | None = None, @@ -97,10 +95,8 @@ class Stack(FundamentalComponent): margin_bottom=margin_bottom, min_width=min_width, min_height=min_height, - max_width=max_width, - max_height=max_height, - width=width, - height=height, + # MAX-SIZE-BRANCH max_width=max_width, + # MAX-SIZE-BRANCH max_height=max_height, grow_x=grow_x, grow_y=grow_y, align_x=align_x, diff --git a/rio/components/switcher_bar.py b/rio/components/switcher_bar.py index 8daac8d1..5e75533c 100644 --- a/rio/components/switcher_bar.py +++ b/rio/components/switcher_bar.py @@ -152,10 +152,8 @@ class SwitcherBar(FundamentalComponent, Generic[T]): margin_bottom: float | None = None, min_width: float | None = None, min_height: float | None = None, - max_width: float | None = None, - max_height: float | None = None, - width: float | Literal["grow", "natural"] | None = None, - height: float | Literal["grow", "natural"] | None = None, + # MAX-SIZE-BRANCH max_width: float | None = None, + # MAX-SIZE-BRANCH max_height: float | None = None, grow_x: bool = False, grow_y: bool = False, align_x: float | None = None, @@ -179,10 +177,8 @@ class SwitcherBar(FundamentalComponent, Generic[T]): margin_bottom=margin_bottom, min_width=min_width, min_height=min_height, - max_width=max_width, - max_height=max_height, - width=width, - height=height, + # MAX-SIZE-BRANCH max_width=max_width, + # MAX-SIZE-BRANCH max_height=max_height, grow_x=grow_x, grow_y=grow_y, align_x=align_x, diff --git a/rio/components/tooltip.py b/rio/components/tooltip.py index cdde1e42..4a98385b 100644 --- a/rio/components/tooltip.py +++ b/rio/components/tooltip.py @@ -75,10 +75,8 @@ class Tooltip(FundamentalComponent): margin_bottom: float | None = None, min_width: float | None = None, min_height: float | None = None, - max_width: float | None = None, - max_height: float | None = None, - width: float | Literal["grow", "natural"] | None = None, - height: float | Literal["grow", "natural"] | None = None, + # MAX-SIZE-BRANCH max_width: float | None = None, + # MAX-SIZE-BRANCH max_height: float | None = None, grow_x: bool = False, grow_y: bool = False, align_x: float | None = None, @@ -97,10 +95,8 @@ class Tooltip(FundamentalComponent): margin_bottom=margin_bottom, min_width=min_width, min_height=min_height, - max_width=max_width, - max_height=max_height, - width=width, - height=height, + # MAX-SIZE-BRANCH max_width=max_width, + # MAX-SIZE-BRANCH max_height=max_height, grow_x=grow_x, grow_y=grow_y, align_x=align_x, diff --git a/rio/deprecations.py b/rio/deprecations.py index 56f12a98..967db5ad 100644 --- a/rio/deprecations.py +++ b/rio/deprecations.py @@ -5,13 +5,23 @@ from typing import * from .component_meta import ComponentMeta from .warnings import * -__all__ = ["deprecated", "parameters_renamed", "_remap_kwargs"] +__all__ = [ + "deprecated", + "parameters_renamed", + "_remap_kwargs", + "warn", + "remap_width_and_height", +] C = TypeVar("C", bound=Union[Callable, ComponentMeta]) F = TypeVar("F", bound=Callable) +def warn(message: str) -> None: + warnings.warn(message, RioDeprecationWarning) + + @overload def deprecated(*, since: str, replacement: Callable | str): ... @@ -106,11 +116,10 @@ def parameters_remapped(since: str, **params: Callable[[Any], dict[str, Any]]): [[new_name, new_value]] = remap_func(old_value).items() kwargs[new_name] = new_value - warnings.warn( + warn( f"The {old_name!r} parameter of rio.{func.__qualname__}" f" is deprecated; please use the {new_name!r} parameter" - f" from now on", - RioDeprecationWarning, + f" from now on" ) return func(*args, **kwargs) @@ -131,7 +140,44 @@ def _remap_kwargs( except KeyError: pass else: - warnings.warn( - f"The {old_name!r} parameter of rio.{func_name} is deprecated; it has been renamed to {new_name!r}", - RioDeprecationWarning, + warn( + f"The {old_name!r} parameter of rio.{func_name} is deprecated;" + f" it has been renamed to {new_name!r}", ) + + +def remap_width_and_height(kwargs): + width: float | Literal["grow", "natural"] | None = kwargs.pop("width", None) + height: float | Literal["grow", "natural"] | None = kwargs.pop( + "height", None + ) + + if width is None: + pass + else: + warn( + "The `width` parameter/attribute of `rio.Component` is deprecated;" + " it has been superseded by `min_width` and `grow_x`" + ) + + if width == "natural": + pass + elif width == "grow": + kwargs["grow_x"] = True + else: + kwargs["min_width"] = width + + if height is None: + pass + else: + warn( + "The `height` parameter/attribute of `rio.Component` is deprecated;" + " it has been superseded by `min_height` and `grow_y`" + ) + + if height == "natural": + pass + elif height == "grow": + kwargs["grow_y"] = True + else: + kwargs["min_height"] = height diff --git a/rio/serialization.py b/rio/serialization.py index 5accf010..ec0e9e62 100644 --- a/rio/serialization.py +++ b/rio/serialization.py @@ -96,29 +96,12 @@ def serialize_and_host_component(component: rio.Component) -> JsonDoc: min_width = component.min_width min_height = component.min_height - max_width = component.max_width - max_height = component.max_height + # MAX-SIZE-BRANCH max_width = component.max_width + # MAX-SIZE-BRANCH max_height = component.max_height grow_x = component.grow_x grow_y = component.grow_y - width: float | Literal["grow", "natural"] | None = component.width # type: ignore - height: float | Literal["grow", "natural"] | None = component.height # type: ignore - - if width is None or width == "natural": - pass - elif width == "grow": - grow_x = True - else: - min_width = width - - if height is None or height == "natural": - pass - elif height == "grow": - grow_y = True - else: - min_height = height - margin_x = component.margin_x margin_y = component.margin_y margin = component.margin @@ -141,10 +124,10 @@ def serialize_and_host_component(component: rio.Component) -> JsonDoc: _float_or_zero(min_width), _float_or_zero(min_height), ) - result["_max_size_"] = ( - _float_if_not_none(max_width), - _float_if_not_none(max_height), - ) + # MAX-SIZE-BRANCH result["_max_size_"] = ( + # MAX-SIZE-BRANCH _float_if_not_none(max_width), + # MAX-SIZE-BRANCH _float_if_not_none(max_height), + # MAX-SIZE-BRANCH ) result["_align_"] = ( component.align_x, component.align_y,