Module: DynamicImageElements::ElementInterface
- Included in:
- BlockElement, ImageElement, TableElement, TextElement
- Defined in:
- lib/elements/element_interface.rb
Overview
Interface providing default methods for all elements in composite. Also contain some private methods which helps element to process common tasks.
Instance Method Summary collapse
-
#final_size ⇒ Object
Gives array that contains size of space occupied of element.
-
#set_height(height, inner = true) ⇒ Object
Changes element’s height option.
-
#set_width(width, inner = true) ⇒ Object
Changes element’s width option.
Instance Method Details
#final_size ⇒ Object
Gives array that contains size of space occupied of element. It’s calculated as #element_size + margin
83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/elements/element_interface.rb', line 83 def final_size w, h = element_size if @margin w += @margin[1] + @margin[3] h += @margin[0] + @margin[2] end if @border && !@border.empty? w += @border[:left][0] if @border[:left] w += @border[:right][0] if @border[:right] h += @border[:top][0] if @border[:top] h += @border[:bottom][0] if @border[:bottom] end [w, h] end |
#set_height(height, inner = true) ⇒ Object
Changes element’s height option
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/elements/element_interface.rb', line 116 def set_height(height, inner = true) #:nodoc: if height.nil? @options[:height] = nil elsif height > 0 unless inner height -= @padding[0] + @padding[2] if @padding height -= @margin[0] + @margin[2] if @margin if @border && !@border.empty? height -= @border[:top][0] if @border[:top] height -= @border[:bottom][0] if @border[:bottom] end end @options[:height] = height < 0 ? 0 : height recalculate_size! end end |
#set_width(width, inner = true) ⇒ Object
Changes element’s width option
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/elements/element_interface.rb', line 99 def set_width(width, inner = true) #:nodoc: if width.nil? @options[:width] = nil elsif width > 0 unless inner width -= @padding[1] + @padding[3] if @padding width -= @margin[1] + @margin[3] if @margin if @border && !@border.empty? width -= @border[:left][0] if @border[:left] width -= @border[:right][0] if @border[:right] end end @options[:width] = width < 0 ? 0 : width recalculate_size! end end |