Module: Plushie::Type::LineHeight

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

Overview

Line height for text widgets.

Accepts three forms:

  • A number (relative multiplier, e.g. 1.5)
  • +n+ for explicit relative line height
  • +n+ for absolute pixel line height

Numbers are passed through as-is (the renderer interprets plain numbers as relative multipliers). Maps are passed through so the renderer can distinguish the two explicit forms.

Examples:

text("msg", "Hello", line_height: 1.5)
text("msg", "Hello", line_height: {relative: 1.2})
text("msg", "Hello", line_height: {absolute: 24})

Class Method Summary collapse

Class Method Details

.encode(value) ⇒ Numeric, ...

Encode a line height value for the wire protocol.

Parameters:

  • value (Numeric, Hash, nil)

Returns:

  • (Numeric, Hash, nil)


27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/plushie/type/line_height.rb', line 27

def encode(value)
  case value
  when Numeric then value
  when Hash
    if value.key?(:relative) || value.key?(:absolute)
      value
    else
      raise ArgumentError, "line_height hash must have :relative or :absolute key, got: #{value.inspect}"
    end
  when nil then nil
  else raise ArgumentError, "invalid line_height: #{value.inspect}"
  end
end