API Reference¶
__all__ = ['Rect', 'Point', 'Size', 'ISize', 'Range', 'Matrix', 'ColorMatrix', 'RoundingRadii', 'Color', 'TextureDescriptor', 'ColorFilter', 'ColorSource', 'ImageFilter', 'MaskFilter', 'Paint', 'DisplayList', 'Path', 'LineMetrics', 'GlyphInfo', 'Paragraph', 'Texture', 'DisplayListBuilder', 'PathBuilder', 'Surface', 'Context', 'Window', 'TypographyContext', 'ParagraphStyle', 'ParagraphBuilder', 'FillType', 'ClipOperation', 'BlendMode', 'DrawStyle', 'StrokeCap', 'StrokeJoin', 'PixelFormat', 'TextureSampling', 'TileMode', 'BlurStyle', 'ColorSpace', 'FontWeight', 'FontStyle', 'TextAlignment', 'TextDirection']
module-attribute
¶
BlendMode
¶
Bases: Enum
Determines how source and destination colors are combined during drawing.
These blend modes follow the standard Porter-Duff compositing operations and additional blend modes from PDF and SVG specifications.
CLEAR = 0
class-attribute
instance-attribute
¶
Clear destination (0)
COLOR = 27
class-attribute
instance-attribute
¶
Hue and saturation from source, luminosity from destination
COLOR_BURN = 19
class-attribute
instance-attribute
¶
Darkens destination based on source
COLOR_DODGE = 18
class-attribute
instance-attribute
¶
Brightens destination based on source
DARKEN = 16
class-attribute
instance-attribute
¶
Darker of source and destination
DESTINATION = 2
class-attribute
instance-attribute
¶
Preserve destination (D)
DESTINATION_ATOP = 10
class-attribute
instance-attribute
¶
Destination atop source (SaD + (1-Da)S)
DESTINATION_IN = 6
class-attribute
instance-attribute
¶
Destination where source is non-zero (Sa*D)
DESTINATION_OUT = 8
class-attribute
instance-attribute
¶
Destination where source is zero ((1-Sa)*D)
DESTINATION_OVER = 4
class-attribute
instance-attribute
¶
Destination over source (D + (1-Da)*S)
DIFFERENCE = 22
class-attribute
instance-attribute
¶
Absolute difference between source and destination
EXCLUSION = 23
class-attribute
instance-attribute
¶
Similar to DIFFERENCE but with lower contrast
HARD_LIGHT = 20
class-attribute
instance-attribute
¶
Hard light blend mode
HUE = 25
class-attribute
instance-attribute
¶
Hue from source, saturation and luminosity from destination
LIGHTEN = 17
class-attribute
instance-attribute
¶
Lighter of source and destination
LUMINOSITY = 28
class-attribute
instance-attribute
¶
Luminosity from source, hue and saturation from destination
MODULATE = 13
class-attribute
instance-attribute
¶
Product of source and destination (S*D)
MULTIPLY = 24
class-attribute
instance-attribute
¶
Multiply source and destination
OVERLAY = 15
class-attribute
instance-attribute
¶
Overlay blend mode
PLUS = 12
class-attribute
instance-attribute
¶
Sum of source and destination (S + D)
SATURATION = 26
class-attribute
instance-attribute
¶
Saturation from source, hue and luminosity from destination
SCREEN = 14
class-attribute
instance-attribute
¶
Screen blend mode
SOFT_LIGHT = 21
class-attribute
instance-attribute
¶
Soft light blend mode
SOURCE = 1
class-attribute
instance-attribute
¶
Copy source (S)
SOURCE_ATOP = 9
class-attribute
instance-attribute
¶
Source atop destination (DaS + (1-Sa)D)
SOURCE_IN = 5
class-attribute
instance-attribute
¶
Source where destination is non-zero (Da*S)
SOURCE_OUT = 7
class-attribute
instance-attribute
¶
Source where destination is zero ((1-Da)*S)
SOURCE_OVER = 3
class-attribute
instance-attribute
¶
Source over destination (S + (1-Sa)*D)
XOR = 11
class-attribute
instance-attribute
¶
Exclusive OR ((1-Sa)D + (1-Da)S)
BlurStyle
¶
Bases: Enum
Determines how blur mask filters are applied.
INNER = 3
class-attribute
instance-attribute
¶
Blur only inside the shape.
NORMAL = 0
class-attribute
instance-attribute
¶
Blur in all directions.
OUTER = 2
class-attribute
instance-attribute
¶
Blur only outside the shape.
SOLID = 1
class-attribute
instance-attribute
¶
Blur and preserve the original shape.
ClipOperation
¶
Color
¶
ColorFilter
¶
Bases: ColorFilter_
ColorFilter_
¶
A filter that transforms colors before they are drawn.
Color filters are functions that take two colors and mix them to produce a single color. This color is then merged with the destination during blending.
blend(color, blend_mode)
staticmethod
¶
Create a color filter that performs blending of pixel values independently.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
color
|
Color_
|
The color to blend with. |
required |
blend_mode
|
BlendMode
|
The blend mode to use for combining colors. |
required |
Returns:
Type | Description |
---|---|
ColorFilter_
|
A new color filter that performs the specified blending. |
matrix(matrix)
staticmethod
¶
Create a color filter that transforms pixel color values independently.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
matrix
|
ColorMatrix_
|
The color matrix to use for transforming colors. |
required |
Returns:
Type | Description |
---|---|
ColorFilter_
|
A new color filter that applies the specified color matrix transformation. |
ColorMatrix
¶
Bases: ColorMatrix_
ColorMatrix_
¶
A 4x5 color transformation matrix used for transforming color values.
The matrix is used to transform RGBA colors using the formula:
| R' | | m[0] m[1] m[2] m[3] m[4] | | R |
| G' | | m[5] m[6] m[7] m[8] m[9] | | G |
| B' | = | m[10] m[11] m[12] m[13] m[14] | * | B |
| A' | | m[15] m[16] m[17] m[18] m[19] | | A |
| 1 | | 0 0 0 0 1 | | 1 |
__getitem__(key)
¶
Get the value at the specified index.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
int
|
The index (0-19) to retrieve. |
required |
Returns:
Type | Description |
---|---|
float
|
The float value at the specified index. |
__init__(values)
¶
Initialize a color matrix with the provided values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
values
|
List[float]
|
A list of 20 float values representing the 4x5 color matrix. |
required |
__setitem__(key, value)
¶
Set the value at the specified index.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
int
|
The index (0-19) to modify. |
required |
value
|
float
|
The new float value to set. |
required |
to_list()
¶
Convert the color matrix to a list of float values.
Returns:
Type | Description |
---|---|
List[float]
|
A list of 20 float values representing the color matrix. |
ColorSource
¶
Bases: ColorSource_
ColorSource_
¶
A source of colors for drawing operations.
Color sources are functions that generate colors for each texture element covered by a draw call. The colors can be generated using a mathematical function (to produce gradients) or sampled from a texture.
conical_gradient(start_center, start_radius, end_center, end_radius, stops, colors, tile_mode, transformation=None)
staticmethod
¶
Create a color source that forms a conical gradient.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start_center
|
Point_
|
The center point of the starting circle. |
required |
start_radius
|
float
|
The radius of the starting circle. |
required |
end_center
|
Point_
|
The center point of the ending circle. |
required |
end_radius
|
float
|
The radius of the ending circle. |
required |
stops
|
List[float]
|
The positions of color stops (0.0 to 1.0). |
required |
colors
|
List[Color_]
|
The colors at each stop position. |
required |
tile_mode
|
TileMode
|
How to handle coordinates outside the gradient. |
required |
transformation
|
Optional[Matrix_]
|
Optional transformation matrix to apply. |
None
|
Returns:
Type | Description |
---|---|
ColorSource_
|
A new color source that generates a conical gradient. |
image(texture, horizontal_tile_mode, vertical_tile_mode, sampling, transformation=None)
staticmethod
¶
Create a color source that samples from an image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
texture
|
Texture_
|
The texture to sample from. |
required |
horizontal_tile_mode
|
TileMode
|
How to handle coordinates outside the texture horizontally. |
required |
vertical_tile_mode
|
TileMode
|
How to handle coordinates outside the texture vertically. |
required |
sampling
|
TextureSampling
|
The sampling method to use when reading the texture. |
required |
transformation
|
Optional[Matrix_]
|
Optional transformation matrix to apply. |
None
|
Returns:
Type | Description |
---|---|
ColorSource_
|
A new color source that samples from the specified texture. |
linear_gradient(start_point, end_point, colors, stops, tile_mode, transformation=None)
staticmethod
¶
Create a color source that forms a linear gradient.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start_point
|
Point_
|
The starting point of the gradient. |
required |
end_point
|
Point_
|
The ending point of the gradient. |
required |
colors
|
List[Color_]
|
The colors at each stop position. |
required |
stops
|
List[float]
|
The positions of color stops (0.0 to 1.0). |
required |
tile_mode
|
TileMode
|
How to handle coordinates outside the gradient. |
required |
transformation
|
Optional[Matrix_]
|
Optional transformation matrix to apply. |
None
|
Returns:
Type | Description |
---|---|
ColorSource_
|
A new color source that generates a linear gradient. |
radial_gradient(center, radius, colors, stops, tile_mode, transformation=None)
staticmethod
¶
Create a color source that forms a radial gradient.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
center
|
Point_
|
The center point of the gradient. |
required |
radius
|
float
|
The radius of the gradient. |
required |
colors
|
List[Color_]
|
The colors at each stop position. |
required |
stops
|
List[float]
|
The positions of color stops (0.0 to 1.0). |
required |
tile_mode
|
TileMode
|
How to handle coordinates outside the gradient. |
required |
transformation
|
Optional[Matrix_]
|
Optional transformation matrix to apply. |
None
|
Returns:
Type | Description |
---|---|
ColorSource_
|
A new color source that generates a radial gradient. |
sweep_gradient(center, start, end, colors, stops, tile_mode, transformation=None)
staticmethod
¶
Create a color source that forms a sweep gradient.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
center
|
Point_
|
The center point of the gradient. |
required |
start
|
float
|
The starting angle in degrees. |
required |
end
|
float
|
The ending angle in degrees. |
required |
colors
|
List[Color_]
|
The colors at each stop position. |
required |
stops
|
List[float]
|
The positions of color stops (0.0 to 1.0). |
required |
tile_mode
|
TileMode
|
How to handle coordinates outside the gradient. |
required |
transformation
|
Optional[Matrix_]
|
Optional transformation matrix to apply. |
None
|
Returns:
Type | Description |
---|---|
ColorSource_
|
A new color source that generates a sweep gradient. |
ColorSpace
¶
Bases: Enum
Specifies the color space for colors.
Color_
¶
Represents a color with red, green, blue, and alpha components.
Attributes:
Name | Type | Description |
---|---|---|
red |
float
|
The red component (0.0 to 1.0). |
green |
float
|
The green component (0.0 to 1.0). |
blue |
float
|
The blue component (0.0 to 1.0). |
alpha |
float
|
The alpha component (0.0 to 1.0). |
color_space |
ColorSpace
|
The color space of the color. |
Context_
¶
An Impeller graphics context.
Contexts are thread-safe objects that are expensive to create. Most applications will only ever create a single context during their lifetimes. Once setup, Impeller is ready to render frames as performantly as possible.
During setup, contexts create the underlying graphics pipelines, allocators, worker threads, etc.
The general guidance is to create as few contexts as possible (typically just one) and share them as much as possible.
__init__()
¶
Initialize a new Metal context using the system default Metal device.
DisplayList
¶
Bases: DisplayList_
DisplayListBuilder
¶
Bases: DisplayListBuilder_
DisplayListBuilder_
¶
Allows for the incremental creation of display lists.
Display list builders are context-agnostic and can be used to create display lists that can be drawn on any surface.
__init__()
¶
Initialize a new display list builder.
build()
¶
Create a new display list using the rendering intent already encoded in the builder.
The builder is reset after this call.
Returns:
Type | Description |
---|---|
DisplayList_
|
A new display list. |
clip_oval(rect, op)
¶
Reduce the clip region to the intersection with the given oval.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rect
|
Rect_
|
The rectangle defining the oval bounds. |
required |
op
|
ClipOperation
|
The clip operation to perform. |
required |
Returns:
Type | Description |
---|---|
DisplayListBuilder_
|
Self for method chaining. |
clip_path(path, op)
¶
Reduce the clip region to the intersection with the given path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
Path_
|
The path to clip with. |
required |
op
|
ClipOperation
|
The clip operation to perform. |
required |
Returns:
Type | Description |
---|---|
DisplayListBuilder_
|
Self for method chaining. |
clip_rect(rect, op)
¶
Reduce the clip region to the intersection with the given rectangle.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rect
|
Rect_
|
The rectangle to clip with. |
required |
op
|
ClipOperation
|
The clip operation to perform. |
required |
Returns:
Type | Description |
---|---|
DisplayListBuilder_
|
Self for method chaining. |
clip_rounded_rect(rect, radii, op)
¶
Reduce the clip region to the intersection with the given rounded rectangle.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rect
|
Rect_
|
The rectangle to clip with. |
required |
radii
|
RoundingRadii_
|
The corner radii of the rectangle. |
required |
op
|
ClipOperation
|
The clip operation to perform. |
required |
Returns:
Type | Description |
---|---|
DisplayListBuilder_
|
Self for method chaining. |
draw_dashed_line(from_point, to_point, on_length, off_length, paint)
¶
Draw a dashed line segment.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
from_point
|
Point_
|
The starting point of the line. |
required |
to_point
|
Point_
|
The ending point of the line. |
required |
on_length
|
float
|
The length of the dash. |
required |
off_length
|
float
|
The length of the gap between dashes. |
required |
paint
|
Paint_
|
The paint to use for drawing. |
required |
Returns:
Type | Description |
---|---|
DisplayListBuilder_
|
Self for method chaining. |
draw_display_list(dl, opacity)
¶
Flatten the contents of another display list into this one.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dl
|
DisplayList_
|
The display list to draw. |
required |
opacity
|
float
|
The opacity to apply (0.0 to 1.0). |
required |
Returns:
Type | Description |
---|---|
DisplayListBuilder_
|
Self for method chaining. |
draw_line(from_point, to_point, paint)
¶
Draw a line segment.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
from_point
|
Point_
|
The starting point of the line. |
required |
to_point
|
Point_
|
The ending point of the line. |
required |
paint
|
Paint_
|
The paint to use for drawing. |
required |
Returns:
Type | Description |
---|---|
DisplayListBuilder_
|
Self for method chaining. |
draw_oval(oval_bounds, paint)
¶
Draw an oval.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
oval_bounds
|
Rect_
|
The rectangle defining the oval bounds. |
required |
paint
|
Paint_
|
The paint to use for drawing. |
required |
Returns:
Type | Description |
---|---|
DisplayListBuilder_
|
Self for method chaining. |
draw_paint(paint)
¶
Fill the current clip with the specified paint.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
paint
|
Paint_
|
The paint to use for filling. |
required |
Returns:
Type | Description |
---|---|
DisplayListBuilder_
|
Self for method chaining. |
draw_paragraph(paragraph, point)
¶
Draw a paragraph at the specified point.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
paragraph
|
Paragraph_
|
The paragraph to draw. |
required |
point
|
Point_
|
The position to draw the paragraph at. |
required |
Returns:
Type | Description |
---|---|
DisplayListBuilder_
|
Self for method chaining. |
draw_path(path, paint)
¶
Draw the specified shape.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
Path_
|
The path to draw. |
required |
paint
|
Paint_
|
The paint to use for drawing. |
required |
Returns:
Type | Description |
---|---|
DisplayListBuilder_
|
Self for method chaining. |
draw_rect(rect, paint)
¶
Draw a rectangle.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rect
|
Rect_
|
The rectangle to draw. |
required |
paint
|
Paint_
|
The paint to use for drawing. |
required |
Returns:
Type | Description |
---|---|
DisplayListBuilder_
|
Self for method chaining. |
draw_rounded_rect(rect, radii, paint)
¶
Draw a rounded rectangle.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rect
|
Rect_
|
The rectangle to draw. |
required |
radii
|
RoundingRadii_
|
The corner radii of the rectangle. |
required |
paint
|
Paint_
|
The paint to use for drawing. |
required |
Returns:
Type | Description |
---|---|
DisplayListBuilder_
|
Self for method chaining. |
draw_rounded_rect_difference(outer_rect, outer_radii, inner_rect, inner_radii, paint)
¶
Draw a shape that is the difference between two rounded rectangles.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
outer_rect
|
Rect_
|
The outer rectangle. |
required |
outer_radii
|
RoundingRadii_
|
The corner radii of the outer rectangle. |
required |
inner_rect
|
Rect_
|
The inner rectangle. |
required |
inner_radii
|
RoundingRadii_
|
The corner radii of the inner rectangle. |
required |
paint
|
Paint_
|
The paint to use for drawing. |
required |
Returns:
Type | Description |
---|---|
DisplayListBuilder_
|
Self for method chaining. |
draw_shadow(path, shadow_color, elevation, occuluder_is_transparent, device_pixel_ratio)
¶
Draw a shadow for a path given a material elevation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
Path_
|
The shadow path. |
required |
shadow_color
|
Color_
|
The shadow color. |
required |
elevation
|
float
|
The material elevation. |
required |
occuluder_is_transparent
|
bool
|
If the object casting the shadow is transparent. |
required |
device_pixel_ratio
|
float
|
The device pixel ratio. |
required |
Returns:
Type | Description |
---|---|
DisplayListBuilder_
|
Self for method chaining. |
draw_texture(texture, point, sampling, paint)
¶
Draw a texture at the specified point.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
texture
|
Texture_
|
The texture to draw. |
required |
point
|
Point_
|
The position to draw the texture at. |
required |
sampling
|
TextureSampling
|
The sampling method to use. |
required |
paint
|
Paint_
|
The paint to use for drawing. |
required |
Returns:
Type | Description |
---|---|
DisplayListBuilder_
|
Self for method chaining. |
draw_texture_rect(texture, src_rect, dst_rect, sampling, paint)
¶
Draw a portion of texture at the specified location.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
texture
|
Texture_
|
The texture to draw. |
required |
src_rect
|
Rect_
|
The source rectangle within the texture. |
required |
dst_rect
|
Rect_
|
The destination rectangle to draw to. |
required |
sampling
|
TextureSampling
|
The sampling method to use. |
required |
paint
|
Paint_
|
The paint to use for drawing. |
required |
Returns:
Type | Description |
---|---|
DisplayListBuilder_
|
Self for method chaining. |
get_transform()
¶
Get the transformation currently built up on the top of the transformation stack.
Returns:
Type | Description |
---|---|
Matrix_
|
The current transformation matrix. |
push_transform(xform)
¶
Append the provided transformation to the transformation already on the save stack.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xform
|
Matrix_
|
The transformation matrix to append. |
required |
Returns:
Type | Description |
---|---|
DisplayListBuilder_
|
Self for method chaining. |
reset_transform()
¶
Reset the transformation on top of the transformation stack to identity.
Returns:
Type | Description |
---|---|
DisplayListBuilder_
|
Self for method chaining. |
restore()
¶
Pop the last entry pushed onto the save stack.
Returns:
Type | Description |
---|---|
DisplayListBuilder_
|
Self for method chaining. |
restore_to_count(count)
¶
Restore the save stack to the specified count.
Effectively calls restore() until the size of the save stack becomes the specified count.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
count
|
int
|
The target save stack count. |
required |
Returns:
Type | Description |
---|---|
DisplayListBuilder_
|
Self for method chaining. |
rotate(angle_in_degrees)
¶
Apply a clockwise rotation to the transformation matrix.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
angle_in_degrees
|
float
|
The angle in degrees. |
required |
Returns:
Type | Description |
---|---|
DisplayListBuilder_
|
Self for method chaining. |
save()
¶
Stash the current transformation and clip state onto a save stack.
Returns:
Type | Description |
---|---|
DisplayListBuilder_
|
Self for method chaining. |
save_count()
¶
Get the current size of the save stack.
Returns:
Type | Description |
---|---|
int
|
The save stack size. |
save_layer(bounds, paint=None, backdrop=None)
¶
Save the current state and create an offscreen layer for rendering.
On the balancing call to restore, the supplied paint's filters and blend modes will be used to composite the offscreen contents back onto the display list.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bounds
|
Rect_
|
The bounds of the layer. |
required |
paint
|
Optional[Paint_]
|
Optional paint to use when compositing the layer. |
None
|
backdrop
|
Optional[ImageFilter_]
|
Optional backdrop filter to apply. |
None
|
Returns:
Type | Description |
---|---|
DisplayListBuilder_
|
Self for method chaining. |
scale(x, y)
¶
Apply a scale to the transformation matrix.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
float
|
The x scale factor. |
required |
y
|
float
|
The y scale factor. |
required |
Returns:
Type | Description |
---|---|
DisplayListBuilder_
|
Self for method chaining. |
set_transform(xform)
¶
Clear the transformation on top of the save stack and replace it with a new value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xform
|
Matrix_
|
The new transformation matrix. |
required |
Returns:
Type | Description |
---|---|
DisplayListBuilder_
|
Self for method chaining. |
translate(x, y)
¶
Apply a translation to the transformation matrix.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
float
|
The x translation. |
required |
y
|
float
|
The y translation. |
required |
Returns:
Type | Description |
---|---|
DisplayListBuilder_
|
Self for method chaining. |
DisplayList_
¶
Represents encoded rendering intent.
Display lists are immutable, reusable, thread-safe, and context-agnostic. They encapsulate a series of drawing commands that can be executed on a surface.
While it is perfectly fine to create new display lists per frame, there may be opportunities for optimization when display lists are reused multiple times.
DrawStyle
¶
Bases: Enum
Determines how shapes are rendered.
FillType
¶
FontStyle
¶
FontWeight
¶
Bases: Enum
Specifies the weight (boldness) of a font.
W100 = 0
class-attribute
instance-attribute
¶
Thin
W200 = 1
class-attribute
instance-attribute
¶
Light
W300 = 2
class-attribute
instance-attribute
¶
Light
W400 = 3
class-attribute
instance-attribute
¶
Regular
W500 = 4
class-attribute
instance-attribute
¶
Medium
W600 = 5
class-attribute
instance-attribute
¶
bold
W700 = 6
class-attribute
instance-attribute
¶
Bold
W800 = 7
class-attribute
instance-attribute
¶
Bold
W900 = 8
class-attribute
instance-attribute
¶
Black
GlyphInfo
¶
Bases: GlyphInfo_
GlyphInfo_
¶
Describes the metrics of glyphs in a paragraph line.
Provides information about a specific glyph in a paragraph, including its position, bounds, and text properties.
grapheme_cluster_bounds()
¶
Get the bounds of the grapheme cluster in the coordinate space of the paragraph.
Returns:
Type | Description |
---|---|
Rect_
|
The grapheme cluster bounds. |
grapheme_cluster_code_unit_range_begin()
¶
Get the start index in the buffer of UTF-16 code units for the grapheme cluster.
Returns:
Type | Description |
---|---|
int
|
The UTF-16 code units start index. |
grapheme_cluster_code_unit_range_end()
¶
Get the end index in the buffer of UTF-16 code units for the grapheme cluster.
Returns:
Type | Description |
---|---|
int
|
The UTF-16 code units end index. |
is_ellipsis()
¶
Check if the glyph represents an ellipsis.
Returns:
Type | Description |
---|---|
bool
|
True if the glyph is an ellipsis, False otherwise. |
text_direction()
¶
Get the direction of the run that contains the glyph.
Returns:
Type | Description |
---|---|
TextDirection
|
The text direction. |
ISize
¶
ISize_
¶
ImageFilter
¶
Bases: ImageFilter_
ImageFilter_
¶
A filter that transforms images before they are drawn.
Image filters are functions that are applied to regions of a texture to produce a single color. Contrast this with color filters that operate independently on a per-pixel basis.
blur(x_sigma, y_sigma, tile_mode)
staticmethod
¶
Create an image filter that applies a Gaussian blur.
The Gaussian blur applied may be an approximation for performance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x_sigma
|
float
|
The standard deviation of the blur in the x direction. |
required |
y_sigma
|
float
|
The standard deviation of the blur in the y direction. |
required |
tile_mode
|
TileMode
|
How to handle coordinates outside the source image. |
required |
Returns:
Type | Description |
---|---|
ImageFilter_
|
A new image filter that applies a Gaussian blur. |
compose(outer, inner)
staticmethod
¶
Create a composed filter that applies inner then outer filters.
The resulting filter is equivalent to: destination = outer_filter(inner_filter(source))
Parameters:
Name | Type | Description | Default |
---|---|---|---|
outer
|
ImageFilter_
|
The outer image filter to apply second. |
required |
inner
|
ImageFilter_
|
The inner image filter to apply first. |
required |
Returns:
Type | Description |
---|---|
ImageFilter_
|
A new image filter that applies both filters in sequence. |
dilate(x_radius, y_radius)
staticmethod
¶
Create an image filter that enhances pixel values to the maximum in a region.
This filter enhances the per-channel pixel values to the maximum value in a circle around the pixel.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x_radius
|
float
|
The radius in the x direction. |
required |
y_radius
|
float
|
The radius in the y direction. |
required |
Returns:
Type | Description |
---|---|
ImageFilter_
|
A new image filter that performs dilation. |
erode(x_radius, y_radius)
staticmethod
¶
Create an image filter that dampens pixel values to the minimum in a region.
This filter dampens the per-channel pixel values to the minimum value in a circle around the pixel.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x_radius
|
float
|
The radius in the x direction. |
required |
y_radius
|
float
|
The radius in the y direction. |
required |
Returns:
Type | Description |
---|---|
ImageFilter_
|
A new image filter that performs erosion. |
matrix(matrix, sampling)
staticmethod
¶
Create an image filter that applies a transformation matrix to the image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
matrix
|
Matrix_
|
The transformation matrix to apply. |
required |
sampling
|
TextureSampling
|
The sampling method to use when reading the transformed image. |
required |
Returns:
Type | Description |
---|---|
ImageFilter_
|
A new image filter that applies the specified transformation. |
LineMetrics
¶
Bases: LineMetrics_
LineMetrics_
¶
Describes the metrics of lines in a fully laid out paragraph.
Regardless of how the string of text is specified to the paragraph builder, offsets into buffers that are returned by line metrics are always assumed to be into buffers of UTF-16 code units.
ascent(line)
¶
Get the rise from the baseline as calculated from the font and style for this line.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
line
|
int
|
The line index (zero based). |
required |
Returns:
Type | Description |
---|---|
float
|
The ascent value. |
baseline(line)
¶
Get the y coordinate of the baseline for this line from the top of the paragraph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
line
|
int
|
The line index (zero based). |
required |
Returns:
Type | Description |
---|---|
float
|
The baseline position. |
code_unit_end_index(line)
¶
Get the end index in the buffer of UTF-16 code units for this line.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
line
|
int
|
The line index (zero based). |
required |
Returns:
Type | Description |
---|---|
int
|
The UTF-16 code units end index. |
code_unit_end_index_excluding_whitespace(line)
¶
Get the end index (excluding whitespace) in the buffer of UTF-16 code units.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
line
|
int
|
The line index (zero based). |
required |
Returns:
Type | Description |
---|---|
int
|
The UTF-16 code units end index excluding whitespace. |
code_unit_end_index_including_newline(line)
¶
Get the end index (including newlines) in the buffer of UTF-16 code units.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
line
|
int
|
The line index (zero based). |
required |
Returns:
Type | Description |
---|---|
int
|
The UTF-16 code units end index including newlines. |
code_unit_start_index(line)
¶
Get the start index in the buffer of UTF-16 code units for this line.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
line
|
int
|
The line index (zero based). |
required |
Returns:
Type | Description |
---|---|
int
|
The UTF-16 code units start index. |
descent(line)
¶
Get the drop from the baseline as calculated from the font and style for this line.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
line
|
int
|
The line index (zero based). |
required |
Returns:
Type | Description |
---|---|
float
|
The descent value. |
height(line)
¶
Get the total height of the line from the top edge to the bottom edge.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
line
|
int
|
The line index (zero based). |
required |
Returns:
Type | Description |
---|---|
float
|
The height of the line. |
is_hardbreak(line)
¶
Check if this line ends with an explicit line break or is the end of the paragraph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
line
|
int
|
The line index (zero based). |
required |
Returns:
Type | Description |
---|---|
bool
|
True if the line is a hard break, False otherwise. |
left(line)
¶
Get the x coordinate of left edge of the line.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
line
|
int
|
The line index (zero based). |
required |
Returns:
Type | Description |
---|---|
float
|
The left edge coordinate. |
unscaled_ascent(line)
¶
Get the rise from the baseline as calculated from the font and style for this line.
This ignores the height from the text style.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
line
|
int
|
The line index (zero based). |
required |
Returns:
Type | Description |
---|---|
float
|
The unscaled ascent value. |
width(line)
¶
Get the width of the line from the left edge of the leftmost glyph to the right edge.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
line
|
int
|
The line index (zero based). |
required |
Returns:
Type | Description |
---|---|
float
|
The width of the line. |
MaskFilter
¶
Bases: MaskFilter_
MaskFilter_
¶
A filter applied to a shape's mask before drawing.
Mask filters are functions that are applied over a shape after it has been drawn but before it has been blended into the final image.
blur(style, sigma)
staticmethod
¶
Create a mask filter that blurs contents in the masked shape.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
style
|
BlurStyle
|
The style of blur to apply. |
required |
sigma
|
float
|
The standard deviation of the blur. |
required |
Returns:
Type | Description |
---|---|
MaskFilter_
|
A new mask filter that applies the specified blur. |
Matrix
¶
Matrix_
¶
A 4x4 transformation matrix using column-major storage.
The matrix is stored as: | m[0] m[4] m[8] m[12] | | m[1] m[5] m[9] m[13] | | m[2] m[6] m[10] m[14] | | m[3] m[7] m[11] m[15] |
__getitem__(key)
¶
Get the value at the specified index.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
int
|
The index (0-15) to retrieve. |
required |
Returns:
Type | Description |
---|---|
float
|
The float value at the specified index. |
__init__(values)
¶
Initialize a matrix with the provided values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
values
|
List[float]
|
A list of 16 float values in column-major order. |
required |
__setitem__(key, value)
¶
Set the value at the specified index.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
int
|
The index (0-15) to modify. |
required |
value
|
float
|
The new float value to set. |
required |
to_list()
¶
Convert the matrix to a list of float values.
Returns:
Type | Description |
---|---|
List[float]
|
A list of 16 float values representing the matrix in column-major order. |
Paint_
¶
Controls the visual properties of drawing operations.
Paints define how shapes and text are rendered, including color, stroke style, blend mode, and various filters.
__init__()
¶
Initialize a paint with default values.
set_blend_mode(blend_mode)
¶
set_color(color)
¶
set_color_filter(filter)
¶
Set the color filter of the paint.
Color filters are functions that take two colors and mix them to produce a single color. This color is then usually merged with the destination during blending.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filter
|
ColorFilter_
|
The color filter to use. |
required |
Returns:
Type | Description |
---|---|
Paint_
|
Self for method chaining. |
set_color_source(source)
¶
Set the color source of the paint.
Color sources are functions that generate colors for each texture element covered by a draw call.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source
|
ColorSource_
|
The color source to use. |
required |
Returns:
Type | Description |
---|---|
Paint_
|
Self for method chaining. |
set_draw_style(style)
¶
set_image_filter(filter)
¶
Set the image filter of the paint.
Image filters are functions that are applied to regions of a texture to produce a single color.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filter
|
ImageFilter_
|
The image filter to use. |
required |
Returns:
Type | Description |
---|---|
Paint_
|
Self for method chaining. |
set_mask_filter(filter)
¶
Set the mask filter of the paint.
Mask filters are functions that are applied over a shape after it has been drawn but before it has been blended into the final image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filter
|
MaskFilter_
|
The mask filter to use. |
required |
Returns:
Type | Description |
---|---|
Paint_
|
Self for method chaining. |
set_stroke_cap(cap)
¶
set_stroke_join(join)
¶
Set how strokes rendered using this paint are joined.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
join
|
StrokeJoin
|
The stroke join style to use. |
required |
Returns:
Type | Description |
---|---|
Paint_
|
Self for method chaining. |
Paragraph
¶
Bases: Paragraph_
ParagraphBuilder
¶
Bases: ParagraphBuilder_
ParagraphBuilder_
¶
Allows for the creation of fully laid out paragraphs.
To build a paragraph, users push/pop paragraph styles onto a stack then add UTF-8 encoded text. The properties on the top of paragraph style stack when the text is added are used to layout and shape that subset of the paragraph.
__init__(type_context)
¶
Initialize a new paragraph builder.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
type_context
|
TypographyContext_
|
The typography context to use. |
required |
add_text(text)
¶
Add UTF-8 encoded text to the paragraph.
The text will be styled according to the paragraph style already on top of the paragraph style stack.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text
|
str
|
The text to add. |
required |
Returns:
Type | Description |
---|---|
ParagraphBuilder_
|
Self for method chaining. |
build(width)
¶
Layout and build a new paragraph using the specified width.
The resulting paragraph is immutable. The paragraph builder must be discarded and a new one created to build more paragraphs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
width
|
float
|
The paragraph width in logical pixels. |
required |
Returns:
Type | Description |
---|---|
Paragraph_
|
A new paragraph. |
pop_style()
¶
Pop a previously pushed paragraph style from the paragraph style stack.
Returns:
Type | Description |
---|---|
ParagraphBuilder_
|
Self for method chaining. |
push_style(style)
¶
Push a new paragraph style onto the paragraph style stack.
Not all paragraph styles can be combined. For instance, it does not make sense to mix text alignment for different text runs within a paragraph. In such cases, the preference of the first paragraph style on the style stack will take hold.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
style
|
ParagraphStyle_
|
The paragraph style to push. |
required |
Returns:
Type | Description |
---|---|
ParagraphBuilder_
|
Self for method chaining. |
ParagraphStyle
¶
Bases: ParagraphStyle_
ParagraphStyle_
¶
Specifies the style properties for text in a paragraph.
Paragraph styles are managed in a stack with specify text properties to apply to text that is added to the paragraph builder.
__init__()
¶
Initialize a new paragraph style with default values.
set_background(paint)
¶
Set the paint used to render the background of the text glyphs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
paint
|
Paint_
|
The paint to use for the background. |
required |
Returns:
Type | Description |
---|---|
ParagraphStyle_
|
Self for method chaining. |
set_font_family(family)
¶
Set the font family.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
family
|
str
|
The font family name. |
required |
Returns:
Type | Description |
---|---|
ParagraphStyle_
|
Self for method chaining. |
set_font_foreground(paint)
¶
Set the paint used to render the text glyph contents.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
paint
|
Paint_
|
The paint to use for the text. |
required |
Returns:
Type | Description |
---|---|
ParagraphStyle_
|
Self for method chaining. |
set_font_size(size)
¶
Set the font size.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
size
|
float
|
The font size in logical pixels. |
required |
Returns:
Type | Description |
---|---|
ParagraphStyle_
|
Self for method chaining. |
set_font_style(style)
¶
Set whether the glyphs should be bolded or italicized.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
style
|
FontStyle
|
The font style. |
required |
Returns:
Type | Description |
---|---|
ParagraphStyle_
|
Self for method chaining. |
set_font_weight(weight)
¶
Set the weight of the font to select when rendering glyphs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
weight
|
FontWeight
|
The font weight. |
required |
Returns:
Type | Description |
---|---|
ParagraphStyle_
|
Self for method chaining. |
set_height(height)
¶
Set the height of the text as a multiple of text size.
When height is 0.0, the line height will be determined by the font's metrics directly, which may differ from the font size. Otherwise the line height of the text will be a multiple of font size, and be exactly fontSize * height logical pixels tall.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
height
|
float
|
The height multiplier. |
required |
Returns:
Type | Description |
---|---|
ParagraphStyle_
|
Self for method chaining. |
set_locale(locale)
¶
Set the paragraph locale.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
locale
|
str
|
The locale string (e.g., "en_US"). |
required |
Returns:
Type | Description |
---|---|
ParagraphStyle_
|
Self for method chaining. |
set_max_lines(count)
¶
Set the maximum line count within the paragraph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
count
|
int
|
The maximum number of lines. |
required |
Returns:
Type | Description |
---|---|
ParagraphStyle_
|
Self for method chaining. |
set_text_alignment(align)
¶
Set the alignment of text within the paragraph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
align
|
TextAlignment
|
The text alignment. |
required |
Returns:
Type | Description |
---|---|
ParagraphStyle_
|
Self for method chaining. |
set_text_direction(direction)
¶
Set the directionality of the text within the paragraph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
direction
|
TextDirection
|
The text direction. |
required |
Returns:
Type | Description |
---|---|
ParagraphStyle_
|
Self for method chaining. |
Paragraph_
¶
An immutable, fully laid out paragraph of text.
Paragraphs are created by paragraph builders and contain the complete layout information for a block of text, including line breaks, font metrics, and glyph positioning.
alphabetic_baseline()
¶
Get the distance from the top of the paragraph to the alphabetic baseline of the first line.
This is used for alphabetic fonts (A-Z, a-z, Greek, etc.).
Returns:
Type | Description |
---|---|
float
|
The alphabetic baseline distance. |
glyph_info_at_code_unit_index(code_unit_index)
¶
Get information about the glyph at the given UTF-16 code unit index.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
code_unit_index
|
int
|
The UTF-16 code unit index. |
required |
Returns:
Type | Description |
---|---|
GlyphInfo_
|
The glyph information. |
glyph_info_at_paragraph_coordinate(x, y)
¶
Get information about the glyph closest to the specified coordinates.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
float
|
The x coordinate relative to paragraph origin. |
required |
y
|
float
|
The y coordinate relative to paragraph origin. |
required |
Returns:
Type | Description |
---|---|
GlyphInfo_
|
The glyph information. |
height()
¶
Get the height of the laid out paragraph.
This is not a tight bounding box and some glyphs may not reach the minimum location they are allowed to reach.
Returns:
Type | Description |
---|---|
float
|
The height of the paragraph. |
ideographic_baseline()
¶
Get the distance from the top of the paragraph to the ideographic baseline of the first line.
This is used for ideographic fonts (Japanese, Korean, etc.).
Returns:
Type | Description |
---|---|
float
|
The ideographic baseline distance. |
line_count()
¶
Get the number of lines visible in the paragraph after line breaking.
Returns:
Type | Description |
---|---|
int
|
The number of lines. |
line_metrics()
¶
Get the line metrics of this laid out paragraph.
Calculating the line metrics is expensive. The first time line metrics are requested, they will be cached along with the paragraph (which is immutable).
Returns:
Type | Description |
---|---|
LineMetrics_
|
The line metrics. |
longest_line_width()
¶
Get the length of the longest line in the paragraph.
This is the horizontal distance between the left edge of the leftmost glyph and the right edge of the rightmost glyph, in the longest line in the paragraph.
Returns:
Type | Description |
---|---|
float
|
The width of the longest line. |
max_intrinsic_width()
¶
Get the width of the paragraph without line breaking.
Returns:
Type | Description |
---|---|
float
|
The maximum intrinsic width. |
max_width()
¶
Get the width provided to the paragraph builder during layout.
This is the maximum width any line in the laid out paragraph can occupy. But, it is not necessarily the actual width of the paragraph after layout.
Returns:
Type | Description |
---|---|
float
|
The maximum width. |
min_intrinsic_width()
¶
Get the actual width of the longest line in the paragraph after layout.
This is expected to be less than or equal to max_width().
Returns:
Type | Description |
---|---|
float
|
The minimum intrinsic width. |
word_boundary(code_unit_index)
¶
Get the range into the UTF-16 code unit buffer that represents the word.
Word boundaries are defined more precisely in Unicode Standard Annex #29.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
code_unit_index
|
int
|
The code unit index. |
required |
Returns:
Type | Description |
---|---|
Range_
|
The range representing the word boundary. |
PathBuilder
¶
Bases: PathBuilder_
PathBuilder_
¶
Allows for the incremental building of paths.
Path builders create immutable Path objects that can be used for drawing and clipping operations.
__init__()
¶
Initialize a new path builder.
add_arc(rect, start_degrees, end_degrees)
¶
Add an arc to the path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rect
|
Rect_
|
The rectangle defining the oval bounds of the arc. |
required |
start_degrees
|
float
|
The starting angle in degrees. |
required |
end_degrees
|
float
|
The ending angle in degrees. |
required |
Returns:
Type | Description |
---|---|
PathBuilder_
|
Self for method chaining. |
add_oval(oval_bounds)
¶
Add an oval to the path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
oval_bounds
|
Rect_
|
The rectangle defining the oval bounds. |
required |
Returns:
Type | Description |
---|---|
PathBuilder_
|
Self for method chaining. |
add_rect(rect)
¶
Add a rectangle to the path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rect
|
Rect_
|
The rectangle to add. |
required |
Returns:
Type | Description |
---|---|
PathBuilder_
|
Self for method chaining. |
add_rounded_rect(rect, radii)
¶
Add a rounded rectangle to the path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rect
|
Rect_
|
The rectangle to add. |
required |
radii
|
RoundingRadii_
|
The corner radii of the rectangle. |
required |
Returns:
Type | Description |
---|---|
PathBuilder_
|
Self for method chaining. |
build(fill)
¶
build_copy(fill)
¶
close()
¶
Close the current subpath.
This adds a line segment from the current point to the first point of the subpath.
Returns:
Type | Description |
---|---|
PathBuilder_
|
Self for method chaining. |
cubic_curve_to(cp1, cp2, end)
¶
Add a cubic Bézier curve from the current point to the specified end point.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cp1
|
Point_
|
The first control point. |
required |
cp2
|
Point_
|
The second control point. |
required |
end
|
Point_
|
The end point. |
required |
Returns:
Type | Description |
---|---|
PathBuilder_
|
Self for method chaining. |
line_to(location)
¶
Add a line segment from the current point to the specified location.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
location
|
Point_
|
The end point of the line. |
required |
Returns:
Type | Description |
---|---|
PathBuilder_
|
Self for method chaining. |
move_to(location)
¶
Move the cursor to the specified location without adding a line segment.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
location
|
Point_
|
The new cursor location. |
required |
Returns:
Type | Description |
---|---|
PathBuilder_
|
Self for method chaining. |
quadratic_curve_to(cp, end)
¶
Add a quadratic Bézier curve from the current point to the specified end point.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cp
|
Point_
|
The control point. |
required |
end
|
Point_
|
The end point. |
required |
Returns:
Type | Description |
---|---|
PathBuilder_
|
Self for method chaining. |
Path_
¶
Represents a two-dimensional path that is immutable and graphics context agnostic.
Paths in Impeller consist of linear, cubic Bézier curve, and quadratic Bézier curve segments. All other shapes are approximations using these building blocks.
Paths are created using path builders that allow for the configuration of the path segments, how they are filled, and/or stroked.
PixelFormat
¶
Bases: Enum
Specifies the format of pixels in textures and surfaces.
RGBA8888 = 0
class-attribute
instance-attribute
¶
8 bits per channel, red, green, blue, alpha.
Point_
¶
Range
¶
Range_
¶
Rect
¶
Rect_
¶
RoundingRadii
¶
Bases: RoundingRadii_
RoundingRadii_
¶
Specifies the radii for rounded corners of a rectangle.
Attributes:
Name | Type | Description |
---|---|---|
top_left |
Point_
|
The radius for the top-left corner. |
bottom_left |
Point_
|
The radius for the bottom-left corner. |
top_right |
Point_
|
The radius for the top-right corner. |
bottom_right |
Point_
|
The radius for the bottom-right corner. |
Size
¶
Size_
¶
StrokeCap
¶
Bases: Enum
Determines how the ends of stroked lines are rendered.
StrokeJoin
¶
Bases: Enum
Determines how corners in stroked paths are rendered.
Surface_
¶
A render target for Impeller to direct rendering to.
Surfaces are how Impeller API users perform Window System Integration (WSI). Users wrap swapchain images as surfaces and draw display lists onto these surfaces to present content.
draw(dl)
¶
Draw a display list onto the surface.
The same display list can be drawn multiple times to different surfaces.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dl
|
DisplayList_
|
The display list to draw. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if the display list was successfully drawn, False otherwise. |
present()
¶
Present the surface to the underlying window system.
Returns:
Type | Description |
---|---|
bool
|
True if the surface was successfully presented, False otherwise. |
TextAlignment
¶
Bases: Enum
Specifies the horizontal alignment of text.
CENTER = 2
class-attribute
instance-attribute
¶
Center text horizontally.
END = 5
class-attribute
instance-attribute
¶
Align text to the end of the line (depends on text direction).
JUSTIFY = 3
class-attribute
instance-attribute
¶
Stretch text to fill the width.
LEFT = 0
class-attribute
instance-attribute
¶
Align text to the left.
RIGHT = 1
class-attribute
instance-attribute
¶
Align text to the right.
START = 4
class-attribute
instance-attribute
¶
Align text to the start of the line (depends on text direction).
TextDirection
¶
TextureDescriptor
¶
Bases: TextureDescriptor_
TextureDescriptor_
¶
Describes the properties of a texture.
Attributes:
Name | Type | Description |
---|---|---|
pixel_format |
PixelFormat
|
The format of pixels in the texture. |
size |
ISize_
|
The dimensions of the texture in pixels. |
mip_count |
int
|
The number of mipmap levels in the texture. |
TextureSampling
¶
Texture_
¶
A reference to a texture whose data is resident on the GPU.
Textures can be referenced in draw calls and paints. Creating textures is extremely expensive and should be done on background threads when possible.
with_contents(context, desc, data)
staticmethod
¶
Create a texture with decompressed bytes.
Note: Do not supply compressed image data directly (PNG, JPEG, etc.). This function only works with tightly packed decompressed data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
context
|
Context_
|
The graphics context. |
required |
desc
|
TextureDescriptor_
|
The texture descriptor. |
required |
data
|
bytes
|
The raw pixel data. |
required |
Returns:
Type | Description |
---|---|
Texture_
|
A new texture. |
TileMode
¶
Bases: Enum
Determines how textures and gradients behave outside their bounds.
CLAMP = 0
class-attribute
instance-attribute
¶
Use the color at the nearest edge.
DECAL = 3
class-attribute
instance-attribute
¶
Use transparent black outside the bounds.
MIRROR = 2
class-attribute
instance-attribute
¶
Repeat the texture or gradient, mirroring on each repetition.
REPEAT = 1
class-attribute
instance-attribute
¶
Repeat the texture or gradient.
TypographyContext
¶
Bases: TypographyContext_
TypographyContext_
¶
A context for text layout and rendering.
Typography contexts allow for the layout and rendering of text. These are typically expensive to create and applications will only ever need to create a single one during their lifetimes.
Unlike graphics contexts, typography contexts are not thread-safe. These must be created, used, and collected on a single thread.
__init__()
¶
Initialize a new typography context.
Window_
¶
A window for rendering content.
Provides a platform-specific window and handles for creating render surfaces.
get_version()
¶
Get the version of Impeller standalone API.
This is the API version that will be accepted for validity checks when provided to the
context creation methods. The current version of the API is denoted by the
IMPELLER_VERSION
macro.
Returns:
Type | Description |
---|---|
int
|
The version of the standalone API. |