mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
[layouts] Address feedback on "Fix vertical layout bug with centered content" PR
This commit is contained in:
@@ -494,18 +494,6 @@ class App(Generic[ReturnType], DOMNode):
|
|||||||
|
|
||||||
return DOMQuery(self.screen, selector)
|
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:
|
def get_child(self, id: str) -> DOMNode:
|
||||||
"""Shorthand for self.screen.get_child(id: str)
|
"""Shorthand for self.screen.get_child(id: str)
|
||||||
Returns the first child (immediate descendent) of this DOMNode
|
Returns the first child (immediate descendent) of this DOMNode
|
||||||
@@ -516,6 +504,9 @@ class App(Generic[ReturnType], DOMNode):
|
|||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
DOMNode: The first child of this node with the specified ID.
|
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)
|
return self.screen.get_child(id)
|
||||||
|
|
||||||
|
|||||||
@@ -397,6 +397,9 @@ class DOMNode(MessagePump):
|
|||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
DOMNode: The first child of this node with the ID.
|
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:
|
for child in self.children:
|
||||||
if child.id == id:
|
if child.id == id:
|
||||||
|
|||||||
@@ -403,7 +403,6 @@ class Widget(DOMNode):
|
|||||||
Returns:
|
Returns:
|
||||||
Region: The widget region minus scrollbars.
|
Region: The widget region minus scrollbars.
|
||||||
"""
|
"""
|
||||||
# return region
|
|
||||||
show_vertical_scrollbar, show_horizontal_scrollbar = self.scrollbars_enabled
|
show_vertical_scrollbar, show_horizontal_scrollbar = self.scrollbars_enabled
|
||||||
if show_horizontal_scrollbar and show_vertical_scrollbar:
|
if show_horizontal_scrollbar and show_vertical_scrollbar:
|
||||||
(region, _, _, _) = region.split(-1, -1)
|
(region, _, _, _) = region.split(-1, -1)
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
import asyncio
|
import asyncio
|
||||||
import platform
|
|
||||||
from typing import cast, List
|
from typing import cast, List
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
@@ -11,9 +10,6 @@ from textual.geometry import Size
|
|||||||
from textual.widget import Widget
|
from textual.widget import Widget
|
||||||
from textual.widgets import Placeholder
|
from textual.widgets import Placeholder
|
||||||
|
|
||||||
PLATFORM = platform.system()
|
|
||||||
WINDOWS = PLATFORM == "Windows"
|
|
||||||
|
|
||||||
# Let's allow ourselves some abbreviated names for those tests,
|
# Let's allow ourselves some abbreviated names for those tests,
|
||||||
# in order to make the test cases a bit easier to read :-)
|
# in order to make the test cases a bit easier to read :-)
|
||||||
SCREEN_W = 100 # width of our Screens
|
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)
|
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():
|
async with app.in_running_state():
|
||||||
app.log_tree()
|
app.log_tree()
|
||||||
|
|
||||||
# root widget checks:
|
# 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
|
assert root_widget.size == expected_screen_size
|
||||||
root_widget_region = app.screen.get_widget_region(root_widget)
|
root_widget_region = app.screen.get_widget_region(root_widget)
|
||||||
assert root_widget_region == (
|
assert root_widget_region == (
|
||||||
|
|||||||
@@ -111,6 +111,7 @@ class ConsoleTest(Console):
|
|||||||
width=width,
|
width=width,
|
||||||
height=height,
|
height=height,
|
||||||
force_terminal=True,
|
force_terminal=True,
|
||||||
|
legacy_windows=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user