pub struct Graphics<'clip, 'gfx, 'pass> { /* private fields */ }
Expand description
A 2d graphics context
Implementations§
source§impl<'clip, 'gfx, 'pass> Graphics<'clip, 'gfx, 'pass>
impl<'clip, 'gfx, 'pass> Graphics<'clip, 'gfx, 'pass>
sourcepub fn new(renderer: Renderer<'gfx, 'pass>) -> Self
pub fn new(renderer: Renderer<'gfx, 'pass>) -> Self
Returns a new graphics context for the given [Renderer
].
sourcepub fn translation(&self) -> Point<Px>
pub fn translation(&self) -> Point<Px>
Returns the offset relative to the clipping rect that the graphics context renders at.
This is used when rendering controls that are partially offscreen to the left or top of the window’s origin.
In general, this is handled automatically. This function should only be
needed when using inner_graphics()
.
sourcepub fn inner_graphics(&mut self) -> &mut Renderer<'gfx, 'pass>
pub fn inner_graphics(&mut self) -> &mut Renderer<'gfx, 'pass>
Returns the underlying renderer.
Note: Kludgine graphics contexts only support clipping. This type adds
self.translation()
to the offset of each drawing
call. When using the underlying renderer, any drawing calls will need
this offset as well, otherwise the widget that is being rendered will
not render correctly when placed in a Scroll
widget.
sourcepub fn clipped_to(&mut self, clip: Rect<Px>) -> Graphics<'_, 'gfx, 'pass>
pub fn clipped_to(&mut self, clip: Rect<Px>) -> Graphics<'_, 'gfx, 'pass>
Returns a context that has been clipped to clip
.
The new clipping rectangle is interpreted relative to the current clipping rectangle. As a side effect, this function can never expand the clipping rect beyond the current clipping rect.
The returned context will report the clipped size, and all drawing
operations will be relative to the origin of clip
.
sourcepub fn clip_rect(&self) -> Rect<UPx>
pub fn clip_rect(&self) -> Rect<UPx>
Returns the current clipping rectangle.
The clipping rectangle is represented in unsigned pixels in the window’s coordinate system.
sourcepub fn region(&self) -> Rect<Px>
pub fn region(&self) -> Rect<Px>
Returns the current region being rendered to.
The rendering region utilizes signed pixels, which allows it to represent regions that are out of bounds of the window’s visible region.
sourcepub fn visible_rect(&self) -> Option<Rect<UPx>>
pub fn visible_rect(&self) -> Option<Rect<UPx>>
Returns the visible region of the graphics context.
This is the intersection of Self::region()
and
Self::clip_rect()
.
sourcepub fn size(&self) -> Size<UPx>
pub fn size(&self) -> Size<UPx>
Returns the size of the current region.
This is self.region().size
converted to unsigned pixels.
sourcepub fn scale(&self) -> Fraction
pub fn scale(&self) -> Fraction
Returns the current DPI scaling factor applied to the window this context is attached to.
sourcepub fn fill(&mut self, color: Color)
pub fn fill(&mut self, color: Color)
Fills the entire context with color
.
If the alpha channel of color
is 0, this function does nothing.
sourcepub fn draw_shape<'a, Unit>(
&mut self,
shape: impl Into<Drawable<&'a Shape<Unit, false>, Unit>>,
)where
Unit: Zero + ShaderScalable + ScreenUnit + Copy,
pub fn draw_shape<'a, Unit>(
&mut self,
shape: impl Into<Drawable<&'a Shape<Unit, false>, Unit>>,
)where
Unit: Zero + ShaderScalable + ScreenUnit + Copy,
Draws a shape at the origin, rotating and scaling as needed.
sourcepub fn draw_texture<Unit>(
&mut self,
texture: &impl TextureSource,
destination: Rect<Unit>,
opacity: ZeroToOne,
)
pub fn draw_texture<Unit>( &mut self, texture: &impl TextureSource, destination: Rect<Unit>, opacity: ZeroToOne, )
Draws texture
at destination
, scaling as necessary.
sourcepub fn draw_textured_shape<'shape, Unit, Shape>(
&mut self,
shape: impl Into<Drawable<&'shape Shape, Unit>>,
texture: &impl TextureSource,
opacity: ZeroToOne,
)
pub fn draw_textured_shape<'shape, Unit, Shape>( &mut self, shape: impl Into<Drawable<&'shape Shape, Unit>>, texture: &impl TextureSource, opacity: ZeroToOne, )
Draws a shape that was created with texture coordinates, applying the provided texture.
sourcepub fn measure_text<'a, Unit>(
&mut self,
text: impl Into<Text<'a, Unit>>,
) -> MeasuredText<Unit>where
Unit: ScreenUnit,
pub fn measure_text<'a, Unit>(
&mut self,
text: impl Into<Text<'a, Unit>>,
) -> MeasuredText<Unit>where
Unit: ScreenUnit,
Measures text
using the current text settings.
default_color
does not affect the
sourcepub fn draw_text<'a, Unit>(
&mut self,
text: impl Into<Drawable<Text<'a, Unit>, Unit>>,
)where
Unit: ScreenUnit,
pub fn draw_text<'a, Unit>(
&mut self,
text: impl Into<Drawable<Text<'a, Unit>, Unit>>,
)where
Unit: ScreenUnit,
Draws text
using the current text settings.
sourcepub fn draw_text_buffer<'a, Unit>(
&mut self,
buffer: impl Into<Drawable<&'a Buffer, Unit>>,
default_color: Color,
origin: TextOrigin<Px>,
)where
Unit: ScreenUnit,
pub fn draw_text_buffer<'a, Unit>(
&mut self,
buffer: impl Into<Drawable<&'a Buffer, Unit>>,
default_color: Color,
origin: TextOrigin<Px>,
)where
Unit: ScreenUnit,
Prepares the text layout contained in buffer
to be rendered.
When the text in buffer
has no color defined, default_color
will be
used.
origin
allows controlling how the text will be drawn relative to the
coordinate provided in render()
.
sourcepub fn measure_text_buffer<Unit>(
&mut self,
buffer: &Buffer,
default_color: Color,
) -> MeasuredText<Unit>where
Unit: ScreenUnit,
pub fn measure_text_buffer<Unit>(
&mut self,
buffer: &Buffer,
default_color: Color,
) -> MeasuredText<Unit>where
Unit: ScreenUnit,
Measures buffer
and caches the results using default_color
when
the buffer has no color associated with text.
sourcepub fn draw_measured_text<'a, Unit>(
&mut self,
text: impl Into<Drawable<&'a MeasuredText<Unit>, Unit>>,
origin: TextOrigin<Unit>,
)where
Unit: ScreenUnit,
pub fn draw_measured_text<'a, Unit>(
&mut self,
text: impl Into<Drawable<&'a MeasuredText<Unit>, Unit>>,
origin: TextOrigin<Unit>,
)where
Unit: ScreenUnit,
Prepares the text layout contained in buffer
to be rendered.
When the text in buffer
has no color defined, default_color
will be
used.
origin
allows controlling how the text will be drawn relative to the
coordinate provided in render()
.
sourcepub fn draw<Op: RenderOperation>(&mut self)
pub fn draw<Op: RenderOperation>(&mut self)
Draws the custom rendering operation when this graphics is presented to the screen.
The rendering operation will be clipped automatically, but the rendering operation will need to position and size itself accordingly.
sourcepub fn draw_with<Op: RenderOperation>(&mut self, context: Op::DrawInfo)
pub fn draw_with<Op: RenderOperation>(&mut self, context: Op::DrawInfo)
Draws Op
with the given context.
sourcepub fn font_system(&mut self) -> &mut FontSystem
pub fn font_system(&mut self) -> &mut FontSystem
Returns a reference to the font system used to render.
sourcepub fn as_plot_area(
&mut self,
) -> DrawingArea<PlotterBackend<'_, 'gfx, 'pass>, Shift>
pub fn as_plot_area( &mut self, ) -> DrawingArea<PlotterBackend<'_, 'gfx, 'pass>, Shift>
Returns this renderer as a
DrawingArea
compatible with the
plotters crate.
Methods from Deref<Target = Kludgine>§
pub fn font_system(&mut self) -> &mut FontSystem
pub fn font_system(&mut self) -> &mut FontSystem
Returns a mutable reference to the [cosmic_text::FontSystem
] used when
rendering text.
pub fn rebuild_font_system(&mut self)
pub fn rebuild_font_system(&mut self)
Rebuilds the font system, invalidating font database caches.
This function can be invoked after loading fonts into the font database to ensure that all future text rendering considers the newly loaded fonts.
pub fn set_font_size(&mut self, size: impl ScreenScale<Lp = Lp>)
pub fn set_font_size(&mut self, size: impl ScreenScale<Lp = Lp>)
Sets the font size.
pub fn font_size(&self) -> Lp
pub fn font_size(&self) -> Lp
Returns the current font size.
pub fn set_line_height(&mut self, size: impl ScreenScale<Lp = Lp>)
pub fn set_line_height(&mut self, size: impl ScreenScale<Lp = Lp>)
Sets the line height for multi-line layout.
pub fn line_height(&self) -> Lp
pub fn line_height(&self) -> Lp
Returns the current line height.
pub fn set_font_family(&mut self, family: FamilyOwned)
pub fn set_font_family(&mut self, family: FamilyOwned)
Sets the current font family.
pub fn font_family(&self) -> Family<'_>
pub fn font_family(&self) -> Family<'_>
Returns the current font family.
pub fn set_font_style(&mut self, style: Style)
pub fn set_font_style(&mut self, style: Style)
Sets the current font style.
pub fn font_style(&self) -> Style
pub fn font_style(&self) -> Style
Returns the current font style.
pub fn set_font_weight(&mut self, weight: Weight)
pub fn set_font_weight(&mut self, weight: Weight)
Sets the current font weight.
pub fn font_weight(&self) -> Weight
pub fn font_weight(&self) -> Weight
Returns the current font weight.
pub fn set_text_stretch(&mut self, width: Width)
pub fn set_text_stretch(&mut self, width: Width)
Sets the current text stretching.
pub fn text_stretch(&self) -> Width
pub fn text_stretch(&self) -> Width
Returns the current text stretch.
pub fn text_attrs(&self) -> Attrs<'_>
pub fn text_attrs(&self) -> Attrs<'_>
Returns the current text attributes.
pub fn set_text_attributes(&mut self, attrs: Attrs<'_>)
pub fn set_text_attributes(&mut self, attrs: Attrs<'_>)
Sets the current text attributes.
pub fn reset_text_attributes(&mut self)
pub fn reset_text_attributes(&mut self)
Resets all of the text related properties to their default settings.
pub const REQURED_FEATURES: Features = wgpu::Features::PUSH_CONSTANTS
pub fn texture_format(&self) -> TextureFormat
pub fn texture_format(&self) -> TextureFormat
Returns the texture format this instance was initialized with.
pub fn multisample_state(&self) -> MultisampleState
pub fn multisample_state(&self) -> MultisampleState
Returns the multisample state this instance was initialized with.
pub fn id(&self) -> KludgineId
pub fn id(&self) -> KludgineId
Returns the unique id of this instance.
pub fn resize(
&mut self,
new_size: Size<UPx>,
new_scale: impl Into<Fraction>,
new_zoom: impl Into<Fraction>,
queue: &Queue,
)
pub fn resize( &mut self, new_size: Size<UPx>, new_scale: impl Into<Fraction>, new_zoom: impl Into<Fraction>, queue: &Queue, )
Updates the size and scale of this Kludgine instance.
This function updates data stored in the GPU that affects how graphics
are rendered. It should be called before calling next_frame()
if the
size or scale of the underlying surface has changed.
pub fn set_zoom(&mut self, new_zoom: impl Into<Fraction>, queue: &Queue)
pub fn set_zoom(&mut self, new_zoom: impl Into<Fraction>, queue: &Queue)
Sets the current zoom level.
Zoom and DPI scale are multiplied to create an effective scale for all DPI-scaled operations.
pub fn set_dpi_scale(&mut self, new_scale: impl Into<Fraction>, queue: &Queue)
pub fn set_dpi_scale(&mut self, new_scale: impl Into<Fraction>, queue: &Queue)
Sets the current DPI scale.
This scaling factor should come from the window server when possible.
pub fn next_frame(&mut self) -> Frame<'_>
pub fn next_frame(&mut self) -> Frame<'_>
Begins rendering a new frame.
pub fn size(&self) -> Size<UPx>
pub fn size(&self) -> Size<UPx>
Returns the currently configured size to render.
pub fn scale(&self) -> Fraction
pub fn scale(&self) -> Fraction
Returns the effective scale to apply to graphics contexts.
pub fn dpi_scale(&self) -> Fraction
pub fn dpi_scale(&self) -> Fraction
Returns the DPI scale of the underlying context.
pub fn zoom(&self) -> Fraction
pub fn zoom(&self) -> Fraction
Returns the current zoom applied.
Trait Implementations§
Auto Trait Implementations§
impl<'clip, 'gfx, 'pass> Freeze for Graphics<'clip, 'gfx, 'pass>
impl<'clip, 'gfx, 'pass> !RefUnwindSafe for Graphics<'clip, 'gfx, 'pass>
impl<'clip, 'gfx, 'pass> Send for Graphics<'clip, 'gfx, 'pass>
impl<'clip, 'gfx, 'pass> Sync for Graphics<'clip, 'gfx, 'pass>
impl<'clip, 'gfx, 'pass> Unpin for Graphics<'clip, 'gfx, 'pass>
impl<'clip, 'gfx, 'pass> !UnwindSafe for Graphics<'clip, 'gfx, 'pass>
Blanket Implementations§
source§impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
source§fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
source§fn adapt_into(self) -> D
fn adapt_into(self) -> D
source§impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
source§fn arrays_from(colors: C) -> T
fn arrays_from(colors: C) -> T
source§impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
source§fn arrays_into(self) -> C
fn arrays_into(self) -> C
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<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
impl<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
source§type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
parameters
when converting.source§fn cam16_into_unclamped(
self,
parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>,
) -> T
fn cam16_into_unclamped( self, parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>, ) -> T
self
into C
, using the provided parameters.§impl<A> Cast for A
impl<A> Cast for A
source§impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
source§fn components_from(colors: C) -> T
fn components_from(colors: C) -> T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
source§impl<T> FromAngle<T> for T
impl<T> FromAngle<T> for T
source§fn from_angle(angle: T) -> T
fn from_angle(angle: T) -> T
angle
.source§impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
source§fn from_stimulus(other: U) -> T
fn from_stimulus(other: U) -> T
other
into Self
, while performing the appropriate scaling,
rounding and clamping.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
impl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
source§fn into_angle(self) -> U
fn into_angle(self) -> U
T
.source§impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
source§type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
parameters
when converting.source§fn into_cam16_unclamped(
self,
parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>,
) -> T
fn into_cam16_unclamped( self, parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>, ) -> T
self
into C
, using the provided parameters.source§impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
source§fn into_color(self) -> U
fn into_color(self) -> U
source§impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
source§fn into_color_unclamped(self) -> U
fn into_color_unclamped(self) -> U
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<T> IntoReadOnly<T> for T
impl<T> IntoReadOnly<T> for T
source§fn into_read_only(self) -> ReadOnly<T>
fn into_read_only(self) -> ReadOnly<T>
self
as a ReadOnly
.source§impl<T> IntoStimulus<T> for T
impl<T> IntoStimulus<T> for T
source§fn into_stimulus(self) -> T
fn into_stimulus(self) -> T
self
into T
, while performing the appropriate scaling,
rounding and clamping.source§impl<T> IntoValue<T> for T
impl<T> IntoValue<T> for T
source§fn into_value(self) -> Value<T>
fn into_value(self) -> Value<T>
Value
.§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
source§type Error = <C as TryFromComponents<T>>::Error
type Error = <C as TryFromComponents<T>>::Error
try_into_colors
fails to cast.source§fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
source§impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
source§fn try_into_color(self) -> Result<U, OutOfBounds<U>>
fn try_into_color(self) -> Result<U, OutOfBounds<U>>
OutOfBounds
error is returned which contains
the unclamped color. Read more