Class: Curtis::View

Inherits:
BaseView show all
Defined in:
lib/curtis/view.rb

Instance Attribute Summary collapse

Attributes inherited from BaseView

#cursor, #position, #size, #window

Instance Method Summary collapse

Methods inherited from BaseView

instance, #method_missing, #move_cursor, #respond_to_missing?, #setup

Methods included from Helpers::Border

#border, #box

Methods included from Helpers::Text

#puts

Constructor Details

#initialize(**opts) {|_self| ... } ⇒ View

Returns a new instance of View.

Yields:

  • (_self)

Yield Parameters:

  • _self (Curtis::View)

    the object that the method was called on



7
8
9
10
11
12
13
14
15
16
# File 'lib/curtis/view.rb', line 7

def initialize(**opts)
  @lines     = opts[:lines]   || -> { parent.size.lines }
  @columns   = opts[:columns] || -> { parent.size.columns }
  @line      = opts[:line]    || 0
  @column    = opts[:column]  || 0

  yield self if block_given?

  super Ncurses::WINDOW.new(*computed_dimensions, *computed_coordinates)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Curtis::BaseView

Instance Attribute Details

#column=(value) ⇒ Object (writeonly)

Sets the attribute column

Parameters:

  • the value to set the attribute column to.



5
6
7
# File 'lib/curtis/view.rb', line 5

def column=(value)
  @column = value
end

#columns=(value) ⇒ Object (writeonly)

Sets the attribute columns

Parameters:

  • the value to set the attribute columns to.



5
6
7
# File 'lib/curtis/view.rb', line 5

def columns=(value)
  @columns = value
end

#line=(value) ⇒ Object (writeonly)

Sets the attribute line

Parameters:

  • the value to set the attribute line to.



5
6
7
# File 'lib/curtis/view.rb', line 5

def line=(value)
  @line = value
end

#lines=(value) ⇒ Object (writeonly)

Sets the attribute lines

Parameters:

  • the value to set the attribute lines to.



5
6
7
# File 'lib/curtis/view.rb', line 5

def lines=(value)
  @lines = value
end

Instance Method Details

#clearObject



39
40
41
42
# File 'lib/curtis/view.rb', line 39

def clear
  clear_thread!
  window.clear
end

#parentObject



18
19
20
# File 'lib/curtis/view.rb', line 18

def parent
  BaseView.instance
end

#render(every: 0.04) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/curtis/view.rb', line 22

def render(every: 0.04)
  clear_thread!

  if block_given?
    @thread = Thread.new do
      loop do
        yield self
        window.refresh
        sleep every
      end
    end
  else
    setup
    window.refresh
  end
end

#reposition(line: nil, column: nil) ⇒ Object



50
51
52
53
54
# File 'lib/curtis/view.rb', line 50

def reposition(line: nil, column: nil)
  @line   = line   if line
  @column = column if column
  window.mvwin(*computed_coordinates)
end

#resize(lines: nil, columns: nil) ⇒ Object



44
45
46
47
48
# File 'lib/curtis/view.rb', line 44

def resize(lines: nil, columns: nil)
  @lines   = lines   if lines
  @columns = columns if columns
  window.resize(*computed_dimensions)
end