Class: RatatuiRuby::Widgets::Shape::Label

Inherits:
Object
  • Object
show all
Includes:
CoerceableWidget
Defined in:
lib/ratatui_ruby/widgets/shape/label.rb

Overview

A text label on a canvas.

Labels render text at specific coordinates in canvas space. Unlike shapes, labels are always rendered on top of all other canvas elements.

x

The x-coordinate in canvas space (Numeric).

y

The y-coordinate in canvas space (Numeric).

text

The text content (String or Text::Line).

style

Optional style for the text.

Examples

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

# Simple label
Shape::Label.new(x: 0, y: 0, text: "Origin")

# Styled label
Shape::Label.new(
  x: -122.4, y: 37.8,
  text: "San Francisco",
  style: Style.new(fg: :cyan, add_modifier: :bold)
)

# Label with Text::Line for rich formatting
Shape::Label.new(
  x: 0.0, y: 0.0,
  text: Text::Line.new(spans: [
    Text::Span.new(content: "Hello ", style: Style.new(fg: :red)),
    Text::Span.new(content: "World", style: Style.new(fg: :blue))
  ])
)

– SPDX-SnippetEnd ++

Instance Method Summary collapse

Methods included from CoerceableWidget

included

Constructor Details

#initialize(x:, y:, text:, style: nil) ⇒ Label

Creates a new Label.

x

X coordinate (Numeric).

y

Y coordinate (Numeric).

text

Text content (String or Text::Line).

style

Style (optional).



74
75
76
# File 'lib/ratatui_ruby/widgets/shape/label.rb', line 74

def initialize(x:, y:, text:, style: nil)
  super(x: Float(x), y: Float(y), text:, style:)
end