Repository navigation
Layout switcher #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Layout switcher #15
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -16,6 +16,14 @@ const TRACKS = [ | |||||||||||||||||
| { id: "A2", kind: "audio", h: 42, color: "#5a9e3a" }, | ||||||||||||||||||
| { id: "A3", kind: "audio", h: 42, color: "#4a8a2f" }, | ||||||||||||||||||
| ]; | ||||||||||||||||||
| /* Three timeline density presets. L matches the original track heights (with thumbs). | ||||||||||||||||||
| S is compact solid-color rows; M is in between. */ | ||||||||||||||||||
| const TRACK_SIZE_PRESETS = { | ||||||||||||||||||
| s: { thumbs: false, h: { V4: 26, V3: 26, V2: 26, V1: 26, A1: 22, A2: 22, A3: 22 } }, | ||||||||||||||||||
| m: { thumbs: true, h: { V4: 36, V3: 36, V2: 44, V1: 44, A1: 32, A2: 32, A3: 32 } }, | ||||||||||||||||||
| l: { thumbs: true, h: { V4: 44, V3: 44, V2: 58, V1: 58, A1: 42, A2: 42, A3: 42 } }, | ||||||||||||||||||
| }; | ||||||||||||||||||
| const TRACK_SIZE_KEY = "fablecut-track-size"; | ||||||||||||||||||
| const RULER_H = 26; | ||||||||||||||||||
| const SNAP_PX = 8; | ||||||||||||||||||
| const MIN_DUR = 0.05; | ||||||||||||||||||
|
|
@@ -128,6 +136,7 @@ const state = { | |||||||||||||||||
| time: 0, playing: false, pps: 60, snap: true, | ||||||||||||||||||
| selId: null, // primary selection (drives the inspector) | ||||||||||||||||||
| selIds: new Set(), // full multi-selection (includes selId) | ||||||||||||||||||
| trackSize: "l", // s | m | l — timeline track density preset | ||||||||||||||||||
| connected: false, exporting: false, | ||||||||||||||||||
| rendering: false, // fast (server/ffmpeg) export in progress | ||||||||||||||||||
| guides: false, // safe-area overlay on the monitor | ||||||||||||||||||
|
|
@@ -834,7 +843,7 @@ function rebuildClips() { | |||||||||||||||||
| div.style.left = c.start * state.pps + "px"; | ||||||||||||||||||
| div.style.width = Math.max(8, c.duration * state.pps) + "px"; | ||||||||||||||||||
| let inner = ""; | ||||||||||||||||||
| if (c.kind === "video") { | ||||||||||||||||||
| if (c.kind === "video" && trackSizeShowsThumbs()) { | ||||||||||||||||||
| const thumb = runtime.mediaAux.get(c.mediaId)?.thumb; | ||||||||||||||||||
| if (thumb) inner += `<div class="thumbs" style="background-image:url('${thumb}')"></div>`; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
@@ -2751,6 +2760,11 @@ els.btnSnap.addEventListener("click", () => { | |||||||||||||||||
| state.snap = !state.snap; | ||||||||||||||||||
| els.btnSnap.classList.toggle("on", state.snap); | ||||||||||||||||||
| }); | ||||||||||||||||||
| $("btnLayoutReset").addEventListener("click", restoreDefaultLayout); | ||||||||||||||||||
| $("trackSizeGroup").addEventListener("click", (e) => { | ||||||||||||||||||
| const b = e.target.closest("[data-track-size]"); | ||||||||||||||||||
| if (b) setTrackSize(b.dataset.trackSize); | ||||||||||||||||||
| }); | ||||||||||||||||||
| els.binTabs.addEventListener("click", (e) => { | ||||||||||||||||||
| const b = e.target.closest("[data-tab]"); | ||||||||||||||||||
| if (b) setBinTab(b.dataset.tab); | ||||||||||||||||||
|
|
@@ -2822,9 +2836,123 @@ window.addEventListener("keydown", (e) => { | |||||||||||||||||
| else if ((e.ctrlKey || e.metaKey) && (k === "y" || k === "Y")) { e.preventDefault(); redo(); } | ||||||||||||||||||
| }); | ||||||||||||||||||
|
|
||||||||||||||||||
| window.addEventListener("resize", () => { state.dirtyTimeline = true; }); | ||||||||||||||||||
| window.addEventListener("resize", () => { state.dirtyTimeline = true; clampTimelineHeight(); }); | ||||||||||||||||||
|
|
||||||||||||||||||
| /* ── Resizable upper / timeline split ── */ | ||||||||||||||||||
| const TL_H_KEY = "fablecut-timeline-h"; | ||||||||||||||||||
| const TL_H_MIN = 180; | ||||||||||||||||||
| const UPPER_MIN = 140; | ||||||||||||||||||
| function availableTimelineMax() { | ||||||||||||||||||
| const app = $("app").getBoundingClientRect(); | ||||||||||||||||||
| const topbar = document.querySelector(".topbar")?.getBoundingClientRect(); | ||||||||||||||||||
| const topbarH = topbar ? topbar.height : 46; | ||||||||||||||||||
| const split = 6; | ||||||||||||||||||
| const gaps = 18; // three 6px flex gaps between four children | ||||||||||||||||||
| return Math.floor(app.height - topbarH - UPPER_MIN - split - gaps); | ||||||||||||||||||
| } | ||||||||||||||||||
| function setTimelineHeight(px) { | ||||||||||||||||||
| const h = clamp(Math.round(px), TL_H_MIN, Math.max(TL_H_MIN, availableTimelineMax())); | ||||||||||||||||||
| $("app").style.setProperty("--timeline-h", h + "px"); | ||||||||||||||||||
| state.dirtyTimeline = true; | ||||||||||||||||||
| return h; | ||||||||||||||||||
| } | ||||||||||||||||||
| /* Tall enough for the toolbar + ruler + every track row (no vertical overflow). */ | ||||||||||||||||||
| function defaultTimelineHeight() { | ||||||||||||||||||
| const tracksH = TRACKS.reduce((s, t) => s + t.h, 0); | ||||||||||||||||||
| const toolbar = document.querySelector(".timeline-toolbar"); | ||||||||||||||||||
| const toolbarH = toolbar ? toolbar.getBoundingClientRect().height : 40; | ||||||||||||||||||
| return tracksH + RULER_H + toolbarH + 8; | ||||||||||||||||||
| } | ||||||||||||||||||
| function resetTimelineHeight() { | ||||||||||||||||||
| const h = setTimelineHeight(defaultTimelineHeight()); | ||||||||||||||||||
| localStorage.removeItem(TL_H_KEY); | ||||||||||||||||||
| state.dirtyTimeline = true; | ||||||||||||||||||
| return h; | ||||||||||||||||||
| } | ||||||||||||||||||
| function trackSizeShowsThumbs() { | ||||||||||||||||||
| return !!(TRACK_SIZE_PRESETS[state.trackSize] || TRACK_SIZE_PRESETS.l).thumbs; | ||||||||||||||||||
| } | ||||||||||||||||||
| function syncTrackSizeButtons() { | ||||||||||||||||||
| const group = $("trackSizeGroup"); | ||||||||||||||||||
| if (!group) return; | ||||||||||||||||||
| for (const b of group.querySelectorAll("[data-track-size]")) | ||||||||||||||||||
| b.classList.toggle("on", b.dataset.trackSize === state.trackSize); | ||||||||||||||||||
| document.body.classList.toggle("track-size-s", state.trackSize === "s"); | ||||||||||||||||||
| document.body.classList.toggle("track-size-m", state.trackSize === "m"); | ||||||||||||||||||
| document.body.classList.toggle("track-size-l", state.trackSize === "l"); | ||||||||||||||||||
| } | ||||||||||||||||||
| function applyTrackHeights() { | ||||||||||||||||||
| const preset = TRACK_SIZE_PRESETS[state.trackSize] || TRACK_SIZE_PRESETS.l; | ||||||||||||||||||
| for (const t of TRACKS) { | ||||||||||||||||||
| if (preset.h[t.id] != null) t.h = preset.h[t.id]; | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
| /* Switch S/M/L track density, rebuild the timeline, and grow/shrink the pane | ||||||||||||||||||
| so every track fits without a vertical scrollbar. */ | ||||||||||||||||||
| function setTrackSize(size, { persist = true, fitPane = true } = {}) { | ||||||||||||||||||
| if (!TRACK_SIZE_PRESETS[size]) size = "l"; | ||||||||||||||||||
| state.trackSize = size; | ||||||||||||||||||
| applyTrackHeights(); | ||||||||||||||||||
| if (persist) localStorage.setItem(TRACK_SIZE_KEY, size); | ||||||||||||||||||
| syncTrackSizeButtons(); | ||||||||||||||||||
| buildTrackDOM(); | ||||||||||||||||||
| state.dirtyTimeline = true; | ||||||||||||||||||
| rebuildClips(); | ||||||||||||||||||
| if (fitPane) { | ||||||||||||||||||
| const h = setTimelineHeight(defaultTimelineHeight()); | ||||||||||||||||||
| localStorage.setItem(TL_H_KEY, String(h)); | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
| function restoreDefaultLayout() { | ||||||||||||||||||
| setTrackSize("l", { persist: true, fitPane: false }); | ||||||||||||||||||
| resetTimelineHeight(); | ||||||||||||||||||
| } | ||||||||||||||||||
| function clampTimelineHeight() { | ||||||||||||||||||
| const cur = $("timelinePanel")?.getBoundingClientRect().height; | ||||||||||||||||||
| if (cur) setTimelineHeight(cur); | ||||||||||||||||||
| } | ||||||||||||||||||
| function initPanelSplit() { | ||||||||||||||||||
| const handle = $("splitUpperTimeline"); | ||||||||||||||||||
| const tl = $("timelinePanel"); | ||||||||||||||||||
| if (!handle || !tl) return; | ||||||||||||||||||
| const savedSize = localStorage.getItem(TRACK_SIZE_KEY); | ||||||||||||||||||
| if (TRACK_SIZE_PRESETS[savedSize]) state.trackSize = savedSize; | ||||||||||||||||||
| applyTrackHeights(); | ||||||||||||||||||
| syncTrackSizeButtons(); | ||||||||||||||||||
|
|
||||||||||||||||||
| const saved = parseFloat(localStorage.getItem(TL_H_KEY)); | ||||||||||||||||||
| if (saved > 0) setTimelineHeight(saved); | ||||||||||||||||||
| else resetTimelineHeight(); | ||||||||||||||||||
|
|
||||||||||||||||||
| handle.addEventListener("pointerdown", (e) => { | ||||||||||||||||||
| if (e.button !== 0) return; | ||||||||||||||||||
| e.preventDefault(); | ||||||||||||||||||
| handle.setPointerCapture(e.pointerId); | ||||||||||||||||||
| handle.classList.add("dragging"); | ||||||||||||||||||
| document.body.classList.add("resizing-panels"); | ||||||||||||||||||
| const y0 = e.clientY; | ||||||||||||||||||
| const h0 = tl.getBoundingClientRect().height; | ||||||||||||||||||
| const onMove = (ev) => setTimelineHeight(h0 - (ev.clientY - y0)); | ||||||||||||||||||
| const onUp = () => { | ||||||||||||||||||
| handle.releasePointerCapture(e.pointerId); | ||||||||||||||||||
| handle.classList.remove("dragging"); | ||||||||||||||||||
| document.body.classList.remove("resizing-panels"); | ||||||||||||||||||
| handle.removeEventListener("pointermove", onMove); | ||||||||||||||||||
| handle.removeEventListener("pointerup", onUp); | ||||||||||||||||||
| localStorage.setItem(TL_H_KEY, String(Math.round(tl.getBoundingClientRect().height))); | ||||||||||||||||||
| state.dirtyTimeline = true; | ||||||||||||||||||
| }; | ||||||||||||||||||
| handle.addEventListener("pointermove", onMove); | ||||||||||||||||||
| handle.addEventListener("pointerup", onUp); | ||||||||||||||||||
| }); | ||||||||||||||||||
| handle.addEventListener("dblclick", (e) => { | ||||||||||||||||||
| e.preventDefault(); | ||||||||||||||||||
| resetTimelineHeight(); | ||||||||||||||||||
| }); | ||||||||||||||||||
|
Comment on lines
+2948
to
+2951
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Double-click only resets the pane height, not the "default layout". The PR's commit message describes double-click as "Restore the default layout when the resize handle is double-clicked," and 🐛 Proposed fix handle.addEventListener("dblclick", (e) => {
e.preventDefault();
- resetTimelineHeight();
+ restoreDefaultLayout();
});📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| /* ── Boot ── */ | ||||||||||||||||||
| initPanelSplit(); | ||||||||||||||||||
| buildTrackDOM(); | ||||||||||||||||||
| rebuildClips(); | ||||||||||||||||||
| renderBin(); | ||||||||||||||||||
|
|
||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,14 @@ | |
| <div class="logo"><span class="logo-mark">▶</span> Fable<b>Cut</b></div> | ||
| <div class="topbar-center" id="projectName">Untitled Project</div> | ||
| <div class="topbar-right"> | ||
| <span class="layout-tools"> | ||
| <button type="button" class="btn tiny" id="btnLayoutReset" title="Restore default layout">⊡ Layout</button> | ||
| <span class="btn-group" id="trackSizeGroup" title="Timeline track height"> | ||
| <button type="button" class="btn tiny" data-track-size="s" title="Compact tracks (no thumbnails)">S</button> | ||
| <button type="button" class="btn tiny" data-track-size="m" title="Medium tracks">M</button> | ||
| <button type="button" class="btn tiny" data-track-size="l" title="Large tracks">L</button> | ||
| </span> | ||
| </span> | ||
| <button class="btn ghost" id="btnHelp" title="Keyboard shortcuts">?</button> | ||
| <button class="btn primary" id="btnExport">⬇ Export</button> | ||
| </div> | ||
|
|
@@ -92,8 +100,10 @@ | |
| </aside> | ||
| </div> | ||
|
|
||
| <div class="v-split" id="splitUpperTimeline" role="separator" aria-orientation="horizontal" title="Drag to resize · double-click to reset"></div> | ||
|
|
||
|
Comment on lines
+103
to
+104
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win Timeline/upper split handle is not keyboard-operable.
📍 Affects 3 files
🤖 Prompt for AI Agents |
||
| <!-- ══════════ TIMELINE ══════════ --> | ||
| <section class="panel timeline-panel"> | ||
| <section class="panel timeline-panel" id="timelinePanel"> | ||
| <div class="timeline-toolbar"> | ||
| <button class="btn tiny" id="btnSplit" title="Split at playhead (S)">✂ Split</button> | ||
| <button class="btn tiny" id="btnDelete" title="Delete selected (Del)">🗑 Delete</button> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
availableTimelineMax()omits.app's own padding, over-allocating space for the timeline pane.style.csssets.app { padding: 6px; }, so the flex children's content box isapp.height - 12px, notapp.height. This function only subtractstopbarH,UPPER_MIN,split, andgaps, so the computed max is 12px too large. Combined with the.uppermin-heightoverride flagged instyle.css(no CSS floor left to catch the overshoot), dragging/fitting the timeline to max will silently squeeze.upperbelow its intended 140px minimum instead of being clamped.🐛 Proposed fix
function availableTimelineMax() { const app = $("app").getBoundingClientRect(); + const appStyle = getComputedStyle($("app")); + const appPad = parseFloat(appStyle.paddingTop) + parseFloat(appStyle.paddingBottom); const topbar = document.querySelector(".topbar")?.getBoundingClientRect(); const topbarH = topbar ? topbar.height : 46; const split = 6; const gaps = 18; // three 6px flex gaps between four children - return Math.floor(app.height - topbarH - UPPER_MIN - split - gaps); + return Math.floor(app.height - appPad - topbarH - UPPER_MIN - split - gaps); }📝 Committable suggestion
🤖 Prompt for AI Agents