Class: Vedeu::Cursors::Reposition Private

Inherits:
Object
  • Object
show all
Defined in:
lib/vedeu/cursors/reposition.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Arbitrarily move the cursor to a given position.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Vedeu::Cursors::Reposition

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Vedeu::Cursors::Reposition.

Parameters:

  • attributes (Hash<Symbol => Fixnum|Symbol|String]) (defaults to: {})

    ttributes [Hash<Symbol => Fixnum|Symbol|String]

Options Hash (attributes):

  • mode (Symbol)

    One of either :absolute or :relative. Relates to the coordinates provided.

  • name (String|Symbol)

    The name of the cursor and related interface/view.

  • x (Fixnum)

    The new row/line position.

  • y (Fixnum)

    The new column/character position.



24
25
26
27
28
# File 'lib/vedeu/cursors/reposition.rb', line 24

def initialize(attributes = {})
  defaults.merge!(attributes).each do |key, value|
    instance_variable_set("@#{key}", value)
  end
end

Instance Attribute Details

#nameNilClass|Symbol|String (readonly, protected)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns The name of the model, the target model or the name of the associated model.

Returns:

  • (NilClass|Symbol|String)

    The name of the model, the target model or the name of the associated model.



41
42
43
# File 'lib/vedeu/cursors/reposition.rb', line 41

def name
  @name
end

#xFixnum (readonly, protected)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Fixnum)


45
46
47
# File 'lib/vedeu/cursors/reposition.rb', line 45

def x
  @x
end

#yFixnum (readonly, protected)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Fixnum)


49
50
51
# File 'lib/vedeu/cursors/reposition.rb', line 49

def y
  @y
end

Instance Method Details

#absoluteHash<Symbol => Fixnum> (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Hash<Symbol => Fixnum>)


54
55
56
57
58
59
60
61
# File 'lib/vedeu/cursors/reposition.rb', line 54

def absolute
  {
    x:  coordinate((x - geometry.x), :x).x,
    y:  coordinate((y - geometry.y), :y).y,
    ox: 0,
    oy: 0,
  }
end

#absolute?Boolean (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:



64
65
66
# File 'lib/vedeu/cursors/reposition.rb', line 64

def absolute?
  mode == :absolute
end

#coordinate(offset, type) ⇒ Vedeu::Cursors::Coordinate (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Determine correct x and y related coordinates.

Parameters:

  • offset (Fixnum)
  • type (Symbol)

Returns:



73
74
75
76
77
# File 'lib/vedeu/cursors/reposition.rb', line 73

def coordinate(offset, type)
  Vedeu::Cursors::Coordinate.new(geometry: geometry,
                                 offset:   offset,
                                 type:     type)
end

#cursorVedeu::Cursors::Cursor (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



80
81
82
# File 'lib/vedeu/cursors/reposition.rb', line 80

def cursor
  Vedeu.cursors.by_name(name)
end

#defaultsHash<Symbol => void> (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The default options/attributes for a new instance of this class.

Returns:

  • (Hash<Symbol => void>)


85
86
87
88
89
90
91
92
# File 'lib/vedeu/cursors/reposition.rb', line 85

def defaults
  {
    mode: :relative,
    name: Vedeu.focus,
    x:    0,
    y:    0,
  }
end

#geometryVedeu::Geometries::Geometry (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the named geometry from the geometries repository.



95
96
97
# File 'lib/vedeu/cursors/reposition.rb', line 95

def geometry
  Vedeu.geometries.by_name(name)
end

#inside_geometry?Boolean (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:



100
101
102
103
104
105
# File 'lib/vedeu/cursors/reposition.rb', line 100

def inside_geometry?
  x >= geometry.x &&
    x <= geometry.xn &&
    y >= geometry.y &&
    y <= geometry.yn
end

#modeSymbol (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Symbol)


108
109
110
111
112
113
114
115
116
# File 'lib/vedeu/cursors/reposition.rb', line 108

def mode
  @mode = if modes.include?(@mode)
            @mode

          else
            defaults[:mode]

          end
end

#modesArray<Symbol> (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Positioning is handled either with absolute or relative coordinates, the coordinates are checked against the geometry of the interface/view and altered to reside within the boundary defined.

Returns:

  • (Array<Symbol>)


124
125
126
# File 'lib/vedeu/cursors/reposition.rb', line 124

def modes
  [:relative, :absolute]
end

#new_attributesHash<Symbol => Fixnum> (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Hash<Symbol => Fixnum>)


129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/vedeu/cursors/reposition.rb', line 129

def new_attributes
  if absolute? && inside_geometry?
    cursor.attributes.merge!(absolute)

  elsif relative?
    cursor.attributes.merge!(relative)

  else
    cursor.attributes

  end
end

#relativeHash<Symbol => Fixnum> (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Hash<Symbol => Fixnum>)


143
144
145
146
147
148
149
150
# File 'lib/vedeu/cursors/reposition.rb', line 143

def relative
  {
    x:  coordinate(x, :x).x,
    y:  coordinate(y, :y).y,
    ox: x,
    oy: y,
  }
end

#relative?Boolean (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:



153
154
155
# File 'lib/vedeu/cursors/reposition.rb', line 153

def relative?
  mode == :relative
end

#repositionVedeu::Cursors::Cursor

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



31
32
33
34
35
# File 'lib/vedeu/cursors/reposition.rb', line 31

def reposition
  Vedeu::Cursors::Cursor.store(new_attributes) do
    Vedeu.trigger(:_refresh_cursor_, name)
  end
end