moved layout

This commit is contained in:
Will McGugan
2022-04-28 13:26:29 +01:00
parent 8999ca5a3d
commit 4a20455838
3 changed files with 45 additions and 3 deletions

40
src/textual/_layout.py Normal file
View File

@@ -0,0 +1,40 @@
from __future__ import annotations
from abc import ABC, abstractmethod
from typing import ClassVar, NamedTuple, TYPE_CHECKING
from .geometry import Region, Offset, Size
if TYPE_CHECKING:
from .widget import Widget
class WidgetPlacement(NamedTuple):
"""The position, size, and relative order of a widget within its parent."""
region: Region
widget: Widget | None = None # A widget of None means empty space
order: int = 0
class Layout(ABC):
"""Responsible for arranging Widgets in a view and rendering them."""
name: ClassVar[str] = ""
@abstractmethod
def arrange(
self, parent: Widget, size: Size, scroll: Offset
) -> tuple[list[WidgetPlacement], set[Widget]]:
"""Generate a layout map that defines where on the screen the widgets will be drawn.
Args:
parent (Widget): Parent widget.
size (Size): Size of container.
scroll (Offset): Offset to apply to the Widget placements.
Returns:
Iterable[WidgetPlacement]: An iterable of widget location
"""

View File

@@ -182,7 +182,8 @@ class App(Generic[ReturnType], DOMNode):
self._return_value = result
self.close_messages_no_wait()
def compose(self) -> Iterable[Widget]:
def compose(self) -> ComposeResult:
"""Yield child widgets for a container."""
return
yield

View File

@@ -39,7 +39,7 @@ from .renderables.opacity import Opacity
if TYPE_CHECKING:
from .app import App
from .app import App, ComposeResult
from .scrollbar import (
ScrollBar,
ScrollTo,
@@ -115,7 +115,8 @@ class Widget(DOMNode):
self.app.register(self, *anon_widgets, **widgets)
self.screen.refresh()
def compose(self) -> Iterable[Widget]:
def compose(self) -> ComposeResult:
"""Yield child widgets for a container."""
return
yield