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>,
font_state: &'clip mut FontState
) -> Self
pub fn new( renderer: Renderer<'gfx, 'pass>, font_state: &'clip mut FontState ) -> 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 find_available_font_family(
&mut self,
list: &FontFamilyList
) -> Option<FamilyOwned>
pub fn find_available_font_family( &mut self, list: &FontFamilyList ) -> Option<FamilyOwned>
Returns the first font family in list that is currently in the font
system, or None if no font families match.
sourcepub fn set_available_font_family(&mut self, list: &FontFamilyList)
pub fn set_available_font_family(&mut self, list: &FontFamilyList)
Sets the font family to the first family in list.
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>
)
pub fn draw_texture<Unit>( &mut self, texture: &impl TextureSource, destination: Rect<Unit> )
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
)where
Unit: Zero + ShaderScalable + ScreenUnit + Copy,
i32: From<<Unit as IntoSigned>::Signed>,
Shape: ShapeSource<Unit, true> + 'shape,
pub fn draw_textured_shape<'shape, Unit, Shape>(
&mut self,
shape: impl Into<Drawable<&'shape Shape, Unit>>,
texture: &impl TextureSource
)where
Unit: Zero + ShaderScalable + ScreenUnit + Copy,
i32: From<<Unit as IntoSigned>::Signed>,
Shape: ShapeSource<Unit, true> + 'shape,
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().
Methods from Deref<Target = Kludgine>§
sourcepub 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.
sourcepub 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.
sourcepub 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.
sourcepub fn line_height(&self) -> Lp
pub fn line_height(&self) -> Lp
Returns the current line height.
sourcepub fn set_font_family(&mut self, family: FamilyOwned)
pub fn set_font_family(&mut self, family: FamilyOwned)
Sets the current font family.
sourcepub fn font_family(&self) -> Family<'_>
pub fn font_family(&self) -> Family<'_>
Returns the current font family.
sourcepub fn set_font_style(&mut self, style: Style)
pub fn set_font_style(&mut self, style: Style)
Sets the current font style.
sourcepub fn font_style(&self) -> Style
pub fn font_style(&self) -> Style
Returns the current font style.
sourcepub fn set_font_weight(&mut self, weight: Weight)
pub fn set_font_weight(&mut self, weight: Weight)
Sets the current font weight.
sourcepub fn font_weight(&self) -> Weight
pub fn font_weight(&self) -> Weight
Returns the current font weight.
sourcepub fn set_text_stretch(&mut self, width: Width)
pub fn set_text_stretch(&mut self, width: Width)
Sets the current text stretching.
sourcepub fn text_stretch(&self) -> Width
pub fn text_stretch(&self) -> Width
Returns the current text stretch.
sourcepub fn text_attrs(&self) -> Attrs<'_>
pub fn text_attrs(&self) -> Attrs<'_>
Returns the current text attributes.
sourcepub fn set_text_attributes(&mut self, attrs: Attrs<'_>)
pub fn set_text_attributes(&mut self, attrs: Attrs<'_>)
Sets the current text attributes.
sourcepub fn reset_text_attributes(&mut self)
pub fn reset_text_attributes(&mut self)
Resets all of the text related properties to their default settings.
sourcepub fn resize(&mut self, new_size: Size<UPx>, new_scale: f32, queue: &Queue)
pub fn resize(&mut self, new_size: Size<UPx>, new_scale: f32, 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.
sourcepub fn next_frame(&mut self) -> Frame<'_>
pub fn next_frame(&mut self) -> Frame<'_>
Begins rendering a new frame.
Trait Implementations§
Auto Trait Implementations§
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<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.source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§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<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> 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.source§impl<'a, T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
impl<'a, T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
§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