feat: home button to center view + fix sequencer step count growth

- Add ⌂ button to zoom bar (sandbox + puzzle) that centers camera on
  all modules
- Fix sequencer _steps array not growing when step count param increases
  (e.g. 8→32 now properly adds new empty steps)
- Make piano roll width dynamic based on bar count (BEAT_PX constant
  density instead of fixed ROLL_W)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Jose Luis
2026-03-21 04:53:31 +01:00
parent fce0bcdace
commit 73532074b1
3 changed files with 55 additions and 5 deletions

View File

@@ -191,6 +191,26 @@ export default function App({ onSwitchToGame }) {
emit();
}, []);
// Center view on all modules
const handleCenterView = useCallback(() => {
if (state.modules.length === 0) { state.camX = 0; state.camY = 0; emit(); return; }
const container = containerRef.current;
const cw = container?.clientWidth || 800;
const ch = container?.clientHeight || 600;
let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
for (const m of state.modules) {
minX = Math.min(minX, m.x);
minY = Math.min(minY, m.y);
maxX = Math.max(maxX, m.x + 200);
maxY = Math.max(maxY, m.y + 150);
}
const cx = (minX + maxX) / 2 * state.zoom;
const cy = (minY + maxY) / 2 * state.zoom;
state.camX = cw / 2 - cx;
state.camY = ch / 2 - cy;
emit();
}, []);
const handleToggleAudio = async () => {
if (state.isRunning) {
stopAudio();
@@ -305,6 +325,7 @@ export default function App({ onSwitchToGame }) {
{(state.zoom * 100).toFixed(0)}%
</button>
<button className="zoom-btn" onClick={handleZoomOut} title="Zoom out"></button>
<button className="zoom-btn" onClick={handleCenterView} title="Centrar vista"></button>
</div>
{/* Module palette */}