factoriax.playground.ui.compositing

factoriax.playground.ui.compositing#

Image compositing utilities for numpy-array-based UI rendering.

factoriax.playground.ui.compositing.blit_rgba(overlay: ndarray, src: ndarray, y: int, x: int) → None#

Alpha-composite src onto overlay at (y, x), clipping to bounds.

Parameters:
  • overlay – Destination RGBA array of shape (H, W, 4). Modified in place.

  • src – Source RGBA array of shape (h, w, 4).

  • y – Top row in overlay.

  • x – Left column in overlay.

factoriax.playground.ui.compositing.blit_scroll_view(overlay: ndarray, content: ndarray, vp_x: int, vp_y: int, vp_w: int, vp_h: int, scroll_offset: int) → None#

Composite a scrollable content canvas into a viewport on overlay.

When the content is taller than the viewport a scrollbar is drawn along the right edge.

Parameters:
  • overlay – Destination RGBA array. Modified in place.

  • content – Full content RGBA canvas of shape (content_h, vp_w, 4).

  • vp_x – Left edge of the viewport in overlay coordinates.

  • vp_y – Top edge of the viewport in overlay coordinates.

  • vp_w – Viewport width in pixels (includes scrollbar when shown).

  • vp_h – Viewport height in pixels.

  • scroll_offset – Number of content pixels scrolled off the top.

factoriax.playground.ui.compositing.clip_scroll_offset(offset: int, content_h: int, viewport_h: int) → int#

Clamp a scroll offset to the valid range.

Parameters:
  • offset – Proposed scroll offset in pixels.

  • content_h – Total height of the scrollable content in pixels.

  • viewport_h – Height of the visible viewport in pixels.

Return type:

Clamped offset in [0, max(0, content_h - viewport_h)].

factoriax.playground.ui.compositing.composite_rgba_over_rgb(background: ndarray, overlay: ndarray) → None#

Composite an RGBA overlay onto an RGB background in-place.

The function mixes the pixels inside the box that holds the visible part of the overlay. It does no float arithmetic for the clear area around a menu panel, which is most of the surface.

Parameters:
  • background – RGB image array of shape (H, W, 3), modified in place.

  • overlay – RGBA image array of shape (H, W, 4).