calx-react
is a React-based UI builder for CalX OS that renders on configurable monochrome displays (default 128x64 pixels).
function App() {
return (
<Text>Hello, world!</Text>
);
}
calx.render(<App />, calx.device.screen);
This converts the text "Hello, world!" into pixels and sends an array of pixels to the device screen.
The output for the default screen (128x64) would look like this:
[[1,0,0,1,0,0,1...], [1,0,0,1,0,0,1...], ...]
The device would then render it on the screen, displaying "Hello, world!" in a 3x5 pixel font.
The default screen size is 128x64 pixels, but this can be configured:
import { SCREEN } from 'calx-react';
// Check current screen dimensions
console.log(`Screen: ${SCREEN.WIDTH}x${SCREEN.HEIGHT}`);
// Use custom screen size
const customBuffer = new PixelBuffer(256, 128); // 256x128 screen
# Install dependencies
bun install
For development and testing, use the VirtualScreen
class that logs output to the console:
import { render, Text, VirtualScreen } from 'calx-react';
const screen = new VirtualScreen('my-screen');
function App() {
return <Text>Hello, CalX!</Text>;
}
render(<App />, screen);
The examples/
folder contains sample applications:
# Run basic example with text and pixel art
cd examples
bun run basic
# Run interactive example with drawing and calculator
bun run interactive
function App() {
return (
<>
<Text x={10} y={10}>Hello, CalX!</Text>
<Pixels coordinates={[[64, 32], [65, 32], [66, 32]]} />
</>
);
}
Since this is a simplified renderer, state updates require manual re-rendering:
let counter = 0;
function updateCounter() {
counter++;
render(<Text>Count: {counter}</Text>, screen);
}
// Update every second
setInterval(updateCounter, 1000);
- No automatic re-rendering: Unlike full React, state changes don't automatically trigger re-renders
-
Manual updates: Call
render()
again to update the display - Functional components: Supports functional components and JSX
- No hooks: useState, useEffect etc. are not supported in this simplified version
The Text component supports a complete character set:
A-Z (full alphabet)
a-z (full alphabet)
0-9
! ? . , : ; ' " - + = * / \ | ( ) [ ] { } < > @ # $ % & ^ _ ` ~
function App() {
return (
<>
<Text x={0} y={0}>UPPERCASE: ABCDEFGHIJKLMNOPQRSTUVWXYZ</Text>
<Text x={0} y={8}>lowercase: abcdefghijklmnopqrstuvwxyz</Text>
<Text x={0} y={16}>Numbers: 0123456789</Text>
<Text x={0} y={24}>Symbols: !@#$%^&*()_+-={}[]|;':",./<>?</Text>
</>
);
}
Each character is rendered in a 3x5 pixel grid with 1 pixel spacing between characters.
calx-react/
├── src/
│ ├── types.ts # Type definitions
│ ├── pixel-buffer.ts # Pixel buffer management
│ ├── component-registry.ts # Component system
│ ├── simple-renderer.ts # Simple React renderer
│ └── virtual-screen.ts # Development screen
├── components/
│ ├── pixels.tsx # Pixels component
│ └── text.tsx # Text component
├── examples/
│ ├── basic-example.tsx # Basic usage examples
│ └── interactive-example.tsx # Interactive demos
└── index.ts # Main exports
const screen = new VirtualScreen('screen-id');
// Send pixels (automatically called by render)
screen.send(pixels);
// Clear screen
screen.clear();
// Get last rendered pixels
const lastPixels = screen.getLastPixels();
// Get rendering statistics
const stats = screen.getPixelStats();
// Returns: { totalPixels: 8192, onPixels: 245, offPixels: 7947 }