skin studio fix

This commit is contained in:
bryanthaboi
2026-08-21 14:38:54 -04:00
parent 0e407dca7a
commit 06e06e305b
5 changed files with 433 additions and 58 deletions
+37 -3
View File
@@ -23,6 +23,7 @@ local function session()
Studio.pageIndex = 1
Studio.selected = nil
Studio.canvasIndex = 1
Studio.viewZoom = 1
Studio.aspectLock = true
Studio.drag = nil
Studio.dirty = false
@@ -73,11 +74,16 @@ eq(Studio.selected, nil, "and clears the selection")
local ids = {}
for _, c in ipairs(Studio.CANVASES) do
check(c.w > 0 and c.h > 0, c.id .. " has real pixel dimensions")
if c.live then
check(c.id == "this_device", "the live preset is this screen")
else
check(c.w > 0 and c.h > 0, c.id .. " has real pixel dimensions")
end
check(not ids[c.id], c.id .. " appears once")
ids[c.id] = true
end
check(ids.phone_portrait, "a phone portrait preset exists")
check(ids.this_device, "a this-screen live preset exists")
check(ids.desktop_1080, "a desktop preset exists")
check(ids.ultrawide, "an ultrawide preset exists")
check(ids.sgb_border, "a Super Game Boy border preset exists")
@@ -105,9 +111,8 @@ check(Studio.page().viewport ~= nil, "the SGB cutout cannot be toggled off")
Studio.setCanvas(#Studio.CANVASES + 1)
eq(Studio.canvasIndex, 1, "canvas selection wraps")
-- ------------------------------------------------------------ canvas fit
Studio.setCanvas(1)
Studio.viewZoom = 1
local cx, cy, cw, ch = Studio.canvasRect(0, 0, 800, 600)
near(cw / ch, Studio.canvas().w / Studio.canvas().h, 1e-6,
"the mock device keeps its aspect")
@@ -115,6 +120,35 @@ check(cw <= 800 + 1e-6 and ch <= 600 + 1e-6, "and fits inside the workspace")
near(cx + cw / 2, 400, 1e-6, "centred horizontally")
near(cy + ch / 2, 300, 1e-6, "centred vertically")
eq(Studio.zoomOut(), 0.75, "zoom out steps to 75%")
local zx, zy, zw, zh = Studio.canvasRect(0, 0, 800, 600)
near(zw, cw * 0.75, 1e-6, "zoom out shrinks the mock device")
near(zh, ch * 0.75, 1e-6, "on both axes")
near(zx + zw / 2, 400, 1e-6, "and stays centred")
near(zw / zh, cw / ch, 1e-6, "keeping the same aspect")
check(zw < cw, "so there is margin around the device for a larger screen hole")
eq(Studio.zoomIn(), 1, "zoom in restores fit")
eq(Studio.zoomOut(), 0.75)
eq(Studio.zoomOut(), 0.5)
eq(Studio.zoomOut(), 0.35)
eq(Studio.zoomOut(), 0.35, "zoom out stops at the smallest level")
eq(Studio.zoomFit(), 1, "fit snaps back to contain")
local oldDims = love.graphics.getDimensions
love.graphics.getDimensions = function() return 1170, 2532 end
session()
local live = Studio.detectDeviceCanvas()
eq(live.id, "this_device", "detect this screen selects the live canvas")
eq(live.w, 1170, "at the window width")
eq(live.h, 2532, "and the window height")
eq(Studio.canvas().w / Studio.canvas().h, 1170 / 2532,
"so the mock device is this screen's form factor")
Studio.matchOrient = true
Studio.syncCanvasToPage()
eq(Studio.canvas().id, "this_device",
"Match canvas leaves the live screen selected")
love.graphics.getDimensions = oldDims
-- ----------------------------------------------------------- touch bridge
session()
+43 -1
View File
@@ -18,6 +18,7 @@ local function session()
Studio.pageIndex = 1
Studio.selected = nil
Studio.canvasIndex = 1
Studio.viewZoom = 1
Studio.aspectLock = true
Studio.drag = nil
Studio.dirty = false
@@ -325,11 +326,52 @@ love.graphics.getDimensions = love.graphics.getDimensions
or function() return 1280, 720 end
session()
Studio.addControl()
for _, kind in ipairs({ "bind", "image", "open", "page", "export" }) do
for _, kind in ipairs({ "bind", "image", "open", "page", "export", "screen" }) do
Studio.openModal(kind)
check(pcall(Studio.draw), "the studio draws with the " .. kind .. " modal up")
end
Studio.closeModal()
check(Studio.openScreenMenu(), "Screen opens the canvas/screen modal")
eq(Studio.modal.kind, "screen", "as the screen modal")
Studio.closeModal()
-- chrome stays inside the platform safe area (notch / home indicator)
local Kit = require("src.ui.kit.Kit")
local oldDims = love.graphics.getDimensions
local oldSafe = love.window.getSafeArea
love.graphics.getDimensions = function() return 400, 800 end
love.window.getSafeArea = function() return 12, 48, 376, 704 end
session()
Studio.mode = "library"
Studio.available = {}
Kit.audit = {}
check(pcall(Studio.draw), "My Skins draws inside an inset safe area")
local function insideSafe(rects, ox, oy, sw, sh, where)
for _, r in ipairs(rects or {}) do
check(r.x >= ox - 0.5,
where .. " control '" .. r.label .. "' is right of the left inset")
check(r.y >= oy - 0.5,
where .. " control '" .. r.label .. "' is below the notch")
check(r.x + r.w <= ox + sw + 0.5,
where .. " control '" .. r.label .. "' stays left of the right inset")
check(r.y + r.h <= oy + sh + 0.5,
where .. " control '" .. r.label .. "' stays above the home indicator")
end
end
insideSafe(Kit.audit, 12, 48, 376, 704, "library")
Studio.mode = "editor"
Studio.addControl()
Kit.audit = {}
check(pcall(Studio.draw), "the editor draws inside an inset safe area")
insideSafe(Kit.audit, 12, 48, 376, 704, "editor")
check(Studio.lastCanvas ~= nil, "the editor still has a mock device")
check(Studio.lastCanvas.y >= 48 - 0.5, "the mock device is below the notch")
check(Studio.lastCanvas.y + Studio.lastCanvas.h <= 48 + 704 + 0.5,
"and above the home indicator")
Kit.audit = nil
love.graphics.getDimensions = oldDims
love.window.getSafeArea = oldSafe
Studio.closeModal()
Studio.ask("sure?", function() end)
check(pcall(Studio.draw), "and with the confirm prompt up")
Studio.confirmNo()