class RatatuiRuby::Widgets::Center
Centers content within available space.
Layouts often require alignment. Manually calculating offsets for centering is error-prone and brittle.
This widget handles the math. It centers a child widget within the current area, resizing the child according to optional percentage modifiers.
Use it to position modals, splash screens, or floating dialogue boxes.
Examples
# Center a paragraph using 50% of width and height Center.new( child: Paragraph.new(text: "Hello"), width_percent: 50, height_percent: 50 )
Attributes
The widget to be centered.
Height of the centered area as a percentage (0-100).
If 50, the child occupies half the available height.
Width of the centered area as a percentage (0-100).
If 50, the child occupies half the available width.
Public Class Methods
Source
# File lib/ratatui_ruby/widgets/center.rb, line 62 def initialize(child:, width_percent: 100, height_percent: 100) super( child:, width_percent: Float(width_percent), height_percent: Float(height_percent) ) end
Creates a new Center widget.
- child
-
Widget to render.
width_percent-
Target width percentage (Integer, default: 100).
height_percent-
Target height percentage (Integer, default: 100).
Calls superclass method