https://kotlinlang.org logo
#compose
Title
# compose
o

Omkar Amberkar

01/27/2023, 4:25 PM
how do i draw a line with rounded corners on one side and straight on the other
Copy code
drawLine(
            Color.White,
            sliderStart,
            sliderEnd,
            trackHeightPx,
            StrokeCap.Round)
there isn't a straightforward method to draw line with such case, either both are rounded or have a Square stroke
r

romainguy

01/27/2023, 4:53 PM
You’ll have to draw two lines that connect somewhere in the middle
o

Omkar Amberkar

01/27/2023, 4:58 PM
wouldn't that be a problem? since you'd see the area of the ui thats behind the rounded corners of one line, when they both meet since the rounded corners would be drawn behind the meeting point?
the only fix is to extend it to the height of the line so that it covers up the rounded line, but it seems quite not right. wish there was something out of the box for this impl
r

romainguy

01/27/2023, 5:00 PM
You can use clipping to remove one of the caps to connect the lines
Alternatively you can draw the caps as separate draw calls
i.e. draw a circle at the end of the line
It’s fine with opaque colors, with translucent colors you’d have to use a graphics layer to have the correct result
You can also connect the lines without clipping by extending one of the lines a little further btw (again, it will work with opaque colors, not translucent colors)
13 Views