Skip to content

Instantly share code, notes, and snippets.

Created January 26, 2013 02:31
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/4639734 to your computer and use it in GitHub Desktop.
Save anonymous/4639734 to your computer and use it in GitHub Desktop.
RoboVM IOSDemo ported to Scala + some additional crap.
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])
}
}
}
@sebnozzi
Copy link

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:

NSDictionary[_ <: NSObject, _ <: NSObject]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment