[layouts] Address feedback on "Fix vertical layout bug with centered content" PR

This commit is contained in:
Olivier Philippon
2022-05-10 09:12:55 +01:00
parent 7843683f5c
commit 72c9622b82
5 changed files with 8 additions and 29 deletions

View File

@@ -494,18 +494,6 @@ class App(Generic[ReturnType], DOMNode):
return DOMQuery(self.screen, selector)
def query_one(self, selector: str) -> DOMNode | None:
"""Retrieves a single node via a DOM query in the current screen.
Args:
selector (str): A CSS selector .
Returns:
DOMNode | None: The first node matching the query, or None if no node matches the selector.
"""
result = self.query(selector)
return result.first() if len(result) else None
def get_child(self, id: str) -> DOMNode:
"""Shorthand for self.screen.get_child(id: str)
Returns the first child (immediate descendent) of this DOMNode
@@ -516,6 +504,9 @@ class App(Generic[ReturnType], DOMNode):
Returns:
DOMNode: The first child of this node with the specified ID.
Raises:
NoMatchingNodesError: if no children could be found for this ID
"""
return self.screen.get_child(id)

View File

@@ -397,6 +397,9 @@ class DOMNode(MessagePump):
Returns:
DOMNode: The first child of this node with the ID.
Raises:
NoMatchingNodesError: if no children could be found for this ID
"""
for child in self.children:
if child.id == id:

View File

@@ -403,7 +403,6 @@ class Widget(DOMNode):
Returns:
Region: The widget region minus scrollbars.
"""
# return region
show_vertical_scrollbar, show_horizontal_scrollbar = self.scrollbars_enabled
if show_horizontal_scrollbar and show_vertical_scrollbar:
(region, _, _, _) = region.split(-1, -1)

View File

@@ -1,6 +1,5 @@
from __future__ import annotations
import asyncio
import platform
from typing import cast, List
import pytest
@@ -11,9 +10,6 @@ from textual.geometry import Size
from textual.widget import Widget
from textual.widgets import Placeholder
PLATFORM = platform.system()
WINDOWS = PLATFORM == "Windows"
# Let's allow ourselves some abbreviated names for those tests,
# in order to make the test cases a bit easier to read :-)
SCREEN_W = 100 # width of our Screens
@@ -153,22 +149,11 @@ async def test_composition_of_vertical_container_with_children(
expected_screen_size = Size(*screen_size)
# On Windows the screen size is always 1 cell smaller than the requested dimensions.
# Let's take this into account into our "expected_*" measurements:
if WINDOWS:
expected_screen_size = expected_screen_size._replace(
width=expected_screen_size.width - 1
)
expected_placeholders_size = (
expected_placeholders_size[0] - 1,
expected_placeholders_size[1],
)
async with app.in_running_state():
app.log_tree()
# root widget checks:
root_widget = cast(Widget, app.query_one("#root"))
root_widget = cast(Widget, app.get_child("root"))
assert root_widget.size == expected_screen_size
root_widget_region = app.screen.get_widget_region(root_widget)
assert root_widget_region == (

View File

@@ -111,6 +111,7 @@ class ConsoleTest(Console):
width=width,
height=height,
force_terminal=True,
legacy_windows=False,
)