Class: Shoes::Dimension

Inherits:
Object
  • Object
show all
Defined in:
shoes-core/lib/shoes/dimension.rb

Overview

Class representing position and length in a single dimension (x or y).

These are used primarily as the x_dimension and y_dimension variables in the Shoes::Dimensions class. Instances of this class are rarely expected to be accessed themselves directly.

Direct Known Subclasses

ParentDimension

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent = nil, start_as_center = false) ⇒ Dimension

belongs to starting positions as the center of its owning element or not.

Parameters:

  • parent (Shoes::Common::UIElement) (defaults to: nil)

    Shoes element this dimension

  • start_as_center (Boolean) (defaults to: false)

    Whether to treat this dimensions



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'shoes-core/lib/shoes/dimension.rb', line 31

def initialize(parent = nil, start_as_center = false)
  @parent              = parent
  @start_as_center     = start_as_center
  @combined_margins    = 0
  @displace_start      = nil
  @displace_start_relative = nil
  @end                 = nil
  @extent              = nil
  @extent_negative     = nil
  @extent_relative     = nil
  @margin_end          = nil
  @margin_end_relative = nil
  @margin_start        = nil
  @margin_start_relative = nil
  @start               = nil
  @start               = nil
  @start_relative      = nil
end

Instance Attribute Details

#absolute_startObject

Returns the value of attribute absolute_start.



11
12
13
# File 'shoes-core/lib/shoes/dimension.rb', line 11

def absolute_start
  @absolute_start
end

Instance Method Details

#absolute_endObject



86
87
88
89
# File 'shoes-core/lib/shoes/dimension.rb', line 86

def absolute_end
  return absolute_start if extent.nil? || absolute_start.nil?
  absolute_start + extent + PIXEL_COUNTING_ADJUSTMENT
end

#absolute_end_position?Boolean

Returns:

  • (Boolean)


122
123
124
# File 'shoes-core/lib/shoes/dimension.rb', line 122

def absolute_end_position?
  !@end.nil?
end

#absolute_position?Boolean

Returns:

  • (Boolean)


126
127
128
# File 'shoes-core/lib/shoes/dimension.rb', line 126

def absolute_position?
  absolute_start_position? || absolute_end_position?
end

#absolute_start_position?Boolean

Returns:

  • (Boolean)


118
119
120
# File 'shoes-core/lib/shoes/dimension.rb', line 118

def absolute_start_position?
  !@start.nil?
end

#displace_startObject



151
152
153
# File 'shoes-core/lib/shoes/dimension.rb', line 151

def displace_start
  value_factoring_in_relative(@displace_start, @displace_start_relative)
end

#displace_start=(value) ⇒ Object



184
185
186
187
# File 'shoes-core/lib/shoes/dimension.rb', line 184

def displace_start=(value)
  @displace_start_relative = relative?(value)
  @displace_start = parse_int_value(value)
end

#element_endObject



113
114
115
116
# File 'shoes-core/lib/shoes/dimension.rb', line 113

def element_end
  return nil if element_start.nil? || element_extent.nil?
  element_start + element_extent + PIXEL_COUNTING_ADJUSTMENT
end

#element_extentObject



91
92
93
94
95
96
97
98
# File 'shoes-core/lib/shoes/dimension.rb', line 91

def element_extent
  my_extent = extent
  if my_extent.nil?
    nil
  else
    my_extent - @combined_margins
  end
end

#element_extent=(value) ⇒ Object



100
101
102
103
104
105
106
# File 'shoes-core/lib/shoes/dimension.rb', line 100

def element_extent=(value)
  self.extent = if value.nil?
                  nil
                else
                  margin_start + value + margin_end
                end
end

#element_startObject



108
109
110
111
# File 'shoes-core/lib/shoes/dimension.rb', line 108

def element_start
  return nil if absolute_start.nil?
  absolute_start + margin_start + displace_start
end

#endObject



56
57
58
# File 'shoes-core/lib/shoes/dimension.rb', line 56

def end
  @end || report_relative_to_parent_end
end

#end=(value) ⇒ Object



166
167
168
# File 'shoes-core/lib/shoes/dimension.rb', line 166

def end=(value)
  @end = parse_int_value(value)
end

#extentObject



60
61
62
63
64
65
66
67
# File 'shoes-core/lib/shoes/dimension.rb', line 60

def extent
  result = @extent
  if @parent
    result = calculate_relative(result) if @extent_relative
    result = calculate_negative(result) if @extent_negative
  end
  result
end

#extent=(value) ⇒ Object

Set length/extent of the element in a given dimension

Float values between 0 and 1.0 are treated as a percentage of their parent extend.

Negative values are treated as an amount less than the containing parent extent.

Parameters:

  • value (Fixnum, Float)

    Length to set



78
79
80
81
82
83
84
# File 'shoes-core/lib/shoes/dimension.rb', line 78

def extent=(value)
  @extent = value
  @extent = parse_from_string @extent if string? @extent

  @extent_relative = relative?(@extent)
  @extent_negative = negative?(@extent)
end

#in_bounds?(value) ⇒ Boolean

Returns:

  • (Boolean)


134
135
136
# File 'shoes-core/lib/shoes/dimension.rb', line 134

def in_bounds?(value)
  (absolute_start <= value) && (value <= absolute_end)
end

#margin_endObject



147
148
149
# File 'shoes-core/lib/shoes/dimension.rb', line 147

def margin_end
  value_factoring_in_relative(@margin_end, @margin_end_relative)
end

#margin_end=(value) ⇒ Object



177
178
179
180
181
182
# File 'shoes-core/lib/shoes/dimension.rb', line 177

def margin_end=(value)
  @margin_end_relative = relative?(value)
  @margin_end = parse_int_value(value)

  @combined_margins = margin_start + margin_end
end

#margin_startObject



138
139
140
141
142
143
144
145
# File 'shoes-core/lib/shoes/dimension.rb', line 138

def margin_start
  # For... reasons it is important to have the value of the instance
  # variable set to nil if it's not modified and then return a default
  # value on the getter... reason being that for ParentDimensions we need
  # to be able to figure out if a value has been modified or if we should
  # consult the parent value - see ParentDimension implementation
  value_factoring_in_relative(@margin_start, @margin_start_relative)
end

#margin_start=(value) ⇒ Object



170
171
172
173
174
175
# File 'shoes-core/lib/shoes/dimension.rb', line 170

def margin_start=(value)
  @margin_start_relative = relative?(value)
  @margin_start = parse_int_value(value)

  @combined_margins = margin_start + margin_end
end

#positioned?Boolean

Returns:

  • (Boolean)


130
131
132
# File 'shoes-core/lib/shoes/dimension.rb', line 130

def positioned?
  absolute_start
end

#startObject



50
51
52
53
54
# File 'shoes-core/lib/shoes/dimension.rb', line 50

def start
  value = basic_start_value
  value = adjust_start_for_center(value) if start_as_center?
  value
end

#start=(value) ⇒ Object



161
162
163
164
# File 'shoes-core/lib/shoes/dimension.rb', line 161

def start=(value)
  @start_relative = relative?(value)
  @start = parse_int_value(value)
end

#value_factoring_in_relative(value, relative) ⇒ Object



155
156
157
158
159
# File 'shoes-core/lib/shoes/dimension.rb', line 155

def value_factoring_in_relative(value, relative)
  value ||= 0
  value = calculate_relative value if relative
  value
end