Class: Vedeu::Geometry
- Inherits:
-
Object
- Object
- Vedeu::Geometry
- Defined in:
- lib/vedeu/models/geometry.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#centred ⇒ Object
readonly
Returns the value of attribute centred.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
- #bottom ⇒ Fixnum
- #defaults ⇒ Hash private
-
#east(value = 1) ⇒ Fixnum
Returns the column after right by default.
-
#initialize(attributes = {}) ⇒ Geometry
constructor
Calculate and provide interface geometry determined by both the client’s requirements and the terminal’s current viewing area.
-
#left ⇒ Fixnum
Returns 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.
-
#origin(index = 0, &block) ⇒ String
Returns the top-left coordinate, relative to the interface’s position.
-
#right ⇒ Fixnum
Returns a fixed or dynamic value depending on whether the interface is centred or not.
-
#south(value = 1) ⇒ Fixnum
Returns the row below the bottom by default.
-
#top ⇒ Fixnum
Returns a fixed or dynamic value depending on whether the interface is centred or not.
-
#viewport_height ⇒ Fixnum
Returns a dynamic value calculated from the current terminal height, combined with the desired row start point.
-
#viewport_width ⇒ Fixnum
Returns a dynamic value calculated from the current terminal width, combined with the desired column start point.
-
#virtual_x ⇒ Array
private
Provides a virtual x position within the interface’s dimensions.
-
#virtual_y ⇒ Array
private
Provides a virtual y position within the interface’s dimensions.
-
#west(value = 1) ⇒ Fixnum
Returns the column before left by default.
-
#x ⇒ Fixnum
Returns the column position for the interface.
-
#y ⇒ Fixnum
Returns the row/line position for the interface.
Constructor Details
#initialize(attributes = {}) ⇒ Geometry
Calculate and provide interface geometry determined by both the client’s requirements and the terminal’s current viewing area.
11 12 13 14 15 16 17 |
# File 'lib/vedeu/models/geometry.rb', line 11 def initialize(attributes = {}) @attributes = defaults.merge!(attributes) @centred = @attributes[:centred] @height = @attributes[:height] @width = @attributes[:width] end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
4 5 6 |
# File 'lib/vedeu/models/geometry.rb', line 4 def attributes @attributes end |
#centred ⇒ Object (readonly)
Returns the value of attribute centred.
4 5 6 |
# File 'lib/vedeu/models/geometry.rb', line 4 def centred @centred end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
4 5 6 |
# File 'lib/vedeu/models/geometry.rb', line 4 def height @height end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
4 5 6 |
# File 'lib/vedeu/models/geometry.rb', line 4 def width @width end |
Instance Method Details
#bottom ⇒ Fixnum
154 155 156 |
# File 'lib/vedeu/models/geometry.rb', line 154 def bottom top + height end |
#defaults ⇒ Hash (private)
213 214 215 216 217 218 219 220 221 |
# File 'lib/vedeu/models/geometry.rb', line 213 def defaults { y: 1, x: 1, width: Terminal.width, height: Terminal.height, centred: false, } end |
#east(value = 1) ⇒ Fixnum
Returns the column after right by default.
192 193 194 |
# File 'lib/vedeu/models/geometry.rb', line 192 def east(value = 1) right + value end |
#left ⇒ Fixnum
Returns a fixed or dynamic value depending on whether the interface is centred or not.
128 129 130 131 132 133 134 135 136 |
# File 'lib/vedeu/models/geometry.rb', line 128 def left if centred Terminal.centre_x - ( / 2) else x end end |
#north(value = 1) ⇒ Fixnum
Returns the row above the top by default.
120 121 122 |
# File 'lib/vedeu/models/geometry.rb', line 120 def north(value = 1) top - value end |
#origin(index = 0, &block) ⇒ String
Returns the top-left coordinate, relative to the interface’s position.
91 92 93 |
# File 'lib/vedeu/models/geometry.rb', line 91 def origin(index = 0, &block) Esc.set_position(virtual_y[index], left, &block) end |
#right ⇒ Fixnum
Returns a fixed or dynamic value depending on whether the interface is centred or not.
177 178 179 |
# File 'lib/vedeu/models/geometry.rb', line 177 def right left + width end |
#south(value = 1) ⇒ Fixnum
Returns the row below the bottom by default.
169 170 171 |
# File 'lib/vedeu/models/geometry.rb', line 169 def south(value = 1) bottom + value end |
#top ⇒ Fixnum
Returns a fixed or dynamic value depending on whether the interface is centred or not.
99 100 101 102 103 104 105 106 107 |
# File 'lib/vedeu/models/geometry.rb', line 99 def top if centred Terminal.centre_y - ( / 2) else y end end |
#viewport_height ⇒ Fixnum
Returns a dynamic value calculated from the current terminal height, combined with the desired row 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.
76 77 78 79 80 81 82 83 84 |
# File 'lib/vedeu/models/geometry.rb', line 76 def if (y + height) > Terminal.height height - ((y + height) - Terminal.height) else height end end |
#viewport_width ⇒ Fixnum
Returns a dynamic value calculated from the current terminal width, combined with the desired column 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 no row/line overruns or that the content is not off-screen.
56 57 58 59 60 61 62 63 64 |
# File 'lib/vedeu/models/geometry.rb', line 56 def if (x + width) > Terminal.width width - ((x + width) - Terminal.width) else width end end |
#virtual_x ⇒ Array (private)
Provides a virtual x position within the interface’s dimensions.
208 209 210 |
# File 'lib/vedeu/models/geometry.rb', line 208 def virtual_x (left..right).to_a end |
#virtual_y ⇒ Array (private)
Provides a virtual y position within the interface’s dimensions.
201 202 203 |
# File 'lib/vedeu/models/geometry.rb', line 201 def virtual_y (top..bottom).to_a end |
#west(value = 1) ⇒ Fixnum
Returns the column before left by default.
149 150 151 |
# File 'lib/vedeu/models/geometry.rb', line 149 def west(value = 1) left - value end |
#x ⇒ Fixnum
Returns the column position for the interface.
35 36 37 38 39 40 41 42 43 |
# File 'lib/vedeu/models/geometry.rb', line 35 def x if attributes[:x].is_a?(Proc) attributes[:x].call else attributes[:x] end end |
#y ⇒ Fixnum
Returns the row/line position for the interface.
22 23 24 25 26 27 28 29 30 |
# File 'lib/vedeu/models/geometry.rb', line 22 def y if attributes[:y].is_a?(Proc) attributes[:y].call else attributes[:y] end end |