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
-
#expand_to!(t, other) ⇒ Object
Augments the margins so that they also encompass those given in other.
-
#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
-
#to_output(t, fact = 1.0) ⇒ Object
Converts to output coordinates.
Methods inherited from Box
#classes, #to_frame_margins, #within_frames
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.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/ctioga2/graphics/types/boxes.rb', line 79 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.
72 73 74 |
# File 'lib/ctioga2/graphics/types/boxes.rb', line 72 def bottom @bottom end |
#left ⇒ Object
Margin specifications. These are Dimension objects.
72 73 74 |
# File 'lib/ctioga2/graphics/types/boxes.rb', line 72 def left @left end |
#right ⇒ Object
Margin specifications. These are Dimension objects.
72 73 74 |
# File 'lib/ctioga2/graphics/types/boxes.rb', line 72 def right @right end |
#top ⇒ Object
Margin specifications. These are Dimension objects.
72 73 74 |
# File 'lib/ctioga2/graphics/types/boxes.rb', line 72 def top @top end |
Instance Method Details
#expand_to!(t, other) ⇒ Object
Augments the margins so that they also encompass those given in other. Based on the current interpretation of the measures as bp.
128 129 130 131 132 133 134 135 136 |
# File 'lib/ctioga2/graphics/types/boxes.rb', line 128 def (t, other) for w in %w(left right top bottom) mine = self.send(w) theirs = other.send(w) if mine.to_bp(t) < theirs.to_bp(t) self.send("#{w}=", theirs) end end end |
#margins ⇒ Object
Returns the dimensions composing the MarginsBox, in the order left, right, top, bottom, suitable for feeding to MarginsBox.new.
121 122 123 |
# File 'lib/ctioga2/graphics/types/boxes.rb', line 121 def margins return [@left, @right, @top, @bottom] end |
#to_frame_coordinates(t) ⇒ Object
100 101 102 103 |
# File 'lib/ctioga2/graphics/types/boxes.rb', line 100 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 |
#to_output(t, fact = 1.0) ⇒ Object
Converts to output coordinates
106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/ctioga2/graphics/types/boxes.rb', line 106 def to_output(t, fact = 1.0) a = to_frame_coordinates(t) 4.times do |i| a[i] = if (i % 2 == 0) fact * t.convert_page_to_output_x(t.convert_frame_to_page_x(a[i])) else fact * t.convert_page_to_output_y(t.convert_frame_to_page_y(a[i])) end end return a end |