Skip to content

Commit

Permalink
Improve zooming UX
Browse files Browse the repository at this point in the history
  • Loading branch information
kra-mo committed Dec 21, 2023
1 parent 3b28e70 commit a26755a
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 25 deletions.
2 changes: 1 addition & 1 deletion hyperplane/assets/folder-closed.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion hyperplane/assets/folder-open.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 6 additions & 5 deletions hyperplane/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,9 @@ def __zoom(self, _obj: Any, zoom_level: int) -> None:

match zoom_level:
case 1:
self.thumbnail.set_size_request(96, 80)
# This is not the exact aspect ratio, but it is close enough.
# It's good for keeping the folder textures sharp
self.thumbnail.set_size_request(96, 74)
case 2:
self.thumbnail.set_size_request(96, 96)
case _:
Expand Down Expand Up @@ -373,12 +375,11 @@ def __zoom(self, _obj: Any, zoom_level: int) -> None:
self.dir_thumbnail_2.set_size_request(56, 56)
self.dir_thumbnail_3.set_size_request(56, 56)

# Pixel size is set instead of icon size because otherwise GTK gets confused
# and it can lead to graphical glitches after zooming
if zoom_level < 2:
self.icon.set_pixel_size(20)
self.icon.set_pixel_size(16)
else:
# Pixel size is set instead of GTK_ICON_SIZE_LARGE
# because otherwise GTK gets confused even if pixel-size is reset to -1
# and it can lead to graphical glitches after zooming
self.icon.set_pixel_size(32)

def __select_self(self) -> None:
Expand Down
23 changes: 23 additions & 0 deletions hyperplane/items_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,17 @@ def __init__(
self.create_action("trash-delete", self.__trash_delete, ("Delete",))
self.create_action("trash-restore", self.__trash_restore)

# Set up zoom scrolling

self.scroll = Gtk.EventControllerScroll.new(
(
Gtk.EventControllerScrollFlags.VERTICAL
| Gtk.EventControllerScrollFlags.DISCRETE
),
)
self.scroll.connect("scroll", self.__scroll)
self.scrolled_window.add_controller(self.scroll)

def reload(self) -> None:
"""Refresh the view."""
if isinstance(self.dir_list, Gtk.DirectoryList):
Expand Down Expand Up @@ -747,3 +758,15 @@ def __trash_restore(self, *_args: Any) -> None:

for gfile in gfiles:
restore(gfile)

def __scroll(
self, _scroll: Gtk.EventControllerScroll, _dx: float, dy: float
) -> None:
if self.scroll.get_current_event_state() != Gdk.ModifierType.CONTROL_MASK:
return

if dy < 0:
self.get_root().zoom_in()
return

self.get_root().zoom_out()
2 changes: 1 addition & 1 deletion hyperplane/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def __init__(self, gfile: Gio.File, **kwargs) -> None:
icon_group.add(
Adw.Clamp(
child=Adw.Clamp(child=picture, maximum_size=150),
maximum_size=100,
maximum_size=120,
orientation=Gtk.Orientation.VERTICAL,
)
)
Expand Down
40 changes: 23 additions & 17 deletions hyperplane/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ def __init__(self, **kwargs: Any) -> None:

self.create_action(
"zoom-in",
self.__zoom_in,
self.zoom_in,
("<primary>plus", "<Primary>KP_Add", "<primary>equal"),
)
self.create_action(
"zoom-out",
self.__zoom_out,
self.zoom_out,
("<primary>minus", "<Primary>KP_Subtract", "<Primary>underscore"),
)
self.create_action(
Expand Down Expand Up @@ -177,6 +177,21 @@ def __init__(self, **kwargs: Any) -> None:
self.rename_entry.connect("entry-activated", self.__do_rename)
self.rename_button.connect("clicked", self.__do_rename)

# Set up search

self.searched_page = self.get_visible_page()
self.search_entry.set_key_capture_widget(self)

# Build sidebar

self.sidebar_items = set()
self.__update_tags()

self.__trash_changed()
shared.trash_list.connect("notify::n-items", self.__trash_changed)

# Set up sidebar actions

sidebar_items = {
self.sidebar_recent: Gio.File.new_for_uri("recent://"),
self.sidebar_home: Gio.File.new_for_path(str(shared.home)),
Expand All @@ -197,19 +212,6 @@ def __init__(self, **kwargs: Any) -> None:

self.__set_actions()

# Set up search

self.searched_page = self.get_visible_page()
self.search_entry.set_key_capture_widget(self)

# Build sidebar

self.sidebar_items = set()
self.__update_tags()

self.__trash_changed()
shared.trash_list.connect("notify::n-items", self.__trash_changed)

def send_toast(self, message: str, undo: bool = False) -> None:
"""Displays a toast with the given message and optionally an undo button in the window."""
toast = Adw.Toast.new(message)
Expand Down Expand Up @@ -598,14 +600,18 @@ def __forward(self, *_args: Any) -> None:

nav_bin.view.push(nav_bin.next_pages[-1])

def __zoom_in(self, *_args: Any) -> None:
def zoom_in(self, *_args: Any) -> None:
"""Increases the zoom level of all views."""

if (zoom_level := shared.state_schema.get_uint("zoom-level")) > 4:
return

shared.state_schema.set_uint("zoom-level", zoom_level + 1)
self.update_zoom()

def __zoom_out(self, *_args: Any) -> None:
def zoom_out(self, *_args: Any) -> None:
"""Decreases the zoom level of all views."""

if (zoom_level := shared.state_schema.get_uint("zoom-level")) < 2:
return

Expand Down

0 comments on commit a26755a

Please sign in to comment.