Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for visiblity #1327

Merged
merged 2 commits into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Fixed

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

## [0.5.0] - 2022-11-20

Expand Down
65 changes: 38 additions & 27 deletions src/textual/_compositor.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ def add_widget(
order: tuple[tuple[int, ...], ...],
layer_order: int,
clip: Region,
visible: bool,
) -> None:
"""Called recursively to place a widget and its children in the map.

Expand All @@ -356,7 +357,12 @@ def add_widget(
order (tuple[int, ...]): A tuple of ints to define the order.
clip (Region): The clipping region (i.e. the viewport which contains it).
"""
widgets.add(widget)
visibility = widget.styles.get_rule("visibility")
if visibility is not None:
visible = visibility == "visible"

if visible:
widgets.add(widget)
styles_offset = widget.styles.offset
layout_offset = (
styles_offset.resolve(region.size, clip.size)
Expand Down Expand Up @@ -420,32 +426,34 @@ def add_widget(
widget_order,
layer_order,
sub_clip,
visible,
)
layer_order -= 1

# Add any scrollbars
for chrome_widget, chrome_region in widget._arrange_scrollbars(
container_region
):
map[chrome_widget] = MapGeometry(
chrome_region + layout_offset,
if visible:
# Add any scrollbars
for chrome_widget, chrome_region in widget._arrange_scrollbars(
container_region
):
map[chrome_widget] = MapGeometry(
chrome_region + layout_offset,
order,
clip,
container_size,
container_size,
chrome_region,
)

map[widget] = MapGeometry(
region + layout_offset,
order,
clip,
total_region.size,
container_size,
container_size,
chrome_region,
virtual_region,
)

map[widget] = MapGeometry(
region + layout_offset,
order,
clip,
total_region.size,
container_size,
virtual_region,
)

else:
elif visible:
# Add the widget to the map
map[widget] = MapGeometry(
region + layout_offset,
Expand All @@ -457,7 +465,15 @@ def add_widget(
)

# Add top level (root) widget
add_widget(root, size.region, size.region, ((0,),), layer_order, size.region)
add_widget(
root,
size.region,
size.region,
((0,),),
layer_order,
size.region,
True,
)
return map, widgets

@property
Expand Down Expand Up @@ -630,11 +646,6 @@ def _get_renders(
if not self.map:
return

def is_visible(widget: Widget) -> bool:
"""Return True if the widget is (literally) visible by examining various
properties which affect whether it can be seen or not."""
return widget.visible and widget.styles.opacity > 0

_Region = Region

visible_widgets = self.visible_widgets
Expand All @@ -644,13 +655,13 @@ def is_visible(widget: Widget) -> bool:
widget_regions = [
(widget, region, clip)
for widget, (region, clip) in visible_widgets.items()
if crop_overlaps(clip) and is_visible(widget)
if crop_overlaps(clip) and widget.styles.opacity > 0
]
else:
widget_regions = [
(widget, region, clip)
for widget, (region, clip) in visible_widgets.items()
if is_visible(widget)
if widget.styles.opacity > 0
]

intersection = _Region.intersection
Expand Down
Loading