I'd like a way to paint text on a TextField such t...
# compose
t
I'd like a way to paint text on a TextField such that it's guaranteed to be visible regardless of what background colour happens to be under it. so either automatically choosing white/black per-char or per-pixel... or a way to paint text using inverse (changing the alpha blending somehow?)
example situation - can't just set it to all black or all white because some parts of the background are lighter than others
r
You can use one of the blend modes like Xor, Overlay, Screen, Color Dodge...
t
I had attempted to use those via ImageFilter but everything rendered roughly the same or worse
I'm guessing XOR is the one I want, I just have to find the right way to get it applied
setting it via graphicsLayer, for example:
I've read through how TextPainter is painting the text and it really just looks like I have no place to set this
unless I paint the entire composable to a canvas just to get it as an image
ah here we go, brand new API in 1.7 but I was using 1.6
Copy code
val graphicsLayer = rememberGraphicsLayer()

        Surface(modifier = Modifier.fillMaxSize()) {
            Box(modifier = Modifier.fillMaxSize()) {
                TextField(
                    value = sksl,
                    onValueChange = { sksl = it },
                    modifier = Modifier
                        .fillMaxSize()
                        .then(backgroundModifier)
                        .drawWithContent {
                            graphicsLayer.blendMode = BlendMode.Exclusion
                            graphicsLayer.record {
                                this@drawWithContent.drawContent()
                            }
                            drawLayer(graphicsLayer)
                        }
image.png,image.png,image.png
it's maybe a little muddy around the middle of the lightness range, but I'm not sure there's much I could do about that
ah it also does terribly if the background image is very noisy
so I might also need to do some sort of drop shadow behind the text in general anyway
r
Ah you're building one those shader editors that shows the shader source above the shader itself? I personally find those editors a pain to use 😅
😅 1
Anyway you could do what KodeLife does and add a background behind each line of text
Image from iOS.jpg
It's not "pretty" but it works well
t
Yeah it’s more like a live coding tool than a useful editor you’d want to daily drive