https://kotlinlang.org logo
Title
a

abbic

12/06/2021, 10:56 AM
Hi all, very excited about the release of Compose multiplatform! I've been trying to think about how to apply it for game UIs, it's clearly possible but there are some questions i have about how to implement a style that is significantly different from material (for example a pixelated theme) Continued in thread...
focusing on a pixelated theme, oftentimes the sources forbutton decorations and UI elements comes from a tileset. would having a sprite outline on a button be a case of painting bitmaps on a custom button implementation, or something of the sort?
that wouldnt work in combination with theme colours however
m

mcpiroman

12/06/2021, 1:25 PM
A nice thing about Compose is that although many useful pieces are missing, you can quite easily go to appropriately lower level and implement them yourself (unlike, say, html). It should not be very hard to ignore all of the material design and implement your own UI building blocks. E.g. take a look how `Surface`is implemented - it mostly just calls a `Box`with some padding, shadows, clipping etc. Same with
TextField
but it has more levels of indirection. You can simply copy a function at some level and change what can't be changed via parameters. The same can be done with creating your own composition locals e.g. for controlling a theme. In fact I also plan to use Compose for a pixel-art game (not only UI) and although `Image`probabely won't fit it is also not hard to adjust it.
a

abbic

12/06/2021, 1:43 PM
@mcpiroman thank you for your reply, i get about that far down before starting to scratch my head against the implementation details of how to actually do this eg with a button that has a frame made out of box-drawing characters https://en.wikipedia.org/wiki/Box-drawing_character
because the source is from a bitmap it feels as though you have no choice but to make every button an image or canvas or something, and even then that might lock you out of making the most of existing UI apis
m

mcpiroman

12/06/2021, 1:48 PM
You want to mix sprites and ascii-art?
a

abbic

12/06/2021, 1:49 PM
technically the ascii are sprites too since they come from a png tileset, for my implementation anyway
totally wasnt clear with what i linked, consider those box drawing characters equivalent with corner and line sprites for drawing a pixel art box
m

mcpiroman

12/06/2021, 2:06 PM
AFAIK all the existing UI elements that actually draw something do that through a quite minimal APIs like `Modifier.paint`or `DrawScope`and whatever you try to achieve should also be doable by mixing the manual use of these and existing higher level blocks. E.g. to wrap something like a button in a ascii-art border just make a copy of `Modifier.border`that instead of drawing solid shape on the
DrawScope
, draws corner and edges tiles. Edges could then be optimized to use repeated texture sampling I think.
a

abbic

12/06/2021, 2:09 PM
I see! thank you thats a good pointer and i'll try experiment with this some time in the near future