Skip to content

michalstankiewicz4-cell/UI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

79 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

UI System - Canvas-based Windows & Multi-Simulation Architecture

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.


πŸ€– For Claude AI (Important!)

BEFORE starting work:

  • ❌ DO NOT read dist/ui.js - auto-generated bundle (2400+ lines, wastes tokens!)
  • βœ… Work with source files in ui/ and core/ directories
  • βœ… Use build.ps1 to regenerate dist/ui.js after changes
  • βœ… Read documentation first:

Project location: C:\Users\micha\source\repos\UI


πŸš€ Quick Start

Standalone (single file)

<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>

Full System

# Just open index.html
# No server needed - works with file:// protocol

⚑ Performance (v2.3 NEW!)

Major 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.


πŸ“¦ Project Structure

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

πŸ—οΈ Core Architecture

SimulationManager

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();

EventBus

Pub-sub communication:

// Subscribe
eventBus.on('simulation:added', (data) => {
    console.log('New sim:', data.simId);
});

// Emit
eventBus.emit('simulation:added', { simId: 'sim1' });

DataBridge

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');

🎨 UI Features

Windows

  • βœ… 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

Controls (FAZA C3)

// 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');

Taskbar

  • βœ… Windows-style menu (Start β†’ Simulations, System)
  • βœ… Window buttons (minimize/restore)
  • βœ… Dynamic width calculation
  • βœ… Resize-aware positioning

Styling

  • βœ… Colors: #00FF88 (green), #00F5FF (cyan stats)
  • βœ… Font: Courier New 12px
  • βœ… Sections: centered dividers
  • βœ… Word wrap for long text

πŸ”§ Development

Build Bundle

# Windows
.\build.ps1

# Linux/Mac
./build.sh

Output: dist/ui.js (1972 lines, ~71KB)

Add New Simulation

  1. Create simulations/mysim/MySim.js
  2. Register in main.js:
    simulationManager.register('mysim',
        () => import('./simulations/mysim/MySim.js'),
        { name: 'My Sim' }
    );
  3. Add UI button
  4. Done!

πŸ“Š Current Status

Completed (v2.3 - 2026-01-12)

  • βœ… 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

πŸ“ˆ Statistics

  • 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+

πŸ“š Documentation


🎯 Key Files

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

βš–οΈ License

Extracted from Petrie Dish v5.1-C2.
Use according to original project license.


Last Updated: 2026-01-12
Version: v2.3 (Interactive HUD + Polish)

About

One UI to rule them all

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published