class RatatuiRuby::Widgets::Canvas
Provides a drawing surface for custom shapes.
Standard widgets cover standard cases. Sometimes you need to draw a map, a custom diagram, or a game. Character grids are too coarse for fine detail.
This widget increases the resolution. It uses Braille patterns or block characters to create a “sub-pixel” drawing surface.
Use it to implement free-form graphics, high-resolution plots, or geographic maps.
Examples
Canvas.new( x_bounds: [-180, 180], y_bounds: [-90, 90], shapes: [ Shape::Map.new(color: :green, resolution: :high), Shape::Circle.new(x: 0, y: 0, radius: 10, color: :red), Shape::Label.new(x: -122.4, y: 37.8, text: "San Francisco") ] )
Attributes
The background color of the canvas.
Optional wrapping block.
The marker type used for drawing.
:braille (high res), :half_block, :dot, :block, :bar.
Array of shapes to render.
Includes {Shape::Line}, {Shape::Circle}, {Shape::Map}, etc.
- min, max
-
range for the x-axis.
- min, max
-
range for the y-axis.
Public Class Methods
Source
# File lib/ratatui_ruby/widgets/canvas.rb, line 229 def initialize(shapes: [], x_bounds: [0.0, 100.0], y_bounds: [0.0, 100.0], marker: :braille, block: nil, background_color: nil) super( shapes:, x_bounds: [Float(x_bounds[0]), Float(x_bounds[1])], y_bounds: [Float(y_bounds[0]), Float(y_bounds[1])], marker:, block:, background_color: ) end
Creates a new Canvas.
- shapes
-
Array of Shapes.
x_bounds-
Array of [min, max] (Numeric, duck-typed via
to_f). y_bounds-
Array of [min, max] (Numeric, duck-typed via
to_f). - marker
-
Symbol (default:
:braille). - block
-
Block(optional). background_color-
Color (optional).