module RatatuiRuby::TUI::CanvasFactories
Canvas shape factory methods for Session.
Provides convenient access to Widgets::Shape::* classes for creating custom drawings on Canvas widgets.
Public Instance Methods
Creates a circle shape (terse alias). @return [Widgets::Shape::Circle]
Creates a circle shape (bidirectional alias). @return [Widgets::Shape::Circle]
Source
# File lib/ratatui_ruby/tui/canvas_factories.rb, line 68 def label(first = nil, **kwargs) Widgets::Shape::Label.coerce_args(first, kwargs) end
Creates a label shape (terse alias).
Note: shape_label is defined in WidgetFactories. @return [Widgets::Shape::Label]
Creates a label shape (bidirectional alias). @return [Widgets::Shape::Label]
Creates a map shape (bidirectional alias). @return [Widgets::Shape::Map]
Creates a point shape (terse alias). @return [Widgets::Shape::Point]
Creates a point shape (bidirectional alias). @return [Widgets::Shape::Point]
Creates a rectangle shape (bidirectional alias). Note: Terse ‘rectangle’ is intentionally excluded to avoid confusion with Layout::Rect, but ‘rectangle_shape’ is unambiguous. @return [Widgets::Shape::Rectangle]
Source
# 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
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
# 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))
@param type [Symbol] Shape type: :circle, :line, :point, :rectangle, :map, :label @return [Widgets::Shape::*]
Source
# File lib/ratatui_ruby/tui/canvas_factories.rb, line 35 def shape_circle(...) Widgets::Shape::Circle.new(...) end
Creates a circle shape for Canvas. @return [Widgets::Shape::Circle]
Source
# File lib/ratatui_ruby/tui/canvas_factories.rb, line 23 def shape_line(...) Widgets::Shape::Line.new(...) end
Creates a line shape for Canvas. @return [Widgets::Shape::Line]
Source
# File lib/ratatui_ruby/tui/canvas_factories.rb, line 17 def shape_map(...) Widgets::Shape::Map.new(...) end
Creates a map shape for Canvas. @return [Widgets::Shape::Map]
Source
# File lib/ratatui_ruby/tui/canvas_factories.rb, line 29 def shape_point(...) Widgets::Shape::Point.new(...) end
Creates a point (single pixel) shape for Canvas. @return [Widgets::Shape::Point]
Source
# File lib/ratatui_ruby/tui/canvas_factories.rb, line 41 def shape_rectangle(...) Widgets::Shape::Rectangle.new(...) end
Creates a rectangle shape for Canvas. @return [Widgets::Shape::Rectangle]