Red Otter logo
Red Otter
0.1.15

Interactivity

The recent version of Red Otter includes new systems for handling user inputs. This required the layout to become more opinionated.

API

Example of a simple app loop that reads events:

TypeScript
import { EventManager, WebGPURenderer, View, compose, paint } from "red-otter";

const eventManager = new EventManager();
const renderer = new WebGPURenderer(/* ... */);
const root = new View(/* ... */);

function render() {
  // Deliver events to views.
  eventManager.deliverEvents(root);

  // Update scroll offsets etc. in response to events.
  compose(renderer, root);

  // Dispatch commands for renderer.
  paint(renderer, root);

  // Prepare rendering instructions and dispatch them to the GPU.
  const commandEncoder = device.createCommandEncoder();
  renderer.render(commandEncoder);
  device.queue.submit([commandEncoder.finish()]);

  // Request next frame.
  requestAnimationFrame(render);
}

render();

/EventManager.ts

Responsible for dispatching events to the correct views.

Field
Type and description
events
UserEvent[]
focused
View
lastPosition
Vec2

Adds an event to the queue.

Parameter
Type and description
event
UserEvent
returns
void

Type declaration

TypeScript
(event: UserEvent) => void
Parameter
Type and description
view
View
returns
void

Type declaration

TypeScript
(view: View) => void

Processes all events in the queue, leaving it empty, by visiting all views in the given root tree and offering them to the views in the reverse DFS order.

Parameter
Type and description
root
View
returns
void

Type declaration

TypeScript
(root: View) => void

Copyright © Tomasz Czajęcki 2023