Module: Shoes::Common::Style

Included in:
UIElement, InternalApp, Link
Defined in:
shoes-core/lib/shoes/common/style.rb

Defined Under Namespace

Modules: StyleWith

Constant Summary collapse

DEFAULT_STYLES =
{
  rotate:      0,
  stroke:      Shoes::COLORS[:black],
  strokewidth: 1
}
STYLE_GROUPS =
{
  art_styles:           [:angle, :cap, :click, :fill, :rotate, :stroke,
                         :strokewidth, :transform, :translate],
  common_styles:        [:displace_left, :displace_top, :hidden],
  dimensions:           [:bottom, :height, :left, :margin,
                         :margin_bottom, :margin_left, :margin_right,
                         :margin_top, :right, :top, :width],
  text_block_styles:    [:align, :click, :emphasis, :family, :fill, :font,
                         :justify, :kerning, :leading, :rise, :size, :stretch,
                         :strikecolor, :strikethrough, :stroke, :undercolor,
                         :underline, :weight, :wrap],
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object

end of StyleWith module


127
128
129
# File 'shoes-core/lib/shoes/common/style.rb', line 127

def self.included(klass)
  klass.extend StyleWith
end

Instance Method Details

#applicable_app_stylesObject


62
63
64
65
66
67
68
69
# File 'shoes-core/lib/shoes/common/style.rb', line 62

def applicable_app_styles
  @app.style.each_with_object({}) do |(key, value), memo|
    changed_from_default = DEFAULT_STYLES[key] != value
    if supported_styles.include?(key) && changed_from_default
      memo[key] = value
    end
  end
end

#create_style_hashObject


55
56
57
58
59
60
# File 'shoes-core/lib/shoes/common/style.rb', line 55

def create_style_hash
  @style = {}
  supported_styles.each do |key|
    @style[key] = nil
  end
end

#style(new_styles = nil) ⇒ Object

Adds styles, or just returns current style if no argument


32
33
34
35
# File 'shoes-core/lib/shoes/common/style.rb', line 32

def style(new_styles = nil)
  update_style(new_styles) if need_to_update_style?(new_styles)
  @style
end

#style_init(arg_styles, new_styles = {}) ⇒ Object


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'shoes-core/lib/shoes/common/style.rb', line 37

def style_init(arg_styles, new_styles = {})
  create_style_hash
  @style.merge!(DEFAULT_STYLES)
  @style.merge!(self.class::STYLES) if defined?(self.class::STYLES)
  @style.merge!(applicable_app_styles)
  @style.merge!(@app.element_styles[self.class]) if @app.element_styles[self.class]

  @app.remove_styles.each do |to_remove|
    @style.delete(to_remove)
  end

  @style.merge!(new_styles)
  @style.merge!(arg_styles)
  @style = StyleNormalizer.new.normalize(@style)

  set_hovers(@style)
end