Skip to content

Commit b474ad1

Browse files
committed
Update prev/next
1 parent 5197fd0 commit b474ad1

File tree

1 file changed

+46
-0
lines changed
  • examples/led-matrix-painter/assets

1 file changed

+46
-0
lines changed

examples/led-matrix-painter/assets/app.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ const rotate180Btn = document.getElementById('rotate180');
1414
const flipHBtn = document.getElementById('flip-h');
1515
const flipVBtn = document.getElementById('flip-v');
1616
const frameTitle = document.getElementById('frame-title');
17+
const frameBackBtn = document.getElementById('frame-back');
18+
const frameForwardBtn = document.getElementById('frame-forward');
1719

1820
function showError(message) {
1921
const errorContainer = document.getElementById('error-container');
@@ -117,6 +119,25 @@ function collectGridBrightness(){
117119
return grid;
118120
}
119121

122+
function updateArrowButtonsState() {
123+
if (!frameBackBtn || !frameForwardBtn) return;
124+
if (!loadedFrameId) {
125+
frameBackBtn.disabled = true;
126+
frameForwardBtn.disabled = true;
127+
return;
128+
}
129+
130+
const currentIndex = sessionFrames.findIndex(f => f.id === loadedFrameId);
131+
if (currentIndex === -1) {
132+
frameBackBtn.disabled = true;
133+
frameForwardBtn.disabled = true;
134+
return;
135+
}
136+
137+
frameBackBtn.disabled = currentIndex === 0;
138+
frameForwardBtn.disabled = currentIndex === sessionFrames.length - 1;
139+
}
140+
120141
function markLoaded(frame){
121142
const oldFrameId = loadedFrameId; // Store the old ID
122143

@@ -143,6 +164,7 @@ function markLoaded(frame){
143164
}
144165
}catch(e){/* ignore */}
145166
}
167+
updateArrowButtonsState();
146168
}
147169

148170
function clearLoaded(){
@@ -154,6 +176,7 @@ function clearLoaded(){
154176
}
155177
loadedFrameId = null;
156178
loadedFrame = null;
179+
updateArrowButtonsState();
157180
}
158181

159182
function makeGrid(){
@@ -406,6 +429,28 @@ if (stopAnimationBtn) {
406429
});
407430
}
408431

432+
if (frameForwardBtn) {
433+
frameForwardBtn.addEventListener('click', () => {
434+
if (!loadedFrameId) return;
435+
const currentIndex = sessionFrames.findIndex(f => f.id === loadedFrameId);
436+
if (currentIndex < sessionFrames.length - 1) {
437+
const nextFrame = sessionFrames[currentIndex + 1];
438+
loadFrameIntoEditor(nextFrame.id);
439+
}
440+
});
441+
}
442+
443+
if (frameBackBtn) {
444+
frameBackBtn.addEventListener('click', () => {
445+
if (!loadedFrameId) return;
446+
const currentIndex = sessionFrames.findIndex(f => f.id === loadedFrameId);
447+
if (currentIndex > 0) {
448+
const prevFrame = sessionFrames[currentIndex - 1];
449+
loadFrameIntoEditor(prevFrame.id);
450+
}
451+
});
452+
}
453+
409454
// Save frame button removed - auto-persist replaces it
410455
const animControls = document.getElementById('anim-controls');
411456
const animNameInput = document.getElementById('anim-name');
@@ -451,6 +496,7 @@ async function refreshFrames(){
451496
el.classList.add('selected');
452497
}
453498
}
499+
updateArrowButtonsState();
454500
}catch(e){ console.warn(e) }
455501
}
456502

0 commit comments

Comments
 (0)