Class: Vedeu::Geometry::Move Private

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/vedeu/geometry/move.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.

Move an interface/view via changing its geometry.

When moving an interface/view;

1) Reset the alignment and maximised states to false;

it wont be aligned to a side if moved, and cannot be moved
if maximised.

2) Get the current coordinates of the interface, then: 3) Override the attributes with the new coordinates for

desired movement; these are usually +/- 1 of the current
state, depending on direction.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Vedeu::Geometry::Move

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::Geometry::Move.

Parameters:

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

    ttributes [Hash<Symbol => Boolean|Fixnum|String| Symbol|Vedeu::Geometry::Repository]

Options Hash (attributes):

  • name (String|Symbol)

    The name of the interface/view.

  • direction (Symbol)

    The direction to move; one of: :down, :left, :origin, :right, :up.

  • offset (Fixnum)

    The number of columns or rows to move by.



46
47
48
49
50
# File 'lib/vedeu/geometry/move.rb', line 46

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

Instance Attribute Details

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

  • (Symbol)


66
67
68
# File 'lib/vedeu/geometry/move.rb', line 66

def direction
  @direction
end

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


70
71
72
# File 'lib/vedeu/geometry/move.rb', line 70

def name
  @name
end

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

  • (Symbol)


74
75
76
# File 'lib/vedeu/geometry/move.rb', line 74

def offset
  @offset
end

Class Method Details

.move(attributes = {}) ⇒ Object

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 See #move.

Parameters:

  • attributes (defaults to: {})

    See #initialize

Returns:

  • See #move



31
32
33
# File 'lib/vedeu/geometry/move.rb', line 31

def self.move(attributes = {})
  new(attributes).move
end

Instance Method Details

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

Returns:

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


79
80
81
82
83
84
85
# File 'lib/vedeu/geometry/move.rb', line 79

def defaults
  {
    direction: :none,
    name:      '',
    offset:    1,
  }
end

#direction?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)


88
89
90
# File 'lib/vedeu/geometry/move.rb', line 88

def direction?
  direction != :none
end

#downHash<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.

Moves the geometry down by the offset.

Returns:

  • (Hash<Symbol => Fixnum])

    Hash<Symbol => Fixnum]



95
96
97
98
99
100
# File 'lib/vedeu/geometry/move.rb', line 95

def down
  {
    y: y + offset,
    yn: yn + offset,
  }
end

#eventHash<Symbol => 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.

Returns:

  • (Hash<Symbol => Symbol>)


103
104
105
106
107
108
109
110
111
# File 'lib/vedeu/geometry/move.rb', line 103

def event
  {
    down:   :_cursor_down_,
    left:   :_cursor_left_,
    origin: :_cursor_origin_,
    right:  :_cursor_right_,
    up:     :_cursor_up_,
  }[direction]
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.



114
115
116
# File 'lib/vedeu/geometry/move.rb', line 114

def geometry
  Vedeu.geometries.by_name(name)
end

#leftHash<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.

Moves the geometry left by the offset.

Returns:

  • (Hash<Symbol => Fixnum])

    Hash<Symbol => Fixnum]



121
122
123
124
125
126
# File 'lib/vedeu/geometry/move.rb', line 121

def left
  {
    x: x - offset,
    xn: xn - offset,
  }
end

#moveFalseClass|Vedeu::Geometry::Geometry

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:



53
54
55
56
57
58
59
60
# File 'lib/vedeu/geometry/move.rb', line 53

def move
  return false unless valid?

  Vedeu::Geometry::Geometry.store(new_attributes) do
    update_cursor!
    refresh!
  end
end

#new_attributesHash<Symbol => Boolean|String|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.

Returns:

  • (Hash<Symbol => Boolean|String|Symbol>)


129
130
131
# File 'lib/vedeu/geometry/move.rb', line 129

def new_attributes
  geometry.attributes.merge!(unalign_unmaximise).merge!(send(direction))
end

#originHash<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.

Moves the geometry to the top left of the terminal.

Returns:

  • (Hash<Symbol => Fixnum])

    Hash<Symbol => Fixnum]



136
137
138
139
140
141
142
143
# File 'lib/vedeu/geometry/move.rb', line 136

def origin
  {
    x:  1,
    xn: (xn - x + 1),
    y:  1,
    yn: (yn - y + 1),
  }
end

#refresh!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.

This method returns an undefined value.

Refresh the screen after moving.



148
149
150
# File 'lib/vedeu/geometry/move.rb', line 148

def refresh!
  Vedeu.trigger(:_movement_refresh_, name)
end

#rightHash<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.

Moves the geometry right by the offset.

Returns:

  • (Hash<Symbol => Fixnum])

    Hash<Symbol => Fixnum]



155
156
157
158
159
160
# File 'lib/vedeu/geometry/move.rb', line 155

def right
  {
    x: x + offset,
    xn: xn + offset,
  }
end

#unalign_unmaximiseHash<Symbol => Boolean|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.

Returns Hash<Symbol => Boolean|Symbol].

Returns:

  • (Hash<Symbol => Boolean|Symbol])

    Hash<Symbol => Boolean|Symbol]



163
164
165
166
167
168
169
# File 'lib/vedeu/geometry/move.rb', line 163

def unalign_unmaximise
  {
    horizontal_alignment: :none,
    maximised:            false,
    vertical_alignment:   :none,
  }
end

#upHash<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.

Moves the geometry up by the offset.

Returns:

  • (Hash<Symbol => Fixnum])

    Hash<Symbol => Fixnum]



174
175
176
177
178
179
# File 'lib/vedeu/geometry/move.rb', line 174

def up
  {
    y: y - offset,
    yn: yn - offset,
  }
end

#update_cursor!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.

This method returns an undefined value.

Refresh the cursor after moving.



184
185
186
# File 'lib/vedeu/geometry/move.rb', line 184

def update_cursor!
  Vedeu.trigger(event, name)
end

#valid?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)


189
190
191
192
193
194
195
196
197
# File 'lib/vedeu/geometry/move.rb', line 189

def valid?
  {
    down:   valid_down?,
    left:   valid_left?,
    origin: true,
    right:  valid_right?,
    up:     valid_up?,
  }.fetch(direction, false)
end

#valid_down?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)


200
201
202
# File 'lib/vedeu/geometry/move.rb', line 200

def valid_down?
  yn + offset <= Vedeu.height
end

#valid_left?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)


205
206
207
# File 'lib/vedeu/geometry/move.rb', line 205

def valid_left?
  x - offset >= 1
end

#valid_right?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)


210
211
212
# File 'lib/vedeu/geometry/move.rb', line 210

def valid_right?
  xn + offset <= Vedeu.width
end

#valid_up?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)


215
216
217
# File 'lib/vedeu/geometry/move.rb', line 215

def valid_up?
  y - offset >= 1
end