Class: Vedeu::Geometry::DSL
- Inherits:
-
Object
- Object
- Vedeu::Geometry::DSL
- Defined in:
- lib/vedeu/geometry/dsl.rb
Overview
Geometry allows the configuration of the position and size of an interface. Within Vedeu, as the same for ANSI terminals, has the origin at top-left, y = 1, x = 1. The ‘y’ coordinate is deliberately first.
The Geometry DSL can be used within the Interface DSL or standalone. Here are example of declarations for a ‘geometry` block:
A standalone geometry definition:
Vedeu.geometry :some_interface do
height 5 # Sets the height of the view to 5
width 20 # Sets the width of the view to 20
x 3 # Start drawing 3 spaces from left
y 10 # Start drawing 10 spaces from top
xn 30 # Stop drawing 30 spaces from the left
yn 20 # Stop drawing 20 spaces from top
end
An interface including a geometry definition:
Vedeu.interface :some_interface do
geometry do
height 5
width 20
x 3
y 10
xn 30
yn 20
end
# ... some code here
end
If a declaration is omitted for ‘height` or `width` the full remaining space available in the terminal will be used. `x` and `y` both default to 1.
You can also make a geometry declaration dependent on another view:
Vedeu.interface :other_panel do
# ... some code here
end
Vedeu.interface :main do
geometry do
height 10
y { use(:other_panel).south }
end
# ... some code here
end
This view will begin just below “other_panel”.
This crude ASCII diagram represents a Geometry within Vedeu, each of the labels is a value you can access or define.
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
-
#client ⇒ Object
included
from DSL
readonly
protected
The object instance where the DSL is being used.
-
#model ⇒ void
included
from DSL
readonly
protected
The new model object which the DSL is constructing.
Class Method Summary collapse
-
.geometry(name, &block) ⇒ Vedeu::Geometry::Geometry
Specify the geometry of an interface or view with a simple DSL.
Instance Method Summary collapse
-
#absent?(variable) ⇒ Boolean
included
from Common
Returns a boolean indicating whether a variable is nil or empty.
-
#align_centre(width) ⇒ Vedeu::Geometry::Geometry
(also: #align_center)
Align the interface/view centrally.
-
#align_left(width) ⇒ Vedeu::Geometry::Geometry
Align the interface/view to the left.
-
#align_right(width) ⇒ Vedeu::Geometry::Geometry
Align the interface/view to the right.
-
#alignment(value, width) ⇒ Vedeu::Geometry::Geometry
Instructs Vedeu to align the interface/view either left, centre or right.
-
#attributes ⇒ Hash<Symbol => void>
included
from DSL
private
Returns the default attributes for the new model.
-
#centred(value = true) ⇒ Boolean
(also: #centred!, #centred=)
Instructs Vedeu to calculate x and y geometry automatically based on the centre character of the terminal, the width and the height.
-
#columns(value) ⇒ Fixnum|Vedeu::Error::OutOfRange
Returns the width in characters for the number of columns specified.
-
#demodulize(klass) ⇒ String
included
from Common
Removes the module part from the expression in the string.
-
#height(value) ⇒ Fixnum
(also: #height=)
Specify the number of characters/rows/lines tall the interface will be.
-
#initialize(model, client = nil) ⇒ void
included
from DSL
Returns an instance of the DSL class including DSL.
-
#method_missing(method, *args, &block) ⇒ void
included
from DSL
private
Attempts to find the missing method on the client object.
-
#present?(variable) ⇒ Boolean
included
from Common
Returns a boolean indicating whether a variable has a useful value.
-
#rows(value) ⇒ Fixnum
Returns the height in characters for the number of rows specified.
-
#snake_case(name) ⇒ String
included
from Common
Converts a class name to a lowercase snake case string.
-
#use(name) ⇒ void
included
from DSL::Use
Use the attribute of stored model.
-
#width(value) ⇒ Fixnum
(also: #width=)
Specify the number of characters/columns wide the interface will be.
-
#x(value = 1, &block) ⇒ Fixnum
(also: #x=)
Specify the starting x position (column) of the interface.
-
#xn(value = 1, &block) ⇒ Fixnum
(also: #xn=)
Specify the ending x position (column) of the interface.
-
#y(value = 1, &block) ⇒ Fixnum
(also: #y=)
Specify the starting y position (row/line) of the interface.
-
#yn(value = 1, &block) ⇒ Fixnum
(also: #yn=)
Specify the ending y position (row/line) of the interface.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Vedeu::DSL
Instance Attribute Details
#client ⇒ Object (readonly, protected) Originally defined in module DSL
Returns The object instance where the DSL is being used.
#model ⇒ void (readonly, protected) Originally defined in module DSL
This method returns an undefined value.
Returns The new model object which the DSL is constructing.
Class Method Details
.geometry(name, &block) ⇒ Vedeu::Geometry::Geometry
Specify the geometry of an interface or view with a simple DSL.
Vedeu.geometry :some_interface do
# ...
end
92 93 94 95 96 |
# File 'lib/vedeu/geometry/dsl.rb', line 92 def self.geometry(name, &block) fail Vedeu::Error::RequiresBlock unless block_given? Vedeu::Geometry::Geometry.build(name: name, &block).store end |
Instance Method Details
#absent?(variable) ⇒ Boolean Originally defined in module Common
Returns a boolean indicating whether a variable is nil or empty.
#align_centre(width) ⇒ Vedeu::Geometry::Geometry Also known as: align_center
Align the interface/view centrally.
Vedeu.geometry :some_interface do
# `width` is a positive integer, e.g. 30
align_centre 30
# this is the same as:
# alignment(:centre, 30)
# ... some code
end
# Also allows `align_center` if preferred.
147 148 149 |
# File 'lib/vedeu/geometry/dsl.rb', line 147 def align_centre(width) alignment(:centre, width) end |
#align_left(width) ⇒ Vedeu::Geometry::Geometry
Align the interface/view to the left.
Vedeu.geometry :some_interface do
# `width` is a positive integer, e.g. 30
align_left 30
# this is the same as:
# alignment(:left, 30)
# ... some code
end
168 169 170 |
# File 'lib/vedeu/geometry/dsl.rb', line 168 def align_left(width) alignment(:left, width) end |
#align_right(width) ⇒ Vedeu::Geometry::Geometry
Align the interface/view to the right.
Vedeu.geometry :some_interface do
# `width` is a positive integer, e.g. 30
align_right 30
# this is the same as:
# alignment(:right, 30)
# ... some code
end
188 189 190 |
# File 'lib/vedeu/geometry/dsl.rb', line 188 def align_right(width) alignment(:right, width) end |
#alignment(value, width) ⇒ Vedeu::Geometry::Geometry
Instructs Vedeu to align the interface/view either left, centre or right. A width is also required so that required coordinates are calculated correctly.
Vedeu.geometry :some_interface do
# :some_value must be one of: :left, :none, :center,
# :centre, or :right
# `width` is a positive integer, e.g. 30
alignment(:some_value, width)
# ... some code
end
117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/vedeu/geometry/dsl.rb', line 117 def alignment(value, width) fail Vedeu::Error::InvalidSyntax, 'No alignment given. Valid values are :center, :centre, :left, ' \ ':none, :right.'.freeze unless present?(value) fail Vedeu::Error::InvalidSyntax, 'No width given.'.freeze unless present?(width) model.alignment = Vedeu::Geometry::Alignment.align(value) model.width = width model end |
#attributes ⇒ Hash<Symbol => void> (private) Originally defined in module DSL
Specific DSL classes may be overriding this method.
Returns the default attributes for the new model.
#centred(value = true) ⇒ Boolean Also known as: centred!, centred=
Instructs Vedeu to calculate x and y geometry automatically based on the centre character of the terminal, the width and the height.
Vedeu.geometry :some_interface do
centred false # or...
centred true # or...
centred! # or...
# ... some code
end
207 208 209 210 211 |
# File 'lib/vedeu/geometry/dsl.rb', line 207 def centred(value = true) boolean = value ? true : false model.centred = boolean end |
#columns(value) ⇒ Fixnum|Vedeu::Error::OutOfRange
Returns the width in characters for the number of columns specified.
Vedeu.geometry :main_interface do
# ... some code
width columns(9) # Vedeu.width # => 92 (for example)
# 92 / 12 = 7
# 7 * 9 = 63
# Therefore, width is 63 characters.
end
230 231 232 |
# File 'lib/vedeu/geometry/dsl.rb', line 230 def columns(value) Vedeu::Geometry::Grid.columns(value) end |
#demodulize(klass) ⇒ String Originally defined in module Common
Removes the module part from the expression in the string.
#height(value) ⇒ Fixnum Also known as: height=
Specify the number of characters/rows/lines tall the interface will be. This value will be ignored when ‘y` and `yn` are set.
Vedeu.geometry :some_interface do
height 8
# ... some code
end
244 245 246 |
# File 'lib/vedeu/geometry/dsl.rb', line 244 def height(value) model.height = proc { value } end |
#initialize(model, client = nil) ⇒ void Originally defined in module DSL
Returns an instance of the DSL class including Vedeu::DSL.
#present?(variable) ⇒ Boolean Originally defined in module Common
Returns a boolean indicating whether a variable has a useful value.
#rows(value) ⇒ Fixnum
Returns the height in characters for the number of rows specified.
Vedeu.geometry :main_interface do
# ... some code
height rows(3) # Vedeu.height # => 38 (for example)
# 38 / 12 = 3
# 3 * 3 = 9
# Therefore, height is 9 characters.
end
264 265 266 |
# File 'lib/vedeu/geometry/dsl.rb', line 264 def rows(value) Vedeu::Geometry::Grid.rows(value) end |
#snake_case(name) ⇒ String Originally defined in module Common
Converts a class name to a lowercase snake case string.
#use(name) ⇒ void Originally defined in module DSL::Use
-
Only models of the same repository can be used in this way.
-
If the stored model cannot be found, a ModelNotFound exception may be raised, or the request for an attribute may raise a NoMethodError exception.
This method returns an undefined value.
Use the attribute of stored model.
This DSL method provides access to a stored model by name. You can then request an attribute of that model for use within the current model. The models which current support this are Border, Geometry and Interface.
#width(value) ⇒ Fixnum Also known as: width=
Specify the number of characters/columns wide the interface will be. This value will be ignored when ‘x` and `xn` are set.
Vedeu.geometry :some_interface do
width 25
# ... some code
end
278 279 280 |
# File 'lib/vedeu/geometry/dsl.rb', line 278 def width(value) model.width = proc { value } end |
#x(value = 1, &block) ⇒ Fixnum Also known as: x=
Specify the starting x position (column) of the interface.
Vedeu.geometry :some_interface do
x 7 # start on column 7.
# start on column 8, if :other_interface changes position
# then :some_interface will too.
x { use(:other_interface).east }
# ... some code
end
297 298 299 300 301 |
# File 'lib/vedeu/geometry/dsl.rb', line 297 def x(value = 1, &block) return model.x = block if block_given? model.x = value end |
#xn(value = 1, &block) ⇒ Fixnum Also known as: xn=
Specify the ending x position (column) of the interface. This value will override ‘width`.
Vedeu.geometry :some_interface do
xn 37 # end at column 37.
# when :other_interface changes position,
# :some_interface will too.
xn { use(:other_interface).right }
# ... some code
end
319 320 321 322 323 |
# File 'lib/vedeu/geometry/dsl.rb', line 319 def xn(value = 1, &block) return model.xn = block if block_given? model.xn = value end |
#y(value = 1, &block) ⇒ Fixnum Also known as: y=
Specify the starting y position (row/line) of the interface.
Vedeu.geometry :some_interface do
y 4 # start at row 4
# start on row/line 3, when :other_interface changes
# position, :some_interface will too.
y { use(:other_interface).north }
# ... some code
end
340 341 342 343 344 |
# File 'lib/vedeu/geometry/dsl.rb', line 340 def y(value = 1, &block) return model.y = block if block_given? model.y = value end |
#yn(value = 1, &block) ⇒ Fixnum Also known as: yn=
Specify the ending y position (row/line) of the interface. This value will override ‘height`.
Vedeu.geometry :some_interface do
yn 24 # end at row 24.
# if :other_interface changes position, :some_interface
# will too.
yn { use(:other_interface).bottom }
# ... some code
end
362 363 364 365 366 |
# File 'lib/vedeu/geometry/dsl.rb', line 362 def yn(value = 1, &block) return model.yn = block if block_given? model.yn = value end |