Module: RatatuiRuby::TUI::CanvasFactories

Included in:
RatatuiRuby::TUI
Defined in:
lib/ratatui_ruby/tui/canvas_factories.rb

Overview

Canvas shape factory methods for Session.

Provides convenient access to Widgets::Shape::* classes for creating custom drawings on Canvas widgets.

Instance Method Summary collapse

Instance Method Details

#label(first = nil, **kwargs) ⇒ Widgets::Shape::Label Also known as: label_shape

Creates a label shape (terse alias).

Note: shape_label is defined in WidgetFactories.



68
69
70
# File 'lib/ratatui_ruby/tui/canvas_factories.rb', line 68

def label(first = nil, **kwargs)
  Widgets::Shape::Label.coerce_args(first, kwargs)
end

#shape(type) ⇒ Widgets::Shape::*

Creates a shape by type symbol.

Hard-coding method names limits flexibility. Programmatic shape creation from user input or config files requires tedious case statements.

This dispatcher routes shape creation through a single entry point. Pass the type as a symbol and the remaining parameters as kwargs.

Use it for dynamic shape generation, config-driven UIs, or when you prefer explicit type specification over method names.

Also available as: tui.circle, tui.shape_circle

Examples

– SPDX-SnippetBegin SPDX-FileCopyrightText: 2026 Kerrick Long SPDX-License-Identifier: MIT-0 ++

# Direct dispatch
tui.shape(:circle, x: 5.0, y: 5.0, radius: 2.5, color: :red)

# Dynamic shape creation from config
config = { type: :rectangle, x: 0.0, y: 0.0, width: 10.0, height: 10.0 }
tui.shape(config[:type], **config.except(:type))

– SPDX-SnippetEnd ++

Parameters:

  • type (Symbol)

    Shape type: :circle, :line, :point, :rectangle, :map, :label

Returns:



134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/ratatui_ruby/tui/canvas_factories.rb', line 134

def shape(type, **)
  case type
  when :circle then shape_circle(**)
  when :line then shape_line(**)
  when :point then shape_point(**)
  when :rectangle then shape_rectangle(**)
  when :map then shape_map(**)
  when :label then label(**)
  else
    raise ArgumentError, "Unknown shape type: #{type.inspect}. " \
      "Valid types: :circle, :line, :point, :rectangle, :map, :label"
  end
end

#shape_circleWidgets::Shape::Circle Also known as: circle, circle_shape

Creates a circle shape for Canvas.



35
36
37
# File 'lib/ratatui_ruby/tui/canvas_factories.rb', line 35

def shape_circle(...)
  Widgets::Shape::Circle.new(...)
end

#shape_lineWidgets::Shape::Line

Creates a line shape for Canvas.



23
24
25
# File 'lib/ratatui_ruby/tui/canvas_factories.rb', line 23

def shape_line(...)
  Widgets::Shape::Line.new(...)
end

#shape_mapWidgets::Shape::Map Also known as: map, map_shape

Creates a map shape for Canvas.

Returns:



17
18
19
# File 'lib/ratatui_ruby/tui/canvas_factories.rb', line 17

def shape_map(...)
  Widgets::Shape::Map.new(...)
end

#shape_pointWidgets::Shape::Point Also known as: point, point_shape

Creates a point (single pixel) shape for Canvas.



29
30
31
# File 'lib/ratatui_ruby/tui/canvas_factories.rb', line 29

def shape_point(...)
  Widgets::Shape::Point.new(...)
end

#shape_rectangleWidgets::Shape::Rectangle Also known as: rectangle_shape

Creates a rectangle shape for Canvas.



41
42
43
# File 'lib/ratatui_ruby/tui/canvas_factories.rb', line 41

def shape_rectangle(...)
  Widgets::Shape::Rectangle.new(...)
end