pub struct Painter { /* private fields */ }
Expand description
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).
Implementations§
Source§impl Painter
impl Painter
Sourcepub fn new(ctx: Context, layer_id: LayerId, clip_rect: Rect) -> Painter
pub fn new(ctx: Context, layer_id: LayerId, clip_rect: Rect) -> Painter
Create a painter to a specific layer within a certain clip rectangle.
Sourcepub fn with_layer_id(self, layer_id: LayerId) -> Painter
pub fn with_layer_id(self, layer_id: LayerId) -> Painter
Redirect where you are painting.
Sourcepub fn with_clip_rect(&self, rect: Rect) -> Painter
pub fn with_clip_rect(&self, rect: Rect) -> Painter
Sourcepub fn set_layer_id(&mut self, layer_id: LayerId)
pub fn set_layer_id(&mut self, layer_id: LayerId)
Redirect where you are painting.
pub fn sub_region(&self, rect: Rect) -> Painter
Source§impl Painter
§Accessors etc
impl Painter
§Accessors etc
Sourcepub fn clip_rect(&self) -> Rect
pub fn 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.
Sourcepub fn set_clip_rect(&mut self, clip_rect: Rect)
pub fn set_clip_rect(&mut self, clip_rect: Rect)
Everything painted in this Painter
will be clipped against this.
This means nothing outside of this rectangle will be visible on screen.
Sourcepub fn round_to_pixel(&self, point: f32) -> f32
pub fn round_to_pixel(&self, point: f32) -> f32
Useful for pixel-perfect rendering.
Sourcepub fn round_vec_to_pixels(&self, vec: Vec2) -> Vec2
pub fn round_vec_to_pixels(&self, vec: Vec2) -> Vec2
Useful for pixel-perfect rendering.
Sourcepub fn round_pos_to_pixels(&self, pos: Pos2) -> Pos2
pub fn round_pos_to_pixels(&self, pos: Pos2) -> Pos2
Useful for pixel-perfect rendering.
Source§impl Painter
§Low level
impl Painter
§Low level
Sourcepub fn add(&self, shape: impl Into<Shape>) -> ShapeIdx
pub fn add(&self, shape: impl Into<Shape>) -> ShapeIdx
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!
Sourcepub fn extend<I>(&self, shapes: I)where
I: IntoIterator<Item = Shape>,
pub fn extend<I>(&self, shapes: I)where
I: IntoIterator<Item = Shape>,
Add many shapes at once.
Calling this once is generally faster than calling Self::add
multiple times.
Source§impl Painter
§Paint different primitives
impl Painter
§Paint different primitives
Sourcepub fn line_segment(&self, points: [Pos2; 2], stroke: impl Into<Stroke>)
pub fn line_segment(&self, points: [Pos2; 2], stroke: impl Into<Stroke>)
Paints a line from the first point to the second.
Sourcepub fn hline(&self, x: impl Into<Rangef>, y: f32, stroke: impl Into<Stroke>)
pub fn hline(&self, x: impl Into<Rangef>, y: f32, stroke: impl Into<Stroke>)
Paints a horizontal line.
Sourcepub fn vline(&self, x: f32, y: impl Into<Rangef>, stroke: impl Into<Stroke>)
pub fn vline(&self, x: f32, y: impl Into<Rangef>, stroke: impl Into<Stroke>)
Paints a vertical line.
pub fn circle( &self, center: Pos2, radius: f32, fill_color: impl Into<Color32>, stroke: impl Into<Stroke>, )
pub fn circle_filled( &self, center: Pos2, radius: f32, fill_color: impl Into<Color32>, )
pub fn circle_stroke( &self, center: Pos2, radius: f32, stroke: impl Into<Stroke>, )
pub fn rect( &self, rect: Rect, rounding: impl Into<Rounding>, fill_color: impl Into<Color32>, stroke: impl Into<Stroke>, )
pub fn rect_filled( &self, rect: Rect, rounding: impl Into<Rounding>, fill_color: impl Into<Color32>, )
pub fn rect_stroke( &self, rect: Rect, rounding: impl Into<Rounding>, stroke: impl Into<Stroke>, )
Sourcepub fn arrow(&self, origin: Pos2, vec: Vec2, stroke: Stroke)
pub fn arrow(&self, origin: Pos2, vec: Vec2, stroke: Stroke)
Show an arrow starting at origin
and going in the direction of vec
, with the length vec.length()
.
Sourcepub fn image(&self, texture_id: TextureId, rect: Rect, uv: Rect, tint: Color32)
pub fn image(&self, texture_id: TextureId, rect: Rect, uv: Rect, tint: Color32)
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 crate::Image::paint_at
instead:
egui::Image::new(egui::include_image!("../assets/ferris.png"))
.rounding(5.0)
.tint(egui::Color32::LIGHT_BLUE)
.paint_at(ui, rect);
Source§impl Painter
§Text
impl Painter
§Text
Sourcepub fn text(
&self,
pos: Pos2,
anchor: Align2,
text: impl ToString,
font_id: FontId,
text_color: Color32,
) -> Rect
pub fn text( &self, pos: Pos2, anchor: Align2, text: impl ToString, 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
Self::layout
or Self::layout_no_wrap
.
Returns where the text ended up.
Sourcepub fn layout(
&self,
text: String,
font_id: FontId,
color: Color32,
wrap_width: f32,
) -> Arc<Galley>
pub fn layout( &self, text: String, font_id: FontId, color: Color32, wrap_width: f32, ) -> Arc<Galley>
Will wrap text at the given width and line break at \n
.
Paint the results with Self::galley
.
Sourcepub fn layout_no_wrap(
&self,
text: String,
font_id: FontId,
color: Color32,
) -> Arc<Galley>
pub fn layout_no_wrap( &self, text: String, font_id: FontId, color: Color32, ) -> Arc<Galley>
Will line break at \n
.
Paint the results with Self::galley
.
Sourcepub fn galley(&self, pos: Pos2, galley: Arc<Galley>)
pub fn galley(&self, pos: Pos2, galley: Arc<Galley>)
Paint text that has already been laid out in a Galley
.
You can create the Galley
with Self::layout
.
If you want to change the color of the text, use Self::galley_with_color
.
Sourcepub fn galley_with_color(
&self,
pos: Pos2,
galley: Arc<Galley>,
text_color: Color32,
)
pub fn galley_with_color( &self, pos: Pos2, galley: Arc<Galley>, text_color: Color32, )
Paint text that has already been laid out in a Galley
.
You can create the Galley
with Self::layout
.
The text color in the Galley
will be replaced with the given color.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Painter
impl !RefUnwindSafe for Painter
impl Send for Painter
impl Sync for Painter
impl Unpin for Painter
impl !UnwindSafe for Painter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.