[css] Add missing occurrences of the now-flexible scrollbars thicknesses in the Widget class

This commit is contained in:
Olivier Philippon
2022-05-25 15:47:26 +01:00
parent a55b122967
commit 2462a0e402
2 changed files with 36 additions and 29 deletions

View File

@@ -131,7 +131,7 @@ TweetBody {
} }
Tweet.scroll-horizontal TweetBody { Tweet.scroll-horizontal TweetBody {
width: 130%; width: 350;
} }
.button { .button {

View File

@@ -184,6 +184,7 @@ class Widget(DOMNode):
int: The optimal width of the content. int: The optimal width of the content.
""" """
if self.is_container: if self.is_container:
assert self.layout is not None
return ( return (
self.layout.get_content_width(self, container, viewport) self.layout.get_content_width(self, container, viewport)
+ self.scrollbar_width + self.scrollbar_width
@@ -288,7 +289,7 @@ class Widget(DOMNode):
if self._vertical_scrollbar is not None: if self._vertical_scrollbar is not None:
return self._vertical_scrollbar return self._vertical_scrollbar
(vertical_scrollbar_thickness, _) = self._get_scrollbar_thicknesses() vertical_scrollbar_thickness = self._get_scrollbar_thickness_vertical()
self._vertical_scrollbar = scroll_bar = ScrollBar( self._vertical_scrollbar = scroll_bar = ScrollBar(
vertical=True, name="vertical", thickness=vertical_scrollbar_thickness vertical=True, name="vertical", thickness=vertical_scrollbar_thickness
) )
@@ -306,7 +307,7 @@ class Widget(DOMNode):
if self._horizontal_scrollbar is not None: if self._horizontal_scrollbar is not None:
return self._horizontal_scrollbar return self._horizontal_scrollbar
(_, horizontal_scrollbar_thickness) = self._get_scrollbar_thicknesses() horizontal_scrollbar_thickness = self._get_scrollbar_thickness_horizontal()
self._horizontal_scrollbar = scroll_bar = ScrollBar( self._horizontal_scrollbar = scroll_bar = ScrollBar(
vertical=False, name="horizontal", thickness=horizontal_scrollbar_thickness vertical=False, name="horizontal", thickness=horizontal_scrollbar_thickness
) )
@@ -362,17 +363,20 @@ class Widget(DOMNode):
@property @property
def scrollbar_dimensions(self) -> tuple[int, int]: def scrollbar_dimensions(self) -> tuple[int, int]:
"""Get the size of any scrollbars on the widget""" """Get the size of any scrollbars on the widget"""
return (int(self.show_horizontal_scrollbar), int(self.show_vertical_scrollbar)) return (
self._get_scrollbar_thickness_horizontal(),
self._get_scrollbar_thickness_vertical(),
)
@property @property
def scrollbar_width(self) -> int: def scrollbar_width(self) -> int:
"""Get the width used by the *vertical* scrollbar.""" """Get the width used by the *vertical* scrollbar."""
return int(self.show_vertical_scrollbar) return self._get_scrollbar_thickness_vertical()
@property @property
def scrollbar_height(self) -> int: def scrollbar_height(self) -> int:
"""Get the height used by the *horizontal* scrollbar.""" """Get the height used by the *horizontal* scrollbar."""
return int(self.show_horizontal_scrollbar) return self._get_scrollbar_thickness_horizontal()
def set_dirty(self) -> None: def set_dirty(self) -> None:
"""Set the Widget as 'dirty' (requiring re-render).""" """Set the Widget as 'dirty' (requiring re-render)."""
@@ -580,10 +584,8 @@ class Widget(DOMNode):
# Let's _always_ reserve some space, whether the scrollbar is actually displayed or not: # Let's _always_ reserve some space, whether the scrollbar is actually displayed or not:
show_vertical_scrollbar = True show_vertical_scrollbar = True
( horizontal_scrollbar_thickness = self._get_scrollbar_thickness_horizontal()
vertical_scrollbar_thickness, vertical_scrollbar_thickness = self._get_scrollbar_thickness_vertical()
horizontal_scrollbar_thickness,
) = self._get_scrollbar_thicknesses()
if show_horizontal_scrollbar and show_vertical_scrollbar: if show_horizontal_scrollbar and show_vertical_scrollbar:
(region, _, _, _) = region.split( (region, _, _, _) = region.split(
-vertical_scrollbar_thickness, -horizontal_scrollbar_thickness -vertical_scrollbar_thickness, -horizontal_scrollbar_thickness
@@ -609,13 +611,11 @@ class Widget(DOMNode):
region = size.region region = size.region
show_vertical_scrollbar, show_horizontal_scrollbar = self.scrollbars_enabled show_vertical_scrollbar, show_horizontal_scrollbar = self.scrollbars_enabled
( horizontal_scrollbar_thickness = self._get_scrollbar_thickness_horizontal()
vertical_scrollbar_thickness, vertical_scrollbar_thickness = self._get_scrollbar_thickness_vertical()
horizontal_scrollbar_thickness,
) = self._get_scrollbar_thicknesses()
if show_horizontal_scrollbar and show_vertical_scrollbar: if show_horizontal_scrollbar and show_vertical_scrollbar:
( (
region, _,
vertical_scrollbar_region, vertical_scrollbar_region,
horizontal_scrollbar_region, horizontal_scrollbar_region,
_, _,
@@ -627,30 +627,37 @@ class Widget(DOMNode):
if horizontal_scrollbar_region: if horizontal_scrollbar_region:
yield self.horizontal_scrollbar, horizontal_scrollbar_region yield self.horizontal_scrollbar, horizontal_scrollbar_region
elif show_vertical_scrollbar: elif show_vertical_scrollbar:
region, scrollbar_region = region.split_vertical( _, scrollbar_region = region.split_vertical(-vertical_scrollbar_thickness)
-vertical_scrollbar_thickness
)
if scrollbar_region: if scrollbar_region:
yield self.vertical_scrollbar, scrollbar_region yield self.vertical_scrollbar, scrollbar_region
elif show_horizontal_scrollbar: elif show_horizontal_scrollbar:
region, scrollbar_region = region.split_horizontal( _, scrollbar_region = region.split_horizontal(
-horizontal_scrollbar_thickness -horizontal_scrollbar_thickness
) )
if scrollbar_region: if scrollbar_region:
yield self.horizontal_scrollbar, scrollbar_region yield self.horizontal_scrollbar, scrollbar_region
def _get_scrollbar_thicknesses(self) -> tuple[int, int]: def _get_scrollbar_thickness_horizontal(self) -> int:
""" """Get the thickness of the horizontal scrollbar
Returns: Returns:
tuple[int, int]: first integer is the thickness of the vertical scrollbar, int: the thickness of the horizontal scrollbar (can be zero if CSS rules prevent horizontal scrolling)
2nd integer is the thickness of the horizontal scrollbar
""" """
vertical_scrollbar_size = horizontal_scrollbar_size = 1 scrollbar_size = 1 if self.show_horizontal_scrollbar else 0
if self.styles.scrollbar_size_vertical is not None: if scrollbar_size and self.styles.scrollbar_size_horizontal is not None:
vertical_scrollbar_size = int(self.styles.scrollbar_size_vertical.value) scrollbar_size = int(self.styles.scrollbar_size_horizontal.value)
if self.styles.scrollbar_size_horizontal is not None: return scrollbar_size
horizontal_scrollbar_size = int(self.styles.scrollbar_size_horizontal.value)
return vertical_scrollbar_size, horizontal_scrollbar_size def _get_scrollbar_thickness_vertical(self) -> int:
"""Get the thickness of the vertical scrollbar
Returns:
int: the thickness of the vertical scrollbar (can be zero if CSS rules prevent vertical scrolling)
"""
scrollbar_size = 1 if self.show_vertical_scrollbar else 0
if scrollbar_size and self.styles.scrollbar_size_vertical is not None:
scrollbar_size = int(self.styles.scrollbar_size_vertical.value)
return scrollbar_size
def get_pseudo_classes(self) -> Iterable[str]: def get_pseudo_classes(self) -> Iterable[str]:
"""Pseudo classes for a widget""" """Pseudo classes for a widget"""