Class: Symbol

Inherits:
Object
  • Object
show all
Defined in:
lib/sugarcube/symbol.rb,
lib/sugarcube/defaults.rb,
lib/sugarcube/symbol/symbol_uicolor.rb

Overview

Adds some UI classes to the Symbol class. These methods are prefixed with ‘ui` to make their intent clear, and to provide a little bit of “namespacing”

# alignment
:left.uialignment => UITextAlignmentLeft

# uicolors
:black.uicolor => UIColor.blackColor

:darkturquoise.uicolor => UIColor.blackColor

# fonts
:system.uifont => UIFont.systemFontOfSize(UIFont.systemFontSize)
:label.uifont => UIFont.systemFontOfSize(UIFont.labelFontSize)

You can extend the defaults by adding entries:

Symbol.css_colors[:my_color] = 0x123456
Symbol.font_sizes[:big] = 40

:my_color.uicolor => UIColor
:big.uifont => UIFont

Class Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.alignmentsObject

Returns the value of attribute alignments.



28
29
30
# File 'lib/sugarcube/symbol.rb', line 28

def alignments
  @alignments
end

.bordertypesObject

Returns the value of attribute bordertypes.



31
32
33
# File 'lib/sugarcube/symbol.rb', line 31

def bordertypes
  @bordertypes
end

.buttontypesObject

Returns the value of attribute buttontypes.



30
31
32
# File 'lib/sugarcube/symbol.rb', line 30

def buttontypes
  @buttontypes
end

.controleventsObject

Returns the value of attribute controlevents.



33
34
35
# File 'lib/sugarcube/symbol.rb', line 33

def controlevents
  @controlevents
end

.controlstatesObject

Returns the value of attribute controlstates.



32
33
34
# File 'lib/sugarcube/symbol.rb', line 32

def controlstates
  @controlstates
end

.css_colorsObject

Returns the value of attribute css_colors.



4
5
6
# File 'lib/sugarcube/symbol/symbol_uicolor.rb', line 4

def css_colors
  @css_colors
end

.devicesObject

Returns the value of attribute devices.



27
28
29
# File 'lib/sugarcube/symbol.rb', line 27

def devices
  @devices
end

.font_sizesObject

Returns the value of attribute font_sizes.



35
36
37
# File 'lib/sugarcube/symbol.rb', line 35

def font_sizes
  @font_sizes
end

.orientationsObject

Returns the value of attribute orientations.



29
30
31
# File 'lib/sugarcube/symbol.rb', line 29

def orientations
  @orientations
end

.system_fontsObject

Returns the value of attribute system_fonts.



34
35
36
# File 'lib/sugarcube/symbol.rb', line 34

def system_fonts
  @system_fonts
end

.uicolorsObject

Returns the value of attribute uicolors.



3
4
5
# File 'lib/sugarcube/symbol/symbol_uicolor.rb', line 3

def uicolors
  @uicolors
end

Instance Method Details

#get_defaultObject



3
4
5
# File 'lib/sugarcube/defaults.rb', line 3

def get_default
  NSUserDefaults.standardUserDefaults.objectForKey(self)
end

#remove_defaultObject



11
12
13
# File 'lib/sugarcube/defaults.rb', line 11

def remove_default
  NSUserDefaults.standardUserDefaults.removeObjectForKey(self)
end

#set_default(val) ⇒ Object



7
8
9
# File 'lib/sugarcube/defaults.rb', line 7

def set_default val
  NSUserDefaults.standardUserDefaults.setObject(val, forKey:self)
end

#to_teacup_stylesheetObject



186
187
188
# File 'lib/sugarcube/symbol.rb', line 186

def to_teacup_stylesheet
  Teacup::Stylesheet[self]
end

#uialignmentObject



140
141
142
# File 'lib/sugarcube/symbol.rb', line 140

def uialignment
  look_in(Symbol.alignments)
end

#uibordertypeObject



152
153
154
# File 'lib/sugarcube/symbol.rb', line 152

def uibordertype
  look_in(Symbol.bordertypes)
end

#uibuttontypeObject



148
149
150
# File 'lib/sugarcube/symbol.rb', line 148

def uibuttontype
  look_in(Symbol.buttontypes)
end

#uicolor(alpha = nil) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/sugarcube/symbol/symbol_uicolor.rb', line 7

def uicolor(alpha=nil)
  begin
    # iOS colors
    color = UIColor.send(look_in(Symbol.uicolors))

    if not alpha.nil?
      color = color.colorWithAlphaComponent(alpha.to_f)
    end
  rescue SugarNotFoundException
    # css colors
    color = look_in(Symbol.css_colors).uicolor(alpha)
  end

  color
end

#uicontroleventObject



160
161
162
# File 'lib/sugarcube/symbol.rb', line 160

def uicontrolevent
  look_in(Symbol.controlevents)
end

#uicontrolstateObject



156
157
158
# File 'lib/sugarcube/symbol.rb', line 156

def uicontrolstate
  look_in(Symbol.controlstates)
end

#uideviceObject



132
133
134
135
136
137
138
# File 'lib/sugarcube/symbol.rb', line 132

def uidevice
  look_in(Symbol.devices)
  if Symbol.devices[self]
    return Symbol.devices[self]
  end
  raise SugarNotFoundException.new(self)
end

#uifont(size = UIFont.systemFontSize) ⇒ Object



164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/sugarcube/symbol.rb', line 164

def uifont(size=UIFont.systemFontSize)
  # system fonts
  begin
    font = look_in(Symbol.system_fonts)
    if Symbol === size
      size = Symbol.font_sizes.fetch(size).uifontsize
    end
    return UIFont.send(font, size)
  rescue SugarNotFoundException
    size = look_in(font_sizes).uifontsize
    return UIFont.systemFontOfSize(size)
  end
end

#uifontsizeObject



178
179
180
181
182
183
184
# File 'lib/sugarcube/symbol.rb', line 178

def uifontsize
  size = look_in(Symbol.system_fonts)
  if Symbol === size
    return UIFont.send(Symbol.font_sizes[self])
  end
  return size.to_f
end

#uiorientationObject



144
145
146
# File 'lib/sugarcube/symbol.rb', line 144

def uiorientation
  look_in(Symbol.orientations)
end