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
new SVerticalLayout { | |
STextView("ID") | |
val userId = SEditText() | |
SButton("Sign in", signin(userId.text)) | |
}.padding(20 dip) |
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
[info] [running phase parser on 9 compilation units] | |
[info] [running phase macroparadise on 9 compilation units] | |
[info] [running phase namer on 9 compilation units] | |
[info] [running phase packageobjects on 9 compilation units] | |
[info] [running phase typer on 9 compilation units] | |
[warn] issue error: type mismatch; | |
[warn] found : c.WeakTypeTag[X&0] | |
[warn] (which expands to) c.universe.WeakTypeTag[X&0] | |
[warn] required: c.universe.WeakTypeTag[needs.this.Need[_$1] forSome { type _$1 }] | |
[warn] issue error: type mismatch; |
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
// deep search inside myLayout | |
myLayout ~~> { | |
// make all buttons have medium-sized text | |
case b: Button ⇒ b ~> TextSize.medium | |
// find layouts consisting of just ImageView and TextView | |
case Layout(m: ImageView, t: TextView) ⇒ | |
t ~> text("I’m next to an image") | |
// hide everything else | |
case otherStuff ⇒ otherStuff ~> hide | |
} |
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á” |
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
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
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
// 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
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
var status = slot[TextView] | |
setContentView { | |
l[LinearLayout]( | |
w[TextView] ~> text("Downloading") ~> wire(status), | |
w[TextView] ~> text("the internet...") ~> id(Id.inet) | |
) | |
} | |
// after some time... |