# frozen_string_literal: true module Vedeu module Presentation # Provides colour related presentation behaviour. # # @api private # module Colour # When the background colour for the model exists, return it, # otherwise returns the parent background colour, or an empty # Vedeu::Colours::Background. # # @return [Vedeu::Colours::Background] def background @background ||= if colour && present?(colour.background) colour.background elsif named_colour? named_colour.background elsif parent && present?(parent.background) parent.background else Vedeu::Colours::Background.new end end # Allows the setting of the background colour by coercing the # given value into a Vedeu::Colours::Background colour. # # @return [Vedeu::Colours::Background] def background=(value) @background = colour.background = value @_colour = @colour = colour end # @return [Vedeu::Colours::Colour] def colour @_colour ||= if colour? Vedeu::Colours::Colour.coerce(@colour) elsif parent_colour? Vedeu::Colours::Colour.coerce(parent_colour) elsif named_colour? Vedeu::Colours::Colour.coerce(named_colour) else Vedeu::Colours::Colour.new end end # Allows the setting of the model's colour by coercing the given # value into a Vedeu::Colours::Colour. # # @return [Vedeu::Colours::Colour] def colour=(value) @_colour = @colour = Vedeu::Colours::Colour.coerce(value) end # @return [Boolean] def colour? present?(@colour) end # When the foreground colour for the model exists, return it, # otherwise returns the parent foreground colour, or an empty # Vedeu::Colours::Foreground. # # @return [Vedeu::Colours::Foreground] def foreground @foreground ||= if colour && present?(colour.foreground) colour.foreground elsif named_colour? named_colour.foreground elsif parent && present?(parent.foreground) parent.foreground else Vedeu::Colours::Foreground.new end end # Allows the setting of the foreground colour by coercing the # given value into a Vedeu::Colours::Foreground colour. # # @return [Vedeu::Colours::Foreground] def foreground=(value) @foreground = colour.foreground = value @_colour = @colour = colour end # @return [NilClass|void] def parent present?(@parent) ? @parent : nil end # @return [NilClass|String|Symbol] def name if present?(@name) @name elsif parent && present?(parent.name) parent.name end end private # @return [Vedeu::Colours::Colour] def named_colour Vedeu.interfaces.by_name(name).colour end # @return [Boolean] def named_colour? return false if is_a?(Vedeu::Interfaces::Interface) present?(name) && Vedeu.interfaces.registered?(name) end # @return [Vedeu::Colours::Colour] def parent_colour parent.colour end # @return [Boolean] def parent_colour? present?(parent) && parent.respond_to?(:colour?) end end # Colour end # Presentation end # Vedeu