Class: Metro::Model::DimensionsProperty

Inherits:
Property
  • Object
show all
Defined in:
lib/metro/models/properties/dimensions_property.rb

Overview

A dimensions property maintains an width and height.

A dimensions property also defines a ‘width` property and a `height` property which allows a more direct interface. Changing these values will update the dimensions the next time that it is drawn.

Dimensions is stored in the properties as a string and is converted into a Dimensions when it is retrieved within the system. When retrieving the dimensions.

Examples:

Defining a dimensions property


class Hero < Metro::Model
  property :dimensions
end

Defining a dimensions providing a default


class Hero < Metro::Model
  property :dimensions, default: Dimensions.of(100.0, 100.0)
end

Using a dimensions property with a different property name


class Hero < Metro::Model
  property :box, type: dimensions, default: Dimensions.of(100.0, 100.0)
  # box_width, box_height
end

Using a dimensions property providing a default block (to be calculated

when the model retrieves the value - allowing for the model's scene and window
to be set.)

  class Hero < Metro::Model
    property :dimensions do
      # Return the dimensions of the current window for the hero
      model.window.dimensions
    end
  end

Constant Summary

Constants included from Units

Units::Bounds

Instance Attribute Summary

Attributes inherited from Property

#block, #model, #options

Instance Method Summary collapse

Methods inherited from Property

define_property, defined_properties, get, #get, get_or_set, gets, hash_with_default_to_nil, inherited, #initialize, properties, properties_hash, property, #set, set, sets

Constructor Details

This class inherits a constructor from Metro::Model::Property

Instance Method Details

#default_dimensionsObject



70
71
72
# File 'lib/metro/models/properties/dimensions_property.rb', line 70

def default_dimensions
  Dimensions.parse default_dimensions_params.to_s
end