Class: Plushie::Widget::Text

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

Overview

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

Construct a Text, 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[content size color font width height line_height align_x align_y
wrapping ellipsis shaping style a11y].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, content = nil, **opts) ⇒ Text

Returns a new instance of Text.



19
20
21
22
23
24
# File 'lib/plushie/widget/text.rb', line 19

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

Instance Attribute Details

#a11yObject (readonly)

Returns the value of attribute a11y.



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

def a11y
  @a11y
end

#align_xObject (readonly)

Returns the value of attribute align_x.



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

def align_x
  @align_x
end

#align_yObject (readonly)

Returns the value of attribute align_y.



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

def align_y
  @align_y
end

#colorObject (readonly)

Returns the value of attribute color.



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

def color
  @color
end

#contentObject (readonly)

Returns the value of attribute content.



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

def content
  @content
end

#ellipsisObject (readonly)

Returns the value of attribute ellipsis.



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

def ellipsis
  @ellipsis
end

#fontObject (readonly)

Returns the value of attribute font.



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

def font
  @font
end

#heightObject (readonly)

Returns the value of attribute height.



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

def height
  @height
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#line_heightObject (readonly)

Returns the value of attribute line_height.



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

def line_height
  @line_height
end

#shapingObject (readonly)

Returns the value of attribute shaping.



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

def shaping
  @shaping
end

#sizeObject (readonly)

Returns the value of attribute size.



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

def size
  @size
end

#styleObject (readonly)

Returns the value of attribute style.



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

def style
  @style
end

#widthObject (readonly)

Returns the value of attribute width.



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

def width
  @width
end

#wrappingObject (readonly)

Returns the value of attribute wrapping.



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

def wrapping
  @wrapping
end

Instance Method Details

#buildPlushie::Node

Build a Node from the current property values.

Returns:



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/plushie/widget/text.rb', line 35

def build
  props = {}
  Build.put_if(props, :content, @content)
  Build.put_if(props, :size, @size)
  Build.put_if(props, :color, @color)
  Build.put_if(props, :font, @font)
  Build.put_if(props, :width, @width)
  Build.put_if(props, :height, @height)
  Build.put_if(props, :line_height, @line_height)
  Build.put_if(props, :align_x, @align_x)
  Build.put_if(props, :align_y, @align_y)
  Build.put_if(props, :wrapping, @wrapping)
  Build.put_if(props, :ellipsis, @ellipsis)
  Build.put_if(props, :shaping, @shaping)
  Build.put_if(props, :style, @style)
  Build.put_if(props, :a11y, @a11y)
  Node.new(id: @id, type: "text", props: props)
end