Class: Plushie::Widget::Column

Inherits:
Object
  • Object
show all
Defined in:
lib/plushie/widget/column.rb

Overview

Typed builder for the column widget (Layer 2 API).

Construct a Column, set properties via fluent +set_*+ methods, then call #build to produce a Node for the view tree.

Constant Summary collapse

PROPS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Supported property keys for this widget.

%i[spacing padding width height max_width align_x clip wrap a11y].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, **opts) ⇒ Column

Returns a new instance of Column.



18
19
20
21
22
# File 'lib/plushie/widget/column.rb', line 18

def initialize(id, **opts)
  @id = id.to_s
  @children = opts.delete(:children) || []
  PROPS.each { |k| instance_variable_set(:"@#{k}", opts[k]) if opts.key?(k) }
end

Instance Attribute Details

#a11yObject (readonly)

Returns the value of attribute a11y.



1
2
3
# File 'lib/plushie/widget/column.rb', line 1

def a11y
  @a11y
end

#align_xObject (readonly)

Returns the value of attribute align_x.



1
2
3
# File 'lib/plushie/widget/column.rb', line 1

def align_x
  @align_x
end

#childrenObject (readonly)

Returns the value of attribute children.



1
2
3
# File 'lib/plushie/widget/column.rb', line 1

def children
  @children
end

#clipObject (readonly)

Returns the value of attribute clip.



1
2
3
# File 'lib/plushie/widget/column.rb', line 1

def clip
  @clip
end

#heightObject (readonly)

Returns the value of attribute height.



1
2
3
# File 'lib/plushie/widget/column.rb', line 1

def height
  @height
end

#idObject (readonly)

Returns the value of attribute id.



1
2
3
# File 'lib/plushie/widget/column.rb', line 1

def id
  @id
end

#max_widthObject (readonly)

Returns the value of attribute max_width.



1
2
3
# File 'lib/plushie/widget/column.rb', line 1

def max_width
  @max_width
end

#paddingObject (readonly)

Returns the value of attribute padding.



1
2
3
# File 'lib/plushie/widget/column.rb', line 1

def padding
  @padding
end

#spacingObject (readonly)

Returns the value of attribute spacing.



1
2
3
# File 'lib/plushie/widget/column.rb', line 1

def spacing
  @spacing
end

#widthObject (readonly)

Returns the value of attribute width.



1
2
3
# File 'lib/plushie/widget/column.rb', line 1

def width
  @width
end

#wrapObject (readonly)

Returns the value of attribute wrap.



1
2
3
# File 'lib/plushie/widget/column.rb', line 1

def wrap
  @wrap
end

Instance Method Details

#buildPlushie::Node

Build a Node from the current property values.

Returns:



41
42
43
44
45
46
47
48
49
# File 'lib/plushie/widget/column.rb', line 41

def build
  props = {}
  PROPS.each do |key|
    val = instance_variable_get(:"@#{key}")
    Build.put_if(props, key, val)
  end
  Node.new(id: @id, type: "column", props: props,
    children: Build.children_to_nodes(@children))
end

#push(child) ⇒ self

Return a copy with the given child appended.

Parameters:

  • child (Object)

    a widget builder or Node to append

Returns:

  • (self)


34
35
36
# File 'lib/plushie/widget/column.rb', line 34

def push(child)
  dup.tap { _1.instance_variable_set(:@children, @children + [child]) }
end