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:
parent
817caf8aa1
commit
a3d70e56e3
@ -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 {
|
||||
|
@ -57,6 +57,7 @@ open class Shape: Node {
|
||||
}
|
||||
|
||||
RenderUtils.setGeometry(self.form, ctx: ctx)
|
||||
RenderUtils.setClip(self.clip, ctx: ctx)
|
||||
|
||||
let point = ctx.currentPointOfPath
|
||||
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user