Class: Vedeu::Geometries::DSL

Inherits:
Object
  • Object
show all
Includes:
Common, DSL, DSL::Geometry, DSL::Use
Defined in:
lib/vedeu/geometries/dsl/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

Attributes included from DSL

#client, #model

Instance Method Summary collapse

Methods included from DSL::Use

#use

Methods included from DSL::Geometry

included

Methods included from DSL

#attributes, #initialize, #method_missing, #name

Methods included from Common

#absent?, #array?, #boolean, #boolean?, #empty_value?, #escape?, #falsy?, #hash?, #line_model?, #numeric?, #positionable?, #present?, #snake_case, #stream_model?, #string?, #symbol?, #truthy?, #view_model?

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Vedeu::DSL

Instance Method Details

#align(vertical: :none, horizontal: :none, width: nil, height: nil) ⇒ Vedeu::Geometries::Geometry

Align the interface/view horizontally or vertically within the terminal.

Parameters:

  • vertical (Symbol) (defaults to: :none)

    One of :bottom, :middle, :none, :top.

  • horizontal (Symbol) (defaults to: :none)

    One of :center, :centre, :left, :none, :right.

  • width (Fixnum) (defaults to: nil)

    The number of characters/columns wide; this is required when the given value for horizontal is any value other than :none.

  • height (Fixnum) (defaults to: nil)

    The number of lines/rows tall; this is required when the given value for vertical is any value other than :none.

Returns:

Raises:

  • (Vedeu::Error::InvalidSyntax)

    When the value given for an argument or parameter cannot be used because it is not valid for the use case, unsupported or the method expects a different type.



100
101
102
103
# File 'lib/vedeu/geometries/dsl/dsl.rb', line 100

def align(vertical: :none, horizontal: :none, width: nil, height: nil)
  horizontal_alignment(horizontal, width)
  vertical_alignment(vertical, height)
end

#align_bottom(height = nil) ⇒ Vedeu::Geometries::Geometry

Parameters:

  • height (Fixnum) (defaults to: nil)

    The number of lines/rows.

Returns:



135
136
137
138
139
140
141
142
143
# File 'lib/vedeu/geometries/dsl/dsl.rb', line 135

def align_bottom(height = nil)
  y = if height
        Vedeu.height - height
      elsif model.height
        Vedeu.height - model.height
      end

  vertical_alignment(:bottom, height, y)
end

#align_centre(width = nil) ⇒ Vedeu::Geometries::Geometry Also known as: align_center

Parameters:

  • width (Fixnum) (defaults to: nil)

    The number of characters/columns.

Returns:



148
149
150
151
152
153
154
155
156
# File 'lib/vedeu/geometries/dsl/dsl.rb', line 148

def align_centre(width = nil)
  x = if width
        Vedeu.centre_x - (width / 2)
      elsif model.width
        Vedeu.centre_x - (model.width / 2)
      end

  horizontal_alignment(:centre, width, x)
end

#align_left(width = nil) ⇒ Vedeu::Geometries::Geometry

Parameters:

  • width (Fixnum) (defaults to: nil)

    The number of characters/columns.

Returns:



162
163
164
# File 'lib/vedeu/geometries/dsl/dsl.rb', line 162

def align_left(width = nil)
  horizontal_alignment(:left, width)
end

#align_middle(height = nil) ⇒ Vedeu::Geometries::Geometry

Parameters:

  • height (Fixnum) (defaults to: nil)

    The number of lines/rows.

Returns:



169
170
171
172
173
174
175
176
177
# File 'lib/vedeu/geometries/dsl/dsl.rb', line 169

def align_middle(height = nil)
  y = if height
        Vedeu.centre_y - (height / 2)
      elsif model.height
        Vedeu.centre_y - (model.height / 2)
      end

  vertical_alignment(:middle, height, y)
end

#align_right(width = nil) ⇒ Vedeu::Geometries::Geometry

Parameters:

  • width (Fixnum) (defaults to: nil)

    The number of characters/columns.

Returns:



182
183
184
185
186
187
188
189
190
# File 'lib/vedeu/geometries/dsl/dsl.rb', line 182

def align_right(width = nil)
  x = if width
        Vedeu.width - width
      elsif model.width
        Vedeu.width - model.width
      end

  horizontal_alignment(:right, width, x)
end

#align_top(height = nil) ⇒ Vedeu::Geometries::Geometry

