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:
RenderTrait: Defines therender()method, which takes aRenderer, coordinates (x, y), and a depth value as arguments. Any type that implementsRendercan be drawn to the screen.- Renderer Abstraction: The
Rendertrait works with theRenderertrait, making rendering code independent of the specific rendering backend (e.g., terminal, in-memory buffer). - Depth-based Rendering: The
depthparameter inrender()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
Rendertrait provides extension methods likewith_color(),transparent(), andwith_bg_color()to easily create styled renderable objects without modifying the original object.
Implementations of Render:
The module provides Render implementations for:
&strandString: Renders text strings.char: Renders a single character.Pixel: Renders a single pixel.Sprite: Renders a sprite (predefined grid of pixels).&TwhereT: 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§
- Half
Block Display Render - A struct representing a display with “double the resolution” of the terminal.
- Sprite
- Represents a sprite (a fixed-size grid of pixels).