Class: RubyTUI::Frame

Inherits:
Object
  • Object
show all
Defined in:
lib/rubytui/frame.rb

Overview

Rendering context yielded by Terminal#draw and render_once.

Frame wraps a Buffer and provides methods for rendering widgets. It is the primary interface for placing widgets during a draw call.

Examples:

Rendering widgets in a frame

terminal.draw do |frame|
  frame.render_widget(block, frame.area)
  frame.render_stateful_widget(list, chunks[1], list_state)
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(buffer, area) ⇒ Frame

Returns a new instance of Frame.

Parameters:



22
23
24
25
26
# File 'lib/rubytui/frame.rb', line 22

def initialize(buffer, area)
  @buffer = buffer
  @area = area
  @cursor_position = nil
end

Instance Attribute Details

#area ⇒ Rect (readonly)

Returns the total renderable area.

Returns:

  • (Rect) —

    the total renderable area



18
19
20
# File 'lib/rubytui/frame.rb', line 18

def area
  @area
end

#buffer ⇒ Buffer (readonly)

Returns the buffer to render into.

Returns:

  • (Buffer) —

    the buffer to render into



16
17
18
# File 'lib/rubytui/frame.rb', line 16

def buffer
  @buffer
end

Instance Method Details

#cursor_position ⇒ Array(Integer, Integer)?

Get the requested cursor position.

Returns:

  • (Array(Integer, Integer), nil) —

    [x, y] pair, or nil if not set



65
# File 'lib/rubytui/frame.rb', line 65

def cursor_position = @cursor_position

#render_stateful_widget(widget, area, state) ⇒ void

This method returns an undefined value.

Render a stateful widget with its state object.

The widget must implement render(area, buf, state) (the StatefulWidget protocol).

Parameters:

  • widget (#render) —

    any object responding to render(area, buf, state)

  • area (Rect) —

    the area to render into

  • state (Object) —

    the widget's external state



47
48
49
# File 'lib/rubytui/frame.rb', line 47

def render_stateful_widget(widget, area, state)
  widget.render(area, @buffer, state)
end

#render_widget(widget, area) ⇒ void

This method returns an undefined value.

Render a widget into a specific area of this frame.

The widget must implement render(area, buf) (the Widget protocol).

Parameters:

  • widget (#render) —

    any object responding to render(area, buf)

  • area (Rect) —

    the area to render into



35
36
37
# File 'lib/rubytui/frame.rb', line 35

def render_widget(widget, area)
  widget.render(area, @buffer)
end

#set_cursor_position(x, y) ⇒ void

This method returns an undefined value.

Request cursor placement at a specific position.

Used by widgets like Widgets::InputField to position the terminal cursor.

Parameters:

  • x (Integer) —

    column position

  • y (Integer) —

    row position



58
59
60
# File 'lib/rubytui/frame.rb', line 58

def set_cursor_position(x, y)
  @cursor_position = [x, y]
end

#size ⇒ Rect

Returns the total renderable area (alias for #area).

Returns:

  • (Rect) —

    the total renderable area (alias for #area)



68
# File 'lib/rubytui/frame.rb', line 68

def size = @area