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 }
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
-
.encode(value) ⇒ Hash?
Encode for the wire protocol.
-
.from_opts(opts) ⇒ Spec
Construct from keyword options.
-
.new ⇒ Spec
Create a new shadow with defaults.
Class Method Details
.encode(value) ⇒ Hash?
Encode for the wire protocol.
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.
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 |