Class: CTioga2::Graphics::Types::MarginsBox

Inherits:
Box
  • Object
show all
Defined in:
lib/ctioga2/graphics/types/boxes.rb

Overview

A box defined by its margins

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Box

#to_frame_margins

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

#bottomObject

Margin specifications. These are Dimension objects.



56
57
58
# File 'lib/ctioga2/graphics/types/boxes.rb', line 56

def bottom
  @bottom
end

#leftObject

Margin specifications. These are Dimension objects.



56
57
58
# File 'lib/ctioga2/graphics/types/boxes.rb', line 56

def left
  @left
end

#rightObject

Margin specifications. These are Dimension objects.



56
57
58
# File 'lib/ctioga2/graphics/types/boxes.rb', line 56

def right
  @right
end

#topObject

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

#marginsObject

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