Module: Plushie::Type::Shadow

Defined in:
lib/plushie/type/shadow.rb

Overview

Shadow specification for widget styling.

Wire format: { color: "#00000080", offset: [4, 4], blur_radius: 8.0 }

Examples:

Keyword construction

Shadow.from_opts(color: "#00000040", offset_x: 2, offset_y: 2, blur_radius: 6)

DSL block form

container("card") do
  shadow do
    color "#00000022"
    offset_y 2
    blur_radius 4
  end
end

Defined Under Namespace

Classes: Spec

Constant Summary collapse

FIELD_KEYS =

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.

Recognized field keys for shadow specs.

%i[color offset offset_x offset_y blur_radius].freeze

Class Method Summary collapse

Class Method Details

.encode(value) ⇒ Hash?

Encode for the wire protocol.

Parameters:

  • value (Spec, Hash, nil)

Returns:

  • (Hash, nil)


69
70
71
72
73
74
75
76
# File 'lib/plushie/type/shadow.rb', line 69

def encode(value)
  case value
  when Spec then value.to_wire
  when Hash then value
  when nil then nil
  else raise ArgumentError, "invalid shadow: #{value.inspect}"
  end
end

.from_opts(opts) ⇒ Spec

Construct from keyword options.

Parameters:

  • opts (Hash)

    :color, :offset (array), :offset_x, :offset_y, :blur_radius

Returns:



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/plushie/type/shadow.rb', line 53

def from_opts(opts)
  spec = Spec.new
  spec = spec.with(color: Color.cast(opts[:color])) if opts[:color]
  if opts[:offset]
    x, y = opts[:offset]
    spec = spec.with(offset_x: x, offset_y: y)
  end
  spec = spec.with(offset_x: opts[:offset_x]) if opts[:offset_x]
  spec = spec.with(offset_y: opts[:offset_y]) if opts[:offset_y]
  spec = spec.with(blur_radius: opts[:blur_radius]) if opts[:blur_radius]
  spec
end

.newSpec

Create a new shadow with defaults.

Returns:



46
47
48
# File 'lib/plushie/type/shadow.rb', line 46

def new
  Spec.new
end