rewrite overlay: spacer-based titlebar layout for close button, 200ms debounce + 100ms skip for aspect ratio enforcement, event-based ratio sync
This commit is contained in:
+4
-4
@@ -458,6 +458,7 @@
|
||||
<button class="chip" onclick={() => {
|
||||
aspectLock = w / h
|
||||
api.setOverlayAspect(aspectLock)
|
||||
emit("overlay-set-ratio", { ratio: aspectLock })
|
||||
api.setOverlaySize(w, h)
|
||||
}}>{label}</button>
|
||||
{/each}
|
||||
@@ -465,6 +466,7 @@
|
||||
<button class="chip unlock" onclick={() => {
|
||||
aspectLock = null
|
||||
api.setOverlayAspect(null)
|
||||
emit("overlay-set-ratio", { ratio: null })
|
||||
}}>Unlock</button>
|
||||
{/if}
|
||||
</div>
|
||||
@@ -532,11 +534,9 @@
|
||||
</div>
|
||||
|
||||
<!-- Preview -->
|
||||
{@const displayPath = dragging && trimPreviewPath ? trimPreviewPath : previewPath}
|
||||
{@const displayBust = dragging && trimPreviewPath ? trimPreviewBust : previewCacheBust}
|
||||
{#if displayPath}
|
||||
{#if (dragging && trimPreviewPath ? trimPreviewPath : previewPath)}
|
||||
<div class="preview-box">
|
||||
<img src={convertFileSrc(displayPath) + "?t=" + displayBust} alt="preview frame" class="preview-img"/>
|
||||
<img src={convertFileSrc(dragging && trimPreviewPath ? trimPreviewPath : previewPath) + "?t=" + (dragging && trimPreviewPath ? trimPreviewBust : previewCacheBust)} alt="preview frame" class="preview-img"/>
|
||||
{#if previewLoading && !dragging}<div class="preview-loading">rendering</div>{/if}
|
||||
{#if dragging}<div class="preview-loading">original</div>{/if}
|
||||
</div>
|
||||
|
||||
+39
-36
@@ -13,10 +13,9 @@
|
||||
let fps: number = $state(30)
|
||||
let elapsed: number = $state(0)
|
||||
let timer: number | null = null
|
||||
let lockedRatio: number | null = null
|
||||
let resizeDebounce: number | null = null
|
||||
let enforcing = false
|
||||
let resizing = false
|
||||
let lockedRatio: number | null = $state(null)
|
||||
let enforceTimer: number | null = null
|
||||
let skipEnforce = false
|
||||
|
||||
onMount(() => {
|
||||
const updateSize = async () => {
|
||||
@@ -25,28 +24,31 @@
|
||||
width = Math.round(sz.width / sf)
|
||||
height = Math.round(sz.height / sf)
|
||||
}
|
||||
// Query aspect ratio from Rust on startup
|
||||
const syncRatio = async () => {
|
||||
try { lockedRatio = await invoke<number | null>("get_overlay_aspect") } catch {}
|
||||
}
|
||||
|
||||
updateSize()
|
||||
syncRatio()
|
||||
// Get initial ratio
|
||||
invoke<number | null>("get_overlay_aspect").then(r => { lockedRatio = r }).catch(() => {})
|
||||
|
||||
let cleanup: (() => void)[] = []
|
||||
|
||||
// Listen for ratio changes from Main window via event
|
||||
listen<{ ratio: number | null }>("overlay-set-ratio", (e) => {
|
||||
lockedRatio = e.payload.ratio
|
||||
}).then(fn => cleanup.push(fn))
|
||||
|
||||
win.onResized(async () => {
|
||||
if (enforcing) return
|
||||
if (skipEnforce) return
|
||||
await updateSize()
|
||||
// Re-sync ratio from Rust in case it changed (e.g. preset clicked)
|
||||
await syncRatio()
|
||||
if (lockedRatio === null) return
|
||||
// Small debounce to break the SetWindowPos → onResized loop
|
||||
if (resizeDebounce !== null) clearTimeout(resizeDebounce)
|
||||
resizeDebounce = window.setTimeout(async () => {
|
||||
enforcing = true
|
||||
// Debounce: only enforce after resize settles (user released mouse)
|
||||
if (enforceTimer !== null) clearTimeout(enforceTimer)
|
||||
enforceTimer = window.setTimeout(async () => {
|
||||
skipEnforce = true
|
||||
try { await invoke("enforce_overlay_aspect") } catch {}
|
||||
await updateSize()
|
||||
enforcing = false
|
||||
}, 30)
|
||||
// Skip events from our own enforcement for a bit
|
||||
setTimeout(() => { skipEnforce = false }, 100)
|
||||
}, 200)
|
||||
}).then(fn => cleanup.push(fn))
|
||||
|
||||
listen<{ phase: "idle"|"recording"|"paused"; fps: number }>(
|
||||
@@ -74,7 +76,7 @@
|
||||
|
||||
return () => {
|
||||
stopTimer()
|
||||
if (resizeDebounce !== null) clearTimeout(resizeDebounce)
|
||||
if (enforceTimer !== null) clearTimeout(enforceTimer)
|
||||
cleanup.forEach(fn => fn())
|
||||
}
|
||||
})
|
||||
@@ -104,6 +106,7 @@
|
||||
<div class="titlebar" onmousedown={drag} role="presentation">
|
||||
<span class="grip" aria-hidden="true">::</span>
|
||||
<span class="dims" aria-label="dimensions">{width} x {height}</span>
|
||||
<div class="spacer"></div>
|
||||
<button class="pick-btn" onclick={openPicker} title="snap to window" aria-label="snap capture frame to a window">
|
||||
<svg width="10" height="10" viewBox="0 0 12 12" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round">
|
||||
<rect x="1" y="1" width="4" height="4" rx="0.5"/>
|
||||
@@ -152,8 +155,8 @@
|
||||
background: rgba(9, 9, 11, 0.92);
|
||||
backdrop-filter: blur(8px);
|
||||
color: rgba(228, 228, 231, 0.7);
|
||||
display: flex; align-items: center; gap: 8px;
|
||||
padding: 0 8px;
|
||||
display: flex; align-items: center; gap: 6px;
|
||||
padding: 0 6px;
|
||||
font: 10px/1 var(--mono, 'JetBrains Mono', monospace);
|
||||
cursor: grab;
|
||||
flex-shrink: 0;
|
||||
@@ -169,37 +172,36 @@
|
||||
font-size: 10px;
|
||||
color: rgba(228, 228, 231, 0.4);
|
||||
letter-spacing: 0.02em;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.spacer { flex: 1; min-width: 0; }
|
||||
|
||||
.pick-btn {
|
||||
.pick-btn, .close-btn {
|
||||
display: grid; place-items: center;
|
||||
width: 20px; height: 20px;
|
||||
background: rgba(20, 184, 166, 0.1);
|
||||
border: 1px solid rgba(20, 184, 166, 0.25);
|
||||
color: rgba(20, 184, 166, 0.7);
|
||||
border-radius: var(--r-sm);
|
||||
width: 18px; height: 18px;
|
||||
border-radius: 3px;
|
||||
cursor: pointer;
|
||||
flex-shrink: 0;
|
||||
transition: all 80ms;
|
||||
border: 1px solid transparent;
|
||||
padding: 0;
|
||||
}
|
||||
.pick-btn {
|
||||
background: rgba(20, 184, 166, 0.1);
|
||||
border-color: rgba(20, 184, 166, 0.25);
|
||||
color: rgba(20, 184, 166, 0.7);
|
||||
}
|
||||
.pick-btn:hover { background: rgba(20, 184, 166, 0.18); border-color: rgba(20, 184, 166, 0.5); color: #14B8A6; }
|
||||
|
||||
.close-btn {
|
||||
display: grid; place-items: center;
|
||||
width: 20px; height: 20px;
|
||||
background: rgba(239, 68, 68, 0.1);
|
||||
border: 1px solid rgba(239, 68, 68, 0.25);
|
||||
border-color: rgba(239, 68, 68, 0.25);
|
||||
color: rgba(239, 68, 68, 0.7);
|
||||
border-radius: var(--r-sm);
|
||||
cursor: pointer;
|
||||
flex-shrink: 0;
|
||||
transition: all 80ms;
|
||||
margin-left: auto;
|
||||
}
|
||||
.close-btn:hover { background: rgba(239, 68, 68, 0.18); border-color: rgba(239, 68, 68, 0.5); color: #EF4444; }
|
||||
|
||||
.status {
|
||||
margin-left: auto;
|
||||
margin-left: 4px;
|
||||
font-family: var(--mono, 'JetBrains Mono', monospace);
|
||||
font-size: 10px; font-weight: 500;
|
||||
color: rgba(228, 228, 231, 0.5);
|
||||
@@ -207,6 +209,7 @@
|
||||
background: rgba(255,255,255,0.04);
|
||||
padding: 1px 6px;
|
||||
border-radius: 2px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.status.recording {
|
||||
background: rgba(34, 197, 94, 0.15);
|
||||
|
||||
Reference in New Issue
Block a user