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.



22
23
24
25
26
# File 'lib/vedeu/cursors/reposition.rb', line 22

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

Instance Attribute Details

#nameString|Symbol (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:

  • (String|Symbol)


39
40
41
# File 'lib/vedeu/cursors/reposition.rb', line 39

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)


43
44
45
# File 'lib/vedeu/cursors/reposition.rb', line 43

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)


47
48
49
# File 'lib/vedeu/cursors/reposition.rb', line 47

def y
  @y
end

Instance Method Details

#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:

  • (Boolean)


52
53
54
# File 'lib/vedeu/cursors/reposition.rb', line 52

def absolute?
  mode == :absolute
end

#coordinate(offset, type) ⇒ Vedeu::Geometry::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
  • type

Returns:



61
62
63
# File 'lib/vedeu/cursors/reposition.rb', line 61

def coordinate(offset, type)
  Vedeu::Geometry::Coordinate.new(name: name, 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.



66
67
68
# File 'lib/vedeu/cursors/reposition.rb', line 66

def cursor
  Vedeu.cursors.by_name(name)
end

#defaultsHash<Symbol => Fixnum|Symbol|String] (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|Symbol|String].

Returns:

  • (Hash<Symbol => Fixnum|Symbol|String])

    Hash<Symbol => Fixnum|Symbol|String]



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

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

#geometryVedeu::Geometry::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.



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

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:

  • (Boolean)


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

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)


94
95
96
97
98
99
100
101
102
# File 'lib/vedeu/cursors/reposition.rb', line 94

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>)


110
111
112
# File 'lib/vedeu/cursors/reposition.rb', line 110

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>)


115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/vedeu/cursors/reposition.rb', line 115

def new_attributes
  if absolute? && inside_geometry?
    cursor.attributes.merge!(x:  coordinate((x - geometry.x), :x).x,
                             y:  coordinate((y - geometry.y), :y).y,
                             ox: 0,
                             oy: 0)

  elsif relative?
    cursor.attributes.merge!(x:  coordinate(x, :x).x,
                             y:  coordinate(y, :y).y,
                             ox: x,
                             oy: y)

  else
    cursor.attributes

  end
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:

  • (Boolean)


135
136
137
# File 'lib/vedeu/cursors/reposition.rb', line 135

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.



29
30
31
32
33
# File 'lib/vedeu/cursors/reposition.rb', line 29

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