mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Merge branch 'vertical-layout' into horizontal-layout
This commit is contained in:
@@ -3,9 +3,8 @@ from __future__ import annotations
|
||||
from typing import Iterable, TYPE_CHECKING
|
||||
|
||||
from ..css.styles import Styles
|
||||
from ..geometry import Offset, Region, Size, Spacing, SpacingDimensions
|
||||
from ..geometry import Offset, Region, Size
|
||||
from ..layout import Layout, WidgetPlacement
|
||||
from .._loop import loop_last
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ..widget import Widget
|
||||
@@ -13,49 +12,30 @@ if TYPE_CHECKING:
|
||||
|
||||
|
||||
class VerticalLayout(Layout):
|
||||
def __init__(
|
||||
self,
|
||||
*,
|
||||
auto_width: bool = False,
|
||||
z: int = 0,
|
||||
gutter: SpacingDimensions = (0, 0, 0, 0)
|
||||
):
|
||||
self.auto_width = auto_width
|
||||
self.z = z
|
||||
self.gutter = Spacing.unpack(gutter)
|
||||
self._max_widget_width = 0
|
||||
super().__init__()
|
||||
|
||||
def get_widgets(self, view: View) -> Iterable[Widget]:
|
||||
return view.children
|
||||
|
||||
def arrange(
|
||||
self, view: View, size: Size, scroll: Offset
|
||||
) -> Iterable[WidgetPlacement]:
|
||||
width, _height = size
|
||||
gutter = self.gutter
|
||||
x, y = self.gutter.top_left
|
||||
render_width = (
|
||||
max(width, self._max_widget_width)
|
||||
if self.auto_width
|
||||
else width - gutter.width
|
||||
)
|
||||
parent_width, parent_height = size
|
||||
x, y = 0, 0
|
||||
|
||||
total_width = render_width
|
||||
gutter_height = max(gutter.top, gutter.bottom)
|
||||
|
||||
for last, widget in loop_last(view.children):
|
||||
for widget in view.children:
|
||||
styles: Styles = widget.styles
|
||||
|
||||
if styles.height:
|
||||
render_height = int(
|
||||
styles.height.resolve_dimension(size, view.app.size)
|
||||
)
|
||||
else:
|
||||
render_height = size.height
|
||||
if styles.width:
|
||||
render_width = min(styles.width.cells, render_width)
|
||||
region = Region(x, y, render_width, render_height)
|
||||
yield WidgetPlacement(region, widget, self.z)
|
||||
y += render_height + (gutter.bottom if last else gutter_height)
|
||||
|
||||
yield WidgetPlacement(Region(0, 0, total_width + gutter.width, y))
|
||||
if styles.width:
|
||||
render_width = int(styles.width.resolve_dimension(size, view.app.size))
|
||||
else:
|
||||
render_width = parent_width
|
||||
|
||||
region = Region(x, y, render_width, render_height)
|
||||
yield WidgetPlacement(region, widget, 0)
|
||||
y += render_height
|
||||
|
||||
Reference in New Issue
Block a user