Skip to content

Commit

Permalink
Fix for 0 height/width.
Browse files Browse the repository at this point in the history
  • Loading branch information
salt-die committed Feb 26, 2024
1 parent dbbcd16 commit 541288b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/batgrl/gadgets/color_picker.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ def update_hue(self, hue: AColor):
self.hue = hue

h, w = self._size
if w == 0:
return
left_side = gradient(AWHITE, ABLACK, 2 * h)
right_side = gradient(hue, ABLACK, 2 * h)

Expand Down Expand Up @@ -102,8 +104,8 @@ def grab_update(self, mouse_event):
y, x = self._shade_indicator.pos = self.to_local(mouse_event.position)
h, w = self.size
self._shade_hint = (
0 if h == 1 else y / (h - 1),
0 if w == 1 else x / (w - 1),
0 if h <= 1 else y / (h - 1),
0 if w <= 1 else x / (w - 1),
)
self.update_swatch_label()

Expand Down Expand Up @@ -149,7 +151,7 @@ def grab(self, mouse_event):
def grab_update(self, mouse_event):
if self.collides_point(mouse_event.position):
x = self._hue_indicator.x = self.to_local(mouse_event.position).x
self._hue_hint = 0 if self.width == 1 else x / (self.width - 1)
self._hue_hint = 0 if self.width <= 1 else x / (self.width - 1)
self.update_hue()


Expand Down
4 changes: 2 additions & 2 deletions src/batgrl/gadgets/scroll_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,12 +548,12 @@ def horizontal_proportion(self, horizontal_proportion: float):
@property
def port_height(self) -> int:
"""Height of view."""
return self.height - self.show_horizontal_bar
return max(0, self.height - self.show_horizontal_bar)

@property
def port_width(self) -> int:
"""Width of view."""
return self.width - self.show_vertical_bar * 2
return max(0, self.width - self.show_vertical_bar * 2)

@property
def total_vertical_distance(self) -> int:
Expand Down

0 comments on commit 541288b

Please sign in to comment.