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
private
Returns a boolean indicating whether a variable is nil or empty.
-
#align(vertical, horizontal, width, height) ⇒ Vedeu::Geometry::Geometry
Align the interface/view horizontally or vertically within the terminal.
-
#align_bottom(height) ⇒ Vedeu::Geometry::Geometry
Vertically align the interface/view to the bottom of the terminal.
-
#align_centre(width) ⇒ Vedeu::Geometry::Geometry
(also: #align_center)
Horizontally align the interface/view centrally.
-
#align_left(width) ⇒ Vedeu::Geometry::Geometry
Horizontally align the interface/view to the left.
-
#align_middle(height) ⇒ Vedeu::Geometry::Geometry
Vertically align the interface/view to the middle of the terminal.
-
#align_right(width) ⇒ Vedeu::Geometry::Geometry
Align the interface/view to the right.
-
#align_top(height) ⇒ Vedeu::Geometry::Geometry
Vertically align the interface/view to the top of the terminal.
-
#attributes ⇒ Hash<Symbol => void>
included
from DSL
private
Returns the default attributes for the new model.
-
#columns(value) ⇒ Fixnum|Vedeu::Error::OutOfRange
Returns the width in characters for the number of columns specified.
-
#demodulize(klass) ⇒ String
included
from Common
private
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.
- #horizontal_alignment(value, width) ⇒ Vedeu::Geometry::Geometry
-
#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
private
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
private
Converts a class name to a lowercase snake case string.
-
#use(name) ⇒ void
included
from DSL::Use
Use the attribute of stored model.
- #validate_height!(value) ⇒ TrueClass included from Validator private
- #validate_horizontal_alignment!(value) ⇒ TrueClass included from Validator private
- #validate_vertical_alignment!(value) ⇒ TrueClass included from Validator private
- #validate_width!(value) ⇒ TrueClass included from Validator private
- #vertical_alignment(value, height) ⇒ Vedeu::Geometry::Geometry
-
#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
93 94 95 96 97 |
# File 'lib/vedeu/geometry/dsl.rb', line 93 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
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 boolean indicating whether a variable is nil or empty.
#align(vertical, horizontal, width, height) ⇒ Vedeu::Geometry::Geometry
Align the interface/view horizontally or vertically within the terminal.
150 151 152 153 154 155 156 157 158 |
# File 'lib/vedeu/geometry/dsl.rb', line 150 def align(vertical, horizontal, width, height) validate_vertical_alignment!(vertical) validate_horizontal_alignment!(horizontal) validate_height!(height) unless vertical == :none validate_width!(width) unless horizontal == :none horizontal_alignment(horizontal, width) vertical_alignment(vertical, height) end |
#align_bottom(height) ⇒ Vedeu::Geometry::Geometry
Vedeu.width in the example above will set the width to the default width of the terminal, this can be substituted for your own positive integer.
Vertically align the interface/view to the bottom of the terminal.
Vedeu.geometry :some_interface do
# `height` is a positive integer, e.g. 30
align_bottom 30
# this is the same as:
# vertical_alignment(:bottom, 30)
# or you can use: (see notes)
# align(:bottom, :none, Vedeu.width, 30)
# ... some code
end
211 212 213 |
# File 'lib/vedeu/geometry/dsl.rb', line 211 def align_bottom(height) vertical_alignment(:bottom, height) end |
#align_centre(width) ⇒ Vedeu::Geometry::Geometry Also known as: align_center
Vedeu.height in the example above will set the height to the default height of the terminal, this can be substituted for your own positive integer.
Horizontally 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:
# horizontal_alignment(:centre, 30)
# or you can use: (see notes)
# align(:none, :centre, 30, Vedeu.height)
# ... some code
end
# Also allows `align_center` if preferred.
240 241 242 |
# File 'lib/vedeu/geometry/dsl.rb', line 240 def align_centre(width) horizontal_alignment(:centre, width) end |
#align_left(width) ⇒ Vedeu::Geometry::Geometry
Vedeu.height in the example above will set the height to the default height of the terminal, this can be substituted for your own positive integer.
Horizontally 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:
# horizontal_alignment(:left, 30)
# or you can use: (see notes)
# align(:none, :left, 30, Vedeu.height)
# ... some code
end
268 269 270 |
# File 'lib/vedeu/geometry/dsl.rb', line 268 def align_left(width) horizontal_alignment(:left, width) end |
#align_middle(height) ⇒ Vedeu::Geometry::Geometry
Vedeu.width in the example above will set the width to the default width of the terminal, this can be substituted for your own positive integer.
Vertically align the interface/view to the middle of the terminal.
Vedeu.geometry :some_interface do
# `height` is a positive integer, e.g. 30
align_middle 30
# this is the same as:
# vertical_alignment(:middle, 30)
# or you can use: (see notes)
# align(:middle, :none, Vedeu.width, 30)
# ... some code
end
296 297 298 |
# File 'lib/vedeu/geometry/dsl.rb', line 296 def align_middle(height) vertical_alignment(:middle, height) end |
#align_right(width) ⇒ Vedeu::Geometry::Geometry
Vedeu.height in the example above will set the height to the default height of the terminal, this can be substituted for your own positive integer.
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:
# horizontal_alignment(:right, 30)
# or you can use: (see notes)
# align(:none, :right, 30, Vedeu.height)
# ... some code
end
323 324 325 |
# File 'lib/vedeu/geometry/dsl.rb', line 323 def align_right(width) horizontal_alignment(:right, width) end |
#align_top(height) ⇒ Vedeu::Geometry::Geometry
Vedeu.width in the example above will set the width to the default width of the terminal, this can be substituted for your own positive integer.
Vertically align the interface/view to the top of the terminal.
Vedeu.geometry :some_interface do
# `height` is a positive integer, e.g. 30
align_top 30
# this is the same as:
# vertical_alignment(:top, 30)
# or you can use: (see notes)
# align(:top, :none, Vedeu.width, 30)
# ... some code
end
351 352 353 |
# File 'lib/vedeu/geometry/dsl.rb', line 351 def align_top(height) vertical_alignment(:top, height) 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.
#columns(value) ⇒ Fixnum|Vedeu::Error::OutOfRange
370 371 372 |
# File 'lib/vedeu/geometry/dsl.rb', line 370 def columns(value) Vedeu::Geometry::Grid.columns(value) end |
#demodulize(klass) ⇒ String Originally defined in module Common
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.
Removes the module part from the expression in the string.
#height(value) ⇒ Fixnum Also known as: height=
384 385 386 |
# File 'lib/vedeu/geometry/dsl.rb', line 384 def height(value) model.height = proc { value } end |
#horizontal_alignment(value, width) ⇒ Vedeu::Geometry::Geometry
164 165 166 167 168 169 170 171 172 |
# File 'lib/vedeu/geometry/dsl.rb', line 164 def horizontal_alignment(value, width) validate_horizontal_alignment!(value) validate_width!(width) model.horizontal_alignment = Vedeu::Geometry::HorizontalAlignment .coerce(value) model.width = width model 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
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 boolean indicating whether a variable has a useful value.
#rows(value) ⇒ Fixnum
404 405 406 |
# File 'lib/vedeu/geometry/dsl.rb', line 404 def rows(value) Vedeu::Geometry::Grid.rows(value) end |
#snake_case(name) ⇒ String Originally defined in module Common
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.
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.
#validate_height!(value) ⇒ TrueClass Originally defined in module Validator
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.
#validate_horizontal_alignment!(value) ⇒ TrueClass Originally defined in module Validator
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.
#validate_vertical_alignment!(value) ⇒ TrueClass Originally defined in module Validator
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.
#validate_width!(value) ⇒ TrueClass Originally defined in module Validator
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.
#vertical_alignment(value, height) ⇒ Vedeu::Geometry::Geometry
177 178 179 180 181 182 183 184 185 |
# File 'lib/vedeu/geometry/dsl.rb', line 177 def vertical_alignment(value, height) validate_vertical_alignment!(value) validate_height!(height) model.vertical_alignment = Vedeu::Geometry::VerticalAlignment .coerce(value) model.height = height model end |
#width(value) ⇒ Fixnum Also known as: width=
418 419 420 |
# File 'lib/vedeu/geometry/dsl.rb', line 418 def width(value) model.width = proc { value } end |
#x(value = 1, &block) ⇒ Fixnum Also known as: x=
437 438 439 440 441 |
# File 'lib/vedeu/geometry/dsl.rb', line 437 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=
459 460 461 462 463 |
# File 'lib/vedeu/geometry/dsl.rb', line 459 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=
480 481 482 483 484 |
# File 'lib/vedeu/geometry/dsl.rb', line 480 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=
502 503 504 505 506 |
# File 'lib/vedeu/geometry/dsl.rb', line 502 def yn(value = 1, &block) return model.yn = block if block_given? model.yn = value end |