Class: CTioga2::Graphics::Types::GridBox
- Defined in:
- lib/ctioga2/graphics/types/grid.rb
Overview
The position of a single element in a GridLayout
todo add the possibility to override one element of the final positions.
Constant Summary collapse
- OptionHashRE =
/([\w-]+)\s*=\s*([^,]+),?\s*/
- GridBoxRE =
/^\s*grid:(\d+)\s*,\s*(\d+)(?:,(#{OptionHashRE}+))?\s*$/
- FrameCoordsOverride =
This hash helps to convert from a hash-based representation of frame coordinates to the array-based one.
todo I should either use existing code or refactor into something globally useful.
{ 'xl' => 0, 'yt' => 1, 'xr' => 2, 'yb' => 3 }
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(grid, x, y, options = {}) ⇒ GridBox
constructor
A new instance of GridBox.
- #to_frame_coordinates(t) ⇒ Object
Methods inherited from Box
Constructor Details
#initialize(grid, x, y, options = {}) ⇒ GridBox
Returns a new instance of GridBox.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/ctioga2/graphics/types/grid.rb', line 57 def initialize(grid, x, y, = {}) if .is_a? String str = = {} str.split(/\s*,\s*/).map { |s| s =~ OptionHashRE [$1] = BaseCoordinate.from_text($2,if FrameCoordsOverride[$1] % 2 == 0 :x else :y end, :frame) } end @x = x.to_i @grid = grid @y = y.to_i @overrides = || {} end |
Class Method Details
.from_text(txt) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/ctioga2/graphics/types/grid.rb', line 47 def self.from_text(txt) if txt =~ GridBoxRE return GridBox.new(GridLayout.current_grid, $1.to_i, $2.to_i, $3) # The latter being to remove # the initial comma else raise "#{txt} is not a grid box." end end |
Instance Method Details
#to_frame_coordinates(t) ⇒ Object
77 78 79 80 81 82 83 84 85 |
# File 'lib/ctioga2/graphics/types/grid.rb', line 77 def to_frame_coordinates(t) a = @grid.frame_coordinates(t, @x, @y) ## \todo write a framework for manipulating this ! for k,v in @overrides next unless FrameCoordsOverride.key?(k) a[FrameCoordsOverride[k]] = v.to_frame(t) end return a end |