Parameters:

  • height (Fixnum) (defaults to: nil)

    The number of lines/rows.

Returns:



195
196
197
# File 'lib/vedeu/geometries/dsl/dsl.rb', line 195

def align_top(height = nil)
  vertical_alignment(:top, height)
end

#columns(value) ⇒ Fixnum|Vedeu::Error::OutOfRange

Parameters:

  • value (Fixnum)

Returns:

Raises:

  • (Vedeu::Error::OutOfRange)

    When the value given for an argument or parameter cannot be used because it is outside the allowed range.



203
204
205
# File 'lib/vedeu/geometries/dsl/dsl.rb', line 203

def columns(value)
  Vedeu::Geometries::Grid.columns(value)
end

#height(value) ⇒ Fixnum Also known as: height=

Parameters:

  • value (Fixnum)

Returns:

  • (Fixnum)


210
211
212
# File 'lib/vedeu/geometries/dsl/dsl.rb', line 210

def height(value)
  model.height = proc { value }
end

#horizontal_alignment(value = :none, width = nil, x = nil) ⇒ Vedeu::Geometries::Geometry

Parameters:

  • value (Symbol) (defaults to: :none)

    One of :center, :centre, :left, :none, :right.

  • width (Fixnum) (defaults to: nil)

    The number of characters/columns.

  • x (Fixnum) (defaults to: nil)

    When given, sets the x coordinate.

Returns:



110
111
112
113
114
115
116
117
# File 'lib/vedeu/geometries/dsl/dsl.rb', line 110

def horizontal_alignment(value = :none, width = nil, x = nil)
  alignment = Vedeu::Coercers::HorizontalAlignment.validate(value)

  model.width = width if width
  model.horizontal_alignment = alignment
  model.x = x if x
  model
end

#rows(value) ⇒ Fixnum

Parameters:

  • value (Fixnum)

Returns:

  • (Fixnum)

Raises:

  • (Vedeu::Error::OutOfRange)

    When the value given for an argument or parameter cannot be used because it is outside the allowed range.



219
220
221
# File 'lib/vedeu/geometries/dsl/dsl.rb', line 219

def rows(value)
  Vedeu::Geometries::Grid.rows(value)
end

#vertical_alignment(value = :none, height = nil, y = nil) ⇒ Vedeu::Geometries::Geometry

Parameters:

  • value (Symbol) (defaults to: :none)

    One of :bottom, :middle, :none, :top.

  • height (Fixnum) (defaults to: nil)

    The number of lines/rows.

  • y (Fixnum) (defaults to: nil)

    When given, sets the y coordinate.

Returns:



123
124
125
126
127
128
129
130
# File 'lib/vedeu/geometries/dsl/dsl.rb', line 123

def vertical_alignment(value = :none, height = nil, y = nil)
  alignment = Vedeu::Coercers::VerticalAlignment.validate(value)

  model.height = height if height
  model.vertical_alignment = alignment
  model.y = y if y
  model
end

#width(value) ⇒ Fixnum Also known as: width=

Parameters:

  • value (Fixnum)

    The number of characters/columns.

Returns:

  • (Fixnum)


226
227
228
# File 'lib/vedeu/geometries/dsl/dsl.rb', line 226

def width(value)
  model.width = proc { value }
end

#x(value = 1, &block) ⇒ Fixnum Also known as: x=

Parameters:

  • value (Fixnum) (defaults to: 1)
  • block (Proc)

Returns:

  • (Fixnum)


235
236
237
238
239
# File 'lib/vedeu/geometries/dsl/dsl.rb', line 235

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=

Parameters:

  • value (Fixnum) (defaults to: 1)
  • block (Proc)

Returns:

  • (Fixnum)


246
247
248
249
250
# File 'lib/vedeu/geometries/dsl/dsl.rb', line 246

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=

Parameters:

  • value (Fixnum) (defaults to: 1)
  • block (Proc)

Returns:

  • (Fixnum)


257
258
259
260
261
# File 'lib/vedeu/geometries/dsl/dsl.rb', line 257

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=

Parameters:

  • value (Fixnum) (defaults to: 1)
  • block (Proc)

Returns:

  • (Fixnum)


268
269
270
271
272
# File 'lib/vedeu/geometries/dsl/dsl.rb', line 268

def yn(value = 1, &block)
  return model.yn = block if block_given?

  model.yn = value
end