Created
July 19, 2012 19:39
-
-
Save jslabovitz/3146276 to your computer and use it in GitHub Desktop.
MacRuby/RubyMotion 'Enum' class & sample code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env macruby | |
class Enum | |
def initialize(value) | |
@value = value | |
end | |
def pointer | |
ptr = Pointer.new(type) | |
ptr[0] = @value | |
ptr | |
end | |
def size | |
size_ptr = Pointer.new('Q') | |
align_ptr = Pointer.new('Q') | |
NSGetSizeAndAlignment(type, size_ptr, align_ptr) | |
size_ptr.value | |
end | |
end | |
class CTTextAlignment < Enum | |
def type | |
'C' | |
end | |
end | |
# sample code to test above classes | |
framework 'ApplicationServices' | |
alignment = CTTextAlignment.new(KCTCenterTextAlignment) | |
setting = CTParagraphStyleSetting.new(KCTParagraphStyleSpecifierAlignment, alignment.size, alignment.pointer) | |
settingsPtr = Pointer.new(CTParagraphStyleSetting.type) | |
settingsPtr[0] = setting | |
paragraphRef = CTParagraphStyleCreate(settingsPtr, 1) | |
p paragraphRef |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment