azul_core::app_resources

Struct AppResources

Source
pub struct AppResources {
    pub css_ids_to_image_ids: FastHashMap<CssImageId, ImageId>,
    pub css_ids_to_font_ids: FastHashMap<CssFontId, FontId>,
    pub image_sources: FastHashMap<ImageId, ImageSource>,
    pub font_sources: FastHashMap<FontId, FontSource>,
    pub currently_registered_images: FastHashMap<PipelineId, FastHashMap<ImageId, ImageInfo>>,
    pub currently_registered_fonts: FastHashMap<PipelineId, FastHashMap<ImmediateFontId, LoadedFont>>,
    pub last_frame_image_keys: FastHashMap<PipelineId, FastHashSet<ImageId>>,
    pub last_frame_font_keys: FastHashMap<PipelineId, FastHashMap<ImmediateFontId, FastHashSet<Au>>>,
    pub text_cache: TextCache,
}
Expand description

Stores the resources for the application, souch as fonts, images and cached texts, also clipboard strings

Images and fonts can be references across window contexts (not yet tested, but should work).

Fields§

§css_ids_to_image_ids: FastHashMap<CssImageId, ImageId>

The CssImageId is the string used in the CSS, i.e. “my_image” -> ImageId(4)

§css_ids_to_font_ids: FastHashMap<CssFontId, FontId>

Same as CssImageId -> ImageId, but for fonts, i.e. “Roboto” -> FontId(9)

§image_sources: FastHashMap<ImageId, ImageSource>

Stores where the images were loaded from

§font_sources: FastHashMap<FontId, FontSource>

Stores where the fonts were loaded from

§currently_registered_images: FastHashMap<PipelineId, FastHashMap<ImageId, ImageInfo>>

All image keys currently active in the RenderApi

§currently_registered_fonts: FastHashMap<PipelineId, FastHashMap<ImmediateFontId, LoadedFont>>

All font keys currently active in the RenderApi

§last_frame_image_keys: FastHashMap<PipelineId, FastHashSet<ImageId>>

If an image isn’t displayed, it is deleted from memory, only the ImageSource (i.e. the path / source where the image was loaded from) remains.

This way the image can be re-loaded if necessary but doesn’t have to reside in memory at all times.

§last_frame_font_keys: FastHashMap<PipelineId, FastHashMap<ImmediateFontId, FastHashSet<Au>>>

If a font does not get used for one frame, the corresponding instance key gets deleted. If a FontId has no FontInstanceKeys anymore, the font key gets deleted.

The only thing remaining in memory permanently is the FontSource (which is only the string of the file path where the font was loaded from, so no huge memory pressure). The reason for this agressive strategy is that the

§text_cache: TextCache

Stores long texts across frames

Implementations§

Source§

impl AppResources

Source

pub fn add_pipeline(&mut self, pipeline_id: PipelineId)

Add a new pipeline to the app resources

Source

pub fn delete_pipeline<T: FontImageApi>( &mut self, pipeline_id: &PipelineId, render_api: &mut T, )

Delete and remove all fonts & font instance keys from a given pipeline

Source§

impl AppResources

Source

pub fn new() -> Self

Source

pub fn get_loaded_font_ids(&self) -> Vec<FontId>

Returns the IDs of all currently loaded fonts in self.font_data

Source

pub fn get_loaded_image_ids(&self) -> Vec<ImageId>

Source

pub fn get_loaded_css_image_ids(&self) -> Vec<CssImageId>

Source

pub fn get_loaded_css_font_ids(&self) -> Vec<CssFontId>

Source

pub fn get_loaded_text_ids(&self) -> Vec<TextId>

Source

pub fn add_image_source(&mut self, image_id: ImageId, image_source: ImageSource)

Add an image from a PNG, JPEG or other source.

Note: For specialized image formats, you’ll have to enable them as features in the Cargo.toml file.

Source

pub fn has_image_source(&self, image_id: &ImageId) -> bool

Returns whether the AppResources has currently a certain image ID registered

Source

pub fn get_image_source(&self, image_id: &ImageId) -> Option<&ImageSource>

Given an ImageId, returns the decoded bytes of that image or None, if the ImageId is invalid. Returns an error on IO failure / image decoding failure or image

Source

pub fn delete_image_source(&mut self, image_id: &ImageId)

Source

pub fn add_css_image_id<S: Into<String>>(&mut self, css_id: S) -> ImageId

Source

pub fn has_css_image_id(&self, css_id: &str) -> bool

Source

pub fn get_css_image_id(&self, css_id: &str) -> Option<&ImageId>

Source

pub fn delete_css_image_id(&mut self, css_id: &str) -> Option<ImageId>

Source

pub fn get_image_info( &self, pipeline_id: &PipelineId, image_key: &ImageId, ) -> Option<&ImageInfo>

Source

pub fn add_css_font_id<S: Into<String>>(&mut self, css_id: S) -> FontId

Source

pub fn has_css_font_id(&self, css_id: &str) -> bool

Source

pub fn get_css_font_id(&self, css_id: &str) -> Option<&FontId>

Source

pub fn delete_css_font_id(&mut self, css_id: &str) -> Option<FontId>

Source

pub fn add_font_source(&mut self, font_id: FontId, font_source: FontSource)

Source

pub fn get_font_source(&self, font_id: &FontId) -> Option<&FontSource>

Given a FontId, returns the bytes for that font or None, if the FontId is invalid.

Source

pub fn has_font_source(&self, id: &FontId) -> bool

Checks if a FontId is valid, i.e. if a font is currently ready-to-use

Source

pub fn delete_font_source(&mut self, id: &FontId)

Source

pub fn get_loaded_font( &self, pipeline_id: &PipelineId, font_id: &ImmediateFontId, ) -> Option<&LoadedFont>

Source

pub fn add_text(&mut self, words: Words) -> TextId

Adds a string to the internal text cache, but only store it as a string, without caching the layout of the string.

Source

pub fn get_text(&self, id: &TextId) -> Option<&Words>

Source

pub fn delete_text(&mut self, id: TextId)

Removes a string from both the string cache and the layouted text cache

Source

pub fn clear_all_texts(&mut self)

Empties the entire internal text cache, invalidating all TextIds. Use with care.

Trait Implementations§

Source§

impl Default for AppResources

Source§

fn default() -> AppResources

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.