From: Christian Heller Date: Mon, 9 Sep 2024 11:53:00 +0000 (+0200) Subject: Fixe sidebar toggling not properly re-sizing slot sizes. X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/process?a=commitdiff_plain;h=df4ca1cb2afef4b82a80270bd62e72b0f7d021fa;p=stable_plom Fixe sidebar toggling not properly re-sizing slot sizes. --- diff --git a/browser.py b/browser.py index a6f864b..8835353 100755 --- a/browser.py +++ b/browser.py @@ -193,6 +193,7 @@ class MainWindow(Gtk.Window): self.img_dir_absolute = abspath(IMG_DIR) self.block_once_hit_file_selection = False self.block_file_selection_updates = False + self.force_width = None viewer = Gtk.Box(orientation=OR_V) viewer.append(init_navbar()) @@ -284,10 +285,11 @@ class MainWindow(Gtk.Window): """Load/unload gallery's file images based on viewport visibility.""" self.gallery.set_min_children_per_line(self.per_row) self.gallery.set_max_children_per_line(self.per_row) - viewport = self.gallery.get_parent().get_parent() - vp_height = viewport.get_height() - vp_width = viewport.get_width() - vp_scroll = viewport.get_vadjustment() + vp = self.gallery.get_parent().get_parent() + vp_height = vp.get_height() + # because sometimes vp.width updates too late for our measurements + vp_width = self.force_width if self.force_width else vp.get_width() + vp_scroll = vp.get_vadjustment() vp_top = vp_scroll.get_value() vp_bottom = vp_top + vp_height margin = 6 @@ -301,8 +303,8 @@ class MainWindow(Gtk.Window): continue slot_top = (i // self.per_row) * (slot_size + margin) slot_bottom = slot_top + slot_size - in_viewport = (slot_bottom >= vp_top and slot_top <= vp_bottom) - if in_viewport: + in_vp = (slot_bottom >= vp_top and slot_top <= vp_bottom) + if in_vp: if not isinstance(slot.content, Gtk.Image): slot.remove(slot.content) slot.content = Gtk.Image.new_from_file(slot.item.full_path) @@ -312,6 +314,7 @@ class MainWindow(Gtk.Window): slot.content = Gtk.Label(label='?') slot.append(slot.content) slot.content.set_size_request(slot_size, slot_size) + # because for some reason vp.scroll_to doesn't do what we want if refocus: for c in self.gallery.get_selected_children(): for i in range(self.gallery_store_filtered.get_n_items()): @@ -443,7 +446,10 @@ class MainWindow(Gtk.Window): def toggle_side_box(self): """Toggle window sidebox visible/invisible.""" self.side_box.props.visible = not self.side_box.get_visible() - self.update_gallery_view() + side_box_width = self.side_box.measure(OR_H, -1).natural + # because relevant viewport measurement happens too late for our needs + self.force_width = self.get_width() - side_box_width + self.update_gallery_view(refocus=True) def reset_include_dirs(self, button): """By button's .active, in-/exclude directories from gallery view."""