This file contains hidden or 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
/* Basic example */ | |
@workflow[List] val x = List(1, 2) * List(4, 5) | |
/* Using @context */ | |
@context[Option] val x = { | |
$(Some(42) + 1) should equal (Some(43)) | |
$(Some(10) + Some(5) * Some(2)) should equal (Some(20)) | |
} | |
@context[List] val x = { |
This file contains hidden or 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
l[ScrollView]( | |
l[LinearLayout]( | |
w[TextView], | |
w[Button], | |
l[LinearLayout]( | |
w[ImageView], | |
w[ImageView] | |
), | |
// this will use ProgressBar(context, attrs, defStyle); context is passed for you automatically! | |
w[ProgressBar](null, android.R.attr.progressBarStyleLarge) |
This file contains hidden or 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
l[LinearLayout]( | |
w[TextView] ~> text("Howdy?") ~> TextSize.large ~> | |
// this will automatically use LinearLayout.LayoutParams | |
layoutParams(MATCH_PARENT, WRAP_CONTENT), | |
w[ImageView] ~> hide ~> { x ⇒ | |
// custom initialization | |
x.setScaleType(ImageView.ScaleType.FIT_START) | |
x.setAdjustViewBounds(true) | |
} |
This file contains hidden or 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
var status = slot[TextView] | |
setContentView { | |
l[LinearLayout]( | |
w[TextView] ~> text("Downloading") ~> wire(status), | |
w[TextView] ~> text("the internet...") ~> id(Id.inet) | |
) | |
} | |
// after some time... |
This file contains hidden or 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
var greeting = slot[TextView] | |
l[LinearLayout]( | |
w[Button] ~> | |
text("Greet me!") ~> | |
On.click { | |
greeting ~> text("Hello there") ~> show | |
}, | |
w[TextView] ~> hide ~> wire(greeting) |
This file contains hidden or 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
// if screen width > 1000 dip, make layout horizontal, else make it vertical | |
l[LinearLayout](...) ~> (minWidth(1000 dp) ? horizontal | vertical) | |
// use different widget depending on screen width | |
(widerThan(1000 dp) ? w[BigTextView] | | |
widerThan(600 dp) ? w[MediumTextView] | | |
w[TextView]) ~> text("Gibberish") | |
// tweak a widget only if a condition is met | |
w[TextView] ~> text("Balderdash!") ~> (hdpi ? TextSize.large) |
This file contains hidden or 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
l[LinearLayout]( | |
// It.stuff generates a new id | |
// Tag.stuff just returns "stuff", but boy! isn’t it fancy? | |
f[MyAwesomeFragment](Id.stuff, Tag.stuff, "items" → 4, "title" → "buzz"), | |
f[SupportMapFragment](Id.map, Tag.mainMap) | |
) |
This file contains hidden or 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
trait MyStyles extends LayoutDsl with MediaQueries with ExtraTweaks { | |
// sets text, large font size and a long click handler | |
def caption(cap: String)(implicit ctx: Context): Tweak[TextView] = | |
text(cap) + TextSize.large + On.longClick { | |
Toast.makeText(ctx, "I’m a caption", Toast.LENGTH_SHORT).show() | |
true | |
} | |
// sets large font size for high-density screens, medium font size for medium-density screens | |
// does nothing in other cases |
This file contains hidden or 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
myTextView ~> | |
text("Voilà") ~@> | |
fadeIn(400) ~@> | |
delay(500) ~> | |
text("Bye!") ~@> | |
fadeOut(400) ~> | |
text("Nobody will see this text") |
This file contains hidden or 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
// apply optional tweak: Option[Tweak[_]] | |
def large(implicit ctx: Context): Option[Tweak[TextView]] = hdpi ? TextSize.large | |
myTextView ~> large | |
// apply a list of tweaks: List[Tweak[_]] | |
myButton ~> List(text("The red button"), id(Id.redButton)) | |
// functional reactive programming: Rx[Tweak[_]] | |
val caption = rx.Var("Olá") | |
myTextView ~> caption.map(c ⇒ text(c)) // sets text to “Olá” |
OlderNewer