S or /

SourceClass Painter

from egui import Painter
class Painter:

Helper to paint shapes and text to a specific region on a specific layer.

All coordinates are screen coordinates in the unit points (one point can consist of many physical pixels).

A Painter never outlive a single frame/pass.

Properties§

Source@property def clip_rect(self, /) -> Rect§

Everything painted in this Painter will be clipped against this. This means nothing outside of this rectangle will be visible on screen.

Source@property def ctx(self, /) -> Context§

Get a reference to the parent Context.

Source@property def layer_id(self, /) -> LayerId§

Where we paint

Methods§

Sourcedef add(self, /, shape: Any) -> int§

It is up to the caller to make sure there is room for this. Can be used for free painting. NOTE: all coordinates are screen coordinates!

Sourcedef arrow(self, /, origin: Pos2, vec: Vec2, stroke: Stroke) -> None§

Show an arrow starting at origin and going in the direction of vec, with the length vec.length().

Sourcedef circle(self, /, center: Pos2, radius: float, fill_color: Color32, stroke: Stroke) -> int§
Sourcedef circle_filled(self, /, center: Pos2, radius: float, fill_color: Color32) -> int§
Sourcedef circle_stroke(self, /, center: Pos2, radius: float, stroke: Stroke) -> int§
def clone_ref(self, /) -> Painter§
Sourcedef debug_rect(self, /, rect: Rect, color: Color32, text: str) -> None§
Sourcedef debug_text(self, /, pos: Pos2, anchor: Align2, color: Color32, text: str) -> Rect§

Text with a background.

See also Context.debug_text.

Sourcedef error(self, /, pos: Pos2, text: str) -> Rect§
Sourcedef extend(self, /, shapes: Sequence[Any]) -> None§

Add many shapes at once.

Calling this once is generally faster than calling egui.Painter.add multiple times.

Sourcedef fonts(self, /) -> Any§

Read-only access to the shared FontsView.

See Context documentation for how locks work.

Sourcedef fonts_mut(self, /) -> Any§

Read-write access to the shared FontsView.

See Context documentation for how locks work.

Sourcedef for_each_shape(self, /) -> list[ClippedShape]§

Access all shapes added this frame.

Sourcedef galley(self, /, pos: Pos2, galley: Galley, fallback_color: Color32) -> None§

Paint text that has already been laid out in a Galley.

You can create the Galley with egui.Painter.layout or egui.Painter.layout_job.

Any uncolored parts of the Galley (using Color32.PLACEHOLDER) will be replaced with the given color.

Any non-placeholder color in the galley takes precedence over this fallback color.

Sourcedef galley_with_override_text_color(self, /, pos: Pos2, galley: Galley, text_color: Color32) -> None§

Paint text that has already been laid out in a Galley.

You can create the Galley with egui.Painter.layout.

All text color in the Galley will be replaced with the given color.

Sourcedef hline(self, /, min_x: float, max_x: float, y: float, stroke: Stroke) -> int§

Paints a horizontal line.

Sourcedef image(self, /, texture_id: TextureId, rect: Rect, uv: Rect, tint: Color32) -> int§

An image at the given position.

uv should normally be Rect.from_min_max(pos2(0.0, 0.0), pos2(1.0, 1.0)) unless you want to crop or flip the image.

tint is a color multiplier. Use Color32.WHITE if you don't want to tint the image.

Usually it is easier to use egui.Image.paint_at instead:

Sourcedef is_visible(self, /) -> bool§

If False, nothing you paint will show up.

Also checks Context.will_discard.

Sourcedef layout(self, /, text: str, font_id: FontId, color: Color32, wrap_width: float) -> Galley§

Will wrap text at the given width and line break at \n.

Paint the results with egui.Painter.galley.

Sourcedef layout_job(self, /, layout_job: LayoutJob) -> Galley§

Lay out this text layut job in a galley.

Paint the results with egui.Painter.galley.

Sourcedef layout_no_wrap(self, /, text: str, font_id: FontId, color: Color32) -> Galley§

Will line break at \n.

Paint the results with egui.Painter.galley.

