Is there such thing as an absolute layout in Compose? Details in thread.
c
Is there such thing as an absolute layout in Compose? Details in thread.
I'm essentially drawing a line programatically. This line may or may not have a curve, and I need to place a checkbox in the middle of that line. I figure the easiest way would be to figure out the point of the line where I deem it's center, and place a checkbox right there.
a
Layout
is about as absolute as it gets 🙂
c
So my end result might look like this
Or this
@Adam Powell okay cool. Still new at this custom layout thing so just making sure I wasn't missing something.
@Adam Powell the one thing I'm finding difficult in Layout is how to grab the location of the path so I can place the placeable. I thought inside of Layout I'd be able to call drawLine or draw on a Canvas, but I can't draw composables inside of Layout. I feel like something in my mental model isn't right about how I'm approaching this.
k
a
keep data flowing from composition => layout => drawing. Lay out the curve/path during the computation of layout and use it to position the checkbox, then simply draw it during the draw phase. This might be as simple as holding the path in a remembered MutableState, writing it during layout, then drawing it in a drawBehind modifier on the layout.
c
Aha. Alright, so maybe the path data is my state, and I lay out my checkbox based on my path data, and I draw in a separate function based on that path data. I think that makes sense.
a
clear producer, consumer, and data transport.
c
Still unclear to me which is which. 🤣 But I'm still learning! Thanks though. I think I should be able to draw my curve and place things upon it too