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