package io.nacular.doodle.docs.apps
import io.nacular.doodle.application.Application
import io.nacular.doodle.core.Display
import io.nacular.doodle.core.view
import io.nacular.doodle.docs.utils.DEFAULT_FONT_FAMILIES
import io.nacular.doodle.drawing.Color.Companion.Blue
import io.nacular.doodle.drawing.Color.Companion.Red
import io.nacular.doodle.drawing.Color.Companion.White
import io.nacular.doodle.drawing.FontLoader
import io.nacular.doodle.drawing.Stroke
import io.nacular.doodle.drawing.SweepGradientPaint
import io.nacular.doodle.drawing.TextMetrics
import io.nacular.doodle.drawing.paint
import io.nacular.doodle.geometry.Point
import io.nacular.doodle.layout.constraints.constrain
import io.nacular.doodle.layout.constraints.fill
import io.nacular.measured.units.Angle.Companion.degrees
import io.nacular.measured.units.times
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
class HelloDoodle(
fonts : FontLoader,
display : Display,
appScope : CoroutineScope,
textMetrics: TextMetrics
): Application {
init {
appScope.launch {
// Fonts are loaded async
val bold = fonts {
families = DEFAULT_FONT_FAMILIES
size = 80
weight = 700
}
val textSize = textMetrics.size("Hello Doodle!", bold)
//sampleStart
display += view {
render = {
text(
"Hello Doodle!",
at = Point((width - textSize.width) / 2, (height - textSize.height) / 2),
font = bold,
stroke = Stroke(SweepGradientPaint(Red, Blue, Point(100, 75), 45 * degrees), thickness = 2.0)
)
}
}
//sampleEnd
display.fill(White.paint)
display.layout = constrain(display.first(), fill)
}
}
override fun shutdown() {}
}
Doodle helps you create beautiful, modern apps entirely in Kotlin. Its render model is intuitive yet powerful, making it easy to achieve complex UIs with pixel level precision and layouts. This simplicity and power applies to everything from user input to drag and drop. Doodle lets you build and animate anything.
Start creating your app for Web and Desktop; just define your View hierarchy and business logic, and go.
Feedback
Doodle is still under active development, so there are going to be gaps and bugs. Please report issues, and submit feature requests. You can also join the discussion on the #doodle Kotlin Slack channel.
tip
http://slack.kotl.in has instructions for invitations to Kotlin Slack.
Leave a star
Don't forget to drop us a star if you like what you see.