Class: Vedeu::Geometry
- Inherits:
-
Object
show all
- Extended by:
- Forwardable
- Includes:
- Model
- Defined in:
- lib/vedeu/geometry/geometry.rb
Overview
TODO:
Consider storing the Terminal size at the time of first creation,
this allows us to return the interface to its original dimensions if the terminal resizes back to normal size.
Calculates and provides interface geometry determined by both the client’s requirements and the terminal’s current viewing area.
Geometry for Vedeu, as the same for ANSI terminals, has the origin at top-left, y = 1, x = 1. The ‘y’ coordinate is deliberately first.
x north xn # north: y - 1
y +--------------+ # top: y
| top | # west: x - 1
| | # left: x
west | left right | east # right: xn
| | # east: xn + 1
| bottom | # bottom: yn
yn +--------------+ # south: yn + 1
south
Instance Attribute Summary collapse
Attributes included from Model
#repository
Instance Method Summary
collapse
Methods included from Model
#demodulize, #deputy, #dsl_class, included, #store
Constructor Details
#initialize(attributes = {}) ⇒ Vedeu::Geometry
Returns a new instance of Vedeu::Geometry.
100
101
102
103
104
|
# File 'lib/vedeu/geometry/geometry.rb', line 100
def initialize(attributes = {})
@attributes = defaults.merge!(attributes)
@attributes.each { |key, value| instance_variable_set("@#{key}", value) }
end
|
Instance Attribute Details
#attributes ⇒ Hash
55
56
57
|
# File 'lib/vedeu/geometry/geometry.rb', line 55
def attributes
@attributes
end
|
#centred ⇒ Boolean
47
48
49
|
# File 'lib/vedeu/geometry/geometry.rb', line 47
def centred
@centred
end
|
#height=(value) ⇒ Fixnum
59
60
61
|
# File 'lib/vedeu/geometry/geometry.rb', line 59
def height=(value)
@height = value
end
|
#maximised ⇒ Boolean
Also known as:
maximised?
63
64
65
|
# File 'lib/vedeu/geometry/geometry.rb', line 63
def maximised
@maximised
end
|
#name ⇒ String
51
52
53
|
# File 'lib/vedeu/geometry/geometry.rb', line 51
def name
@name
end
|
#width=(value) ⇒ Fixnum
68
69
70
|
# File 'lib/vedeu/geometry/geometry.rb', line 68
def width=(value)
@width = value
end
|
#x=(value) ⇒ Fixnum
72
73
74
|
# File 'lib/vedeu/geometry/geometry.rb', line 72
def x=(value)
@x = value
end
|
#xn=(value) ⇒ Fixnum
76
77
78
|
# File 'lib/vedeu/geometry/geometry.rb', line 76
def xn=(value)
@xn = value
end
|
#y=(value) ⇒ Fixnum
80
81
82
|
# File 'lib/vedeu/geometry/geometry.rb', line 80
def y=(value)
@y = value
end
|
#yn=(value) ⇒ Fixnum
84
85
86
|
# File 'lib/vedeu/geometry/geometry.rb', line 84
def yn=(value)
@yn = value
end
|
Instance Method Details
#_x ⇒ Fixnum
Returns the column/character start position for the interface.
203
204
205
|
# File 'lib/vedeu/geometry/geometry.rb', line 203
def _x
@x.is_a?(Proc) ? @x.call : @x
end
|
#_xn ⇒ Fixnum
Returns the column/character end position for the interface.
210
211
212
|
# File 'lib/vedeu/geometry/geometry.rb', line 210
def _xn
@xn.is_a?(Proc) ? @xn.call : @xn
end
|
#_y ⇒ Fixnum
Returns the row/line start position for the interface.
189
190
191
|
# File 'lib/vedeu/geometry/geometry.rb', line 189
def _y
@y.is_a?(Proc) ? @y.call : @y
end
|
#_yn ⇒ Fixnum
Returns the row/line end position for the interface.
196
197
198
|
# File 'lib/vedeu/geometry/geometry.rb', line 196
def _yn
@yn.is_a?(Proc) ? @yn.call : @yn
end
|
142
143
144
|
# File 'lib/vedeu/geometry/geometry.rb', line 142
def area
@area = Vedeu::Area.from_dimensions(y_yn: y_yn, x_xn: x_xn)
end
|
#defaults ⇒ Hash
215
216
217
218
219
220
221
222
223
224
225
226
227
228
|
# File 'lib/vedeu/geometry/geometry.rb', line 215
def defaults
{
centred: nil,
height: nil,
maximised: false,
name: nil,
repository: Vedeu.geometries,
width: nil,
x: nil,
xn: nil,
y: nil,
yn: nil,
}
end
|
#dimension_options ⇒ Hash<Symbol => Boolean>
169
170
171
172
173
174
|
# File 'lib/vedeu/geometry/geometry.rb', line 169
def dimension_options
{
centred: centred,
maximised: maximised,
}
end
|
#height_attributes ⇒ Hash<Symbol => Fixnum, Hash]
Returns Hash<Symbol => Fixnum, Hash].
147
148
149
150
151
152
153
154
155
|
# File 'lib/vedeu/geometry/geometry.rb', line 147
def height_attributes
{
d: _y,
dn: _yn,
d_dn: @height,
default: Vedeu::Terminal.height,
options: dimension_options,
}
end
|
#inspect ⇒ String
107
108
109
|
# File 'lib/vedeu/geometry/geometry.rb', line 107
def inspect
"<Vedeu::Geometry x:#{x} xn:#{xn} y:#{y} yn:#{yn} maximise:#{maximised}>"
end
|
112
113
114
115
116
117
118
119
120
121
122
|
# File 'lib/vedeu/geometry/geometry.rb', line 112
def maximise
unless maximised?
@maximised = true
work = store
Vedeu.trigger(:_refresh_, name)
work
end
end
|
125
126
127
128
129
130
131
132
133
134
135
136
137
|
# File 'lib/vedeu/geometry/geometry.rb', line 125
def unmaximise
if maximised?
Vedeu.trigger(:_clear_, name)
@maximised = false
work = store
Vedeu.trigger(:_refresh_, name)
work
end
end
|
#width_attributes ⇒ Hash<Symbol => Fixnum, Hash]
Returns Hash<Symbol => Fixnum, Hash].
158
159
160
161
162
163
164
165
166
|
# File 'lib/vedeu/geometry/geometry.rb', line 158
def width_attributes
{
d: _x,
dn: _xn,
d_dn: @width,
default: Vedeu::Terminal.width,
options: dimension_options,
}
end
|
#x_xn ⇒ Array<Fixnum>
177
178
179
|
# File 'lib/vedeu/geometry/geometry.rb', line 177
def x_xn
@x_xn = Vedeu::Dimension.pair(width_attributes)
end
|
#y_yn ⇒ Array<Fixnum>
182
183
184
|
# File 'lib/vedeu/geometry/geometry.rb', line 182
def y_yn
@y_yn = Vedeu::Dimension.pair(height_attributes)
end
|