Created
January 26, 2013 02:31
-
-
Save anonymous/4639734 to your computer and use it in GitHub Desktop.
RoboVM IOSDemo ported to Scala + some additional crap.
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
import org.robovm.cocoatouch.coregraphics._ | |
import org.robovm.cocoatouch.foundation._ | |
import org.robovm.cocoatouch.uikit._ | |
object Utils { | |
import scala.language.implicitConversions | |
implicit class RichUIControl(control: UIControl) { | |
def onTouchUpInside(handler: (UIControl, UIEvent) => Unit) { | |
control.addOnTouchUpInsideListener(new UIControl.OnTouchUpInsideListener { | |
override def onTouchUpInside(c: UIControl, e: UIEvent) = handler(c,e) | |
}) | |
} | |
def onTouchUpInside(handler: => Unit) { onTouchUpInside { (_,_) => handler }} | |
} | |
def autoReleasePool(block: => Unit) { | |
val pool = new NSAutoreleasePool() | |
block | |
pool.drain() | |
} | |
implicit def tuple4ToCGRect(tuple4: (Float,Float,Float,Float)) = { | |
val (x,y,w,h) = tuple4 | |
new CGRect(x,y,w,h) | |
} | |
} | |
class RoboTest extends UIApplicationDelegate.Adapter { | |
var window: UIWindow = _ | |
override def didFinishLaunching(application: UIApplication, launchOptions: NSDictionary) = { | |
import Utils._ | |
val label = new UILabel(50.0f, 221.0f, 220.0f, 37.0f) | |
label.setText("") | |
label.setTextAlignment(NSTextAlignment.Center) | |
val button = UIButton.fromType(UIButtonType.RoundedRect) | |
button.setFrame(50.0f, 121.0f, 220.0f, 37.0f) | |
button.setTitle("Click me!", UIControlState.Normal) | |
var clickCount = 0 | |
button.onTouchUpInside { (_,event) => | |
label.setText(event.getTimestamp.toString) | |
button.setTitle("Hello from scala #" + {clickCount = clickCount + 1; clickCount}, UIControlState.Normal); | |
} | |
window = new UIWindow(UIScreen.getMainScreen().getBounds()) | |
window.setBackgroundColor(UIColor.lightGrayColor()) | |
window.addSubview(button) | |
window.addSubview(label) | |
window.makeKeyAndVisible() | |
true | |
} | |
} | |
object RoboTest { | |
def main(args: Array[String]) { | |
Utils.autoReleasePool { | |
UIApplication.main(args, null, classOf[RoboTest]) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Because of my problems compiling this, I created a fork:
https://gist.github.com/sebnozzi/5653898
My situation is described here:
https://groups.google.com/d/topic/scala-user/AyEhjNMHAJ0/discussion
Line 37 should be: