Decorator

fun interface Decorator

One operation wrapping the painting of what it decorates, declared on a component with decoration. It is handed the graphics, the size, and the continuation that paints everything inside it, and it decides what graphics that continuation paints into: a decorator painting around its content hands on the graphics it was given, one cutting the content hands on a clipped one, and one that post-processes the content's pixels, such as a blur or a tint, points it at an offscreen raster. The content keeps its own area: space between a decoration and the content is a padding declared after the decoration.

Each decorator is handed a graphics of its own, created around the call and disposed after it, so a clip, composite, stroke or transform it leaves behind reaches no other painting.

Write one as a data class so it compares structurally: a modifier chain is rebuilt on every recomposition of the enclosing scope, and a decorator that cannot be compared repaints every pass.

A decorator that keeps state across paints, such as an offscreen ImageLayer, is a DecorationModifierNode.

Inheritors

Properties

Link copied to clipboard
open val isOpaque: Boolean

Whether painting through this decorator still covers every pixel of the area it is given; true by default.

Link copied to clipboard
open val outsets: Insets

How far this decorator paints past the content's box; nothing by default, and never negative.

Functions

Link copied to clipboard
open fun needsPaintBounds(width: Int, height: Int): Boolean

Whether this decorator needs the component's paint bounds worked out, through paintBounds, while no visible child has an edge past the layout bounds and no decorator has outsets; true by default. A child with an edge past the layout bounds, or a decorator with outsets, has them worked out whatever this answers. Return false only when this decorator, in a box of width by height, cannot enlarge a box-sized content's paint bounds beyond its outsets.

Link copied to clipboard
abstract fun paint(graphics: Graphics2D, width: Int, height: Int, content: (Graphics2D, Int, Int) -> Unit)

Paints this decoration and, at the point of its own choosing, the content inside it.

Link copied to clipboard
open fun paintBounds(content: Shape, width: Int, height: Int): Shape

The area this decorator and its content can paint, in a box of width by height. The default includes the box and the content's bounds, grown by outsets. Override this when painting, clipping, or transforming content changes that area. The returned shape reserves paint space, not a clip. It also decides hit testing past the layout bounds: a press there reaches a child only where the paint bounds of a one-pixel content at the point cover the point.