pub struct Kludgine { /* private fields */ }
Expand description
A 2d graphics instance.
This type contains the GPU state for a single instance of Kludgine. To
render graphics correctly, it must know the size and scale of the surface
being rendered to. These values are provided in the constructor, but can be
updated using resize()
.
To draw using Kludgine, create a Frame
using
next_frame()
. [wgpu
] has lifetime requirements on
the [wgpu::RenderPass
] which causes each item being rendered to be
attached to the lifetime of the render pass. This means that no temporary
variables can be used to render.
Instead, graphics must be prepared before rendering, and stored somewhere
during the remainder of the RenderingGraphics
. To prepare graphics to be
rendered, call Frame::prepare()
to receive a Graphics
instance that
can be used in various Kludgine APIs such as
Shape::prepare
.
Implementations§
Source§impl Kludgine
impl 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 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.
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: Stretch)
pub fn set_text_stretch(&mut self, width: Stretch)
Sets the current text stretching.
Sourcepub fn text_stretch(&self) -> Stretch
pub fn text_stretch(&self) -> Stretch
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.
Source§impl Kludgine
impl Kludgine
Sourcepub const REQURED_FEATURES: Features = wgpu::Features::PUSH_CONSTANTS
pub const REQURED_FEATURES: Features = wgpu::Features::PUSH_CONSTANTS
The features that wgpu requires in compatible devices.
Sourcepub fn new(
device: &Device,
queue: &Queue,
format: TextureFormat,
multisample: MultisampleState,
initial_size: Size<UPx>,
scale: f32,
) -> Self
pub fn new( device: &Device, queue: &Queue, format: TextureFormat, multisample: MultisampleState, initial_size: Size<UPx>, scale: f32, ) -> Self
Returns a new instance of Kludgine with the provided parameters.
Sourcepub const fn texture_format(&self) -> TextureFormat
pub const fn texture_format(&self) -> TextureFormat
Returns the texture format this instance was initialized with.
Sourcepub const fn multisample_state(&self) -> MultisampleState
pub const fn multisample_state(&self) -> MultisampleState
Returns the multisample state this instance was initialized with.
Sourcepub fn adjust_limits(limits: Limits) -> Limits
pub fn adjust_limits(limits: Limits) -> Limits
Adjusts and returns the wgpu limits to support features used by Kludgine.
Sourcepub const fn id(&self) -> KludgineId
pub const fn id(&self) -> KludgineId
Returns the unique id of this instance.
Sourcepub 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.
Sourcepub 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.
Sourcepub 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.
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 !Freeze for Kludgine
impl !RefUnwindSafe for Kludgine
impl Send for Kludgine
impl Sync for Kludgine
impl Unpin for Kludgine
impl !UnwindSafe for Kludgine
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> 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.§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