Michael Paus
03/07/2023, 1:09 PMgraphicsLayer modifier and setting rotationZ to 90f. That does the rotation but then contentScale.Fit does not work anymore because it ignores the rotation. I have a solution by manually computing some scale offset but that looks awkward. Does anybody know of a simple solution?Chris Fillmore
03/07/2023, 1:20 PMephemient
03/07/2023, 1:21 PMephemient
03/07/2023, 1:24 PMChris Fillmore
03/07/2023, 1:25 PMChris Fillmore
03/07/2023, 1:25 PMChris Fillmore
03/07/2023, 1:26 PMMichael Paus
03/07/2023, 2:45 PMonGloballyPositioned to get the size of Image after the layout and compute a correction factor for the scale. In the modifier graphicsLayer I then apply this correction factor by setting scaleX and scaleY in addition to applying the rotation via rotationZ. This has to be done though via an intermediate remembered mutable state to get the scale offset from onGloballyPositioned to graphicsLayer. (At least I think so.)
This works nicely but it feels like a hack and I think Image should be able to handle that use-case directly.ephemient
03/07/2023, 2:57 PMclass RotatePainter(val painter: Painter) : Painter() {
override val intrinsicSize: Size
get() = Size(painter.intrinsicSize.height, painter.intrinsicSize.width)
override fun DrawScope.onDraw() {
withTransform(
transformBlock = {
val delta = (size.width - size.height) / 2
inset(delta, -delta, delta, -delta)
rotate(90f)
},
drawBlock = { with(painter) { draw(size) } }
)
}
}
if you use Image(painter = RotatePainter(bitmapPainter)) instead of Image(painter = bitmapPainter) (or whatever image source you have), it should do all the "right" things with regards to contentScale, intrinsic sizes, etc.Michael Paus
03/07/2023, 3:03 PMMichael Paus
03/07/2023, 3:09 PM