ComponentInstance class abstract Components Core
The runtime representation of a Component in a layout or rendering process.
A ComponentInstance is created from a Component and is responsible for:
- Tracking layout bounds
- Measuring its required size
- Rendering itself to a CanvasBuffer
Unlike a Component, which is an immutable configuration object,
a ComponentInstance holds mutable state such as _bounds
and is tied
to a specific rendering pass.
Subclasses must implement:
- measure to report the component’s desired size
- fitWidth and fitHeight for layout constraints
- render to draw the component on the screen
Example:
class MyButtonInstance extends ComponentInstance {
@override
Size measure(Size maxSize) {
// Determine size based on content
}
@override
int fitWidth() => 10;
@override
int fitHeight() => 3;
@override
void render(CanvasBuffer buffer, Rect bounds) {
// Draw the button
}
}
See also:
- Component for the immutable configuration counterpart
- EdgeInsets for padding
- Position for placement
- Rect and Size for layout geometry
- Implementers
Constructors
- ComponentInstance.new({EdgeInsets padding = const EdgeInsets.all(0), Position position = const Position(x: 0, y: 0, positionType: PositionType.relative)})
-
Creates a ComponentInstance with optional
padding
andposition
.
Properties
- bounds ↔ Rect
-
The current layout bounds for this component instance.
getter/setter pair
- hashCode → int
-
The hash code for this object.
no setterinherited
- padding → EdgeInsets
-
The padding inside the component’s allocated space.
final
- position → Position
-
The position of this component relative to its parent or container.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
fitHeight(
) → int - Returns the height this component should occupy based on its content or layout rules.
-
fitWidth(
) → int - Returns the width this component should occupy based on its content or layout rules.
-
measure(
Size maxSize) → Size - Measures the size this component would like to occupy, given a maximum available size.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
render(
CanvasBuffer buffer, Rect bounds) → void -
Renders the component into the provided CanvasBuffer
using the given
bounds
as the drawing area. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited