From: Christian Heller Date: Mon, 28 Oct 2024 12:02:57 +0000 (+0100) Subject: Browser: Minor code restructuring. X-Git-Url: https://plomlompom.com/repos/te"st.html?a=commitdiff_plain;h=5f8837ec0c2289c29dc01c6a5bc3e592c5c7028c;p=stable_plom Browser: Minor code restructuring. --- diff --git a/browser.py b/browser.py index bd60c4e..6de2728 100755 --- a/browser.py +++ b/browser.py @@ -538,7 +538,7 @@ class Gallery: scroller = Gtk.ScrolledWindow(propagate_natural_height=True) self._col_headers_frame = Gtk.Fixed() self._col_headers_grid = None - self._vlabel_height_ref = [0] + self._slot_size_ref = [0] self.frame = Gtk.Box(orientation=OR_V) self.frame.append(self._col_headers_frame) self.frame.append(scroller) @@ -810,7 +810,7 @@ class Gallery: if 1 == len(remaining): for i, attr in enumerate(ancestors): vlabel = VerticalLabel(f'{attr[0]}: {attr[1]}', - self._vlabel_height_ref) + self._slot_size_ref) self._grid.attach(vlabel, i, i_row_ref[0], 1, 1) row = [None] * len(attr_values) for item in items_of_parent: @@ -943,16 +943,17 @@ class Gallery: vp_top = vp_scroll.get_value() vp_bottom = vp_top + vp_height side_offset, i_vlabels = 0, 0 - while True: - widget = self._grid.get_child_at(i_vlabels, 0) - if isinstance(widget, VerticalLabel): - side_offset += widget.width - else: - break - i_vlabels += 1 + if self._by_1st: + while True: + widget = self._grid.get_child_at(i_vlabels, 0) + if isinstance(widget, VerticalLabel): + side_offset += widget.width + else: + break + i_vlabels += 1 max_slot_width = (vp_width - side_offset) // self._per_row slot_size = min(vp_height, max_slot_width) - self._vlabel_height_ref[0] = slot_size + self._slot_size_ref[0] = slot_size if self._by_1st: i_widgets = 0 while True: @@ -968,16 +969,17 @@ class Gallery: for idx, slot in enumerate(self.slots): slot.ensure_slot_size(slot_size_sans_margin, self._slot_margin) vp_scroll.set_upper(slot_size * ceil(len(self.slots) / self._per_row)) - if self._scroll_to_focus(slot_size, vp_scroll, vp_top, vp_bottom): + if self._scroll_to_focus(vp_scroll, vp_top, vp_bottom): return for idx, slot in enumerate(self.slots): - in_vp, _, _ = self._position_to_viewport( - idx, slot_size, vp_top, vp_bottom, True) + in_vp, _, _ = self._position_to_viewport(idx, + vp_top, vp_bottom, True) slot.update_widget(in_vp) self._start_redraw_wait = datetime.now() def _position_to_viewport( - self, idx, slot_size, vp_top, vp_bottom, in_vp_greedy=False): + self, idx, vp_top, vp_bottom, in_vp_greedy=False): + slot_size = self._slot_size_ref[0] slot_top = (idx // self._per_row) * slot_size slot_bottom = slot_top + slot_size if in_vp_greedy: @@ -986,7 +988,8 @@ class Gallery: in_vp = (slot_top >= vp_top and slot_bottom <= vp_bottom) return in_vp, slot_top, slot_bottom - def _scroll_to_focus(self, slot_size, vp_scroll, vp_top, vp_bottom): + def _scroll_to_focus(self, vp_scroll, vp_top, vp_bottom): + slot_size = self._slot_size_ref[0] scroll_to_focus = self._shall_scroll_to_focus self._shall_redraw, self._shall_scroll_to_focus = False, False if scroll_to_focus: