Class: CTioga2::Graphics::Types::MarginsBox
- Defined in:
- lib/ctioga2/graphics/types/boxes.rb
Overview
A box defined by its margins
Instance Attribute Summary collapse
-
#bottom ⇒ Object
Margin specifications.
-
#left ⇒ Object
Margin specifications.
-
#right ⇒ Object
Margin specifications.
-
#top ⇒ Object
Margin specifications.
Instance Method Summary collapse
-
#initialize(left, right, top, bottom) ⇒ MarginsBox
constructor
Creates a new MarginsBox object with the specified margins, as String (passed on to Dimension::to_text), float (defaults to frame coordinates) or directly as Dimension objects.
-
#margins ⇒ Object
Returns the dimensions composing the MarginsBox, in the order left, right, top, bottom, suitable for feeding to MarginsBox.new.
- #to_frame_coordinates(t) ⇒ Object
Methods inherited from Box
Constructor Details
#initialize(left, right, top, bottom) ⇒ MarginsBox
Creates a new MarginsBox object with the specified margins, as String (passed on to Dimension::to_text), float (defaults to frame coordinates) or directly as Dimension objects.
The Dimension’s orientation is automatically tweaked.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/ctioga2/graphics/types/boxes.rb', line 63 def initialize(left, right, top, bottom) # First, convert any float into Dimension: a = [left, right, top, bottom] a.each_index do |i| if ! a[i].is_a? Dimension a[i] = Dimension::from_text(a[i].to_s, :x, :frame) end end left, right, top, bottom = a # Then assign to the appropriate stuff: @left = left @left.orientation = :x @right = right @right.orientation = :x @top = top @top.orientation = :y @bottom = bottom @bottom.orientation = :y end |
Instance Attribute Details
#bottom ⇒ Object
Margin specifications. These are Dimension objects.
56 57 58 |
# File 'lib/ctioga2/graphics/types/boxes.rb', line 56 def bottom @bottom end |
#left ⇒ Object
Margin specifications. These are Dimension objects.
56 57 58 |
# File 'lib/ctioga2/graphics/types/boxes.rb', line 56 def left @left end |
#right ⇒ Object
Margin specifications. These are Dimension objects.
56 57 58 |
# File 'lib/ctioga2/graphics/types/boxes.rb', line 56 def right @right end |
#top ⇒ Object
Margin specifications. These are Dimension objects.
56 57 58 |
# File 'lib/ctioga2/graphics/types/boxes.rb', line 56 def top @top end |
Instance Method Details
#margins ⇒ Object
Returns the dimensions composing the MarginsBox, in the order left, right, top, bottom, suitable for feeding to MarginsBox.new.
92 93 94 |
# File 'lib/ctioga2/graphics/types/boxes.rb', line 92 def margins return [@left, @right, @top, @bottom] end |
#to_frame_coordinates(t) ⇒ Object
84 85 86 87 |
# File 'lib/ctioga2/graphics/types/boxes.rb', line 84 def to_frame_coordinates(t) return [@left.to_frame(t), 1 - @top.to_frame(t), 1 - @right.to_frame(t), @bottom.to_frame(t)] end |