1
1
mirror of https://github.com/exyte/Macaw.git synced 2024-09-11 05:05:23 +03:00

Apply clip during bounds calculation

This commit is contained in:
Alisa Mylnikova 2019-07-05 11:31:00 +07:00
parent 817caf8aa1
commit a3d70e56e3
3 changed files with 19 additions and 1 deletions

View File

@ -55,7 +55,16 @@ open class Group: Node {
}
override open var bounds: Rect? {
return BoundsUtils.getNodesBounds(contents)
let bounds = BoundsUtils.getNodesBounds(contents)
if let bounds = bounds?.toCG(),
let clip = self.clip?.bounds().toCG() {
let newX = max(bounds.minX, clip.minX)
let newY = max(bounds.minY, clip.minY)
return CGRect(x: newX, y: newY,
width: min(bounds.maxX, clip.maxX) - newX,
height: min(bounds.maxY, clip.maxY) - newY).toMacaw()
}
return bounds
}
override func shouldCheckForPressed() -> Bool {

View File

@ -57,6 +57,7 @@ open class Shape: Node {
}
RenderUtils.setGeometry(self.form, ctx: ctx)
RenderUtils.setClip(self.clip, ctx: ctx)
let point = ctx.currentPointOfPath

View File

@ -574,4 +574,12 @@ class RenderUtils {
ctx.addPath(locus.toCGPath())
}
}
internal class func setClip(_ clip: Locus?, ctx: CGContext) {
if let rect = clip as? Rect {
ctx.clip(to: CGRect(x: rect.x, y: rect.y, width: rect.w, height: rect.h))
} else if let clip = clip {
RenderUtils.toBezierPath(clip).addClip()
}
}
}