Class: SilkLayout::Layout::Box

Inherits:
Object
  • Object
show all
Defined in:
lib/silk_layout/layout/box.rb

Direct Known Subclasses

AnonymousBlockBox, BlockBox, Inline, InlineBox, LineBox

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node) ⇒ Box

Returns a new instance of Box.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/silk_layout/layout/box.rb', line 28

def initialize(node)
  @node = node
  @children = []

  @x = 0
  @y = 0
  @width = 0
  @height = 0

  @margin = {top: 0, right: 0, bottom: 0, left: 0}
  @padding = {top: 0, right: 0, bottom: 0, left: 0}
  @border = {top: 0, right: 0, bottom: 0, left: 0}
  @border_color = {
    top: nil,
    right: nil,
    bottom: nil,
    left: nil
  }
  @background_color = nil

  @explicit_width = false
  @explicit_height = false
  @flex = {}
  @display = nil
  @replaced = false
  @image_source = nil
  @image_resource = nil
  @intrinsic_width = nil
  @intrinsic_height = nil
end

Instance Attribute Details

#background_colorObject

Returns the value of attribute background_color.



6
7
8
# File 'lib/silk_layout/layout/box.rb', line 6

def background_color
  @background_color
end

#borderObject

Returns the value of attribute border.



6
7
8
# File 'lib/silk_layout/layout/box.rb', line 6

def border
  @border
end

#border_colorObject

Returns the value of attribute border_color.



6
7
8
# File 'lib/silk_layout/layout/box.rb', line 6

def border_color
  @border_color
end

#childrenObject

Returns the value of attribute children.



6
7
8
# File 'lib/silk_layout/layout/box.rb', line 6

def children
  @children
end

#displayObject

Returns the value of attribute display.



6
7
8
# File 'lib/silk_layout/layout/box.rb', line 6

def display
  @display
end

#explicit_heightObject

Returns the value of attribute explicit_height.



6
7
8
# File 'lib/silk_layout/layout/box.rb', line 6

def explicit_height
  @explicit_height
end

#explicit_widthObject

Returns the value of attribute explicit_width.



6
7
8
# File 'lib/silk_layout/layout/box.rb', line 6

def explicit_width
  @explicit_width
end

#flexObject

Returns the value of attribute flex.



6
7
8
# File 'lib/silk_layout/layout/box.rb', line 6

def flex
  @flex
end

#has_borderObject

Returns the value of attribute has_border.



6
7
8
# File 'lib/silk_layout/layout/box.rb', line 6

def has_border
  @has_border
end

#heightObject

Returns the value of attribute height.



6
7
8
# File 'lib/silk_layout/layout/box.rb', line 6

def height
  @height
end

#image_resourceObject

Returns the value of attribute image_resource.



6
7
8
# File 'lib/silk_layout/layout/box.rb', line 6

def image_resource
  @image_resource
end

#image_sourceObject

Returns the value of attribute image_source.



6
7
8
# File 'lib/silk_layout/layout/box.rb', line 6

def image_source
  @image_source
end

#intrinsic_heightObject

Returns the value of attribute intrinsic_height.



6
7
8
# File 'lib/silk_layout/layout/box.rb', line 6

def intrinsic_height
  @intrinsic_height
end

#intrinsic_widthObject

Returns the value of attribute intrinsic_width.



6
7
8
# File 'lib/silk_layout/layout/box.rb', line 6

def intrinsic_width
  @intrinsic_width
end

#marginObject

Returns the value of attribute margin.



6
7
8
# File 'lib/silk_layout/layout/box.rb', line 6

def margin
  @margin
end

#nodeObject

Returns the value of attribute node.



6
7
8
# File 'lib/silk_layout/layout/box.rb', line 6

def node
  @node
end

#paddingObject

Returns the value of attribute padding.



6
7
8
# File 'lib/silk_layout/layout/box.rb', line 6

def padding
  @padding
end

#replacedObject

Returns the value of attribute replaced.



6
7
8
# File 'lib/silk_layout/layout/box.rb', line 6

def replaced
  @replaced
end

#widthObject

Returns the value of attribute width.



6
7
8
# File 'lib/silk_layout/layout/box.rb', line 6

def width
  @width
end

#xObject

Returns the value of attribute x.



6
7
8
# File 'lib/silk_layout/layout/box.rb', line 6

def x
  @x
end

#yObject

Returns the value of attribute y.



6
7
8
# File 'lib/silk_layout/layout/box.rb', line 6

def y
  @y
end

Instance Method Details

#add_child(box) ⇒ Object



59
60
61
# File 'lib/silk_layout/layout/box.rb', line 59

def add_child(box)
  @children << box
end

#border_box_heightObject



75
76
77
# File 'lib/silk_layout/layout/box.rb', line 75

def border_box_height
  height
end

#border_box_widthObject



71
72
73
# File 'lib/silk_layout/layout/box.rb', line 71

def border_box_width
  width
end

#border_box_xObject



63
64
65
# File 'lib/silk_layout/layout/box.rb', line 63

def border_box_x
  x
end

#border_box_yObject



67
68
69
# File 'lib/silk_layout/layout/box.rb', line 67

def border_box_y
  y
end

#content_box_heightObject



91
92
93
# File 'lib/silk_layout/layout/box.rb', line 91

def content_box_height
  [height - border[:top] - border[:bottom] - padding[:top] - padding[:bottom], 0].max
end

#content_box_widthObject



87
88
89
# File 'lib/silk_layout/layout/box.rb', line 87

def content_box_width
  [width - border[:left] - border[:right] - padding[:left] - padding[:right], 0].max
end

#content_box_xObject



79
80
81
# File 'lib/silk_layout/layout/box.rb', line 79

def content_box_x
  x + border[:left] + padding[:left]
end

#content_box_yObject



83
84
85
# File 'lib/silk_layout/layout/box.rb', line 83

def content_box_y
  y + border[:top] + padding[:top]
end

#image?Boolean

Returns:

  • (Boolean)


99
100
101
# File 'lib/silk_layout/layout/box.rb', line 99

def image?
  !image_resource.nil?
end

#image_pathObject



103
104
105
# File 'lib/silk_layout/layout/box.rb', line 103

def image_path
  image_resource&.path
end

#replaced?Boolean

Returns:

  • (Boolean)


95
96
97
# File 'lib/silk_layout/layout/box.rb', line 95

def replaced?
  replaced
end