Class: RatatuiRuby::Widgets::Center
- Inherits:
-
Object
- Object
- RatatuiRuby::Widgets::Center
- Includes:
- CoerceableWidget
- Defined in:
- lib/ratatui_ruby/widgets/center.rb
Overview
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
– SPDX-SnippetBegin SPDX-FileCopyrightText: 2026 Kerrick Long SPDX-License-Identifier: MIT-0 ++
# Center a paragraph using 50% of width and height
Center.new(
child: Paragraph.new(text: "Hello"),
width_percent: 50,
height_percent: 50
)
– SPDX-SnippetEnd ++
Instance Method Summary collapse
-
#initialize(child:, width_percent: 100, height_percent: 100) ⇒ Center
constructor
Creates a new Center widget.
Methods included from CoerceableWidget
Constructor Details
#initialize(child:, width_percent: 100, height_percent: 100) ⇒ Center
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).
62 63 64 65 66 67 68 |
# 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 |