Class: Vedeu::Cursors::Reposition Private
- Inherits:
-
Object
- Object
- Vedeu::Cursors::Reposition
- 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
-
#name ⇒ NilClass|Symbol|String
readonly
protected
private
The name of the model, the target model or the name of the associated model.
- #x ⇒ Fixnum readonly protected private
- #y ⇒ Fixnum readonly protected private
Instance Method Summary collapse
- #absolute ⇒ Hash<Symbol => Fixnum> private private
- #absolute? ⇒ Boolean private private
-
#coordinate(offset, type) ⇒ Vedeu::Cursors::Coordinate
private
private
Determine correct x and y related coordinates.
- #cursor ⇒ Vedeu::Cursors::Cursor private private
-
#defaults ⇒ Hash<Symbol => void>
private
private
The default options/attributes for a new instance of this class.
-
#geometry ⇒ Vedeu::Geometries::Geometry
private
private
Returns the named geometry from the geometries repository.
-
#initialize(attributes = {}) ⇒ Vedeu::Cursors::Reposition
constructor
private
Returns a new instance of Vedeu::Cursors::Reposition.
- #inside_geometry? ⇒ Boolean private private
- #mode ⇒ Symbol private private
-
#modes ⇒ Array<Symbol>
private
private
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.
- #new_attributes ⇒ Hash<Symbol => Fixnum> private private
- #relative ⇒ Hash<Symbol => Fixnum> private private
- #relative? ⇒ Boolean private private
- #reposition ⇒ Vedeu::Cursors::Cursor private
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.
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
#name ⇒ NilClass|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.
41 42 43 |
# File 'lib/vedeu/cursors/reposition.rb', line 41 def name @name end |
#x ⇒ Fixnum (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.
45 46 47 |
# File 'lib/vedeu/cursors/reposition.rb', line 45 def x @x end |
#y ⇒ Fixnum (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.
49 50 51 |
# File 'lib/vedeu/cursors/reposition.rb', line 49 def y @y end |
Instance Method Details
#absolute ⇒ Hash<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.
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.
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.
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 |
#cursor ⇒ Vedeu::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 |
#defaults ⇒ Hash<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.
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 |
#geometry ⇒ Vedeu::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.
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 |
#mode ⇒ 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.
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 |
#modes ⇒ Array<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.
124 125 126 |
# File 'lib/vedeu/cursors/reposition.rb', line 124 def modes [:relative, :absolute] end |
#new_attributes ⇒ Hash<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.
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 |
#relative ⇒ Hash<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.
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.
153 154 155 |
# File 'lib/vedeu/cursors/reposition.rb', line 153 def relative? mode == :relative end |
#reposition ⇒ Vedeu::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 |