Class: Shoes::TextBlockDimensions

Inherits:
Dimensions show all
Defined in:
shoes-core/lib/shoes/text_block_dimensions.rb

Overview

We take over a bunch of the absolute_* measurements since the jagged shape of a flowed TextBlock doesn’t follow the usual rules for dimensions when we get to positioning (which is the main use of these values).

Instance Attribute Summary collapse

Attributes inherited from Dimensions

#x_dimension, #y_dimension

Instance Method Summary collapse

Methods inherited from Dimensions

#absolute_bottom_position?, #absolute_left, #absolute_left=, #absolute_left_position?, #absolute_right_position?, #absolute_top, #absolute_top=, #absolute_top_position?, #absolute_x_position?, #absolute_y_position?, #absolutely_positioned?, #bottom, #bottom=, #contains?, #displace_left, #displace_left=, #displace_top, #displace_top=, #element_bottom, #element_height, #element_height=, #element_left, #element_right, #element_top, #element_width, #element_width=, #height=, #in_bounds?, #left, #left=, #margin, #margin=, #margin_bottom, #margin_bottom=, #margin_left, #margin_left=, #margin_right, #margin_right=, #margin_top, #margin_top=, #needs_positioning?, #positioned?, #right, #right=, #takes_up_space?, #top, #top=, #width=

Methods included from Common::Inspect

#inspect, #to_s

Constructor Details

#initialize(*args) ⇒ TextBlockDimensions

Returns a new instance of TextBlockDimensions.



11
12
13
14
15
16
17
# File 'shoes-core/lib/shoes/text_block_dimensions.rb', line 11

def initialize(*args)
  @absolute_right    = nil
  @absolute_bottom   = nil
  @calculated_width  = nil
  @calculated_height = nil
  super
end

Instance Attribute Details

#absolute_bottomObject



23
24
25
# File 'shoes-core/lib/shoes/text_block_dimensions.rb', line 23

def absolute_bottom
  @absolute_bottom || super
end

#absolute_rightObject



19
20
21
# File 'shoes-core/lib/shoes/text_block_dimensions.rb', line 19

def absolute_right
  @absolute_right || super
end

#calculated_height=(value) ⇒ Object (writeonly)

Sets the attribute calculated_height

Parameters:

  • value

    the value to set the attribute calculated_height to.



8
9
10
# File 'shoes-core/lib/shoes/text_block_dimensions.rb', line 8

def calculated_height=(value)
  @calculated_height = value
end

#calculated_width=(value) ⇒ Object (writeonly)

Sets the attribute calculated_width

Parameters:

  • value

    the value to set the attribute calculated_width to.



8
9
10
# File 'shoes-core/lib/shoes/text_block_dimensions.rb', line 8

def calculated_width=(value)
  @calculated_width = value
end

Instance Method Details

#containing_widthObject

If an explicit width’s set, use that when asking how much space we need. If not, we look to the parent.



61
62
63
# File 'shoes-core/lib/shoes/text_block_dimensions.rb', line 61

def containing_width
  element_width || parent.element_width
end

#desired_width(containing = nil) ⇒ Object

This is the width the text block initially wants to try to fit in.

If an explicit containing width is provided, trust that most If we’ve gotten an explicit width, use that but check that we fit still Last but certainly not least, consult what’s remaining in our parent.



47
48
49
50
51
52
53
54
55
56
57
# File 'shoes-core/lib/shoes/text_block_dimensions.rb', line 47

def desired_width(containing = nil)
  desired = if containing
              parent.absolute_left + containing - absolute_left
            elsif element_width
              [element_width, remaining_in_parent].min
            else
              remaining_in_parent
            end

  desired - margin_left - margin_right
end

#fitting_widthObject

Since we flow, try to fit in almost any space



38
39
40
# File 'shoes-core/lib/shoes/text_block_dimensions.rb', line 38

def fitting_width
  10
end

#heightObject



33
34
35
# File 'shoes-core/lib/shoes/text_block_dimensions.rb', line 33

def height
  super || @calculated_height
end

#remaining_in_parentObject



65
66
67
# File 'shoes-core/lib/shoes/text_block_dimensions.rb', line 65

def remaining_in_parent
  parent.absolute_left + parent.element_width - absolute_left
end

#widthObject

It might seem weird these reverse from above, but if explicit sizes get reported verbatim, while boundaries are set by text fitting.



29
30
31
# File 'shoes-core/lib/shoes/text_block_dimensions.rb', line 29

def width
  super || @calculated_width
end