Skip to content

Instantly share code, notes, and snippets.

@clydebarrow
Last active October 18, 2021 23:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clydebarrow/8c799729e292bb7c6bc3c72f8f9f5469 to your computer and use it in GitHub Desktop.
Save clydebarrow/8c799729e292bb7c6bc3c72f8f9f5469 to your computer and use it in GitHub Desktop.
XLayout sample
package com.mycompany.myapp
import com.controlj.layout.FrameGroup
import com.controlj.layout.Gravity
import com.controlj.layout.HorizontalGroup
import com.controlj.layout.IosUxHost
import com.controlj.layout.Layout
import com.controlj.layout.VerticalGroup
import com.controlj.layout.VerticalGroup.Companion.verticalGroup
import com.controlj.shim.IosCxFactory
import com.controlj.shim.addView
import org.robovm.apple.uikit.UIViewController
import org.robovm.apple.uikit.UIButton
import org.robovm.apple.uikit.UILabel
import org.robovm.apple.uikit.UIColor
import org.robovm.apple.coregraphics.CGRect
import org.robovm.apple.uikit.UIFont
import org.robovm.apple.uikit.NSTextAlignment
import org.robovm.apple.uikit.UIButtonType
import org.robovm.apple.uikit.UIControlState
import org.robovm.apple.uikit.UIControl
import org.robovm.apple.uikit.UIEvent
class MyViewController : UIViewController() {
private var clickCount = 0
private val label: UILabel = UILabel()
private val button = UIButton(UIButtonType.RoundedRect)
override fun loadView() {
// VerticalGroup is like a vertical LinearLayout.
val group = VerticalGroup().apply {
layout.widthMode = Layout.Mode.MatchParent
layout.heightMode = Layout.Mode.MatchParent
// addView adds a native UI element with a Layout to control its size.
addView(button, Layout (widthMode= Layout.Mode.MatchParent, gravity = Gravity.Center ))
addView(label, Layout ( widthMode = Layout.Mode.WrapContent, gravity = Gravity.Center ))
}
// IosUxHost is a native container for XLayout groups (FrameGroup, VerticalGroup, HorizontalGroup)
view = IosUxHost(group)
view.backgroundColor = UIColor.lightGray()
// Setup label.
label.font = UIFont.getSystemFont(24.0)
label.textAlignment = NSTextAlignment.Center
label.text = "Testing..."
// Setup button.
button.setTitle("Click me!", UIControlState.Normal)
button.titleLabel.font = UIFont.getBoldSystemFont(22.0)
button.addOnTouchUpInsideListener { control: UIControl?, event: UIEvent? ->
label.text = "Click Nr. " + ++clickCount
}
button.backgroundColor = UIColor.white()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment