Norris
08/04/2024, 2:57 PMval styledLabel = Label(
bold("Lorem Ipsum").." is simply "..Yellow("dummy text", Background)..
" of the printing and typesetting industry. It has been the industry's standard dummy text "..
TextDecoration(setOf(Under), Red, Wavy) ("ever since the 1500s")..
", when an unknown printer took a galley of type and scrambled it to make a type specimen book."
).apply {
width = 250.0
fitText = setOf(Height)
wrapsWords = true
lineSpacing = 1f
textAlignment = Start
letterSpacing = 0.0
}
I think I am running into this issue because I am trying to build objects imperatively not declaratively. Is it possible to do this?Nick
08/04/2024, 3:07 PMapply
block above is a Kotlinism that gives you a scope where the this
reference is implied; sort of like your code is within the class of the object it is attached to. so anything you see in apply
can be done explicitly like you mentioned.Norris
08/04/2024, 3:08 PMNick
08/04/2024, 3:29 PMclass MyApp(display: Display, tm: TextMetrics): Application {
CommonLabelBehavior(tm, …)
// …
}
this will work as long as you inject it like you do for the Display
. you don’t need additional modules since it is bounded by default.
application {
MyApp(display = instance(), tm = instance())
}
Norris
08/04/2024, 7:52 PMNick
08/04/2024, 7:57 PMApplication
class anywhere (i.e. MyApp
above), since it’s just a regular class. this makes testing possible. but a runnable app has to be inside the application
closure for the platform. that closure creates all the platform instances you need to execute an app, like the Display
, etc. for web vs desktop, and other platforms.
is there a use case you have that needs to avoid the closure?Norris
08/04/2024, 8:09 PMNorris
08/04/2024, 8:33 PMNick
08/04/2024, 9:49 PMapplication
block, Measured (also written by me) for things like time, and Kotlin Date Time when using a some optional controls. otherwise, it tries to get out of your way. a good example of this is you don't actually have to worry about the existence of a injection framework in your actual app. the DI happens in the application
block, and you are free to extend knowledge of that to your app, or just pass dependencies into it manually. i prefer the latter b/c it makes apps more testable and isolates them from Kodein.
beyond that, you can use layouts to manage how stuff is presented on the screen, or you can manually position things. you can use Themes, provide explicit Behaviors to the existing controls, or just roll your own Views that don't even care about themes or behaviors.
a big part of Doodle's philosophy is that it shouldn't feel like a web framework. your app won't actually care about browser concepts and it can all be written in commonMain and then run on the JVM etc. w/o any modifications.
feedback is one of the most useful ways to make something like this better by the way. so please feel free to share you experience as you consider Doodle.