Class: Plushie::Widget::Floating

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

Overview

Floating overlay -- positions child with translation and scaling.

Props:

  • translate_x (number) -- horizontal translation in pixels.
  • translate_y (number) -- vertical translation in pixels.
  • scale (number) -- scale factor.
  • width (length) -- float width.
  • height (length) -- float height.
  • a11y (hash) -- accessibility overrides.

Examples:

f = Plushie::Widget::Floating.new("popup", translate_x: 10, translate_y: 20)
  .push(Plushie::Widget::Text.new("msg", "Hello"))
node = f.build

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[translate_x translate_y scale width height a11y].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, **opts) ⇒ Floating

Returns a new instance of Floating.

Parameters:

  • id (String)

    widget identifier

  • opts (Hash)

    optional properties



30
31
32
33
34
# File 'lib/plushie/widget/floating.rb', line 30

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/floating.rb', line 1

def a11y
  @a11y
end

#childrenObject (readonly)

Returns the value of attribute children.



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

def children
  @children
end

#heightObject (readonly)

Returns the value of attribute height.



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

def height
  @height
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#scaleObject (readonly)

Returns the value of attribute scale.



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

def scale
  @scale
end

#translate_xObject (readonly)

Returns the value of attribute translate_x.



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

def translate_x
  @translate_x
end

#translate_yObject (readonly)

Returns the value of attribute translate_y.



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

def translate_y
  @translate_y
end

#widthObject (readonly)

Returns the value of attribute width.



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

def width
  @width
end

Instance Method Details

#buildPlushie::Node

Returns:



50
51
52
53
54
55
56
57
58
# File 'lib/plushie/widget/floating.rb', line 50

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

#push(child) ⇒ Floating

Append a child widget.

Parameters:

Returns:

  • (Floating)

    new instance with the child appended



45
46
47
# File 'lib/plushie/widget/floating.rb', line 45

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