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
sourceimpl Painter
impl Painter
sourcepub fn new(ctx: Context, layer_id: LayerId, clip_rect: Rect) -> Self
pub fn new(ctx: Context, layer_id: LayerId, clip_rect: Rect) -> Self
Create a painter to a specific layer within a certain clip rectangle.
sourcepub fn with_layer_id(self, layer_id: LayerId) -> Self
pub fn with_layer_id(self, layer_id: LayerId) -> Self
Redirect where you are painting.
sourcepub fn with_clip_rect(&self, rect: Rect) -> Self
pub fn with_clip_rect(&self, rect: Rect) -> Self
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) -> Self
Use Painter::with_clip_rect
sourceimpl Painter
impl Painter
sourcepub fn fonts(&self) -> RwLockReadGuard<'_, Fonts>
pub fn fonts(&self) -> RwLockReadGuard<'_, Fonts>
Available fonts.
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.
sourceimpl Painter
impl Painter
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!
sourceimpl Painter
impl Painter
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: RangeInclusive<f32>, y: f32, stroke: impl Into<Stroke>)
pub fn hline(&self, x: RangeInclusive<f32>, y: f32, stroke: impl Into<Stroke>)
Paints a horizontal line.
sourcepub fn vline(&self, x: f32, y: RangeInclusive<f32>, stroke: impl Into<Stroke>)
pub fn vline(&self, x: f32, y: RangeInclusive<f32>, 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>
)
sourceimpl Painter
impl Painter
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 layed 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 layed 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 !RefUnwindSafe for Painter
impl Send for Painter
impl Sync for Painter
impl Unpin for Painter
impl !UnwindSafe for Painter
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more