From b2d0163728a4da13f420f2a92d43c6a6dd3027c2 Mon Sep 17 00:00:00 2001 From: JayTheBusinessGoose Date: Sun, 17 Dec 2023 23:26:27 -0700 Subject: [PATCH] Try to fix scroll bars not showing up on teeny baby windows. --- .../ui/levels/custom_levels/custom_level_editor.py | 2 ++ src/modlunky2/ui/levels/shared/multi_canvas_container.py | 5 +++++ .../vanilla_levels/multi_room/multi_room_editor_tab.py | 2 ++ .../ui/levels/vanilla_levels/vanilla_level_editor.py | 6 ++---- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/modlunky2/ui/levels/custom_levels/custom_level_editor.py b/src/modlunky2/ui/levels/custom_levels/custom_level_editor.py index fe70a3c9e..39cb0819b 100644 --- a/src/modlunky2/ui/levels/custom_levels/custom_level_editor.py +++ b/src/modlunky2/ui/levels/custom_levels/custom_level_editor.py @@ -555,6 +555,8 @@ def draw_layer(canvas_index, tile_codes): for index, tileset in enumerate(self.tile_codes): draw_layer(CanvasIndex(index, 0), tileset) + self.canvas.update_scroll_region() + # Click event on a canvas for either left or right click to replace the tile at the cursor's position with # the selected tile. def canvas_click(self, canvas_index, row, column, is_primary): diff --git a/src/modlunky2/ui/levels/shared/multi_canvas_container.py b/src/modlunky2/ui/levels/shared/multi_canvas_container.py index f87e12bb8..8e55b9599 100644 --- a/src/modlunky2/ui/levels/shared/multi_canvas_container.py +++ b/src/modlunky2/ui/levels/shared/multi_canvas_container.py @@ -48,6 +48,7 @@ def __init__( scrollable_frame = tk.Frame(scrollable_canvas, bg="#343434") scrollable_frame.grid(row=0, column=0, sticky="nswe") + self.scrollable_frame = scrollable_frame width = scrollable_canvas.winfo_screenwidth() height = scrollable_canvas.winfo_screenheight() @@ -207,6 +208,10 @@ def switch_layer(): ) intro_label.place(relx=0.5, rely=0.5, anchor="center") + def update_scroll_region(self): + self.scrollable_canvas.update_idletasks() + self.scrollable_canvas.config(scrollregion=self.scrollable_frame.bbox("all")) + def _on_mousewheel(self, event, hbar, vbar, canvas): scroll_dir = None if event.num == 5 or event.delta == -120: diff --git a/src/modlunky2/ui/levels/vanilla_levels/multi_room/multi_room_editor_tab.py b/src/modlunky2/ui/levels/vanilla_levels/multi_room/multi_room_editor_tab.py index e963a0068..f1862de83 100644 --- a/src/modlunky2/ui/levels/vanilla_levels/multi_room/multi_room_editor_tab.py +++ b/src/modlunky2/ui/levels/vanilla_levels/multi_room/multi_room_editor_tab.py @@ -919,6 +919,8 @@ def draw_chunk(canvas_index, chunk_start_x, chunk_start_y, tile_codes): room_column_index, ) + self.canvas.update_scroll_region() + def template_item_at(self, map_index, row, col): for room_row_index, room_row in enumerate( self.template_draw_map[map_index].rooms diff --git a/src/modlunky2/ui/levels/vanilla_levels/vanilla_level_editor.py b/src/modlunky2/ui/levels/vanilla_levels/vanilla_level_editor.py index 381a4be37..24cd65466 100644 --- a/src/modlunky2/ui/levels/vanilla_levels/vanilla_level_editor.py +++ b/src/modlunky2/ui/levels/vanilla_levels/vanilla_level_editor.py @@ -681,9 +681,7 @@ def map_layer(layer): comment = str(chunk.comment).lstrip("/ ").strip() - return RoomInstance( - comment, settings, foreground_tiles, background_tiles - ) + return RoomInstance(comment, settings, foreground_tiles, background_tiles) def convert_to_chunk(self, room_instance): bg = [] @@ -1017,7 +1015,7 @@ def room_select(self, _event): # Loads room when click if not parent node. x_coord, y_coord, ) - + self.canvas.update_scroll_region() else: self.canvas.clear() self.canvas.hide_canvas(1, True)