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())
"""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
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)
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()):
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."""