From 98c4b99d7334bb2b463e6aeb28e887d132719121 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 13 Nov 2021 15:24:45 +0530 Subject: [PATCH] DRYer --- src/calibre/gui2/flow_toolbar.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/calibre/gui2/flow_toolbar.py b/src/calibre/gui2/flow_toolbar.py index 6fccd7d41b96..09754e8ba67f 100644 --- a/src/calibre/gui2/flow_toolbar.py +++ b/src/calibre/gui2/flow_toolbar.py @@ -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 @@ -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: @@ -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