Is there an example how to use the Jetpack Compose...
# kilua
s
Is there an example how to use the Jetpack Compose API? I added the
dev.kilua:kilua-jetpack
dependency, but for example I don't find the
Box
class.
โœ… 1
r
You should be able to
s
Yeah, it just started to work.
dev.kilua.compose.foundation.layout.Box
Maybe a Gradle/IDEA issue.
This should give me a red background with a centered text, right?
Copy code
import dev.kilua.Application
import dev.kilua.CoreModule
import dev.kilua.Hot
import dev.kilua.JetpackModule
import dev.kilua.compose.foundation.layout.Box
import dev.kilua.compose.root
import dev.kilua.compose.ui.Alignment
import dev.kilua.compose.ui.Modifier
import dev.kilua.compose.ui.background
import dev.kilua.compose.ui.fillMaxSize
import dev.kilua.form.text.Text
import dev.kilua.html.Color
import dev.kilua.startApplication

class App : Application() {

    override fun start() {

        root("root") {

            Box(
                contentAlignment = Alignment.Center,
                modifier = Modifier
                    .fillMaxSize()
                    .background(Color.Aqua)
            ) {

                Text("Hello")
            }
        }
    }
}

fun main() {
    startApplication(
        ::App,
        bundlerHot(),
        JetpackModule,
        CoreModule
    )
}

fun bundlerHot(): Hot? {
    return js("import.meta.webpackHot").unsafeCast<Hot?>()
}
r
No :)
s
That's why I asked for an example project ๐Ÿ˜„
Yes, my screen is white. How do I do it?
r
the correct code is this:
Copy code
Box(
                            contentAlignment = Alignment.Center,
                            modifier = Modifier
                                .fillMaxSize()
                                .background(Color.Aqua)
                        ) {
                            span {
                                +"Hello"
                            }
                        }
1. Kilua's composable functions are lowercase.
Even though jetpack api (Box, Column, Row) are uppercase, all other functions are lowercase.
s
Ah, I see... I got the wrong "Text"... I was looking for the Compose API text
r
2. class
Text
and composable
text
is text input control
s
Copy code
Box(
                contentAlignment = Alignment.Center,
                modifier = Modifier
                    .background(Color.Aqua)
                    .fillMaxSize()
            ) {

                span {
                    textNode("Hello")
                }
            }
That works, but why is fillMaxSize() not effective?
Ah, I see the implementation.
So I'd need to request the browser window size and set this as size
r
What do you mean "not effective" ?
s
Wouldn't it make sense to have a
dev.kilua.compose.foundation.layout.Text
that does
span {  textNode("Hello")
behind the scenes?
r
Probably yes, but you would like other jetpack classes as well, at that's probably a lot of work.
s
What do you mean "not effective" ?
I somehow expected this to fill the whole screen.
Copy code
root("root") {

            Box(
                contentAlignment = Alignment.Center,
                modifier = Modifier
                    .background(Color.Aqua)
                    .fillMaxSize()
            ) {
                
                span {
                    textNode("Hello")
                }
            }
        }
Also, I wonder where the padding comes from.
Strange. This is the same padding I have seen in my experiments with summon yesterday.
r
No padding for me ...
s
Firefox 146 on Windows 11
Same with Brave/Chrome
r
You can use a wrapper:
Copy code
div {
                            width(100.vw)
                            height(100.vh)
                            Box(
                                contentAlignment = Alignment.Center,
                                modifier = Modifier
                                    .fillMaxSize()
                                    .background(Color.Aqua)
                            ) {
                                span {
                                    +"Hello"
                                }
                            }
                        }
to make fillMaxSize do what you want
๐Ÿ‘ 1
s
Copy code
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Portfolio</title>
    <base href="/">
    <script src="main.bundle.js"></script>
</head>
<body>
<div id="root"></div>
</body>
</html>
r
what the browser dev tools say?
Oh, managed to reproduce your padding :)
๐ŸŽ‰ 1
It's just the dafault when no css is applied
โœ… 1
s
I hate browsers and web dev, lol.
r
I've generated the project with bootstrap module, so I don't see this in my project
frameworks like bootstrap or tailwindcss have their own reasonable defaults
s
Thanks for giving this hint. Super odd that every framework need to add
Copy code
body {
  margin: 0;
}
just to fix this strange browser default
Hmm.. There seem to be limitations on how complex I can make the layout using the Compose API.
Copy code
import androidx.compose.runtime.Composable
import dev.kilua.compose.foundation.layout.Box
import dev.kilua.compose.foundation.layout.Column
import dev.kilua.compose.foundation.layout.Row
import dev.kilua.compose.ui.Alignment
import dev.kilua.compose.ui.Modifier
import dev.kilua.compose.ui.background
import dev.kilua.compose.ui.fillMaxSize
import dev.kilua.compose.ui.fillMaxWidth
import dev.kilua.compose.ui.height
import dev.kilua.core.IComponent
import dev.kilua.html.Color
import dev.kilua.html.div
import dev.kilua.html.em
import dev.kilua.html.span
import dev.kilua.html.textNode
import dev.kilua.html.vh
import dev.kilua.html.vw

@Composable
fun IComponent.MainView() {

    Column {

        div {

            width(100.vw)
            height(100.vh)

            Box(
                modifier = Modifier.fillMaxSize()
            ) {

                Row(
                    modifier = Modifier
                        .align(Alignment.TopCenter)
                        .height(48.em)
                        .fillMaxWidth()
                        .background(color = Color.Red)
                ) {

                    span {
                        textNode("topbar")
                    }
                }

                Column(
                    horizontalAlignment = Alignment.CenterHorizontally,
                    modifier = Modifier
                        .align(Alignment.Center)
                        .fillMaxSize()
                        .background(color = Color.Blue)
                ) {

                    span {
                        textNode("text in middle")
                    }
                }
            }
        }

        span {
            textNode("Shown when scroll down")
        }
    }
}
r
I'm not a Jetpack expert. Can you elaborate a bit more?
For me it looks exactly as you coded :)
s
And I'm not a web dev expert. ๐Ÿซฃ I try to build a portfolio page like https://yujisatojr.github.io/react-portfolio-template , but I think maybe it's time to go to plan B and just let ChatGPT generate a static HTML page. ๐Ÿ˜…
As a portfolio page it should be SEO-friendly. Otherwise I would have done it with Compose for Web already like all my regular apps.
r
creating this wrapper div (with 100vh and 100vw) is definitely not something you would like to use on a webpage, even though it lets you use jetpack vertical alignment
๐Ÿ‘ 1
s
After Yousef presented https://www.yousef.codes/ in #C0BJ0GTE2 I got this feeling that I should have a nice portfolio page like his, too. But I stumble in a lot of issues trying summon, kobweb and kilua. So maybe that's just not my tech and I should give up.
I'm sure that's due to my lack of web knowledge.
creating this wrapper div (with 100vh and 100vw) is definitely not something you would like to use on a webpage, even though it lets you use jetpack vertical alignment
Okay. Thanks for the hint.
r
In my opinion, to build nice looking website you need to be at least proficient in CSS or use some kind of CSS framework. It just not possible with HTML only, and that's what you get in general with Kotlin code (regardless if using Kilua, KVision, Kobweb or Summon).
s
I see. Thank you. ๐Ÿ™‚