Class: Shoes::Dimensions
- Inherits:
-
Object
- Object
- Shoes::Dimensions
- Includes:
- Common::Inspect
- Defined in:
- shoes-core/lib/shoes/dimensions.rb
Overview
Dimensions is a central class that most Shoes classes use to represent their dimensions, e.g. where they are and how much space they are taking up there. All the different position types might be confusing. So here is a little list:
Position (left, top, right, bottom)
plain (left
, top
, right
, bottom
): An offset relative to the parent (parents mostly are slots e.g. flows/stacks), e.g it isn’t fully positioned/doesn’t flow anymore when set
absolute_* (absolute_left
, absolute_top
, absolute_right
, absolute_bottom
): The absolute position an element begins positioning from in the app (in slot.rb
). Margins are not included in absolute position values–that’s the main difference between absolute
and element
values.
element_* (element_left
, element_top
, element_right
, element_bottom
): Derived from absolute_
* but shows the real position of the object, e.g. it adds the margins to absolute_
* (mostly used by backend drawing code).
Space Taken Up (width/height)
plain (width
, height
): The whole space taken up by this element with margins and everything. Used for positioning/by the user.
element_* (element_width
, element_height
): Just the space taken up by the element itself without margins. Used by drawing.
Note that this is NOT how margins work in the CSS box model. We diverge for reasons mentioned here
Direct Known Subclasses
Instance Attribute Summary collapse
-
#x_dimension ⇒ Object
readonly
Returns the value of attribute x_dimension.
-
#y_dimension ⇒ Object
readonly
Returns the value of attribute y_dimension.
Instance Method Summary collapse
- #absolute_bottom ⇒ Object
-
#absolute_bottom_position? ⇒ Boolean
Is this element’s bottom positioned absolutely.
- #absolute_left ⇒ Object
- #absolute_left=(value) ⇒ Object
-
#absolute_left_position? ⇒ Boolean
Is this element’s left positioned absolutely.
- #absolute_right ⇒ Object
-
#absolute_right_position? ⇒ Boolean
Is this element’s right positioned absolutely.
- #absolute_top ⇒ Object
- #absolute_top=(value) ⇒ Object
-
#absolute_top_position? ⇒ Boolean
Is this element’s top positioned absolutely.
-
#absolute_x_position? ⇒ Boolean
Is this element absolutely positioned in the horizontal dimension.
-
#absolute_y_position? ⇒ Boolean
Is this element absolutely positioned in the vertical dimension.
-
#absolutely_positioned? ⇒ Boolean
Is this element absolutely positioned in any dimension.
- #bottom ⇒ Object
- #bottom=(value) ⇒ Object
-
#contains?(other) ⇒ Boolean
Is another element fully contained within this element?.
- #displace_left ⇒ Object
- #displace_left=(value) ⇒ Object
- #displace_top ⇒ Object
- #displace_top=(value) ⇒ Object
- #element_bottom ⇒ Object
- #element_height ⇒ Object
- #element_height=(value) ⇒ Object
- #element_left ⇒ Object
- #element_right ⇒ Object
- #element_top ⇒ Object
- #element_width ⇒ Object
- #element_width=(value) ⇒ Object
- #height ⇒ Object
- #height=(value) ⇒ Object
-
#in_bounds?(x, y) ⇒ Boolean
Is the given point within the bounds of this element.
-
#initialize(parent, left_or_hash = nil, top = nil, width = nil, height = nil, opts = {}) ⇒ Dimensions
constructor
A new instance of Dimensions.
- #left ⇒ Object
- #left=(value) ⇒ Object
-
#margin ⇒ Array<Fixnum>
Margins for the element.
-
#margin=(margin) ⇒ Object
Set margin value for element.
- #margin_bottom ⇒ Object
- #margin_bottom=(value) ⇒ Object
- #margin_left ⇒ Object
- #margin_left=(value) ⇒ Object
- #margin_right ⇒ Object
- #margin_right=(value) ⇒ Object
- #margin_top ⇒ Object
- #margin_top=(value) ⇒ Object
-
#needs_positioning? ⇒ Boolean
Determines if this element participate in slot positioning.
-
#positioned? ⇒ Boolean
Has this element been positioned by layout.
- #right ⇒ Object
- #right=(value) ⇒ Object
-
#takes_up_space? ⇒ Boolean
Determines whether to advance current position during slot layout.
- #top ⇒ Object
- #top=(value) ⇒ Object
- #width ⇒ Object
- #width=(value) ⇒ Object
Methods included from Common::Inspect
Constructor Details
#initialize(parent, left_or_hash = nil, top = nil, width = nil, height = nil, opts = {}) ⇒ Dimensions
Returns a new instance of Dimensions.
55 56 57 58 59 60 61 62 63 |
# File 'shoes-core/lib/shoes/dimensions.rb', line 55 def initialize(parent, left_or_hash = nil, top = nil, width = nil, height = nil, opts = {}) @parent = parent if hash_as_argument?(left_or_hash) init_with_hash(left_or_hash) else init_with_arguments(left_or_hash, top, width, height, opts) end end |
Instance Attribute Details
#x_dimension ⇒ Object (readonly)
Returns the value of attribute x_dimension.
39 40 41 |
# File 'shoes-core/lib/shoes/dimensions.rb', line 39 def x_dimension @x_dimension end |
#y_dimension ⇒ Object (readonly)
Returns the value of attribute y_dimension.
39 40 41 |
# File 'shoes-core/lib/shoes/dimensions.rb', line 39 def y_dimension @y_dimension end |
Instance Method Details
#absolute_bottom ⇒ Object
296 297 298 |
# File 'shoes-core/lib/shoes/dimensions.rb', line 296 def absolute_bottom @y_dimension.absolute_end end |
#absolute_bottom_position? ⇒ Boolean
Is this element’s bottom positioned absolutely
96 97 98 |
# File 'shoes-core/lib/shoes/dimensions.rb', line 96 def absolute_bottom_position? @y_dimension.absolute_end_position? end |
#absolute_left ⇒ Object
276 277 278 |
# File 'shoes-core/lib/shoes/dimensions.rb', line 276 def absolute_left @x_dimension.absolute_start end |
#absolute_left=(value) ⇒ Object
280 281 282 |
# File 'shoes-core/lib/shoes/dimensions.rb', line 280 def absolute_left=(value) @x_dimension.absolute_start = value end |
#absolute_left_position? ⇒ Boolean
Is this element’s left positioned absolutely
81 82 83 |
# File 'shoes-core/lib/shoes/dimensions.rb', line 81 def absolute_left_position? @x_dimension.absolute_start_position? end |
#absolute_right ⇒ Object
284 285 286 |
# File 'shoes-core/lib/shoes/dimensions.rb', line 284 def absolute_right @x_dimension.absolute_end end |
#absolute_right_position? ⇒ Boolean
Is this element’s right positioned absolutely
86 87 88 |
# File 'shoes-core/lib/shoes/dimensions.rb', line 86 def absolute_right_position? @x_dimension.absolute_end_position? end |
#absolute_top ⇒ Object
288 289 290 |
# File 'shoes-core/lib/shoes/dimensions.rb', line 288 def absolute_top @y_dimension.absolute_start end |
#absolute_top=(value) ⇒ Object
292 293 294 |
# File 'shoes-core/lib/shoes/dimensions.rb', line 292 def absolute_top=(value) @y_dimension.absolute_start = value end |
#absolute_top_position? ⇒ Boolean
Is this element’s top positioned absolutely
91 92 93 |
# File 'shoes-core/lib/shoes/dimensions.rb', line 91 def absolute_top_position? @y_dimension.absolute_start_position? end |
#absolute_x_position? ⇒ Boolean
Is this element absolutely positioned in the horizontal dimension
66 67 68 |
# File 'shoes-core/lib/shoes/dimensions.rb', line 66 def absolute_x_position? x_dimension.absolute_position? end |
#absolute_y_position? ⇒ Boolean
Is this element absolutely positioned in the vertical dimension
71 72 73 |
# File 'shoes-core/lib/shoes/dimensions.rb', line 71 def absolute_y_position? y_dimension.absolute_position? end |
#absolutely_positioned? ⇒ Boolean
Is this element absolutely positioned in any dimension
76 77 78 |
# File 'shoes-core/lib/shoes/dimensions.rb', line 76 def absolutely_positioned? absolute_x_position? || absolute_y_position? end |
#bottom ⇒ Object
204 205 206 |
# File 'shoes-core/lib/shoes/dimensions.rb', line 204 def bottom @y_dimension.end end |
#bottom=(value) ⇒ Object
208 209 210 |
# File 'shoes-core/lib/shoes/dimensions.rb', line 208 def bottom=(value) @y_dimension.end = value end |
#contains?(other) ⇒ Boolean
Is another element fully contained within this element?
117 118 119 120 121 122 123 124 125 |
# File 'shoes-core/lib/shoes/dimensions.rb', line 117 def contains?(other) return false unless other.element_left && other.element_top && other.element_right && other.element_bottom element_left <= other.element_left && element_right >= other.element_right && element_top <= other.element_top && element_bottom >= other.element_bottom end |
#displace_left ⇒ Object
300 301 302 |
# File 'shoes-core/lib/shoes/dimensions.rb', line 300 def displace_left @x_dimension.displace_start end |
#displace_left=(value) ⇒ Object
304 305 306 |
# File 'shoes-core/lib/shoes/dimensions.rb', line 304 def displace_left=(value) @x_dimension.displace_start = value end |
#displace_top ⇒ Object
308 309 310 |
# File 'shoes-core/lib/shoes/dimensions.rb', line 308 def displace_top @y_dimension.displace_start end |
#displace_top=(value) ⇒ Object
312 313 314 |
# File 'shoes-core/lib/shoes/dimensions.rb', line 312 def displace_top=(value) @y_dimension.displace_start = value end |
#element_bottom ⇒ Object
240 241 242 |
# File 'shoes-core/lib/shoes/dimensions.rb', line 240 def element_bottom @y_dimension.element_end end |
#element_height ⇒ Object
212 213 214 |
# File 'shoes-core/lib/shoes/dimensions.rb', line 212 def element_height @y_dimension.element_extent end |
#element_height=(value) ⇒ Object
216 217 218 |
# File 'shoes-core/lib/shoes/dimensions.rb', line 216 def element_height=(value) @y_dimension.element_extent = value end |
#element_left ⇒ Object
228 229 230 |
# File 'shoes-core/lib/shoes/dimensions.rb', line 228 def element_left @x_dimension.element_start end |
#element_right ⇒ Object
232 233 234 |
# File 'shoes-core/lib/shoes/dimensions.rb', line 232 def element_right @x_dimension.element_end end |
#element_top ⇒ Object
236 237 238 |
# File 'shoes-core/lib/shoes/dimensions.rb', line 236 def element_top @y_dimension.element_start end |
#element_width ⇒ Object
220 221 222 |
# File 'shoes-core/lib/shoes/dimensions.rb', line 220 def element_width @x_dimension.element_extent end |
#element_width=(value) ⇒ Object
224 225 226 |
# File 'shoes-core/lib/shoes/dimensions.rb', line 224 def element_width=(value) @x_dimension.element_extent = value end |
#height ⇒ Object
172 173 174 |
# File 'shoes-core/lib/shoes/dimensions.rb', line 172 def height @y_dimension.extent end |
#height=(value) ⇒ Object
176 177 178 |
# File 'shoes-core/lib/shoes/dimensions.rb', line 176 def height=(value) @y_dimension.extent = value end |
#in_bounds?(x, y) ⇒ Boolean
Is the given point within the bounds of this element
110 111 112 |
# File 'shoes-core/lib/shoes/dimensions.rb', line 110 def in_bounds?(x, y) x_dimension.in_bounds?(x) && y_dimension.in_bounds?(y) end |
#left ⇒ Object
180 181 182 |
# File 'shoes-core/lib/shoes/dimensions.rb', line 180 def left @x_dimension.start end |
#left=(value) ⇒ Object
184 185 186 |
# File 'shoes-core/lib/shoes/dimensions.rb', line 184 def left=(value) @x_dimension.start = value end |
#margin ⇒ Array<Fixnum>
Margins for the element
130 131 132 |
# File 'shoes-core/lib/shoes/dimensions.rb', line 130 def margin [margin_left, margin_top, margin_right, margin_bottom] end |
#margin=(margin) ⇒ Object
Set margin value for element
If a single value is passed, all margins are set to that value.
If an array is passed, values from array are spread to left, top, right and bottom in that order.
margin to
143 144 145 146 147 |
# File 'shoes-core/lib/shoes/dimensions.rb', line 143 def margin=(margin) margin = [margin, margin, margin, margin] unless margin.is_a? Array self.margin_left, self.margin_top, self.margin_right, self.margin_bottom = margin end |
#margin_bottom ⇒ Object
268 269 270 |
# File 'shoes-core/lib/shoes/dimensions.rb', line 268 def margin_bottom @y_dimension.margin_end end |
#margin_bottom=(value) ⇒ Object
272 273 274 |
# File 'shoes-core/lib/shoes/dimensions.rb', line 272 def margin_bottom=(value) @y_dimension.margin_end = value end |
#margin_left ⇒ Object
244 245 246 |
# File 'shoes-core/lib/shoes/dimensions.rb', line 244 def margin_left @x_dimension.margin_start end |
#margin_left=(value) ⇒ Object
248 249 250 |
# File 'shoes-core/lib/shoes/dimensions.rb', line 248 def margin_left=(value) @x_dimension.margin_start = value end |
#margin_right ⇒ Object
252 253 254 |
# File 'shoes-core/lib/shoes/dimensions.rb', line 252 def margin_right @x_dimension.margin_end end |
#margin_right=(value) ⇒ Object
256 257 258 |
# File 'shoes-core/lib/shoes/dimensions.rb', line 256 def margin_right=(value) @x_dimension.margin_end = value end |
#margin_top ⇒ Object
260 261 262 |
# File 'shoes-core/lib/shoes/dimensions.rb', line 260 def margin_top @y_dimension.margin_start end |
#margin_top=(value) ⇒ Object
264 265 266 |
# File 'shoes-core/lib/shoes/dimensions.rb', line 264 def margin_top=(value) @y_dimension.margin_start = value end |
#needs_positioning? ⇒ Boolean
Determines if this element participate in slot positioning
152 153 154 |
# File 'shoes-core/lib/shoes/dimensions.rb', line 152 def needs_positioning? true end |
#positioned? ⇒ Boolean
Has this element been positioned by layout
101 102 103 |
# File 'shoes-core/lib/shoes/dimensions.rb', line 101 def positioned? x_dimension.positioned? && y_dimension.positioned? end |
#right ⇒ Object
188 189 190 |
# File 'shoes-core/lib/shoes/dimensions.rb', line 188 def right @x_dimension.end end |
#right=(value) ⇒ Object
192 193 194 |
# File 'shoes-core/lib/shoes/dimensions.rb', line 192 def right=(value) @x_dimension.end = value end |
#takes_up_space? ⇒ Boolean
Determines whether to advance current position during slot layout
element
160 161 162 |
# File 'shoes-core/lib/shoes/dimensions.rb', line 160 def takes_up_space? true end |
#top ⇒ Object
196 197 198 |
# File 'shoes-core/lib/shoes/dimensions.rb', line 196 def top @y_dimension.start end |
#top=(value) ⇒ Object
200 201 202 |
# File 'shoes-core/lib/shoes/dimensions.rb', line 200 def top=(value) @y_dimension.start = value end |
#width ⇒ Object
164 165 166 |
# File 'shoes-core/lib/shoes/dimensions.rb', line 164 def width @x_dimension.extent end |
#width=(value) ⇒ Object
168 169 170 |
# File 'shoes-core/lib/shoes/dimensions.rb', line 168 def width=(value) @x_dimension.extent = value end |