Skip to content

Commit

Permalink
DRYer
Browse files Browse the repository at this point in the history
  • Loading branch information
kovidgoyal committed Nov 13, 2021
1 parent 6ca3986 commit 98c4b99
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/calibre/gui2/flow_toolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ def layout_spacing(wid, horizontal=True):
for item in self.items:
if isinstance(item, Separator):
item.setGeometry(0, 0, 0, 0)

def commit_line():
while current_line and isinstance(current_line[-1], Separator):
current_line.pop()
if current_line:
lines.append((line_height, current_line))

for wid in self.items:
if not wid.isVisible() or (not current_line and isinstance(wid, Separator)):
continue
Expand All @@ -157,9 +164,7 @@ def layout_spacing(wid, horizontal=True):
x = rect.x()
y = y + line_height + vs
next_x = x + isz.width() + hs
while current_line and isinstance(current_line[-1], Separator):
current_line.pop()
lines.append((line_height, current_line))
commit_line()
current_line = []
line_height = 0
if apply_geometry:
Expand All @@ -168,7 +173,7 @@ def layout_spacing(wid, horizontal=True):
line_height = max(line_height, isz.height())
current_line.append(wid)

lines.append((line_height, current_line))
commit_line()

if apply_geometry:
self.applied_geometry = rect
Expand Down

0 comments on commit 98c4b99

Please sign in to comment.