Class: Sketch::Layout
Constant Summary
Constants inherited from Sketch
Arc, Circle, Line, Path, Polygon, Polyline, Rectangle, Square
Instance Attribute Summary collapse
-
#alignment ⇒ Symbol
readonly
Alignment the layout alignment.
-
#direction ⇒ Symbol
readonly
Direction the layout direction (either :horizontal or :vertical).
-
#spacing ⇒ Number
readonly
Spacing spacing to add between each element.
Attributes inherited from Group
Attributes inherited from Sketch
#bounds, #elements, #first, #geometry, #last, #max, #min, #minmax, #size, #transformation
Instance Method Summary collapse
-
#initialize(direction = :horizontal, *args) ⇒ Layout
constructor
A new instance of Layout.
-
#push(element, *args) ⇒ Layout
Any pushed element that doesn’t have a transformation property will be wrapped in a Group.
Methods inherited from Group
#rotation, #scale, #translation
Methods inherited from Sketch
#add_arc, #add_circle, #add_line, #add_point, #add_rectangle, #add_square, #add_triangle, #define_parameter, define_parameter
Constructor Details
#initialize(direction = :horizontal, *args) ⇒ Layout
Returns a new instance of Layout.
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/sketch/layout.rb', line 26 def initialize(direction=:horizontal, *args) super , args = args.partition {|a| a.is_a? Hash} = .reduce({}, :merge) @alignment = .delete(:align) @spacing = .delete(:spacing) || 0 @direction = direction end |
Instance Attribute Details
#alignment ⇒ Symbol (readonly)
Returns alignment the layout alignment.
18 19 20 |
# File 'lib/sketch/layout.rb', line 18 def alignment @alignment end |
#direction ⇒ Symbol (readonly)
Returns direction the layout direction (either :horizontal or :vertical).
21 22 23 |
# File 'lib/sketch/layout.rb', line 21 def direction @direction end |
#spacing ⇒ Number (readonly)
Returns spacing spacing to add between each element.
24 25 26 |
# File 'lib/sketch/layout.rb', line 24 def spacing @spacing end |
Instance Method Details
#push(element, *args) ⇒ Layout
Any pushed element that doesn’t have a transformation property will be wrapped in a Group.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/sketch/layout.rb', line 41 def push(element, *args) max = last ? last.max : Point.zero offset = make_offset(element, element.min, max) if offset == Point.zero super element, *args else if element.respond_to?(:transformation=) super element, *args else super Group.new.push element, *args end last.transformation = Geometry::Transformation.new(origin:offset) + last.transformation end self end |