Sourcedef line(self, /, points: Sequence[Pos2], stroke: Stroke) -> int§

Paints a line connecting the points. NOTE: all coordinates are screen coordinates!

Sourcedef line_segment(self, /, a: Pos2, b: Pos2, stroke: Stroke) -> int§

Paints a line from the first point to the second.

Sourcedef multiply_opacity(self, /, opacity: float) -> None§

Like egui.Painter.set_opacity, but multiplies the given value with the current opacity.

See also: egui.Painter.set_opacity and egui.Painter.opacity.

Source@staticmethod def new(ctx: Context, layer_id: LayerId, clip_rect: Rect) -> Painter§

Create a painter to a specific layer within a certain clip rectangle.

Sourcedef opacity(self, /) -> float§

Read the current opacity of the underlying painter.

See also: egui.Painter.set_opacity and egui.Painter.multiply_opacity.

Sourcedef pixels_per_point(self, /) -> float§

Number of physical pixels for each logical UI point.

Sourcedef rect(self, /, rect: Rect, corner_radius: Any, fill_color: Color32, stroke: Stroke, stroke_kind: StrokeKind) -> int§
Sourcedef rect_filled(self, /, rect: Rect, corner_radius: Any, fill_color: Color32) -> int§
Sourcedef rect_stroke(self, /, rect: Rect, corner_radius: Any, stroke: Stroke, stroke_kind: StrokeKind) -> int§
def round_pos_to_pixel_center(self, /, pos: Pos2) -> Pos2§
def round_pos_to_pixels(self, /, pos: Pos2) -> Pos2§
def round_rect_to_pixels(self, /, rect: Rect) -> Rect§
def round_to_pixel(self, /, point: float) -> float§
Sourcedef round_to_pixel_center(self, /, point: float) -> float§

Useful for pixel-perfect rendering of lines that are one pixel wide (or any odd number of pixels).

def round_vec_to_pixels(self, /, vec: Vec2) -> Vec2§
Sourcedef set(self, /, idx: int, shape: Any) -> None§

Modify an existing Shape.

Sourcedef set_clip_rect(self, /, rect: Rect) -> None§

Everything painted in this Painter will be clipped against this. This means nothing outside of this rectangle will be visible on screen.

Warning: growing the clip rect might cause unexpected results! When in doubt, use egui.Painter.shrink_clip_rect instead.

Sourcedef set_invisible(self, /) -> None§

If False, nothing added to the painter will be visible

Sourcedef set_layer_id(self, /, layer_id: LayerId) -> None§

Redirect where you are painting.

It is undefined behavior to change the LayerId of egui.Ui.painter.

Sourcedef set_opacity(self, /, opacity: float) -> None§

Set the opacity (alpha multiplier) of everything painted by this painter from this point forward.

opacity must be between 0.0 and 1.0, where 0.0 means fully transparent (i.e., invisible) and 1.0 means fully opaque.

See also: egui.Painter.opacity and egui.Painter.multiply_opacity.

Sourcedef shrink_clip_rect(self, /, rect: Rect) -> None§

Constrain the rectangle in which we can paint.

Short for painter.set_clip_rect(painter.clip_rect().intersect(new_clip_rect)).

See also: egui.Painter.clip_rect and egui.Painter.set_clip_rect.

Sourcedef text(self, /, pos: Pos2, anchor: Align2, text: str, font_id: FontId, text_color: Color32) -> Rect§

Lay out and paint some text.

To center the text at the given position, use Align2.CENTER_CENTER.

To find out the size of text before painting it, use egui.Painter.layout or egui.Painter.layout_no_wrap.

Returns where the text ended up.

Sourcedef vline(self, /, x: float, min_y: float, max_y: float, stroke: Stroke) -> int§

Paints a vertical line.

Sourcedef with_clip_rect(self, /, rect: Rect) -> Painter§

Create a painter for a sub-region of this Painter.

The clip-rect of the returned Painter will be the intersection of the given rectangle and the clip_rect() of the parent Painter.

Sourcedef with_layer_id(self, /, layer_id: LayerId) -> Painter§

Redirect where you are painting.