Status: β
v2.3 Production Ready + Interactive HUD (2026-01-12)
GitHub: https://github.com/michalstankiewicz4-cell/UI
Modular window system for Canvas API with centralized simulation management, high-performance optimizations, and interactive HUD mode.
BEFORE starting work:
- β DO NOT read
dist/ui.js- auto-generated bundle (2400+ lines, wastes tokens!) - β
Work with source files in
ui/andcore/directories - β
Use
build.ps1to regeneratedist/ui.jsafter changes - β
Read documentation first:
- docs/TODO.md - Current priorities & roadmap
- docs/ROADMAP.md - Performance optimizations
- docs/FILE_STRUCTURE.md - Complete file reference
- docs/CACHE_FIX.md - Troubleshooting guide
Project location: C:\Users\micha\source\repos\UI
<script src="dist/ui.js"></script>
<script>
const manager = new UI.WindowManager();
const window = new UI.BaseWindow(50, 50, 'Hello');
window.addText('Hello World!');
window.addButton('Click', () => alert('Works!'));
manager.add(window);
function render() {
manager.draw(ctx, UI.STYLES);
requestAnimationFrame(render);
}
</script># Just open index.html
# No server needed - works with file:// protocolMajor optimizations + features (2026-01-12):
- Interactive HUD Mode - Transparent windows with full interactivity
- +25-50% FPS improvement (layout cache)
- -15-25% CPU usage (early exits, cache hits)
- Component width fixes + click-through fixes
- All tests passing
See docs/ROADMAP.md for full optimization details.
UI/
βββ core/ # Central architecture
β βββ SimulationManager.js # Controller (360 lines)
β βββ EventBus.js # Pub-sub events (192 lines)
β βββ DataBridge.js # Data flow (224 lines)
β βββ SimulationWindowFactory.js # Auto-window factory
β βββ index.js # Central export point
β
βββ ui/ # UI library source
β βββ BaseWindow.js # Windows (~445 lines)
β βββ WindowManager.js # Manager (~126 lines)
β βββ Taskbar.js # Taskbar (~126 lines)
β βββ EventRouter.js # Events (~144 lines)
β βββ Styles.js # Styling (~49 lines)
β βββ core/ # Core utilities
β β βββ constants.js # Constants & config
β β βββ geometry.js # Hit testing
β β βββ layout.js # Layout engine
β β βββ text-cache.js # Text measurement cache
β βββ components/ # UI components
β βββ ButtonItem.js # Button control
β βββ SliderItem.js # Slider control
β βββ ToggleItem.js # Toggle control
β βββ SectionItem.js # Section divider
β βββ TextItem.js # Text display
β βββ header.js # Window header
β βββ scrollbar.js # Scrollbar
β
βββ simulations/ # 4 placeholder sims
β βββ sim1/ # 2D Particles
β β βββ Sim1.js # Particle simulation logic
β β βββ README.md # Sim1 documentation
β βββ sim2/ # 3D Cubes
β β βββ Sim2.js # 3D cube simulation logic
β β βββ README.md # Sim2 documentation
β βββ sim3/ # Physics
β β βββ Sim3.js # Physics simulation logic
β β βββ README.md # Sim3 documentation
β βββ sim4/ # Automata
β βββ Sim4.js # Cellular automata logic
β βββ README.md # Sim4 documentation
β
βββ data/ # Import/Export (future)
β βββ README.md # Data folder documentation
β βββ presets/ # Ready configs
β βββ exports/ # User data
β
βββ docs/ # Documentation
β βββ TODO.md # Project roadmap
β βββ ROADMAP.md # Optimization roadmap
β βββ CACHE_FIX.md # Cache troubleshooting
β βββ FILE_STRUCTURE.md # Complete file reference (544 lines)
β βββ TREE.md # Visual file tree (293 lines)
β
βββ themes/ # Custom themes (future)
βββ dist/ui.js # Built bundle (1972 lines)
βββ main.js # Main orchestrator
βββ index.html # Entry point
βββ build.ps1/sh # Build scripts
Central controller for all simulations:
// Register & add simulations
simulationManager.register('sim1', () => import('./sim1.js'));
await simulationManager.addSimulation('sim1', canvas);
// Global controls
simulationManager.pauseAll();
simulationManager.updateAll();
simulationManager.renderAll();Pub-sub communication:
// Subscribe
eventBus.on('simulation:added', (data) => {
console.log('New sim:', data.simId);
});
// Emit
eventBus.emit('simulation:added', { simId: 'sim1' });UI β Simulation data flow:
// Parameter: UI β Sim
dataBridge.bindParameter('sim1', 'speed', (v) => sim.setSpeed(v));
dataBridge.setParameter('sim1', 'speed', 2.5);
// Stat: Sim β UI
dataBridge.bindStat('sim1', 'fps', () => sim.fps);
const fps = dataBridge.getStat('sim1', 'fps');- β Draggable with mouse
- β Header buttons (Close, Minimize, HUD mode ποΈ)
- β Interactive transparent overlay (HUD mode)
- β Scrollbar with thumb dragging
- β Z-index management
- β Interactive controls: Buttons, Sliders, Toggles
- β Content: Text, Sections
- β Layout cache (performance optimized)
- β Component width fixes + proper hitboxes
// Button
window.addButton('SPAWN 1000', () => spawnParticles(1000));
// Slider
window.addSlider('Force', () => FORCE, (v) => FORCE = v, 0.5, 10, 0.1);
// Toggle
window.addToggle('Grid', () => showGrid, (v) => showGrid = v);
// Section
window.addSection('physics');
// Text
window.addText('Lorem ipsum...', '#00ff88');- β Windows-style menu (Start β Simulations, System)
- β Window buttons (minimize/restore)
- β Dynamic width calculation
- β Resize-aware positioning
- β Colors: #00FF88 (green), #00F5FF (cyan stats)
- β Font: Courier New 12px
- β Sections: centered dividers
- β Word wrap for long text
# Windows
.\build.ps1
# Linux/Mac
./build.shOutput: dist/ui.js (1972 lines, ~71KB)
- Create
simulations/mysim/MySim.js - Register in
main.js:simulationManager.register('mysim', () => import('./simulations/mysim/MySim.js'), { name: 'My Sim' } );
- Add UI button
- Done!
- β Interactive HUD Mode - Transparent windows with full button/slider functionality
- β Component Width Fixes - Proper hitboxes (Button 100px, Slider 200px, Toggle dynamic)
- β Click-Through Prevention - Buttons no longer pass clicks to windows behind
- β UI Polish - Menu spacing, taskbar colors (cyan=HUD, green=minimized), header improvements
- β
Performance Optimization (+25-50% FPS, -15-25% CPU)
- Layout cache (OPT-1)
- Text measurement cache (OPT-6)
- EventRouter early exit (OPT-7)
- Taskbar resize bugfix (OPT-11)
- Slider drag state fix (critical)
- β Core architecture (SimulationManager, EventBus, DataBridge)
- β FAZA C1: Header buttons (X, _, ποΈ)
- β FAZA C2: Scrollbar with thumb dragging
- β FAZA C3: Sliders, Toggles, Buttons
- β Event-driven communication
- β Data binding UI β Sims
- β HUD mode (interactive transparent overlay)
- β Text styling (green/cyan, word wrap, sections)
- β Menu sections (symulacje/system)
- β Modular component architecture
Next Steps (see docs/TODO.md)
- π FAZA D1: Simulation Window Factory (2-4h) β PRIORITY
- π Remaining optimizations (Package A: 45 min, +7-15%)
- π FAZA C4: Advanced sliders (range, vertical)
- π Import/Export presets
- π Custom themes
- Bundle: 1972 lines (~82.65 KB)
- Performance: +25-50% FPS vs v2.1
- Core: 776 lines
- UI Library: ~1500 lines (source)
- Components: 8 modular files
- Total codebase: ~9200 lines
- Commits: 111+
- docs/TODO.md - Project roadmap and priorities
- docs/ROADMAP.md - Performance optimization details
- docs/FILE_STRUCTURE.md - Complete file reference (544 lines)
- docs/TREE.md - Visual file tree structure (293 lines)
- docs/CACHE_FIX.md - Browser cache troubleshooting
| File | Purpose | Lines |
|---|---|---|
| index.html | Entry point | - |
| main.js | Orchestrator | ~241 |
| dist/ui.js | Complete bundle | 2248 |
| ui/BaseWindow.js | Main window class | ~475 |
| ui/WindowManager.js | Window manager | ~133 |
| ui/Taskbar.js | Taskbar | ~400 |
| core/SimulationManager.js | Sim controller | 360 |
Extracted from Petrie Dish v5.1-C2.
Use according to original project license.
Last Updated: 2026-01-12
Version: v2.3 (Interactive HUD + Polish)