Module render

Module render 

Source
Expand description

Rendering traits and implementations for renderable objects.

This module defines the Render trait, which enables objects to be rendered to a Renderer. It also provides implementations of the Render trait for common types like &str, String, char, Pixel, and Sprite.

Key Concepts:

  • Render Trait: Defines the render() method, which takes a Renderer, coordinates (x, y), and a depth value as arguments. Any type that implements Render can be drawn to the screen.
  • Renderer Abstraction: The Render trait works with the Renderer trait, making rendering code independent of the specific rendering backend (e.g., terminal, in-memory buffer).
  • Depth-based Rendering: The depth parameter in render() controls the rendering order, allowing you to layer objects on top of each other. Higher depth values are rendered on top.
  • Trait Extensions for Styling: The Render trait provides extension methods like with_color(), transparent(), and with_bg_color() to easily create styled renderable objects without modifying the original object.

Implementations of Render:

The module provides Render implementations for:

  • &str and String: Renders text strings.
  • char: Renders a single character.
  • Pixel: Renders a single pixel.
  • Sprite: Renders a sprite (predefined grid of pixels).
  • &T where T: Render: Allows rendering of references to renderable objects.

Styling and Adapters:

The with_color(), transparent(), and with_bg_color() methods don’t directly modify the original object. Instead, they return adapter structs (WithColor, WithTransparency, WithBgColor) that wrap the original object and apply the styling during rendering. This allows for flexible and composable styling without changing the underlying data.

Structs§

HalfBlockDisplayRender
A struct representing a display with “double the resolution” of the terminal.
Sprite
Represents a sprite (a fixed-size grid of pixels).

Traits§

Render
Trait for objects that can be rendered to a Renderer.