Class: Vedeu::Geometry
- Inherits:
-
Object
- Object
- Vedeu::Geometry
- Includes:
- Model
- Defined in:
- lib/vedeu/models/geometry.rb
Overview
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 ⇒ Object
readonly
Returns the value of attribute attributes.
-
#centred ⇒ Object
Returns the value of attribute centred.
- #height ⇒ Object
-
#name ⇒ Object
Returns the value of attribute name.
-
#width ⇒ Fixnum
Returns a dynamic value calculated from the current terminal dimensions, combined with the desired start point.
-
#x ⇒ Fixnum
Returns the column/character start position for the interface.
-
#y ⇒ Fixnum
Returns the row/line start position for the interface.
Attributes included from Model
Instance Method Summary collapse
-
#bottom ⇒ Fixnum
Returns the bottom coordinate of the interface, a fixed or dynamic value depending on the value of #top.
-
#defaults ⇒ Hash
private
The default values for a new instance of this class.
-
#east(value = 1) ⇒ Fixnum
Returns the column after right by default.
-
#initialize(attributes = {}) ⇒ Geometry
constructor
Returns a new instance of Geometry.
-
#left ⇒ Fixnum
Returns the left coordinate of the interface, a fixed or dynamic value depending on whether the interface is centred or not.
-
#north(value = 1) ⇒ Fixnum
Returns the row above the top by default.
-
#right ⇒ Fixnum
Returns the right coordinate of the interface, a fixed or dynamic value depending on the value of #left.
-
#south(value = 1) ⇒ Fixnum
Returns the row below the bottom by default.
-
#top ⇒ Fixnum
Returns the top coordinate of the interface, a fixed or dynamic value depending on whether the interface is centred or not.
-
#west(value = 1) ⇒ Fixnum
Returns the column before left by default.
-
#xn ⇒ Fixnum
Returns the column/character end position for the interface.
-
#yn ⇒ Fixnum
Returns the row/line end position for the interface.
Methods included from Model
#demodulize, #deputy, #dsl_class, included, #store
Constructor Details
#initialize(attributes = {}) ⇒ Geometry
Returns a new instance of Geometry.
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/vedeu/models/geometry.rb', line 50 def initialize(attributes = {}) @attributes = defaults.merge!(attributes) @centred = @attributes[:centred] @height = @attributes[:height] @name = @attributes[:name] @width = @attributes[:width] @x = @attributes[:x] @xn = @attributes[:xn] @y = @attributes[:y] @yn = @attributes[:yn] @repository = Vedeu.geometries end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
35 36 37 |
# File 'lib/vedeu/models/geometry.rb', line 35 def attributes @attributes end |
#centred ⇒ Object
Returns the value of attribute centred.
34 35 36 |
# File 'lib/vedeu/models/geometry.rb', line 34 def centred @centred end |
#height ⇒ Object
131 132 133 |
# File 'lib/vedeu/models/geometry.rb', line 131 def height @height end |
#name ⇒ Object
Returns the value of attribute name.
34 35 36 |
# File 'lib/vedeu/models/geometry.rb', line 34 def name @name end |
#width ⇒ Fixnum
Returns a dynamic value calculated from the current terminal dimensions, combined with the desired start point.
If the interface is ‘centred` then if the terminal resizes, this value should attempt to accommodate that.
For uncentred interfaces, when the terminal resizes, then this will help Vedeu render the view to ensure the content is not off-screen.
126 127 128 |
# File 'lib/vedeu/models/geometry.rb', line 126 def width @width end |
#x ⇒ Fixnum
Returns the column/character start position for the interface.
93 94 95 96 97 98 99 100 101 |
# File 'lib/vedeu/models/geometry.rb', line 93 def x if @x.is_a?(Proc) @x.call else @x end end |
#y ⇒ Fixnum
Returns the row/line start position for the interface.
67 68 69 70 71 72 73 74 75 |
# File 'lib/vedeu/models/geometry.rb', line 67 def y if @y.is_a?(Proc) @y.call else @y end end |
Instance Method Details
#bottom ⇒ Fixnum
Returns the bottom coordinate of the interface, a fixed or dynamic value depending on the value of #top.
203 204 205 |
# File 'lib/vedeu/models/geometry.rb', line 203 def bottom top + height end |
#defaults ⇒ Hash (private)
The default values for a new instance of this class.
250 251 252 253 254 255 256 257 258 259 260 261 262 |
# File 'lib/vedeu/models/geometry.rb', line 250 def defaults { centred: false, client: nil, height: Terminal.height, name: '', width: Terminal.width, x: 1, xn: Terminal.width, y: 1, yn: Terminal.height, } end |
#east(value = 1) ⇒ Fixnum
Returns the column after right by default.
241 242 243 |
# File 'lib/vedeu/models/geometry.rb', line 241 def east(value = 1) right + value end |
#left ⇒ Fixnum
Division which results in a non-integer will be rounded down.
Returns the left coordinate of the interface, a fixed or dynamic value depending on whether the interface is centred or not.
174 175 176 177 178 179 180 181 182 |
# File 'lib/vedeu/models/geometry.rb', line 174 def left if centred Terminal.centre_x - (width / 2) else x end end |
#north(value = 1) ⇒ Fixnum
Returns the row above the top by default.
163 164 165 |
# File 'lib/vedeu/models/geometry.rb', line 163 def north(value = 1) top - value end |
#right ⇒ Fixnum
Returns the right coordinate of the interface, a fixed or dynamic value depending on the value of #left.
226 227 228 |
# File 'lib/vedeu/models/geometry.rb', line 226 def right left + width end |
#south(value = 1) ⇒ Fixnum
Returns the row below the bottom by default.
218 219 220 |
# File 'lib/vedeu/models/geometry.rb', line 218 def south(value = 1) bottom + value end |
#top ⇒ Fixnum
Division which results in a non-integer will be rounded down.
Returns the top coordinate of the interface, a fixed or dynamic value depending on whether the interface is centred or not.
142 143 144 145 146 147 148 149 150 |
# File 'lib/vedeu/models/geometry.rb', line 142 def top if centred Terminal.centre_y - (height / 2) else y end end |
#west(value = 1) ⇒ Fixnum
Returns the column before left by default.
195 196 197 |
# File 'lib/vedeu/models/geometry.rb', line 195 def west(value = 1) left - value end |
#xn ⇒ Fixnum
Returns the column/character end position for the interface.
106 107 108 109 110 111 112 113 114 |
# File 'lib/vedeu/models/geometry.rb', line 106 def xn if @xn.is_a?(Proc) @xn.call else @xn end end |
#yn ⇒ Fixnum
Returns the row/line end position for the interface.
80 81 82 83 84 85 86 87 88 |
# File 'lib/vedeu/models/geometry.rb', line 80 def yn if @yn.is_a?(Proc) @yn.call else @yn end end |