Skip to content

Commit ad67926

Browse files
committed
better zooming and name in title
1 parent 2baf870 commit ad67926

2 files changed

Lines changed: 37 additions & 15 deletions

File tree

scripts/classes/editor/_editor.lua

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,17 @@ end
110110
function Editor:update_title()
111111
local title = self.base_title or self.title
112112
if self.dmi then
113-
title = string.format("%s (%dx%d)", title, self.dmi.width, self.dmi.height)
113+
local name = self.dmi.name
114+
if #name > 19 then name = name:sub(1, 16) .. "..." end
115+
local longest = math.max(self.dmi.width, self.dmi.height)
116+
local pw, ph = self:preview_dimensions()
117+
local visual = math.max(pw, ph)
118+
local ratio = visual / longest
119+
if ratio ~= 1 then
120+
title = string.format("%s (%dx%d) - %.2gx", name, self.dmi.width, self.dmi.height, ratio)
121+
else
122+
title = string.format("%s (%dx%d)", name, self.dmi.width, self.dmi.height)
123+
end
114124
end
115125

116126
self.title = title

scripts/classes/editor/rendering.lua

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ local BOX_BORDER = 4
44
local BOX_PADDING = 5
55

66
function Editor:max_preview_size()
7-
local preview_size = Preferences.getPreviewSize and Preferences.getPreviewSize() or 128
7+
local preview_size = self.zoom_size or (Preferences.getPreviewSize and Preferences.getPreviewSize()) or 128
88
return math.max(1, preview_size)
99
end
1010

@@ -15,10 +15,10 @@ function Editor:preview_dimensions()
1515

1616
local max_preview_size = self:max_preview_size()
1717
local longest = math.max(self.dmi.width, self.dmi.height)
18-
if longest <= max_preview_size then
18+
-- Only scale up beyond native size if the user explicitly zoomed
19+
if not self.zoom_size and longest <= max_preview_size then
1920
return self.dmi.width, self.dmi.height
2021
end
21-
2222
local scale = max_preview_size / longest
2323
return math.max(1, math.floor(self.dmi.width * scale + 0.5)), math.max(1, math.floor(self.dmi.height * scale + 0.5))
2424
end
@@ -364,7 +364,15 @@ end
364364
--- @param ev MouseEvent The mouse event object.
365365
function Editor:onmousedown(ev)
366366
if self.closed then return end
367-
if ev.button == MouseButton.LEFT then
367+
if ev.button == MouseButton.MIDDLE then
368+
-- Middle click: reset zoom to 1x (native size)
369+
if self.zoom_size then
370+
self.zoom_size = nil
371+
self.scroll = 0
372+
self:repaint_states()
373+
end
374+
return
375+
elseif ev.button == MouseButton.LEFT then
368376
-- Don't set this until after selection behaivor is handled
369377
self.focused_widget = nil
370378

@@ -631,19 +639,23 @@ end
631639
function Editor:onwheel(ev)
632640
if self.closed or not self.dmi then return end
633641

634-
-- Ctrl+wheel: zoom preview size
642+
-- Ctrl+wheel: zoom preview size (per-editor)
635643
if ev.ctrlKey then
636-
local current = Preferences.getPreviewSize()
637-
local step = ev.deltaY > 0 and -16 or 16
638-
local newSize = math.max(16, math.min(512, current + step))
639-
-- Check if the visual preview actually changes at this size
640-
local longest = math.max(self.dmi.width, self.dmi.height)
641-
if step > 0 and current >= longest then
642-
return -- Already showing at native size, no point zooming further
644+
-- On first zoom, seed from current visual size
645+
if not self.zoom_size then
646+
local pw, ph = self:preview_dimensions()
647+
self.zoom_size = math.max(pw, ph)
643648
end
644-
newSize = math.min(newSize, math.max(longest, 16))
649+
local current = self.zoom_size
650+
local step
651+
if current < 64 then step = 8
652+
elseif current < 128 then step = 16
653+
elseif current < 256 then step = 32
654+
else step = 64 end
655+
local newSize = current + (ev.deltaY > 0 and -step or step)
656+
newSize = math.max(8, math.min(512, newSize))
645657
if newSize ~= current then
646-
Preferences.plugin.preferences.preview_size = newSize
658+
self.zoom_size = newSize
647659
self.scroll = 0
648660
self:repaint_states()
649661
end

0 commit comments

Comments
 (0)