Skip to content

Commit c68e749

Browse files
authored
Merge pull request #1327 from Textualize/visibility-fix
fix for visiblity
2 parents 8760c3c + a25a60e commit c68e749

File tree

5 files changed

+248
-27
lines changed

5 files changed

+248
-27
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2121
### Fixed
2222

2323
- Type selectors can now contain numbers https://github.com/Textualize/textual/issues/1253
24+
- Fixed visibility not affecting children https://github.com/Textualize/textual/issues/1313
2425

2526
## [0.5.0] - 2022-11-20
2627

src/textual/_compositor.py

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ def add_widget(
347347
order: tuple[tuple[int, ...], ...],
348348
layer_order: int,
349349
clip: Region,
350+
visible: bool,
350351
) -> None:
351352
"""Called recursively to place a widget and its children in the map.
352353
@@ -356,7 +357,12 @@ def add_widget(
356357
order (tuple[int, ...]): A tuple of ints to define the order.
357358
clip (Region): The clipping region (i.e. the viewport which contains it).
358359
"""
359-
widgets.add(widget)
360+
visibility = widget.styles.get_rule("visibility")
361+
if visibility is not None:
362+
visible = visibility == "visible"
363+
364+
if visible:
365+
widgets.add(widget)
360366
styles_offset = widget.styles.offset
361367
layout_offset = (
362368
styles_offset.resolve(region.size, clip.size)
@@ -420,32 +426,34 @@ def add_widget(
420426
widget_order,
421427
layer_order,
422428
sub_clip,
429+
visible,
423430
)
424431
layer_order -= 1
425432

426-
# Add any scrollbars
427-
for chrome_widget, chrome_region in widget._arrange_scrollbars(
428-
container_region
429-
):
430-
map[chrome_widget] = MapGeometry(
431-
chrome_region + layout_offset,
433+
if visible:
434+
# Add any scrollbars
435+
for chrome_widget, chrome_region in widget._arrange_scrollbars(
436+
container_region
437+
):
438+
map[chrome_widget] = MapGeometry(
439+
chrome_region + layout_offset,
440+
order,
441+
clip,
442+
container_size,
443+
container_size,
444+
chrome_region,
445+
)
446+
447+
map[widget] = MapGeometry(
448+
region + layout_offset,
432449
order,
433450
clip,
451+
total_region.size,
434452
container_size,
435-
container_size,
436-
chrome_region,
453+
virtual_region,
437454
)
438455

439-
map[widget] = MapGeometry(
440-
region + layout_offset,
441-
order,
442-
clip,
443-
total_region.size,
444-
container_size,
445-
virtual_region,
446-
)
447-
448-
else:
456+
elif visible:
449457
# Add the widget to the map
450458
map[widget] = MapGeometry(
451459
region + layout_offset,
@@ -457,7 +465,15 @@ def add_widget(
457465
)
458466

459467
# Add top level (root) widget
460-
add_widget(root, size.region, size.region, ((0,),), layer_order, size.region)
468+
add_widget(
469+
root,
470+
size.region,
471+
size.region,
472+
((0,),),
473+
layer_order,
474+
size.region,
475+
True,
476+
)
461477
return map, widgets
462478

463479
@property
@@ -630,11 +646,6 @@ def _get_renders(
630646
if not self.map:
631647
return
632648

633-
def is_visible(widget: Widget) -> bool:
634-
"""Return True if the widget is (literally) visible by examining various
635-
properties which affect whether it can be seen or not."""
636-
return widget.visible and widget.styles.opacity > 0
637-
638649
_Region = Region
639650

640651
visible_widgets = self.visible_widgets
@@ -644,13 +655,13 @@ def is_visible(widget: Widget) -> bool:
644655
widget_regions = [
645656
(widget, region, clip)
646657
for widget, (region, clip) in visible_widgets.items()
647-
if crop_overlaps(clip) and is_visible(widget)
658+
if crop_overlaps(clip) and widget.styles.opacity > 0
648659
]
649660
else:
650661
widget_regions = [
651662
(widget, region, clip)
652663
for widget, (region, clip) in visible_widgets.items()
653-
if is_visible(widget)
664+
if widget.styles.opacity > 0
654665
]
655666

656667
intersection = _Region.intersection

0 commit comments

Comments
 (0)