https://kotlinlang.org logo
#compose-desktop
Title
# compose-desktop
x

Xhivat Hoxhiq

01/25/2023, 8:24 AM
Hi, I am making a text editor with compose and it's not obvious to me how I wanna solve some of the issues. I had trouble with not being able to have a shared edit buffer, changing the internals of the text fields to support multiple cursors, and having a text field only report the changes not the entire value. How I solved these was using a
Layout
with `BasicText`'s for the lines and a
Box
for each cursor. I was able to get the positioning and height of the cursor from the
TextLayoutResult
. Idk if that's a bad or good solution but it works. The real hacky part is how I solved the shared input buffer, what I did is, I placed an invisible
BasicTextField
at one of the cursors and gave it focus that also give me just the "changes" when I type/paste into as it's value is always blank. What would the proper solution to these be? Or even more generically, what if compose on desktop is not enough, do I use a lower lever library that can integrate with it? I am really impressed with how well a
LazyColumn
performs with loading millions of
BasicText
lines which I tested just for fun as I will at most have 30-40 in my tool to edit.
a

Alexander Maryanovsky

01/25/2023, 9:33 AM
Compose is both a low and a high-level library. It has ready-to-use widgets, but you can also draw shapes and text yourself, and receive low-level input events. For a text editor you can try to adapt the existing BasicTextField, but if you need a lot of custom functionality, eventually it will make more sense to write your own widget using the low-level API. Or maybe someone has already written something you can use.
x

Xhivat Hoxhiq

01/25/2023, 10:12 AM
Do you mean on a canvas? The drawText() is not available on multiplatform, I think. By low-level input do you mean key presses or text/IME input? I'd like to take advantage of at the very least IME input from the library instead of making something myself, and also take advantage of the grapheme offsets as that is quite complex to do on my own. So ideally I want some lower level control of the widgets but reuse a bunch of APIs.
For a text editor you can try to adapt the existing BasicTextField, but if you need a lot of custom functionality, eventually it will make more sense to write your own widget using the low-level API.
Oh wow I wasn't aware of this. This is a passion project of mine with no real time limit and I want it to not have such hacks so I'd love to do this. Can you just nudge me in the right direction on how I do lower level stuff? For example I wanted to mess around with a custom lazy grid and make it fully dynamic. Many of the functions that are used to build LazyGrid are internal functions, did you mean by low-level, I should modify the library itself (which is a pain as it's a huge download and compiles slowly on my machine).
Or maybe someone has already written something you can use.
Maybe, I didn't really look but my needs for the text editor are quite niche and I wanted to make my own as a learning experience. It's going to be a tool that allows you to write UI's in a language I'll make just for this that will allow the users to create their own UI's for the mobile app with live previews on the side, that's where the editor comes in. The project goal is to be an easy framework to build home automation/IoT devices with customizable UI's.
a

Alexander Maryanovsky

01/25/2023, 10:34 AM
The drawText() is not available on multiplatform, I think.
I think it’s being added in 1.3.0 (in release-candidate stage in mpp right now, soon to be released). For 1.2 there’s
TextPainter.paint
I’d like to take advantage of at the very least IME input from the library instead of making something myself
There are APIs on all levels. I’m sure some you’ll find useful, others may lack something you need.
Many of the functions that are used to build LazyGrid are internal functions
Depending on your licensing and requirements, you could copy/paste some of the code and adjust to your needs.
Can you just nudge me in the right direction on how I do lower level stuff?
Take a look at all the androidx.compose.ui packages
did you mean by low-level, I should modify the library itself
Whatever works better for you - modify the existing code, or write your own.
x

Xhivat Hoxhiq

01/25/2023, 10:39 AM
I think it’s being added in 1.3.0 (in release-candidate stage in mpp right now, soon to be released). For 1.2 there’s
TextPainter.paint
Thanks I'll take a look at this
Also will look at the
androidx.compose.ui
packages. The project will be open source with probably Apache-2.0 licensing I hope that means I can copy some of the code I didn't look into it tbh
75 Views